| Type TPaddle Extends TGameObject Function Create:TPaddle(Image:TImage,xstart:Int,ystart:Int) Local B:TPaddle=New TPaddle CreateObject(B,Image,xstart,ystart) B.XSpeed :* 1.5 'need a slightly faster speed than the balls B.YSpeed :* 1.5 'otherwise we cannot catch them Return B End Function Method UpdateSelf() '-------Move X direction depending on which key was pressed If KeyDown(KEY_LEFT) X :- XSpeed If KeyDown(KEY_RIGHT) X :+ XSpeed Y = height-60 'Y remains the same '-------Make sure paddle cannot move beyond the gameplay area If X<ImageWidth(Image)/2 X=ImageWidth(Image)/2 If X>(Width-ImageWidth(Image)/2) X=(Width-ImageWidth(Image)/2) End Method End Type |
| TBall.Create(LoadImage(URL+"ball.png"),Width/2,400) 'Creates our Bouncing Ball TPaddle.Create(LoadImage(URL+"paddle.png"),Width/2,0) |
![]() |
| Type TPaddle Extends TGameObject Function Create:TPaddle(Image:TImage,xstart:Int,ystart:Int) Local B:TPaddle=New TPaddle CreateObject(B,Image,xstart,ystart) B.XSpeed :* 1.5 'need a slightly faster speed than the balls B.YSpeed :* 1.5 'otherwise we cannot catch them Return B End Function Method UpdateSelf() '-------Move X direction depending on which key was pressed If KeyDown(KEY_LEFT) X :- XSpeed If KeyDown(KEY_RIGHT) X :+ XSpeed Y = height-60 'Y remains the same '-------Make sure paddle cannot move beyond the gameplay area If X<ImageWidth(Image)/2 X=ImageWidth(Image)/2 If X>(Width-ImageWidth(Image)/2) X=(Width-ImageWidth(Image)/2) '-------Reset Collision Layer and Write image to collision layer ResetCollisions(PLAYER_LAYER) CollideImage(Image,X,Y,0,0,PLAYER_LAYER,Self) End Method End Type |
| Strict ' -----------------SETUP GAME CONDITIONS-------------------- Const PLAYER_LAYER:Int=1 |
| Type TBall Extends TGameObject Function Create:TBall(Image:TImage,xstart:Int,ystart:Int) Local B:TBall=New TBall CreateObject(B,Image,xstart,ystart,2.0) Return B End Function Method UpdateSelf() If GameState<>PLAY Return X :+ XSpeed Y :+ YSpeed If x>Width Or x<0 Then XSpeed=-XSpeed EndIf If Y>Height Or Y<0 Then YSpeed=-YSpeed EndIf Rotation :+ 10 If Rotation >= 360 Then Rotation=0 CheckCollision() End Method Method CheckCollision() '------Set the correct scale and rotation before collision checking SetScale XScale, YScale SetRotation Rotation If CollideImage(Image,X,Y,0,PLAYER_LAYER,0) YSpeed=-YSpeed EndIf End Method End Type |