-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator - Stone and Snow.monkey
127 lines (121 loc) · 3.26 KB
/
Generator - Stone and Snow.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
Import mojo
Class gridbackground
Field mapwidth:Int
Field mapheight:Int
Field tilewidth:Float
Field tileheight:Float
Field mapdepth:Int
Field map:Int[][]
Method New(mapwidth:Int,mapheight:Int)
Self.mapwidth = mapwidth
Self.mapheight = mapheight
tilewidth = DeviceWidth()/Float(mapwidth)
tileheight = DeviceHeight()/Float(mapheight)
map = New Int[mapwidth][]
For Local i = 0 Until mapwidth
map[i] = New Int[mapheight]
Next
addrectslayer
brusheffect()
smooth
lightmap
End Method
Method lightmap()
Local tp:Int=Rnd(1,10)
Local lightx:Int=Rnd(0,mapwidth)
Local lighty:Int=Rnd(0,mapheight)
For Local y=0 Until mapheight
For Local x=0 Until mapwidth
Local d:Int=(distance(x,y,lightx,lighty)/10)+1
If tp<5 Then
map[x][y] = 255-map[x][y]/d
Else
map[x][y] = map[x][y]/d
End If
Next
Next
End Method
Method smooth()
For Local i=0 Until (mapwidth*mapheight)
Local x:Int=Rnd(0,mapwidth-1)
Local y:Int=Rnd(0,mapheight-1)
Local col1:Int=map[x+1][y]
Local col2:Int=map[x+1][y+1]
Local col3:Int=map[x][y+1]
Local col4:Int=(col1+col2+col3)/3
map[x][y] = col4
Next
End Method
Method brusheffect() 'explosion effect copy from in area to another part in area in half the brishtness
For Local i=0 Until (mapwidth*mapheight)/20
Local x:Int=Rnd(-3,mapwidth)
Local y:Int=Rnd(-3,mapheight)
For Local y1=-5 To 5
For Local x1=-5 To 5
Local x2:Int=x+x1
Local y2:Int=y+y1
If Rnd(10)<3
If x2>-1 And y2>-1 And x2<mapwidth And y2<mapheight
Local col:Int=map[x2][y2]
Local x3:Int=x2+Rnd(-5,5)
Local y3:Int=y2+Rnd(-5,5)
If x3>-1 And y3>-1 And x3<mapwidth And y3<mapheight
map[x3][y3] = col/2
End If
End If
End If
Next
Next
Next
End Method
Method addrectslayer()
For Local i=0 Until (mapwidth*mapheight)/20
Local w:Int=Rnd(3,10)
Local h:Int=Rnd(3,10)
Local x:Int=Rnd(-3,mapwidth)
Local y:Int=Rnd(-3,mapheight)
Local col:Int=255
mapdrawrect(x,y,w,h,col)
Next
End Method
Method mapdrawrect(x:Int,y:Int,w:Int,h:Int,col: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
map[x1][y1] = col
End If
Next
Next
End Method
Method draw()
For Local y=0 Until mapheight-1
For Local x=0 Until mapwidth-1
Local col:Int=map[x][y]
SetColor col,col,col
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
End Class
Global mygbg:gridbackground
Class MyGame Extends App
Method OnCreate()
Seed = GetDate[5]
SetUpdateRate(1)
mygbg = New gridbackground(128,128)
End Method
Method OnUpdate()
mygbg = New gridbackground(128,128)
End Method
Method OnRender()
Cls 0,0,0
SetColor 255,255,255
mygbg.draw
End Method
End Class
Function Main()
New MyGame()
End Function