-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid.agc
173 lines (160 loc) · 2.99 KB
/
grid.agc
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#constant gw 10
#constant gh 20
#constant bw 60
#constant bh 60
#constant xo 20
#constant yo -100
global grid as integer[gw,gh]
global cleared as float = 0
global score as integer = 0
global score_display as integer = 0
function ZeroGrid()
for x = 0 to gw - 1
for y = 0 to gh - 1
grid[x,y] = 0
index = y*gw+x+1
createsprite(index,none_sprite)
SetSpriteSize(index,bw,bh)
SetSpritePosition(index,x*bw + xo,y*bh + yo)
next
next
endfunction
function ClearGrid()
for x = 0 to gw - 1
for y = 0 to gh - 1
grid[x,y] = 0
next
next
endfunction
function DrawGrid()
for x = 0 to gw - 1
for y = 0 to gh - 1
index = y*gw+x+1
SetSpriteImage(index,GetColor(grid[x,y]))
if grid[x,y]
SetSpriteColorAlpha(index,255)
else
SetSpriteColorAlpha(index,100)
endif
next
next
endfunction
function DrawBlock(infs as integer[],preview)
blk = blocks[id,infos[2]]
color = GetColor(id)
for y = 0 to 3
for x = 0 to 3
if BitIndex(blk,y*4+x) = 1
index = (y+infs[1])*gw+x+infs[0]+1
SetSpriteImage(index,color)
if preview
SetSpriteColorAlpha(index,150)
else
SetSpriteColorAlpha(index,255)
endif
endif
next
next
endfunction
function PlaceRawBlock(color_id,block,px,py)
for y = 0 to 3
for x = 0 to 3
if BitIndex(block,y*4+x) = 1
grid[x+px,y+py] = color_id
endif
next
next
endfunction
function GetColor(color as integer)
if color = 1
image = purple_sprite
elseif color = 2
image = orange_sprite
elseif color = 3
image = blue_sprite
elseif color = 4
image = green_sprite
elseif color = 5
image = red_sprite
elseif color = 6
image = yellow_sprite
elseif color = 7
image = cyan_sprite
else
image = none_sprite
endif
endfunction image
function ClearLines()
offset = 0
for y = gh - 1 to 0 step -1
clear = 1
for x = 0 to gw - 1
if grid[x,y] = 0
clear = 0
endif
grid[x,y+offset] = grid[x,y]
next
if clear = 1
offset = offset + 1
endif
next
if offset = 4
speed_time = Timer()+0.8 //TETRIS!!!
endif
if offset > 0
cleared = cleared + offset
for y = 0 to offset - 1
for x = 0 to gw - 1
grid[x,y] = 0
next
next
addscore(offset)
endif
endfunction
function addscore(lines)
if lines = 1
score = score + 40
elseif lines = 2
score = score + 100
elseif lines = 3
score = score + 300
else
score = score + 1200
endif
SetTextString(score_display,str(score))
endfunction
function PlaceBlock(instant)
curr as string = ""
blk = blocks[id,infos[2]]
if instant
change as integer = 0
while CheckColision(infos)
change = 1
infos[1] = infos[1] + 1
endwhile
if change
infos[1] = infos[1] - 1
endif
endif
for y = 0 to 3
for x = 0 to 3
if BitIndex(blk,y*4+x) = 1
grid[x+infos[0],y+infos[1]] = id
endif
next
next
endfunction
function DrawPreview()
temp as integer[3]
temp = infos
for y = infos[1] to gh - 1
temp[1] = y
if not CheckColision(temp)
if y-1 > infos[1]
temp[1] = y - 1
DrawBlock(temp,1)
endif
exit
endif
next
endfunction