Sunday, September 20, 2015

Monkey-X - Beginners - KeyDown(Const) - example


KeyDown is different then KeyHit. It will stay true for as long as the key is held down.

Import mojo

Global lastpressed:Int=10

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
    End Method
    Method OnUpdate()
        lastpressed+=1
        If KeyDown(KEY_SPACE)
            lastpressed = 0
        End If     
    End Method
    Method OnRender()
        If lastpressed < 10 Then
            Cls 200,200,200
        Else
            Cls 0,0,0 
        End If        
        SetColor 255,255,255
        DrawText "Monkey-X - KeyDown(key) Example.",10,10
        DrawText "Press the space bar....",10,30
        DrawText "Space last held down "+lastpressed/60+" second(s) ago",100,100
        DrawText "KeyDown(KEY_SPACE)",100,130
    End Method
End Class


Function Main()
    New MyGame()
End Function

No comments:

Post a Comment