-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample - Platformer lasers.bb
199 lines (181 loc) · 3.92 KB
/
Example - Platformer lasers.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
; Platformer with lasers
Graphics 640,480,16,2
SetBuffer BackBuffer()
Dim map(15,10)
Type player
Field x#,y#
Field fall,fallspeed#,jump
Field direction
Field firedelay
End Type
Global p.player = New player
Type laser
Field x#,y#,velx#,vely#
End Type
readlevel(1)
p\x = 0 : p\y = 32*7 : p\direction = 1
While KeyDown(1) = False
Cls
If MouseDown(1) = True Then p\x = MouseX() : p\y = MouseY()
drawlevel
drawplayer
drawlasers
updatelasers
lasermapcollision
gravity
playercontrols
Text 0,0,playermapcollision(0,0)
Flip
Wend
End
Function inilaser(x,y,dir)
this.laser = New laser
this\x = x
this\y = y
this\velx = 3.5*dir
this.laser = New laser
this\x = x
this\y = y
this\velx = 3.5*dir
this\vely = -.2
this.laser = New laser
this\x = x
this\y = y
this\velx = 3.5*dir
this\vely = .2
End Function
Function updatelasers()
For this.laser = Each laser
this\x = this\x + this\velx
this\y = this\y + this\vely
Next
End Function
Function drawlasers()
For this.laser = Each laser
Color 255,0,0
Oval this\x,this\y,8,8,True
Next
End Function
Function lasermapcollision()
For this.laser = Each laser
px = (this\x) / 32
py = (this\y) / 32
For y1 = -1 To 1
For x1 = -1 To 1
If RectsOverlap(px+x1,py+y1,1,1,0,0,15,10) = True Then
If map(px+x1,py+y1) = 1 Then
If RectsOverlap(this\x+x,this\y+y,8,8,px*32+x1*32,py*32+y1*32,32,32) = True Then
delout = True
End If
End If
End If
Next:Next
If RectsOverlap(this\x+x,this\y+y,8,8,0,0,15*32,10*32) = False Then
delout = True
End If
If delout = True Then Delete this : delout = False
Next
End Function
Function playercontrols()
If KeyDown(205) = True Then ; right
p\direction = 1
If playermapcollision(1,0) = False Then
p\x = p\x + 1
End If
End If
If KeyDown(203) = True Then ; left
p\direction = 2
If playermapcollision(-1,0) = False Then
p\x = p\x - 1
End If
End If
If KeyDown(200) = True And p\jump = False Then
If playermapcollision(0,-1) = False Then
p\jump = True : p\fall = True
p\fallspeed = - 4
End If
End If
If KeyDown(57) = True ; space = fire
If p\firedelay < MilliSecs() Then
Select p\direction
Case 1 ; right
inilaser(p\x,p\y,1)
Case 2 ; left
inilaser(p\x,p\y,-1)
End Select
p\firedelay = MilliSecs() + 200
End If
End If
End Function
Function gravity()
If playermapcollision(0,p\fallspeed) = True And p\jump = True Then
p\y = p\y/32*32
p\fallspeed = 0
End If
If playermapcollision(0,1) = False And p\fall = False Then
p\fall = True
p\fallspeed = 1
End If
If p\fall = True Then
p\y=p\y + p\fallspeed
p\fallspeed = p\fallspeed + .1
For i=0 To p\fallspeed+1
If playermapcollision(0,i) = True Then
p\fall = False
p\jump = False
p\y = p\y+i/32*32
Exit
End If
Next
End If
End Function
Function playermapcollision(x,y)
Local px = (p\x + x) / 32
Local py = (p\y + y) / 32
For y1 = -1 To 1
For x1 = -1 To 1
If RectsOverlap(px+x1,py+y1,1,1,0,0,15,10) = True Then
If map(px+x1,py+y1) = 1 Then
If RectsOverlap(p\x+x,p\y+y,16,16,px*32+x1*32,py*32+y1*32,32,32) = True Then Return True
End If
End If
Next:Next
If RectsOverlap(p\x+x,p\y+y,17,16,16,0,14*32,9*32) = False Then
Return True
End If
End Function
Function drawplayer()
Color 255,255,0
Oval p\x,p\y,16,16,True
End Function
Function drawlevel()
For y=0 To 10-1
For x=0 To 15-1
Select map(x,y)
Case 1
Color 255,255,255
Rect x*32,y*32,32,32,True
End Select
Next:Next
End Function
Function readlevel(level)
Select level
Case 1:Restore level1
End Select
For y=0 To 10-1
For x=0 To 15-1
Read a
map(x,y) = a
Next:Next
End Function
.level1
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,1,1,1,1,1,1,1,1,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1
Data 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,1,1,1,1,1,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1