-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example - Puzzle Matching game.bb
283 lines (241 loc) · 4.23 KB
/
Example - Puzzle Matching game.bb
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
;
; By Pakz
;
Graphics 640,480,16,2
SetBuffer BackBuffer()
ClsColor 30,30,30 : Cls
;
Type game
Field btop,bleft
;player
Field pleft,ptop,pwidth,pheight
Field pblock
Field pblockcnt
Field mapbottom
End Type
g.game = New game
resetlevel
;
Global myfont = LoadFont("verdana",16,True)
SetFont myfont
Global timer = CreateTimer(60)
;
Dim blocks(40,40)
;
setupblocks()
;
While KeyDown(1) = False
WaitTimer(timer)
Cls
moveship
drawbeam(0)
DrawBlocks
drawship
grabblock
releaseblock
drawplayingscreen()
If KeyHit(59) Then resetlevel : setupblocks
Color 255,255,255: Text 52,15,"F1 to ",1
Color 255,255,255: Text 52,32,"reset level ",1
Flip
Wend
End
Function resetlevel()
g.game = First game
g\btop = -256
g\bLeft= 96
g\pleft = GraphicsWidth()/2
g\pheight = 64
g\ptop = GraphicsHeight() - g\pheight
g\pwidth = 48
g\pblock = 0
g\pblockcnt = 0
g\mapbottom = 40
End Function
Function drawplayingscreen()
Color 0,0,0
Rect 0,0,96,GraphicsHeight()
Color 50,70,40
Rect 2,2,94,GraphicsHeight()
End Function
Function dropmap()
g.game = First game
For y=38 To 1 Step -1
For x=0 To 40
If ono = False
If blocks(x,y) > 0 Then
bb = y
ono = True
End If
End If
Next:Next
q = g\mapbottom-bb
If q > 10 Then g\mapbottom = (bb+10)
End Function
Function checkcombo(x1,y1,num,rv)
g.game = First game
;x = g\pleft+24
;x=x/48-2
;
For y=y1 To 0 Step -1
If noway = False
If blocks(x1,y) = num Then
cnt=cnt+1
;blocks(x1,y) = 0
Else
noway = True
End If
End If
Next
;
cnt=cnt-1
;DebugLog cnt
;
If cnt > rv Then
For y=y1 To y1-cnt Step - 1
blocks(x1,y) = 0
Next
dropmap
End If
;
;RuntimeError cnt
End Function
Function releaseblock()
g.game = First game
cb = g\pblock
If cb = 0 Then Return
x = g\pleft+24
x=x/48-2
Color 255,0,0
Text 0,0,x
If MouseHit(2) = True Then
For y1=40 To 0 Step -1
If blocks(x,y1) <> 0 And bb = 0 Then
bb = y1
End If
Next
bb=bb+1
For y1=bb To bb+g\pblockcnt-1
blocks(x,y1) = g\pblock
Next
checkcombo(x,bb+g\pblockcnt-1,g\pblock,g\pblockcnt)
g\pblockcnt = 0
g\pblock = 0
EndIf
End Function
Function grabblock()
g.game = First game
;cb = g\pblock
x = g\pleft+24
x=x/48-2
;Color 255,0,0
;Text 0,0,x
If MouseHit(1) = True And g\pblockcnt < 5 Then
lb = 0 : ly = 40
blockselect = False
For y=40 To 0 Step -1
Stepdone = False
bt = blocks(x,y)
If g\pblock = 0 Then
If bt > 0
g\pblock = bt
EndIf
End If
;
If (lb = 0 And bt <> 0) And blockselect = False Then
If g\pblock = bt
lb = bt
ly = y; : DebugLog " set to : " + ly + " from : " + y
blockselect = True
Stepdone = True
Else
Return
End If
End If
;
If Stepdone = False And blockselect = True Then
If lb = bt Then
If (y+1) = ly Then
ly = y
cnt = cnt + 1
End If
EndIf
EndIf
Next
;
If lb <> 0 Then ;RuntimeError "found blok"
g\pblock = lb
g\pblockcnt = cnt + 1 + g\pblockcnt
;remove blocks
For y=ly To 40
blocks(x,y) = 0
Next
End If
;
End If
End Function
Function drawbeam(num)
g.game = First game
x = g\pleft
y = 0
w = g\pwidth
h = GraphicsHeight()
Color 40,40,200
Rect x,y,w,h,True
End Function
Function setupblocks()
For x=0 To 10
For y=0 To 30
blocks(x,y) = Rand(1,4)
Next:Next
End Function
Function moveship()
g.game = First game
If RectsOverlap(MouseX(),MouseY(),1,1,96+g\pwidth/2,0,GraphicsWidth()-(96+g\pwidth),GraphicsHeight()) Then
g\pleft = MouseX() - g\pwidth/2
Else
If MouseX() < 96 Then
g\pLeft = 96
End If
End If
If g\pleft > 12*48 Then g\pleft = 12*48
End Function
Function drawship()
g.game = First game
x = g\pleft
y = g\ptop
w = g\pwidth
h = g\pheight
Color 0,0,0
Rect x,y,w,h,False
Color 160,170,170
x=x+1:w=w-2 : y=y+1:h=h-2
Rect x,y,w,h,True
;
If g\pblockcnt > 0 Then
For y1=y To y-((g\pblockcnt-1)*16) Step -16
draw1block(x,y1,g\pblock)
Next
End If
;
End Function
Function DrawBlocks()
g.game = First game
y2 = (40*16)-(g\mapbottom*16)
For x=0 To 40
For y=0 To 40
draw1block((x*48)+g\bleft,((y*16)+g\btop)+y2,blocks(x,y))
Next:Next
End Function
Function Draw1Block(x,y,num)
If num = 0 Then Return
Color 0,0,0
Rect x,y,48,16,False
Select num
Case 1:Color 255,0,0
Case 2:Color 0,255,0
Case 3:Color 0,0,255
Case 4:Color 255,0,255
End Select
Rect (x+1),(y+1),48-2,16-2,True
End Function