| Case START CreateBricks() TText.Create("BREAKOUT",Font72,80,50) TText.Create("PRESS <ENTER> To START",Font,110,250) TText.Create("PRESS <ESCAPE> TO EXIT",Font,110,300) GameState=WAIT |
| Local FontURL:String="http::www.2dgamecreators.com/tutorials/gameprogramming/breakout/" Global Font:TImageFont=LoadImageFont(FontURL+"BorisBlackBloxx.ttf",24) Global Font72:TImageFont=LoadImageFont(FontURL+"BorisBlackBloxx.ttf",72) |
| ' -----------------SETUP GAME CONDITIONS-------------------- Const PLAYER_LAYER:Int=1 Const PLAY:Int=1 Const PAUSE:Int=2 Const START:Int=3 Const WAIT:Int=4 |
| Case WAIT 'To Start If KeyDown(KEY_ESCAPE) Or AppTerminate() End EndIf If KeyDown(KEY_ENTER) '-------------Remove all Objects ClearList GameObjectList '--------------Now Create the game objects that we need TBall.Create(LoadImage(URL+"ball.png"),Width/2,400) TPaddle.Create(LoadImage(URL+"paddle.png"),Width/2,0) CreateBricks() GameState=PLAY EndIf FlushKeys() |
![]() |
| Case GAMEOVER TText.Create("GAMEOVER",Font72,60,50) TText.Create("PRESS <ENTER> TO RE-START",Font,80,250) TText.Create("PRESS <ESCAPE> TO EXIT",Font,110,300) FlushKeys() GameState=WAIT |
| Type TScore Extends TText Field score:Int Function Create:TScore(Text:String, Font:TImageFont,xstart:Int,ystart:Int) Local B:TScore=New TScore B.Text=Text B.Font=Font B.X=XStart B.Y=YStart ListAddLast GameObjectList, B Return B End Function Method UpdateSelf() If GameState<>PLAY Then Return 'Do not continue if not in PLAY state score=0 For Local B:TBricks=EachIn GameObjectList score :+ 1 Next If score<90 Then GameState=GAMEOVER End Method Method drawself() SetImageFont(Font) SetRotation 0 SetScale 0.75,0.75 SetColor 255,0,0 DrawText Text+Score,X,Y End Method EndType |
| If score<90 Then GameState=GAMEOVER |
| Method drawself() SetImageFont(Font) SetRotation 0 SetScale 0.75,0.75 SetColor 255,0,0 DrawText Text+Score,X,Y End Method |
| Case WAIT 'To Start If KeyDown(KEY_ESCAPE) Or AppTerminate() End EndIf If KeyDown(KEY_ENTER) '-------------Remove all Objects ClearList GameObjectList '--------------Now Create the game objects that we need TBall.Create(LoadImage(URL+"ball.png"),Width/2,400) TPaddle.Create(LoadImage(URL+"paddle.png"),Width/2,0) TScore.CREATE("SCORE:",Font,10,5) CreateBricks() GameState=PLAY EndIf FlushKeys() |
![]() |