-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator - 2d Flasks or bottles - code example.monkey
135 lines (125 loc) · 2.94 KB
/
Generator - 2d Flasks or bottles - code 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
Import mojo
Class tile
Field width:Int,height:Int
Field map:Int[][]
Method New(w:Int,h:Int)
Self.width = w
Self.height = h
map = New Int[width][]
For Local i:Int=0 Until width
map[i] = New Int[height]
Next
End Method
' Here we create the flasks or bottles
' or what else.
Method generate()
'make right side
' from the center top to center bottom
Local x:Float=width/2
Local y:Float=0
Local angle:Int=0
While y<=height
For Local i:Int=0 Until 20
x+=Cos(angle)*.5
y+=Sin(angle)*.5
If x>=width Then x-=1
If x<0 Or y<0 Or x>=width Or y>=height Then Exit
map[x][y] = 1 ' create border point
fillleftside(x-1,y) ' fill left side
Next
angle=Rnd(0,120)
Wend
If y>height Then y=height-1
For Local x1:Int=x Until width/2-1 Step -1
map[x1][y] = 1
Next
'make left side (mirror right side)
For y = 0 Until height
For x = width/2 Until width
map[width-x][y] = map[x][y]
Next
Next
Return
End Method
' here we put the value of
' 2 inside the map from inputted
' coords to most left position
Method fillleftside(fx:Int,fy:Int)
For Local x:Int=fx Until 0 Step -1
map[x][fy] = 2
Next
End Method
Method draw(sx:Int,sy:Int,ar:Int,ag:Int,ab:Int)
Local c:Int
Local g:Int
Local b:Int
Local lightpointx:Int=Rnd(5,width-5)
For Local y:Int=0 Until height
For Local x:Int=0 Until width
If map[x][y] = 0 Then
c=0+((ag/height)*y)
g=0+((ab/height)*y)
b=0+((ar/height)*y)
If c>255 Then c=255
If g>255 Then g=255
If b>255 Then b=255
If c<0 Then c=0
If g<0 Then g=0
If b<0 Then b=0
SetColor c,g,b
DrawRect sx+x,sy+y,1,1
Continue
End If
' here we draw the border
' and the red (rainbowish color)
Select map[x][y]
Case 1'border
c = 255-((255/height)*y)
If x>width/2 Then c/=2
SetColor c,c,c
Case 2
c = ar-((ar/height)*y)
g = ag-((ag/height)*y)
b = ab-((ab/height)*y)
c=-distance(lightpointx,0,x,0)+c
g=-distance(lightpointx,0,x,0)+g
b=-distance(lightpointx,0,x,0)+b
If c>255 Then c=255
If g>255 Then g=255
If b>255 Then b=255
If c<0 Then c=0
If g<0 Then g=0
If b<0 Then b=0
SetColor c,g,b
End Select
DrawRect sx+x,sy+y,1,1
Next
Next
End Method
Function distance:Int(x1:Int,y1:Int,x2:Int,y2:Int)
Return Abs(x2-x1)+Abs(y2-y1)
End Function
End Class
Class MyGame Extends App
Field mytile:tile
Method OnCreate()
Seed = GetDate[4]*GetDate[5]
SetUpdateRate(1)
End Method
Method OnUpdate()
End Method
Method OnRender()
Cls 0,0,0
SetColor 255,255,255
For Local y:Int=0 Until DeviceHeight Step 55
For Local x:Int=0 Until DeviceWidth Step 55
mytile = New tile(48,48)
mytile.generate()
mytile.draw(x,y,Rnd(24,255),Rnd(24,255),Rnd(24,255))
Next
Next
End Method
End Class
Function Main()
New MyGame()
End Function