-
Notifications
You must be signed in to change notification settings - Fork 8
/
Monkey-X - 2d Hexel Draw Example.monkey
101 lines (94 loc) · 2.36 KB
/
Monkey-X - 2d Hexel Draw Example.monkey
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Import mojo
Class hexelmap
Field mapwidth:Int
Field mapheight:Int
Field tilewidth:Float
Field tileheight:Float
Field map1:Int[][]
Field map2:Int[][]
Method New(mapwidth:Int,mapheight:Int)
Self.mapwidth = mapwidth
Self.mapheight = mapheight
tilewidth = DeviceWidth()/Float(mapwidth)
tileheight = DeviceHeight()/Float(mapheight)
map1 = New Int[mapwidth][]
map2 = New Int[mapwidth][]
For Local i = 0 Until mapwidth
map1[i] = New Int[mapheight]
map2[i] = New Int[mapheight]
Next
End Method
Method update()
' find the tile underneath the mouse pointer
Local x:Int=MouseX() / tilewidth
Local y:Int=MouseY() / tileheight
Local y1:Int = MouseY()-y*tileheight
Local x1:Int = MouseX()-x*tilewidth
Local sd:Int=0
Local t:Int=tilewidth
For Local y2=0 Until tileheight
For Local x2=0 Until tilewidth
If x2=x1 And y2=y1 And t<x1 Then sd=1
Next
t-=1
Next
' if mouse hold down
If MouseDown(MOUSE_LEFT)
If sd = 0 Then map1[x][y] = 1
If sd = 1 Then map2[x][y] = 1
Endif
If MouseDown(MOUSE_RIGHT)
If sd = 0 Then map1[x][y] = 0
If sd = 1 Then map2[x][y] = 0
Endif
End Method
Method drawmap()
SetColor 255,255,255
For Local y=0 Until mapheight
For Local x=0 Until mapwidth
If map1[x][y] = 1
Local x1:Float=Float(x)*tilewidth
Local y1:Float=Float(y)*tileheight
Local pol:Float[6]
pol[0] = x1+tilewidth
pol[1] = y1
pol[2] = x1
pol[3] = y1
pol[4] = x1
pol[5] = tileheight+y1
DrawPoly pol
End If
If map2[x][y] = 1
Local x1:Float=Float(x)*tilewidth
Local y1:Float=Float(y)*tileheight
Local pol:Float[6]
pol[0] = x1+tilewidth
pol[1] = y1
pol[2] = x1
pol[3] = y1+tileheight
pol[4] = x1+tilewidth
pol[5] = tileheight+y1
DrawPoly pol
End If
Next
Next
End Method
End Class
Global mymap:hexelmap
Class MyGame Extends App
Method OnCreate()
SetUpdateRate(60)
mymap = New hexelmap(20,20)
End Method
Method OnUpdate()
mymap.update
End Method
Method OnRender()
Cls 0,0,0
SetColor 255,255,255
mymap.drawmap
End Method
End Class
Function Main()
New MyGame()
End Function