-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example - Platformer ice tiles.bb
181 lines (165 loc) · 3.48 KB
/
Example - Platformer ice tiles.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
;
;
; Platform ice tiles
;
Graphics 640,480,16,2
SetBuffer BackBuffer()
Dim map(15,10)
Type disstile ; open list
Field x,y,timeout
End Type
Type player
Field x#,y#
Field fall,jump
Field fallspeed#,direction
Field slidex#,onicetile
End Type
Global p.player = New player
readlevel(1)
While KeyDown(1) = False
Cls
If MouseDown(1) = True Then p\x = MouseX() : p\y = MouseY()
drawmap
drawplayer
gravity
doicetiles
moveplayer
Flip
Wend
End
Function doicetiles()
If p\onicetile = False Then Return
p\x = p\x + p\slidex
Select p\direction
Case 0
p\slidex = p\slidex - .01
If p\slidex <0 Then p\slidex = 0
Case 1
p\slidex = p\slidex + .01
If p\slidex > 0 Then p\slidex = 0
End Select
If icetilecollision(0,1) = False Then p\onicetile = False
End Function
Function icetilecollision(x1,y1)
px = (p\x+x1) / 32
py = (p\y+y1) / 32
For x=-1 To 1
For y=-1 To 1
If RectsOverlap(px+x,py+y,1,1,0,0,15,10) = True Then
Rect px*32+x*32,py*32+y*32,32,32,False
If map(px+x,py+y) = 2 Then
If RectsOverlap(p\x+x1,p\y+y1,16,16,px*32+x*32,py*32+y*32,32,32) = True Then Return True
End If
EndIf
Next:Next
End Function
Function drawplayer()
Color 255,255,0
Oval p\x,p\y,16,16,True
End Function
Function moveplayer()
If KeyDown(205) = True Then
If playermapcollision(1,0) = False Then
p\x = p\x + 1
p\direction = 0
End If
If icetilecollision(0,1) = True Then
p\slidex = 1
p\onicetile = True
p\x = p\x - 1
End If
End If
If KeyDown(203) = True Then
If playermapcollision(-1,0) = False Then
p\x = p\x - 1
p\direction = 1
End If
If icetilecollision(0,1) = True Then
p\slidex = -1
p\onicetile = True
p\x = p\x + 1
End If
End If
If KeyDown(57) = True Then
If p\jump = False Then
p\jump = True
p\fallspeed = -4
p\fall = True
End If
End If
End Function
Function drawmap()
For x=0 To 15-1
For y=0 To 10-1
Select map(x,y)
Case 1
Color 255,255,255:Rect x*32,y*32,32,32,True
Case 2
Color 155,155,155 : Rect x*32,y*32,32,32,True
End Select
Next:Next
End Function
Function playermapcollision(x1,y1)
px = (p\x+x1) / 32
py = (p\y+y1) / 32
For x=-1 To 1
For y=-1 To 1
If RectsOverlap(px+x,py+y,1,1,0,0,15,10) = True Then
Rect px*32+x*32,py*32+y*32,32,32,False
If map(px+x,py+y) = 1 Or map(px+x,py+y) = 2 Then
If RectsOverlap(p\x+x1,p\y+y1,16,16,px*32+x*32,py*32+y*32,32,32) = True Then Return True
End If
EndIf
Next:Next
If RectsOverlap(p\x+x1,p\y+y1,16,16,15,15,14*32,9*32) = False Then
Return True
End If
End Function
Function gravity()
;
;
If playermapcollision(0,p\fallspeed) = True And p\jump = True Then
p\fallspeed = 0
p\y = p\y/32*32
End If
;
If playermapcollision(0,1) = False And p\fall = False
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
If playermapcollision(0,i) = True Then
p\y = p\y+i/32*32
p\fall = False
p\jump = False
Exit
End If
Next
End If
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,1,1,2,2,2,2,2,2,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,1,1,1,1,1,1,1,1,1,1,1,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 1,1,1,1,2,2,2,2,2,2,1,1,1,1,1