pong


Small Basic   The Official Blog of Small Basic
http://blogs.msdn.com/b/smallbasic/archive/2013/06/10/small-basic-for-little-kids-series-pong.aspx


Versión 2
‘ v2
‘ bounces well, left to right
‘ make background
GraphicsWindow.Width = “700″
GraphicsWindow.Height = “500″
‘set pen
GraphicsWindow.PenColor = “gray”
GraphicsWindow.PenWidth = “50″
‘draw border
GraphicsWindow.DrawRectangle(0,0,700,500)
‘ set brush
GraphicsWindow.BrushColor = “white”
‘ make left goal, size 100, from (0,200) to (0,300)
GraphicsWindow.FillRectangle(0,200,26,100)
‘ make right goal, size 100, from (674,200) to (674,300)
GraphicsWindow.FillRectangle(674,200,26,100)
‘ set brush
GraphicsWindow.BrushColor = “black”
‘ make paddles
GraphicsWindow.FillRectangle(30,220,10,60)
GraphicsWindow.FillRectangle(664,220,10,60)
‘ draw ball
Sub DrawBall
GraphicsWindow.BrushColor = “black”
GraphicsWindow.FillEllipse(BallX,BallY,10,10)
EndSub
‘ erase ball
Sub EraseBall
GraphicsWindow.PenWidth = “2″
GraphicsWindow.BrushColor = “white”
GraphicsWindow.FillEllipse(BallX,BallY,10,10)
GraphicsWindow.PenColor = “white”
GraphicsWindow.DrawEllipse(BallX,BallY,10,10)
EndSub
‘ sleep
Timer.Interval = 1
Timer.Tick = RunGame
StepSize = 2
StepX = StepSize
StepY = 0
BallX=345
‘ BallY=245
BallY=100
LeftWallX = 27
RightWallX = 660
DrawBall()
Sub RunGame
EraseBall()
BallX = BallX + StepX
BallY = BallY + StepY
‘ Hit right wall
If BallX >= RightWallX Then
StepX = -StepSize
EndIf
‘ Hit left wall
If BallX <= LeftWallX Then
StepX = StepSize
EndIf
DrawBall()
EndSub

Deja un comentario