How is this possible?
' ---------------------------------------------------------------------------------------------------
' Game Object Type
' Contains The Fields That All Other Objects Will Extend From
'----------------------------------------------------------------------------------------------------
Type TGameObject
Field X_Position:Int
Field Y_Position:Int
Field X_Start_Position:Int
Field Y_Start_Position:Int
Field X_Velocity:Float
Field Y_Velocity:Float
Field X_Start_Velocity:Float=3
Field Y_Start_Velocity:Float=3
Field Image:TImage
Field X_Scale:Float
Field Y_Scale:Float
Field Rotation:Int=0
' ----------------------------------------------------------------------------------------------------
' Method Draw
' Draws The Game Object To The Screen
' --------------------------------------------------------------------------------------------------
Method Draw()
SetScale X_Scale, Y_Scale
SetRotation Rotation
DrawImage Image, X_Position, Y_Position
End Method
' ----------------------------------------------------------------------------------------------------
' Method Reset
' Resets all the Game Objects To Their initial Position
' --------------------------------------------------------------------------------------------------
Method Reset()
X_Position = X_Start_Position
Y_Position = Y_Start_Position
X_Velocity = X_Start_Velocity
Y_Velocity = Y_Start_Velocity
End Method
'---------------------------------------------------------------------------------------------------
' Method Update
' Updates the Game Objects On The Screen
' --------------------------------------------------------------------------------------------------
Method Update() Abstract
'---------------------------------------------------------------------------------------------------
' Fuction CreateObject
' Creates the Game Object
'---------------------------------------------------------------------------------------------------
Function CreateObject(Obj:TGameObject, Image:TImage, New_X_Start_Position:Int,New_Y_Start_Position:Int, New_Scale:Float=1.0)
Obj.X_Start_Position = New_X_Start_Position
Obj.y_start_position = New_Y_Start_Position
Obj.X_Scale = New_Scale
Obj.Y_Scale = New_Scale
Obj.Image = Image
If Obj.Image=Null
Print "Not able to load image file. Program aborting"
End
EndIf
Obj.Reset()
ListAddLast GameObjects, Obj
End Function
Type TGameEngine Extends TGameObject
Function Create:TGameEngine(Image:TImage)
Local GameEngine:TGameEngine = New TGameEngine
CreateObject(GameEngine, Image, 0, 0, 1.0)
Return GameEngine
End Function
Method Update()
'not needed at the moment
End Method
Function StartGame()
TBall.Create(LoadImage(Data_Path + "ball.png"), Screen_Width/2, 400)
Repeat
Cls
For Local o:TGameObject = EachIn GameObjects
o.Draw()
o.Update()
Next
Flip
Until KeyDown(KEY_ESCAPE) Or AppTerminate()
End
End Function
End Type
Type TBall Extends TGameObject
Function Create:TBall(Image:TImage, X_Start_Position:Int, Y_Start_Position:Int)
Local Ball:TBall = New TBall
CreateObject(Ball, Image, X_Start_Position, Y_Start_Position, 2.0)
Return Ball
End Function
Method Update()
X_Position :+ X_Velocity 'The Ball Moves By Its X_Velocity In The X Direction
Y_Position :+ Y_Velocity 'The Ball Moves By Its Y Velocity In The Y Direction
'If A Collision With The Left Or Right Walls Has Occured
If X_Position > Screen_Width Or X_Position < 0 Then
X_Velocity =- X_Velocity 'Reverse The Balls X Velocity
EndIf
'If A Collision With The Top or Bottom Walls Has Occured
If Y_Position > Screen_Height Or Y_Position < 0 Then
Y_Velocity =- Y_Velocity 'Reverse The Balls Y Velocity
EndIf
Rotation :+ 10
If Rotation >= 360 Then Rotation = 0
End Method
End Type
SuperStrict
Include "GameObject.bmx"
Include "Ball.bmx"
Include "Brick.bmx"
Include "GameEngine.bmx"
Include "Paddle.bmx"
Include "Score.bmx"
AppTitle$ = "Space Xscape v0.1"
Global GameObjects:TList=CreateList()
Global Screen_Width:Int=640
Global Screen_Height:Int=480
Global Data_Path:String=BlitzMaxPath()+"/samples/Breakout/media/"
Graphics Screen_Width, Screen_Height
AutoMidHandle True
HideMouse()
TGameEngine.Create(LoadImage(DATA_PATH + "back1.png"))
TGameEngine.StartGame()
As you can see all the objects call Create which is a call to CreateObject which creates the object and adds it to the GameObjects List. I don't see why this is happening.