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
|
' Hardwire
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict
Import "types.bmx"
Import "particle.bmx"
Import "sounds.bmx"
Import "gametypes.bmx"
Type TGame
Field level:Int
Field score:Int
Field gm:TGameMap
Field timer:Int
Field alpha:Double
Field alphainc:Double
Field count:Int
Field block:TPiece
Field nextblock:TPiece
Field drop:Int
Method New()
score=0
gm=New TGameMap
level=1
Particles.Clear()
alpha=0.7
alphainc=0.01
count=0
nextblock=TPiece.Create()
drop=False
CreateNext()
End Method
Method SetInitLevel(l:Int)
level=l
SetTimer()
End Method
Method SetTimer()
If drop
timer=5
Else
timer=Max(HERTZ/5,(16-level)*HERTZ/5)
EndIf
End Method
Method LevelUp()
level:+1
count=0
End Method
Method CreateNext()
block=nextblock
block.y=-4
block.x=Pit.WIDTH/2
nextblock=TPiece.Create()
nextblock.x=Pit.WIDTH+3
nextblock.y=1
drop=False
End Method
Method Pause()
Local i:Timage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,MASKEDIMAGE|DYNAMICIMAGE|FILTEREDIMAGE)
GrabImage(i,0,0)
MidHandleImage(i)
SetColor(255,255,255)
FlushKeys()
Local a:Int[]=[0,0,0,0,0,0,0,0]
Local ac:Int[]=[7,6,5,4,3,2,1,0]
While Not KeyHit(GameConfig.kpause)
Cls
Local al:Double=0.3
For Local f:Int=0 Until a.length
SetAlpha(al)
SetRotation(a[f])
SetScale(al,al)
DrawImage(i,GraphicsWidth()/2,GraphicsHeight()/2)
If ac[f]>0
ac[f]:-1
Else
a[f]:+1
EndIf
al:+0.1
Next
SetRotation(0)
SetScale(1,1)
GameGFX.large.Centre("PAUSED",GraphicsHeight()/2-16)
Flip
Wend
SetAlpha(1)
SetRotation(0)
SetScale(1,1)
FlushKeys
End Method
Method Play:Int()
Local playing:Int=True
Cls
GameGFX.large.DrawColoured("SCORE",0,0,255,255,0)
GameGFX.large.Draw(score,0,20)
GameGFX.large.DrawColoured("LEVEL",0,100,255,255,0)
GameGFX.large.Draw(level,0,120)
GameGFX.large.DrawColoured("NEXT",Pit.X(Pit.WIDTH+2),Pit.Y(-1),255,255,0)
nextblock.Draw()
If Not gm.overflow
If KeyHit(KEY_ESCAPE)
playing=False
EndIf
If Not gm.BlockInteract()
timer:-1
If timer<=0
SetTimer()
block.y:+1
If block.Collides(gm)
block.y:-1
block.AddToMap(gm)
count:+1
If count>10
LevelUp()
EndIf
If Not gm.overflow
CreateNext()
EndIf
EndIf
EndIf
If KeyHit(GameConfig.kleft)
block.x:-1
If block.Collides(gm)
block.x:+1
EndIf
EndIf
If KeyHit(GameConfig.kright)
block.x:+1
If block.Collides(gm)
block.x:-1
EndIf
EndIf
If KeyHit(GameConfig.krotright)
block.RotateRight()
If block.Collides(gm)
block.RotateLeft()
EndIf
EndIf
If KeyHit(GameConfig.krotleft)
block.RotateLeft()
If block.Collides(gm)
block.RotateRight()
EndIf
EndIf
If KeyDown(GameConfig.kdrop)
timer=0
'drop=True
EndIf
EndIf
block.Draw()
score:+gm.Draw()*level*10
Else
gm.Draw()
SetAlpha(alpha)
SetColor(255,255,255)
DrawImage(GameGFX.gameover,GraphicsWidth()/2,GraphicsHeight()/2)
SetAlpha(1)
alpha:+alphainc
If alpha<=0.7 Or alpha>=1.0
alpha=Max(0,Min(1,alpha))
alphainc=-alphainc
EndIf
If KeyHit(KEY_ENTER) Or KeyHit(KEY_ESCAPE)
playing=False
EndIf
EndIf
Particles.Draw()
If KeyHit(GameConfig.kpause) And Not gm.overflow
Pause()
EndIf
Flip
Return playing
End Method
End Type
|