-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockExplosion.bas
More file actions
1576 lines (1338 loc) · 50.5 KB
/
BlockExplosion.bas
File metadata and controls
1576 lines (1338 loc) · 50.5 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
REM SmallBASIC 12.23
REM "Let them fall" by PIXELGUY
delay(100)
w=window()
if(rinstr(SBVER,"Android"))
IS_ANDROID = true
else
w.setSize(680, 850)
IS_ANDROID = false
endif
'IS_ANDROID = true
SCREEN_X = XMAX
SCREEN_Y = YMAX
const BOARD_X = 8
const BOARD_Y = 14
const INFO_X = 4
PIXELSIZE = 1
TILESIZE = 16
FONTSIZE = 8
const GAME_COLUMN_IS_MOVING = 0
const GAME_COLUMN_IS_FALLING = 1
const GAME_REMOVE_BLOCKS = 2
const GAME_EXPLODE_BLOCKS = 3
const GAME_FALL_BLOCKS = 4
const GAME_PAUSE = 5
const GAME_END = 6
const GAME_SETTINGS = 7
const GAME_COLUMN_FALLING_SPEED = 1
const GAME_COLUMN_SPEED = 1
const NUMBER_OF_MAX_SPECIAL_BLOCKS = 3
const NUMBER_OF_MAX_BLOCKS = 6
NUMBER_OF_BLOCKS = NUMBER_OF_MAX_BLOCKS + NUMBER_OF_MAX_SPECIAL_BLOCKS
const NUMBER_OF_BLOCKS_ANIMATIONS = 1
const NUMBER_OF_BLOCKS_EXPLOSION_ANIMATIONS = 4
const BLOCKS_EXPLOSION_ANIMATION_SPEED = 0.02
BLOCKS_EXPLOSION_OFFSET = 0
BlocksExplosionAnimationFrame = 0
NUMBER_OF_TILES = (NUMBER_OF_MAX_BLOCKS + NUMBER_OF_MAX_SPECIAL_BLOCKS) * NUMBER_OF_BLOCKS_ANIMATIONS
NUMBER_OF_TILES = NUMBER_OF_TILES + NUMBER_OF_BLOCKS_EXPLOSION_ANIMATIONS
dim Tiles[NUMBER_OF_TILES]
const BOARD_BLOCKS = 0
const BOARD_REMOVE = 1
const BOARD_MICROSTEP = 2
const BOARD_ANIMATION_OFFSET = 3
const BOARD_ANIMATION_FRAME = 4
dim Board[BOARD_X,BOARD_Y,4]
dim Column[2]
dim NextColumn[2]
dim ColorPalette[31]
'Init Game Settings
Randomize(ticks())
GAME_IS_RUNNING = true
SoundOnOff = true
GameStateTemp = 0
GameStateTempPause = 0
Level = 1
StartLevel = 1
Highscore = 0
BlocksTotal = 0
Speed = GAME_COLUMN_SPEED * 0.02
TimeStep = 0
MicroStep = 0
MouseX = 0
MouseY = 0
PointsTotal = 0
PointsTemp = 0
PointsMultiplier = 1
NextColumn[0] = int(rnd() * NUMBER_OF_BLOCKS) + 1
NextColumn[1] = int(rnd() * NUMBER_OF_BLOCKS) + 1
NextColumn[2] = int(rnd() * NUMBER_OF_BLOCKS) + 1
ColumnPositionX = 4
ColumnPositionY = 0
ColumnPositionNewX = -1
ColumnPositionNewY = -1
'Init
LoadSettings()
InitScreen()
InitButtonClass()
CreateColorPalette()
CreateBoard()
CreateButtons()
CreateTiles()
CreateColumn()
DrawEverything()
definekey(32, Callback_Key_SPACE)
definekey(13, Callback_Key_RETURN)
definekey(0xFF04, Callback_Left)
definekey(0xFF05, Callback_Right)
definekey(0xFF09, Callback_Cycle) 'Up
definekey(0xFF0A, Callback_Cycle) 'Down
definekey(112, Callback_Pause) 'P
GAME_STATE = GAME_END
'Start game loop
while GAME_IS_RUNNING
StartTime = ticks()
Select case GAME_STATE
case GAME_COLUMN_IS_MOVING
DrawColumn()
ButtonClass.DoEvents()
case GAME_COLUMN_IS_FALLING
DrawColumn()
ButtonClass.DoEvents()
case GAME_REMOVE_BLOCKS
RemoveBlocks()
DrawScore()
case GAME_EXPLODE_BLOCKS
ExplodeBlocks()
DrawBoard()
DrawScore()
case GAME_FALL_BLOCKS
FallBlocks()
DrawBoard()
case GAME_PAUSE
ButtonClass.DoEvents()
case GAME_END
ButtonClass.DoEvents()
case GAME_SETTINGS
GameSettings()
ButtonClass.DoEvents()
end select
showpage
EndTime = ticks()
TimeStep = EndTime - StartTime
'at 1,SCREEN_Y - 4*FONTSIZE: print TimeStep;"ms "
'print Status
if(TimeStep < 20)
delay(20 - TimeStep)
TimeStep = 20
endif
wend
Rem --------------------------------------------
sub PlaySoundExplosion()
local A
if(SoundOnOff)
A = [213,381,446,251,443,270,120,236,347,331,101,371,125,434,335,401,235,392,156,356,311,338,266,251,462,331,216,311,277,112]
for ii = 0 to 29
sound A[ii],10, (30-ii)/30 * 100 BG
next
endif
end sub
sub PlaySoundCycle()
local A
if(SoundOnOff)
A = [3000,1500,1000,750,600,500]
for ii = 0 to 5
sound A[ii],10, (5-ii)/5 * 100 BG
next
endif
end sub
sub PlaySoundLeftRight()
local A
if(SoundOnOff)
A = [100,200,300,400,500,600]
for ii = 0 to 5
sound A[ii],10 BG
next
endif
end sub
sub PlaySoundTouchdown()
local A
if(SoundOnOff)
A = [400,600,450,550,480,500]
for ii = 0 to 5
sound A[ii],20 BG
next
endif
end sub
sub LoadSettings()
local dim SaveArray[3]
if(exist("settings.dat"))
tload "settings.dat", SaveArray
Highscore = val(SaveArray[0])
NUMBER_OF_BLOCKS = val(SaveArray[1])
StartLevel = val(SaveArray[2])
SoundOnOff = val(SaveArray[3])
endif
end sub
sub SaveSettings()
local dim SaveArray[3]
SaveArray[0] = Highscore
SaveArray[1] = NUMBER_OF_BLOCKS
SaveArray[2] = StartLevel
SaveArray[3] = SoundOnOff
tsave "settings.dat", SaveArray
end sub
sub InitButtonClass()
dim Button
Button.x1 = 0
Button.y1 = 0
Button.x2 = 0
Button.y2 = 0
Button.text = ""
Button.active = true
Button.cooldown = 0
Button.Draw = @ButtonDraw()
dim Button.Callback
sub ButtonDraw()
local text_x, text_y
rect self.x1+PIXELSIZE, self.y1+PIXELSIZE, self.x2 - PIXELSIZE, self.y2 - PIXELSIZE, ColorPalette[11] filled
rect self.x1 + 2*PIXELSIZE, self.y1, self.x2 - 2*PIXELSIZE, self.y1 + PIXELSIZE, ColorPalette[13] filled
rect self.x1 + PIXELSIZE, self.y1, self.x1 + 2*PIXELSIZE, self.y1 + PIXELSIZE, ColorPalette[12] filled
rect self.x2 - 3*PIXELSIZE, self.y1, self.x2 - 2*PIXELSIZE, self.y1 + PIXELSIZE, ColorPalette[12] filled
rect self.x1, self.y1 + 2*PIXELSIZE, self.x1 + PIXELSIZE, self.y2 - 3*PIXELSIZE, ColorPalette[13] filled
rect self.x1, self.y1 + PIXELSIZE, self.x1 + PIXELSIZE, self.y1 + 2*PIXELSIZE, ColorPalette[12] filled
rect self.x1, self.y2 - 3*PIXELSIZE, self.x1 + PIXELSIZE, self.y2 - 2*PIXELSIZE, ColorPalette[12] filled
rect self.x2 - PIXELSIZE, self.y1 + PIXELSIZE, self.x2 , self.y2 - 2*PIXELSIZE, ColorPalette[10] filled
rect self.x1 + PIXELSIZE, self.y2 - PIXELSIZE, self.x2 - 2*PIXELSIZE, self.y2 , ColorPalette[10] filled
rect self.x2 - 2*PIXELSIZE, self.y2 - 2*PIXELSIZE, self.x2 - PIXELSIZE, self.y2 - PIXELSIZE, ColorPalette[10] filled
text_x = self.x1 + (self.x2 - self.x1 - Textwidth(self.text))/2
text_y = self.y1 + (self.y2 - self.y1 - Textheight(self.text))/2
color ColorPalette[7], ColorPalette[11]
at text_x, text_y: print self.text
end sub
dim ButtonClass.Buttons
ButtonClass.NumberOfButtons = 0
ButtonClass.LastTime = ticks()
ButtonClass.AddButton = @ButtonClassAddButton
ButtonClass.DrawButtons = @ButtonClassDrawButtons
ButtonClass.ChangeText = @ButtonClassChangeText
ButtonClass.SetActive = @ButtonClassSetActive
ButtonClass.DoEvents = @ButtonClassDoEvents
func ButtonClassAddButton(x,y,w,h,text, Callback)
local temp
temp = Button
temp.x1 = x
temp.y1 = y
temp.x2 = x + w
temp.y2 = y + h
temp.text = text
temp.Callback = CallBack
self.Buttons << temp
self.NumberOfButtons++
ButtonClassAddButton = self.NumberOfButtons - 1
end
sub ButtonClassDrawButtons()
local ii, temp
for ii = 0 to self.NumberOfButtons - 1
temp = self.Buttons[ii]
if(temp.active)
temp.Draw()
endif
next
end sub
sub ButtonClassChangeText(Button, Text)
self.Buttons[Button].text = text
end sub
sub ButtonClassSetActive(Button, s)
if(s == false)
self.Buttons[Button].active = false
else
self.Buttons[Button].active = true
endif
end sub
sub ButtonClassDoEvents()
local ii, pressed, TimeStep
'Do cooldown of buttons to prevent double click
for ii = 0 to self.NumberOfButtons - 1
if(self.Buttons[ii].cooldown > 0)
TimeStep = ticks() - self.LastTime
self.LastTime = ticks()
self.Buttons[ii].cooldown = self.Buttons[ii].cooldown - TimeStep
endif
next
'Detect mouse click and call callbacks of the buttons
if(Pen(3))
MouseX = Pen(1)
MouseY = Pen(2)
for ii = 0 to self.NumberOfButtons - 1
if(self.Buttons[ii].cooldown <= 0 and self.Buttons[ii].active)
'AABB Collision Detection
pressed = 1
if(MouseX < self.Buttons[ii].x1)
pressed = 0
elseif(MouseX > self.Buttons[ii].x2)
pressed = 0
elseif(MouseY < self.Buttons[ii].y1)
pressed = 0
elseif(MouseY > self.Buttons[ii].y2)
pressed = 0
endif
'Call Button Callback
if(pressed == 1)
self.Buttons[ii].cooldown = 200
self.LastTime = ticks()
call self.Buttons[ii].Callback
endif
endif
next
endif
end sub
end sub
'######################
sub Callback_Left()
if(ColumnPositionX > 0)
if(Board[ColumnPositionX-1,ColumnPositionY,BOARD_BLOCKS] == 0)
if(Board[ColumnPositionX-1,ColumnPositionY+1,BOARD_BLOCKS] == 0)
if(Board[ColumnPositionX-1,ColumnPositionY+2,BOARD_BLOCKS] == 0)
if(Board[ColumnPositionX-1,ColumnPositionY+3,BOARD_BLOCKS]==0)
PlaySoundLeftRight()
ColumnPositionNewX = ColumnPositionX - 1
endif
endif
endif
endif
endif
end sub
sub Callback_Right()
if(ColumnPositionX < BOARD_X)
if(Board[ColumnPositionX+1,ColumnPositionY,BOARD_BLOCKS] == 0)
if(Board[ColumnPositionX+1,ColumnPositionY+1,BOARD_BLOCKS] == 0)
if(Board[ColumnPositionX+1,ColumnPositionY+2,BOARD_BLOCKS] == 0)
if(Board[ColumnPositionX+1,ColumnPositionY+3,BOARD_BLOCKS]==0)
PlaySoundLeftRight()
ColumnPositionNewX = ColumnPositionX + 1
endif
endif
endif
endif
endif
end sub
sub Callback_Key_SPACE()
if(GAME_STATE == GAME_COLUMN_IS_MOVING)
Callback_Drop()
elseif(GAME_STATE == GAME_END)
Callback_GameStart()
endif
end
sub Callback_Key_RETURN()
if(GAME_STATE == GAME_END)
Callback_GameStart()
endif
end
sub Callback_Drop()
GAME_STATE = GAME_COLUMN_IS_FALLING
Speed = GAME_COLUMN_FALLING_SPEED
end sub
sub Callback_Cycle()
PlaySoundCycle()
CycleColumn()
end sub
sub Callback_Pause()
if(GAME_STATE = GAME_PAUSE)
GAME_STATE = GameStateTempPause
else
GameStateTempPause = GAME_STATE
GAME_STATE = GAME_PAUSE
endif
end sub
sub Callback_SettingsSound()
SoundOnOff = not SoundOnOff
if(SoundOnOff) then
ButtonClass.ChangeText(B_SettingsSound, "ON")
else
ButtonClass.ChangeText(B_SettingsSound, "OFF")
endif
ButtonClass.DrawButtons()
end sub
sub Callback_GameStart()
ButtonClass.SetActive(B_GameStart, false)
Level = StartLevel
BlocksTotal = 0
Speed = GAME_COLUMN_SPEED * 0.02
MicroStep = 0
PointsTotal = 0
PointsTemp = 0
PointsMultiplier = 1
NextColumn[0] = int(rnd() * NUMBER_OF_BLOCKS) + 1
NextColumn[1] = int(rnd() * NUMBER_OF_BLOCKS) + 1
NextColumn[2] = int(rnd() * NUMBER_OF_BLOCKS) + 1
GameStateTemp = 0
CreateBoard()
CreateColumn()
DrawEverything()
end sub
sub Callback_Menu()
local xx,yy
GameStateTemp = GAME_STATE
GAME_STATE = GAME_SETTINGS
if(IS_ANDROID)
ButtonClass.SetActive(B_Drop, false)
ButtonClass.SetActive(B_Cycle, false)
ButtonClass.SetActive(B_Left, false)
ButtonClass.SetActive(B_Right, false)
endif
ButtonClass.SetActive(B_Menu, false)
ButtonClass.SetActive(B_Pause, false)
ButtonClass.SetActive(B_GameStart, false)
ButtonClass.SetActive(B_SettingsLevelUp, true)
ButtonClass.SetActive(B_SettingsLevelDown, true)
ButtonClass.SetActive(B_SettingsNumberOfBlocksUp, true)
ButtonClass.SetActive(B_SettingsNumberOfBlocksDown, true)
ButtonClass.SetActive(B_SettingsSound, true)
ButtonClass.SetActive(B_SettingsClose, true)
DrawBackground()
rect 1*TILESIZE, 1*TILESIZE, (TILES_X-1)*TILESIZE, (TILES_Y - 1)*TILESIZE, ColorPalette[11] filled
for yy = 1 to TILES_Y-3
FRAME_LEFT_TILE.draw(0, yy*TILESIZE)
FRAME_RIGHT_TILE.draw((TILES_X-1)*TILESIZE, yy*TILESIZE)
next
for xx = 1 to TILES_X-1
FRAME_BOTTOM_TILE.draw(xx*TILESIZE, (TILES_Y-2) * TILESIZE)
FRAME_TOP_TILE.draw(xx*TILESIZE, 0)
next
FRAME_CORNER_TOP_LEFT_TILE.draw(0,0)
FRAME_CORNER_TOP_RIGHT_TILE.draw((TILES_X-1)*TILESIZE, 0)
FRAME_CORNER_BOTTOM_LEFT_TILE.draw(0,(TILES_Y-2) * TILESIZE)
FRAME_CORNER_BOTTOM_RIGHT_TILE.draw((TILES_X-1)*TILESIZE, (TILES_Y-2)*TILESIZE)
ButtonClass.DrawButtons()
end sub
sub Callback_SettingsLevelUp()
StartLevel = StartLevel + 1
end sub
sub Callback_SettingsLevelDown()
if(StartLevel > 1)
StartLevel = StartLevel - 1
endif
end sub
sub Callback_SettingsNumberOfBlocksUp()
NUMBER_OF_BLOCKS = NUMBER_OF_BLOCKS + 1
if(NUMBER_OF_BLOCKS > NUMBER_OF_MAX_BLOCKS + NUMBER_OF_MAX_SPECIAL_BLOCKS)
NUMBER_OF_BLOCKS = NUMBER_OF_MAX_BLOCKS + NUMBER_OF_MAX_SPECIAL_BLOCKS
endif
end sub
sub Callback_SettingsNumberOfBlocksDown()
NUMBER_OF_BLOCKS = NUMBER_OF_BLOCKS - 1
if(NUMBER_OF_BLOCKS < 2)
NUMBER_OF_BLOCKS = 2
endif
end sub
sub Callback_SettingsClose()
SaveSettings()
GAME_STATE = GameStateTemp
if(IS_ANDROID)
ButtonClass.SetActive(B_Drop, true)
ButtonClass.SetActive(B_Cycle, true)
ButtonClass.SetActive(B_Left, true)
ButtonClass.SetActive(B_Right, true)
endif
ButtonClass.SetActive(B_Menu, true)
ButtonClass.SetActive(B_Pause, true)
if(GAME_STATE == GAME_END) then ButtonClass.SetActive(B_GameStart, true)
ButtonClass.SetActive(B_SettingsLevelUp, false)
ButtonClass.SetActive(B_SettingsLevelDown, false)
ButtonClass.SetActive(B_SettingsNumberOfBlocksUp, false)
ButtonClass.SetActive(B_SettingsNumberOfBlocksDown, false)
ButtonClass.SetActive(B_SettingsClose, false)
ButtonClass.SetActive(B_SettingsSound, false)
DrawEverything()
end sub
sub GameSettings()
at 2*TILESIZE, 3*TILESIZE - FONTSIZE/2
print "Start Level: "; StartLevel
at 2*TILESIZE, 6*TILESIZE - FONTSIZE/2
print "Number of Blocks: "; NUMBER_OF_BLOCKS
at 2*TILESIZE, 9*TILESIZE - FONTSIZE/2
print "Sound: "
end
sub DrawEverything()
color ColorPalette[10], ColorPalette[10]
cls
DrawBackground()
'DrawColorPalette()
DrawBoard()
DrawScore()
ButtonClass.DrawButtons()
end
sub DrawScore()
local posx
posx = (BOARD_X+1.2)*TILESIZE + BOARD_OFFSET_X
color ColorPalette[7], ColorPalette[10]
at posx,BOARD_OFFSET_Y: print "HIGHSCORE"
at posx,BOARD_OFFSET_Y + FONTSIZE: print Highscore
at posx,BOARD_OFFSET_Y + 3*FONTSIZE: print "SCORE"
rect posx, BOARD_OFFSET_Y + 4*FONTSIZE, posx + (INFO_X-1.2)*TILESIZE, BOARD_OFFSET_Y + 5*FONTSIZE, ColorPalette[10] filled
if(PointsTemp > 0) then
at posx,BOARD_OFFSET_Y + 4*FONTSIZE:print PointsTotal; "+"; PointsTemp
else
at posx,BOARD_OFFSET_Y + 4*FONTSIZE:print PointsTotal
endif
at posx,BOARD_OFFSET_Y + 6*FONTSIZE: print "LEVEL"
at posx,BOARD_OFFSET_Y + 7*FONTSIZE: print Level
at posx,BOARD_OFFSET_Y + 9*FONTSIZE: print "BLOCKS"
at posx,BOARD_OFFSET_Y + 10*FONTSIZE: print BlocksTotal
'Draw next column
rect posx+0.5*TILESIZE, BOARD_OFFSET_Y+13*FONTSIZE, posx + 1.5*TILESIZE, BOARD_OFFSET_Y+13*FONTSIZE + 3*TILESIZE, ColorPalette[10] filled
TempImg = Tiles[NextColumn[0]]
TempImg.draw(posx+0.5*TILESIZE, BOARD_OFFSET_Y+13*FONTSIZE)
TempImg = Tiles[NextColumn[1]]
TempImg.draw(posx+0.5*TILESIZE, BOARD_OFFSET_Y+13*FONTSIZE+TILESIZE)
TempImg = Tiles[NextColumn[2]]
TempImg.draw(posx+0.5*TILESIZE, BOARD_OFFSET_Y+13*FONTSIZE+2*TILESIZE)
end
sub FallBlocks()
local xx,yy,ii,finished = true
MicroStep = MicroStep + 1 * TimeStep
if(MicroStep >= TILESIZE)
MicroStep = 0
for xx = 0 to BOARD_X
for yy = BOARD_Y-1 to 0 Step -1
if( Board[xx,yy,BOARD_MICROSTEP] > 0) then
Board[xx,yy+1,BOARD_MICROSTEP] = 0
Board[xx,yy+1,BOARD_REMOVE] = Board[xx,yy,BOARD_REMOVE]
Board[xx,yy+1,BOARD_BLOCKS] = Board[xx,yy,BOARD_BLOCKS]
Board[xx,yy,BOARD_BLOCKS] = 0
Board[xx,yy,BOARD_REMOVE] = 0
Board[xx,yy,BOARD_MICROSTEP] = 0
endif
next
next
endif
for xx = 0 to BOARD_X
for yy = BOARD_Y to 1 Step -1
if(Board[xx,yy,BOARD_REMOVE] == 1) then
finished = false
for ii = yy-1 to 0 Step -1
Board[xx,ii,BOARD_MICROSTEP] = MicroStep
next
exit
endif
next
next
if(finished) then
GAME_STATE = GAME_REMOVE_BLOCKS
endif
end sub
sub ExplodeBlocks()
local Explosions = 0
local xx,yy
for yy = 0 to BOARD_Y
for xx = 0 to BOARD_X
if(Board[xx,yy,BOARD_REMOVE] == 1) then
Explosions++
Board[xx,yy,BOARD_BLOCKS] = BLOCKS_EXPLOSION_OFFSET + floor(BlocksExplosionAnimationFrame)
endif
next
next
BlocksExplosionAnimationFrame = BlocksExplosionAnimationFrame + TimeStep * BLOCKS_EXPLOSION_ANIMATION_SPEED
if(BlocksExplosionAnimationFrame > NUMBER_OF_BLOCKS_EXPLOSION_ANIMATIONS) then
BlocksExplosionAnimationFrame = 0
if(Explosions > 0) then
PlaySoundExplosion()
GAME_STATE = GAME_FALL_BLOCKS
MicroStep = 0
else
CreateColumn()
endif
for yy = 0 to BOARD_Y
for xx = 0 to BOARD_X
if(Board[xx,yy,BOARD_REMOVE] == 1) then
Board[xx,yy,BOARD_BLOCKS] = 0
endif
next
next
endif
end
sub RemoveBlocks()
local xx,yy,ii,bb,block,count
for yy = 0 to BOARD_Y
for xx = 0 to BOARD_X
Board[xx,yy,BOARD_REMOVE] = 0
next
next
'in a row
for yy = 0 to BOARD_Y
for xx = 1 to BOARD_X - 1
if(Board[xx,yy,BOARD_BLOCKS] > 0) THEN
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx-1,yy,BOARD_BLOCKS]) then
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx+1,yy,BOARD_BLOCKS]) then
Board[xx-1,yy,BOARD_REMOVE] = 1
Board[xx ,yy,BOARD_REMOVE] = 1
Board[xx+1,yy,BOARD_REMOVE] = 1
select Board[xx,yy,BOARD_BLOCKS]
case BLOCKS_EXPLODE_X
for bb = 0 to BOARD_X
Board[bb,yy,BOARD_REMOVE] = 1
next
case BLOCKS_EXPLODE_R
if(yy>0)
Board[xx-1,yy-1,BOARD_REMOVE] = 1
Board[xx,yy-1, BOARD_REMOVE] = 1
Board[xx+1,yy-1,BOARD_REMOVE] = 1
endif
if(yy < BOARD_Y-1)
Board[xx-1,yy+1,BOARD_REMOVE] = 1
Board[xx,yy+1, BOARD_REMOVE] = 1
Board[xx+1,yy+1,BOARD_REMOVE] = 1
endif
end select
endif
endif
endif
next xx
next yy
'in a column
for yy = 1 to BOARD_Y-1
for xx = 0 to BOARD_X
if(Board[xx,yy,BOARD_BLOCKS] > 0) then
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx,yy-1,BOARD_BLOCKS]) then
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx,yy+1,BOARD_BLOCKS]) then
Board[xx,yy-1,BOARD_REMOVE] = 1
Board[xx,yy ,BOARD_REMOVE] = 1
Board[xx,yy+1,BOARD_REMOVE] = 1
select Board[xx,yy,BOARD_BLOCKS]
case BLOCKS_EXPLODE_Y
for bb = 0 to BOARD_Y
Board[xx,bb, BOARD_REMOVE] = 1
next
case BLOCKS_EXPLODE_R
if(xx>0)
Board[xx-1,yy+1,BOARD_REMOVE] = 1
Board[xx-1,yy , BOARD_REMOVE] = 1
Board[xx-1,yy-1,BOARD_REMOVE] = 1
endif
if(xx < BOARD_X)
Board[xx+1,yy+1, BOARD_REMOVE] = 1
Board[xx+1,yy , BOARD_REMOVE] = 1
Board[xx+1,yy-1, BOARD_REMOVE] = 1
endif
end select
endif
endif
endif
next xx
next yy
'diagonal
for yy = 1 to BOARD_Y - 1
for xx = 1 to BOARD_X - 1
'LT2RB
if(Board[xx,yy,BOARD_BLOCKS] > 0) then
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx-1,yy-1,BOARD_BLOCKS]) then
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx+1,yy+1,BOARD_BLOCKS]) then
Board[xx-1,yy-1,BOARD_REMOVE] = 1
Board[xx ,yy, BOARD_REMOVE] = 1
Board[xx+1,yy+1,BOARD_REMOVE] = 1
select Board[xx,yy,BOARD_BLOCKS]
case BLOCKS_EXPLODE_R
Board[xx,yy-1, BOARD_REMOVE] = 1
Board[xx+1,yy-1,BOARD_REMOVE] = 1
Board[xx-1,yy ,BOARD_REMOVE] = 1
Board[xx+1,yy ,BOARD_REMOVE] = 1
Board[xx-1,yy+1,BOARD_REMOVE] = 1
Board[xx ,yy+1,BOARD_REMOVE] = 1
end select
endif
endif
'LB2RT
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx-1,yy+1,BOARD_BLOCKS]) then
if(Board[xx,yy,BOARD_BLOCKS] == Board[xx+1,yy-1,BOARD_BLOCKS]) then
Board[xx-1,yy+1,BOARD_REMOVE] = 1
Board[xx ,yy ,BOARD_REMOVE] = 1
Board[xx+1,yy-1,BOARD_REMOVE] = 1
select Board[xx,yy,BOARD_BLOCKS]
case BLOCKS_EXPLODE_R
Board[xx-1,yy-1, BOARD_REMOVE] = 1
Board[xx ,yy-1,BOARD_REMOVE] = 1
Board[xx-1,yy ,BOARD_REMOVE] = 1
Board[xx+1,yy ,BOARD_REMOVE] = 1
Board[xx ,yy+1,BOARD_REMOVE] = 1
Board[xx+1,yy+1,BOARD_REMOVE] = 1
end select
endif
endif
endif
next
next
BlocksRemoved = 0
for yy = 0 to BOARD_Y
for xx = 0 to BOARD_X
if(Board[xx,yy,BOARD_REMOVE] == 1) then
Board[xx,yy,BOARD_BLOCKS] = 0
BlocksRemoved++
endif
next
next
if(BlocksRemoved > 0) then
GAME_STATE = GAME_EXPLODE_BLOCKS
PointsTemp = PointsTemp + 10*BlocksRemoved * PointsMultiplier
PointsMultiplier++
BlocksTotal = BlocksTotal + BlocksRemoved
else
CreateColumn()
endif
end
sub CalcColumnTouchDown()
local ii
for ii = ColumnPositionY to BOARD_Y - 1
if(Board[ColumnPositionX,ii,BOARD_BLOCKS] > 0)
exit
endif
NEXT ii
COLUMM_TOUCH_DOWN = ii - 4
end
sub DrawBoard()
local xx,yy,TempImg,posy
'Draw Tiles
for xx = 0 to BOARD_X
for yy = 0 to BOARD_Y-1
posy = yy * TILESIZE + BOARD_OFFSET_Y
TempImg = Tiles[0]
TempImg.draw(xx*TILESIZE + BOARD_OFFSET_X, posy)
if(Board[xx,yy,BOARD_BLOCKS] > 0)
posy = yy * TILESIZE + Board[xx,yy,BOARD_MICROSTEP] + BOARD_OFFSET_Y
TempImg =Tiles[Board[xx,yy,BOARD_BLOCKS]]
TempImg.draw(xx*TILESIZE + BOARD_OFFSET_X, posy)
end if
next yy
next xx
end
sub CycleColumn()
local temp
temp = Column[0]
Column[0] = Column[2]
Column[2] = Column[1]
Column[1] = temp
end
sub CreateButtons()
if(ScreenMode = 0) 'Portrait
if(IS_ANDROID)
B_Cycle = ButtonClass.AddButton(0, BOARD_Y * TILESIZE + BOARD_OFFSET_Y + 1*TILESIZE , SCREEN_X/10*4.5-5*PIXELSIZE, 3*TILESIZE - PIXELSIZE, "Cycle", @Callback_Cycle)
B_Drop = ButtonClass.AddButton(0, BOARD_Y * TILESIZE + BOARD_OFFSET_Y + 4*TILESIZE + PIXELSIZE, SCREEN_X/10*4.5-5*PIXELSIZE, 3*TILESIZE - PIXELSIZE, "Drop", @Callback_Drop)
B_Right = ButtonClass.AddButton(SCREEN_X/10*5.5+5*PIXELSIZE, BOARD_Y * TILESIZE + BOARD_OFFSET_Y + 1*TILESIZE, SCREEN_X/10*4.5 - 5*PIXELSIZE, 3*TILESIZE - PIXELSIZE, ">", @Callback_Right)
B_Left = ButtonClass.AddButton(SCREEN_X/10*5.5+5*PIXELSIZE, BOARD_Y * TILESIZE + BOARD_OFFSET_Y + 4*TILESIZE + PIXELSIZE, SCREEN_X/10*4.5-5*PIXELSIZE, 3*TILESIZE - PIXELSIZE, "<", @Callback_Left)
B_Pause = ButtonClass.AddButton(SCREEN_X/10*4.5, BOARD_Y * TILESIZE + BOARD_OFFSET_Y + 1*TILESIZE, SCREEN_X/10*1, 3*TILESIZE - PIXELSIZE, "Pause", @Callback_Pause)
B_Menu = ButtonClass.AddButton(SCREEN_X/10*4.5, BOARD_Y * TILESIZE + BOARD_OFFSET_Y + 4*TILESIZE + PIXELSIZE, SCREEN_X/10*1, 3*TILESIZE - PIXELSIZE, "Menu", @Callback_Menu)
else
B_Pause = ButtonClass.AddButton(SCREEN_X/10*3 - 5*PIXELSIZE, SCREEN_Y - 1.8*TILESIZE, SCREEN_X/10*2, 1.5*TILESIZE, "Pause", @Callback_Pause)
B_Menu = ButtonClass.AddButton(SCREEN_X/10*5 + 5*PIXELSIZE, SCREEN_Y - 1.8*TILESIZE, SCREEN_X/10*2, 1.5*TILESIZE, "Menu", @Callback_Menu)
endif
else 'Lanscape
B_Cycle = ButtonClass.AddButton(0, SCREEN_Y/2 - 4*TILESIZE , 6*TILESIZE, 4*TILESIZE, "Cycle", @Callback_Cycle)
B_Drop = ButtonClass.AddButton(0, SCREEN_Y/2 - 4*TILESIZE + 4*TILESIZE + 5*PIXELSIZE, 6*TILESIZE, 4*TILESIZE, "Drop", @Callback_Drop)
B_Right = ButtonClass.AddButton(SCREEN_X - 6*TILESIZE, SCREEN_Y/2 - 4*TILESIZE , 6*TILESIZE, 4*TILESIZE, ">", @Callback_Right)
B_Left = ButtonClass.AddButton(SCREEN_X - 6*TILESIZE, SCREEN_Y/2 - 4*TILESIZE + 4*TILESIZE + 5*PIXELSIZE, 6*TILESIZE, 4*TILESIZE, "<", @Callback_Left)
B_Pause = ButtonClass.AddButton(0 , SCREEN_Y - 3*TILESIZE, 2*TILESIZE, 2*TILESIZE, "Pause", @Callback_Pause)
B_Menu = ButtonClass.AddButton(SCREEN_X - 2*TILESIZE, SCREEN_Y - 3*TILESIZE, 2*TILESIZE, 2*TILESIZE, "Menu", @Callback_Menu)
endif
B_GameStart = ButtonClass.AddButton(0.5*TILESIZE + BOARD_OFFSET_X, (BOARD_Y/2 - 1.5 ) * TILESIZE + BOARD_OFFSET_Y, (BOARD_X) * TILESIZE, 4*TILESIZE, "START NEW GAME", @Callback_GameStart)
'Settings
B_SettingsLevelDown = ButtonClass.AddButton((TILES_X-6)*TILESIZE, 2*TILESIZE, 2*TILESIZE-2*PIXELSIZE, 2*TILESIZE, "-", @Callback_SettingsLevelDown)
B_SettingsLevelUp = ButtonClass.AddButton((TILES_X-4)*TILESIZE, 2*TILESIZE, 2*TILESIZE-2, 2*TILESIZE, "+", @Callback_SettingsLevelUp)
B_SettingsNumberOfBlocksDown = ButtonClass.AddButton((TILES_X-6)*TILESIZE, 5*TILESIZE, 2*TILESIZE-2*PIXELSIZE, 2*TILESIZE, "-", @Callback_SettingsNumberOfBlocksDown)
B_SettingsNumberOfBlocksUp = ButtonClass.AddButton((TILES_X-4)*TILESIZE, 5*TILESIZE, 2*TILESIZE-2*PIXELSIZE, 2*TILESIZE, "+", @Callback_SettingsNumberOfBlocksUp)
if(SoundOnOFF)
B_SettingsSound = ButtonClass.AddButton((TILES_X-4)*TILESIZE, 8*TILESIZE, 2*TILESIZE-2*PIXELSIZE, 2*TILESIZE, "ON", @Callback_SettingsSound)
else
B_SettingsSound = ButtonClass.AddButton((TILES_X-4)*TILESIZE, 8*TILESIZE, 2*TILESIZE-2*PIXELSIZE, 2*TILESIZE, "OFF", @Callback_SettingsSound)
endif
B_SettingsClose = ButtonClass.AddButton(((TILES_X-3)/2)*TILESIZE, (TILES_Y - 5)*TILESIZE, 4*TILESIZE, 2*TILESIZE, "CLOSE", @Callback_SettingsClose)
ButtonClass.SetActive(B_SettingsLevelUp, false)
ButtonClass.SetActive(B_SettingsLevelDown, false)
ButtonClass.SetActive(B_SettingsNumberOfBlocksUp, false)
ButtonClass.SetActive(B_SettingsNumberOfBlocksDown, false)
ButtonClass.SetActive(B_SettingsSound, false)
ButtonClass.SetActive(B_SettingsClose, false)
end
sub DrawBackground()
local xx,yy
for xx = 1 to SCREEN_X step TILESIZE
for yy = 1 to SCREEN_Y step TILESIZE
BACKGROUND_TILE.draw(xx,yy)
next
next
rect BOARD_OFFSET_X, BOARD_OFFSET_Y, BOARD_OFFSET_X + (BOARD_X + INFO_X) * TILESIZE, BOARD_OFFSET_Y + BOARD_Y * TILESIZE, ColorPalette[10] filled
for yy = 0 to BOARD_Y - 1
FRAME_LEFT_TILE.draw(BOARD_OFFSET_X - TILESIZE, BOARD_OFFSET_Y + yy * TILESIZE)
FRAME_RIGHT_TILE.draw(BOARD_OFFSET_X + (BOARD_X + INFO_X) * TILESIZE, BOARD_OFFSET_Y + yy * TILESIZE)
next
for xx = 0 to BOARD_X + INFO_X - 1
FRAME_BOTTOM_TILE.draw(BOARD_OFFSET_X + xx*TILESIZE, BOARD_OFFSET_Y + BOARD_Y * TILESIZE)
FRAME_TOP_TILE.draw(BOARD_OFFSET_X + xx*TILESIZE, BOARD_OFFSET_Y - TILESIZE)
next
FRAME_CORNER_TOP_LEFT_TILE.draw(BOARD_OFFSET_X - TILESIZE, BOARD_OFFSET_Y - TILESIZE)
FRAME_CORNER_TOP_RIGHT_TILE.draw(BOARD_OFFSET_X + (BOARD_X + INFO_X)*TILESIZE, BOARD_OFFSET_Y - TILESIZE)
FRAME_CORNER_BOTTOM_LEFT_TILE.draw(BOARD_OFFSET_X - TILESIZE, BOARD_OFFSET_Y + BOARD_Y * TILESIZE)
FRAME_CORNER_BOTTOM_RIGHT_TILE.draw(BOARD_OFFSET_X + (BOARD_X + INFO_X)*TILESIZE, BOARD_OFFSET_Y + BOARD_Y*TILESIZE)
end
sub DrawColumn()
local px, py
px = ColumnPositionX * TILESIZE + BOARD_OFFSET_X
py = ColumnPositionY * TILESIZE + BOARD_OFFSET_Y
if(ColumnPositionNewX > -1) then
TempImg =Tiles[0] 'Background Tile
TempImg.draw(px,ColumnPositionY*TILESIZE + BOARD_OFFSET_Y)
TempImg.draw(px,(ColumnPositionY+1)*TILESIZE + BOARD_OFFSET_Y)
TempImg.draw(px,(ColumnPositionY+2)*TILESIZE + BOARD_OFFSET_Y)
TempImg.draw(px,(ColumnPositionY+3)*TILESIZE + BOARD_OFFSET_Y)
ColumnPositionX = ColumnPositionNewX
ColumnPositionNewX = -1
CalcColumnTouchDown()
px = ColumnPositionX * TILESIZE + BOARD_OFFSET_X
else
TempImg =Tiles[0] 'Background Tile
TempImg.draw(px,py)
endif
MicroStep = MicroStep + Speed * TimeStep
if(MicroStep >= TILESIZE)
MicroStep = 0
ColumnPositionY++
py = ColumnPositionY * TILESIZE + BOARD_OFFSET_Y
if(ColumnPositionY > COLUMM_TOUCH_DOWN) then
Board[ColumnPositionX,ColumnPositionY,BOARD_BLOCKS]= Column[0]
Board[ColumnPositionX,ColumnPositionY+1,BOARD_BLOCKS]= Column[1]
Board[ColumnPositionX,ColumnPositionY+2,BOARD_BLOCKS]= Column[2]
GAME_STATE = GAME_REMOVE_BLOCKS
endif
TempImg =Tiles[0] 'Background Tile
TempImg.draw(px,py)
TempImg.draw(px,py + TILESIZE)
TempImg.draw(px,py + 2*TILESIZE)
else
TempImg =Tiles[0] 'Background Tile
'TempImg.draw(px,py)
TempImg.draw(px,py + TILESIZE)
TempImg.draw(px,py + 2*TILESIZE)
TempImg.draw(px,py + 3*TILESIZE)
endif
py = py + MicroStep
py = floor(py / PIXELSIZE) * PIXELSIZE