forked from Pakz001/MonkeyXExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonkey - 2D Player jumping code example.monkey
More file actions
51 lines (48 loc) · 1.29 KB
/
Monkey - 2D Player jumping code example.monkey
File metadata and controls
51 lines (48 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Import mojo
Global px:Float = 320
Global py:Float = 240
Global playerjump:Bool = False
Global pincy:Float = 0
Class MyGame Extends App
Method OnCreate()
SetUpdateRate(60)
End
Method OnUpdate()
' If the player is on the ground and the space bar is pressed
If playerjump = False And KeyDown(KEY_SPACE) = True
pincy = -3
playerjump = True
End
'If the player is in the jump
If playerjump = True
pincy += 0.1
'if the player is going up
If pincy <=0
For Local i:Int = 0 Until Abs(pincy)
py -= 1
End
End
' if the player if going down
If pincy > 0
For Local i:Int = 0 Until pincy
py += 1
'if the player touches the ground
If py > 240 Then
playerjump = False
py = 240
Exit
End
End
End
End
End
Method OnRender()
Cls(0,0,0)
SetColor(255,255,255)
DrawRect px,py,32,32
DrawText "Press space bar to jump the rectangle player",10,10
End
End
Function Main()
New MyGame()
End