Strict
Import mojo
Enumerate LEFT=$01, RIGHT=$02, UP=$04, DOWN=$08, JUMP=$10, FIRE=$20
Enumerate BLOCK_WALL, BLOCK_FLOOR
' Base class that all game sprites should inherit
Class BaseObject
Field x:Float
Field y:Float
Field w:Int
Field h:Int
Method New(x:Int, y:Int, width:Int, height:Int)
Self.x = x
Self.y = y
Self.w = width
Self.h = height
End Method
Method X:Float() Property
Return Self.x
End Method
Method X:Void(x:Float) Property
Self.x = x
End Method
Method Y:Float() Property
Return Self.y
End Method
Method Y:Void(y:Float) Property
Self.y = y
End Method
Method Width:Float() Property
Return Self.w
End Method
Method Width:Void(width:Float) Property
Self.w = width
End Method
Method Height:Float() Property
Return Self.h
End Method
Method Height:Void(height:Float) Property
Self.h = height
End Method
End Class
' Class template to represent a platform or wall
Class PlatformObject Extends BaseObject
Field dir:Int
Field count:Int
Field blockWidth:Int
Field blockHeight:Int
Field type:Int
' A block size of 20*20 gives a screen grid of 32*24 cells on a display of 640*480
Method New(x:Int, y:Int, dir:Int, count:Int, blockType:Int=BLOCK_FLOOR, blockWidth:Int=20, blockHeight:Int=20)
Super.New(x*blockWidth, y*blockHeight, blockWidth, blockHeight)
Self.blockWidth = blockWidth
Self.blockHeight = blockHeight
Self.count = count
Self.type = blockType
If dir=DOWN
Self.dir=DOWN
Self.Height = count*blockHeight
Else
Self.dir=RIGHT
Self.Width = count*blockWidth
Endif
End Method
' Get the direction
Method PlatformDirection:Int()
Return Self.dir
End Method
' Get the block type
Method PlatformType:Int()
Return Self.type
End Method
Method DrawPlatform:Void()
For Local c:=0 Until Self.count
Select Self.type
Case BLOCK_FLOOR
SetColor(Rnd(255),255,255)
Case BLOCK_WALL
SetColor(200,0,0)
Default
SetColor(255, 255, 255)
End Select
If Self.dir=DOWN
DrawRect(Self.X, Self.Y+c*Self.blockHeight, Self.blockWidth, Self.blockHeight)
Else
DrawRect(Self.X+c*Self.blockWidth, Self.Y, Self.blockWidth, Self.blockHeight)
Endif
Next
End Method
End Class
Class Game Extends App
Field platformList:= New List<PlatformObject>
Method OnCreate:Int()
platformList.AddLast(New PlatformObject(0, 0, DOWN, 24, BLOCK_WALL))
platformList.AddLast(New PlatformObject(31, 0, DOWN, 24, BLOCK_WALL))
platformList.AddLast(New PlatformObject(1, 23, RIGHT, 30))
platformList.AddLast(New PlatformObject(1, 12, RIGHT, 10))
platformList.AddLast(New PlatformObject(15, 18, RIGHT, 6))
Return 0
End Method
Method OnUpdate:Int()
Return 0
End Method
Method OnRender:Int()
Cls
For Local i:=Eachin Self.platformList
i.DrawPlatform()
Next
Return 0
End Method
End Class
Function Main:Int()
New Game()
Return 0
End Function