-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator - Grey Bars.monkey
131 lines (124 loc) · 3.24 KB
/
Generator - Grey Bars.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
Import mojo
Class gridbackground
Field mapwidth:Int
Field mapheight:Int
Field tilewidth:Float
Field tileheight:Float
Field mapdepth:Int
Field mapr:Int[][]
Field mapg:Int[][]
Field mapb:Int[][]
Field pixels:Int[]
Field image:Image
Method New(mapwidth:Int,mapheight:Int)
Self.mapwidth = mapwidth
Self.mapheight = mapheight
pixels = New Int[mapwidth*mapheight]
image = CreateImage(mapwidth,mapheight)
tilewidth = DeviceWidth()/Float(mapwidth)
tileheight = DeviceHeight()/Float(mapheight)
mapr = New Int[mapwidth][]
mapg = New Int[mapwidth][]
mapb = New Int[mapwidth][]
For Local i = 0 Until mapwidth
mapr[i] = New Int[mapheight]
mapg[i] = New Int[mapheight]
mapb[i] = New Int[mapheight]
Next
Local col:int=50
Local dir:String="up"
For Local x=0 Until mapwidth
For Local y=0 Until mapheight
mapr[x][y] = col
mapg[x][y] = col
mapb[x][y] = col
Next
If dir="up" Then
If Rnd(3) > 1
col+=Rnd(0,4)
If col>100 Then dir="down"
End If
End If
If dir="down" Then
If Rnd(3) > 1
col-=Rnd(0,4)
If col<50 Then dir="up"
Endif
End If
Next
putinimage
End Method
Method mapdrawrect(x:Int,y:Int,w:Int,h:Int,colr:Int,colg:Int,colb:Int)
For Local y1=y Until y+h
For Local x1=x Until x+w
If x1>-1 And y1>-1 And x1<mapwidth And y1<mapheight
mapr[x1][y1] = colr
mapg[x1][y1] = colg
mapb[x1][y1] = colb
End If
Next
Next
End Method
Method draw()
Local sx:Float=5
Local sy:Float=3.75
If mapwidth>255 Then sx = 2.5 ; sy=1.9
If mapwidth>511 Then sx = 1.25 ; sy=0.9
DrawImage image,0,0,0,sx,sy
Return
For Local y=0 Until mapheight-1
For Local x=0 Until mapwidth-1
Local colr:Int=mapr[x][y]
Local colg:Int=mapg[x][y]
Local colb:Int=mapb[x][y]
SetColor colr,colg,colb
DrawRect x*tilewidth,y*tileheight,tilewidth+1,tileheight+1
Next
Next
End Method
Method distance:Int(x1:Int,y1:Int,x2:Int,y2:Int)
Return Abs(x2-x1)+Abs(y2-y1)
End Method
Method argb:Int(r:Int, g:Int, b:Int ,alpha:Int=255)
Return (alpha Shl 24) | (r Shl 16) | (g Shl 8) | b
End Method
Method putinimage()
Local cnt:Int=0
For Local y=0 Until mapheight
For Local x=0 Until mapwidth
pixels[cnt] = argb(mapr[x][y],mapg[x][y],mapb[x][y])
cnt+=1
Next
Next
image.WritePixels(pixels, 0, 0, mapwidth, mapheight, 0)
End Method
End Class
Global mygbg:gridbackground
Class MyGame Extends App
Field time:Int=0
Method OnCreate()
Seed = GetDate[5]
SetUpdateRate(1)
mygbg = New gridbackground(256,256)
End Method
Method OnUpdate()
time+=1
If time>10 Then
time=0
Local r:Int=Rnd(3)
Local ts:Int=128
If r=0 Then ts=128
If r=1 Then ts=256
If r=2 Then ts=512
mygbg = New gridbackground(ts,ts)
End If
End Method
Method OnRender()
Cls 0,0,0
SetColor 255,255,255
mygbg.draw
End Method
End Class
Function Main()
New MyGame()
End Function