Artificial intelligence/templates/examples/rts/rpg/strategy ect. in MonkeyX/CerberusX language. You can download the free version of MonkeyX from itch.io or Cerberus-x.com The Flash applets will stop working in around 2020.
The code below draws a rectangle that can be moved with the cursor keys. The rectangle can not get outside of the screen.
Code below :
Import mojo Global mleft:Bool = False Global mright:Bool = False Global mup:Bool = False Global mdown:Bool = False Global px:Int = 320 Global py:Int = 220 Class MyGame Extends App Method OnCreate() SetUpdateRate(60) End Method OnUpdate() If KeyDown(KEY_LEFT) Then mleft = True Else mleft = False If KeyDown(KEY_RIGHT) Then mright = True Else mright = False If KeyDown(KEY_UP) Then mup = True Else mup = False If KeyDown(KEY_DOWN) Then mdown = True Else mdown = False If mleft And px > 0 Then px-=1 If mright And px <640-16 Then px+=1 If mup And py > 0 Then py-=1 If mdown And py <480-16 Then py+=1 End Method OnRender() Cls(0,0,0) SetColor(255,255,255) DrawRect(px,py,16,16) DrawText("Use cursors to move player",10,10) End End Function Main() New MyGame() End
Isn't "If KeyDown(KEY_LEFT) Then mleft = True Else mleft = False" basically just "mleft = KeyDown(KEY_LEFT)" ?
I just checked. Its mleft = Bool(KeyDown(KEY_LEFT)) that works. You need the bool thing else it gives a compiler error.
Note: Only a member of this blog may post a comment.
Isn't "If KeyDown(KEY_LEFT) Then mleft = True Else mleft = False" basically just "mleft = KeyDown(KEY_LEFT)" ?
ReplyDeleteI just checked. Its mleft = Bool(KeyDown(KEY_LEFT)) that works. You need the bool thing else it gives a compiler error.
Delete