| Type TBall Extends TGameObject Function Create:TBall(Image:TImage,xstart:Int,ystart:Int) Local B:TBall=New TBall CreateObject(B,Image,xstart,ystart) Return B End Function Method UpdateSelf() X :+ XSpeed 'Ball moves by its speed in the X direction Y :+ YSpeed 'Ball moves by its speed in the Y direction If x>Width Or x<0 Then 'Collision with left or right boundary XSpeed=-XSpeed 'simply reverses direction EndIf If Y>Height Or Y<0 Then 'Collision with left or right boundary YSpeed=-YSpeed 'simply reverses direction EndIf End Method End Type |
| Strict ' -----------------SETUP GAME CONDITIONS-------------------- Global GameObjectList:TList=CreateList() Global Width:Int=640 Global Height:Int=480 Global URL:String=BlitzMaxPath()+"/samples/Breakout/media/" Graphics Width,Height AutoMidHandle True HideMouse() TBall.Create(LoadImage(URL+"ball.png"),Width/2,400) '========================================================= ' ---------------------MAIN LOOP------------------------- Repeat Cls For Local o:TGameObject=EachIn GameObjectList o.DrawSelf() o.UpdateSelf() Next Flip Until KeyDown(KEY_ESCAPE) Or AppTerminate() End '========================================================== ' ---------------THE MOTHER OF ALL OBJECT, TYPE GAMEOBJECT------------- Type TGameObject Field X:Int Field Y:Int Field XSpeed:Float=3 Field YSpeed:Float=-3 Field Image:TImage Field XScale:Float=1.0 Field YScale:Float=1.0 Method DrawSelf() DrawImage Image,X,Y End Method Method UpdateSelf() Abstract End Type ' ---------------------DEFINE REQUIRED GAME OBJECTS------------------------- Type TBall Extends TGameObject Function Create:TBall(Image:TImage,xstart:Int,ystart:Int) Local B:TBall=New TBall CreateObject(B,Image,xstart,ystart) Return B End Function Method UpdateSelf() X :+ XSpeed 'Ball moves by its speed in the X direction Y :+ YSpeed 'Ball moves by its speed in the Y direction If x>Width Or x<0 Then 'Collision with left or right boundary XSpeed=-XSpeed 'simply reverses direction EndIf If Y>Height Or Y<0 Then 'Collision with left or right boundary YSpeed=-YSpeed 'simply reverses direction EndIf End Method End Type '------------------------------HELPER FUNCTIONS------------------------ Function CreateObject(Obj:TGameObject, Image:TImage,xstart:Int,ystart:Int,Scale:Float=1.0) Obj.X=xstart Obj.Y=ystart Obj.XScale=Scale Obj.YScale=Scale Obj.Image=Image If Obj.Image=Null Print "Not able to load image file. Program aborting" End EndIf ListAddLast GameObjectList, Obj End Function |
![]() |
| ' ---------------THE MOTHER OF ALL OBJECT, TYPE GAMEOBJECT------------- Type TGameObject Field X:Int Field Y:Int Field XSpeed:Float=3 Field YSpeed:Float=-3 Field Image:TImage Field XScale:Float=1.0 Field YScale:Float=1.0 Field Rotation:int=0 Method DrawSelf() SetScale XScale, YScale SetRotation Rotation DrawImage Image,X,Y End Method Method UpdateSelf() Abstract End Type |
| ' ---------------------DEFINE REQUIRED GAME OBJECTS------------------------- 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() 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 End Method End Type |
| 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 |