-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example - Sideview Plane Game.bb
312 lines (261 loc) · 6.07 KB
/
Example - Sideview Plane 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
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
Function iniplane()
Color 0,0,0
SetBuffer ImageBuffer(lvl)
Color 0,0,11
Rect 100-128,grond - 164,240,168,True
Color 255,255,255
Rect 100,grond+8,30,20,True
SetBuffer BackBuffer()
p.plane = New plane
p\x = 100
p\y = grond
;
p\xac# = 0.009 ; plane acceleration
p\yac# = 0.02 ; plane y acceleration
p\w=16
p\h=4
p\maxx = 2 ; maximum speed
p\airborn_at# = .3 ; .airborn liftoff speed
p\airborn = True
End Function
;drop it in the
; hat baron v2
Graphics 640,480,16,2
SetBuffer BackBuffer()
Global lvl = CreateImage(640,480)
Global hoogte# = GraphicsHeight()
Global breedte# = GraphicsWidth()
Global grond# = hoogte-68
;RuntimeError grond + " L "+ GraphicsHeight()
Global debug = True
Global vert# = GraphicsHeight()/1.2
Type drops
Field x#,y#,w#,h#,incx#,incy#
End Type
;
Type plane
Field x#,y#,w,h,xforce#,yforce#
Field maxx#
Field airborn_at,airborn
Field xac#,yac#
End Type
Type grav
Field g#
End Type
Global grav.grav = New grav
grav\g# = .03
timer = CreateTimer(30)
SeedRnd MilliSecs()
For y=GraphicsHeight()-128 To GraphicsHeight() Step 64
For x = 0 To GraphicsWidth() Step 48
so = Rand(1,2)
If do=True Then
; makelevel x ,y
Else
If so = True Then
; makelevel x,y
End If
End If
Next
do=True
Next
iniplane()
While KeyDown(1) = False
WaitTimer(timer)
Cls
DrawBlock lvl,0,0
drawplane
controls()
handleplane
gravity
updatedrops
drawdrops
Rect GraphicsWidth()/2,GraphicsHeight()-90,16,16,False
For this.plane = Each plane
If Abs(this\xforce) > this\maxx/3 Then Color 0,255,0
If Abs(this\xforce) < this\maxx/3 Then Color 255,0,0
pbar 0,0 ,50,10 ,Abs(this\xforce) ,this\maxx
pbar 0,10,50,10 ,Abs(this\yforce) ,2
pbar 0,20,50,10 ,Abs(this\maxx) ,2
Next
my.plane = First plane
If KeyHit(57) = True Then inidrops(my)
Color 255,0,0
Rect 0,grond,breedte,20,False
; pbar 0,0,110,20,Rand(100),100
Flip
Wend
End
;
Function controls()
this.plane = First plane
If KeyDown(205) = True ; right cursor ; speed
speedup(this\xac)
End If
If KeyDown(208) = True
End If
If KeyDown(200) = True ; up cursor ; up
rotateup(-this\yac)
End If
If KeyDown(203) = True ; cursor back ; brake
speedup(-this\xac)
End If
End Function
Function gravity()
For this.plane = Each plane
If this\airborn = True;;;; <airborn
If this\yforce < 2 Then
this\yforce = this\yforce + .01
; DebugLog "ddd " + this\yforce
End If
If this\maxx > .1 Then this\maxx = this\maxx -.0001
If this\maxx < -.1 Then this\maxx = this\maxx +.0001
; End If
If RectsOverlap(this\x,this\y,1,1,0,0,GraphicsWidth(),GraphicsHeight()) = False Then
this\x = 100
this\y = 100
this\xforce = 0
this\yforce = 0
End If
If this\xforce > 0 Then this\xforce = this\xforce - 0.001
If this\xforce < 0 Then this\xforce = this\xforce + 0.001
End If
If this\airborn = True And this\y > grond Then
this\y = grond
this\xforce = 0
this\yforce = 0
this\airborn = False
End If
If this\airborn = False And this\y < grond Then
this\airborn = True
End If
Next
End Function
Function rotateup(val#)
For this.plane = Each plane
If Abs(this\xforce) > this\maxx/2 Then
this\yforce = this\yforce + val#
End If
Next
End Function
Function speedup(val#)
For this.plane = Each plane
this\xforce = this\xforce + val#
;If Abs(this\xforce) > Abs(this\maxx) Then this\xforce = this\maxx
If this\xforce < 0
If this\xforce < -this\maxx Then this\xforce = -this\maxx
Else
If this\xforce > this\maxx Then this\xforce = this\maxx
End If
; If debug = True Then If Rand(10)=1 Then DebugLog this\xforce
Next
End Function
Function drawplane()
For this.plane = Each plane
temp = CreateImage(4+(Abs(this\xforce*8)),this\h)
SetBuffer ImageBuffer(temp)
ClsColor 255,255,255 :Cls
Color 200,40,20
Rect 0, 0,ImageWidth(temp),ImageHeight(temp)/5,True
Rect 0,(ImageHeight(temp)/5),ImageWidth(temp),ImageHeight(temp)/5,True
Rect 0,(ImageHeight(temp)/5)*2,ImageWidth(temp),ImageHeight(temp)/5,True
SetBuffer BackBuffer()
If this\xforce>0 RotateImage temp , this\yforce * 12
If this\xforce<0 RotateImage temp , -this\yforce * 12
DrawImage temp,this\x,this\y
FreeImage temp
Next
End Function
;
Function handleplane()
For this.plane = Each plane
this\x = this\x + this\xforce#
this\y = this\y + this\yforce#
If this\yforce < -1 Then this\yforce = -1
Next
End Function
;
Function pbar(x,y,w,h,s#,max#)
;
a# = (w/max)*s
; Color 255,0,0
Rect x,y,a,10,True
; Color 100,100,100
Rect x,y,w,h,False
;
End Function
Function makelevel(x1,y)
; SetBuffer CanvasBuffer(can)
SetBuffer ImageBuffer(lvl)
; x1=x1+20
; y=y-140
; For x=x1 To 320 Step 48
t=CreateImage(64,64)
SetBuffer ImageBuffer(t)
Color 255,255,255
While i < 320
a = (Cos(i+Rnd(i)))*22
b = (Sin(Rand(i)))*22
a = a ;+ x1
b = b ;+ y
; If b > 30 And b<50 Then Color 20,130,250 Else Color 255,255,255
Color 255,255,255
a1=a+22
a2=b+Rand(20)
a3=Rand(13,10)
a4=Rand(3,20)+ls
Rect a1,a2,a3,a4
Oval a1,a2,a3+4,a4+4
;Rect a+22,b+Rand(30),Rand(13,10),Rand(3,10) + ls
Oval a+22,b,Rand(13,15),Rand(13,35) + ls
;
;
ls = 0
If a < 20 Then ls = Rand(15)
If a > 140 Then ls = Rand(30)
;
i=i+10
;
Wend
; Color 100,100,100
; Rect 0,0,64,64,False
SetBuffer ImageBuffer(lvl)
DrawImage t,x1,y
If Rand(5) = True Then
Color 255,255,255
Rect x1,y,32,32,True
End If
If Rand(5) = True Then
Color 255,255,255
Rect x1+32,y,32,32,True
End If
; Next
SetBuffer BackBuffer()
End Function
Function inidrops(this.plane)
;
that.drops = New drops
that\x = this\x
that\y = this\y
that\incy = this\yforce
that\incx = this\xforce
;
End Function
Function updatedrops()
For this.drops = Each drops
this\x = this\x + this\incx
this\y = this\y + this\incy
this\incy = this\incy + grav\g
If this\incx > 0 Then this\incx = this\incx - .01
If this\incx < 0 Then this\incx = this\incx + .01
If RectsOverlap(this\x,this\y,this\w,this\h,0,0,breedte,hoogte) = False
Delete this
End If
Next
End Function
Function drawdrops()
For this.drops = Each drops
Color 255,255,255
Oval this\x,this\y,6,6,True
Next
End Function