-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.adept
228 lines (211 loc) · 7.86 KB
/
world.adept
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
// ---------------------------- world.adept ----------------------------
// Module for detecting and handling world events
// ---------------------------------------------------------------------
import 'sys/cstdio.adept'
import 'gamedata.adept'
func isPlayerOnGround(window *GLFWwindow, gamedata *GameData) bool {
player_box AABB; player_box = gamedata.getPlayerBox()
player_box.y += 2.0f
// Test to see if the player is on a platform
i usize = 0; while i != gamedata.platforms_length {
if gamedata.platforms[i].box.intersecting(&player_box) {
if(gamedata.platforms[i].type == PLATFORM_TYPE_BOUNCY){
gamedata.player_vspeed = -20.0f
gamedata.resources_ref.bounce.play()
} else if(gamedata.platforms[i].type == PLATFORM_TYPE_DEATH){
gamedata.reset()
gamedata.resources_ref.death.play()
} else if(gamedata.platforms[i].type == PLATFORM_TYPE_ASCEND){
if gamedata.platforms[i].moveY(gamedata, -2.0f) {
unless movePlayerY(gamedata, -2.0f), gamedata.reset(); gamedata.resources_ref.death.play()
}
return true
} else if(gamedata.platforms[i].type == PLATFORM_TYPE_DESCEND){
if gamedata.platforms[i].moveY(gamedata, 2.0f) {
unless movePlayerY(gamedata, 2.0f), gamedata.platforms[i].box.y -= 2.0f
}
return true
} else if(gamedata.platforms[i].type == PLATFORM_TYPE_ELEVATOR){
if gamedata.player_x <= gamedata.platforms[i].box.x {
// Ascend
if gamedata.platforms[i].moveY(gamedata, -2.0f) {
unless movePlayerY(gamedata, -2.0f), gamedata.reset(); gamedata.resources_ref.death.play()
}
} else {
// Descend
if gamedata.platforms[i].moveY(gamedata, 2.0f) {
unless movePlayerY(gamedata, 2.0f), gamedata.platforms[i].box.y -= 2.0f
}
}
return true
} else return true
}
i += 1
}
// Test to see if the player is on a box
i = 0; while i != gamedata.boxes_length {
box *Box = &gamedata.boxes[i]
if box.gone == false and box.box.intersecting(&player_box), return true
i += 1
}
// Test to see if the player is on a jumper
i = 0; while i != gamedata.jumpers_length {
jumper *Jumper = &gamedata.jumpers[i]
if jumper.gone == false and jumper.box.intersecting(&player_box) {
if jumper.jumping, gamedata.reset(); gamedata.resources_ref.death.play()
return true
}
i += 1
}
return false
}
func onGround(this *Box, gamedata *GameData) bool {
check AABB; check.set(&this.box); check.y += 1.0
// Test to see the box is on a platform
i usize = 0; while i != gamedata.platforms_length {
if gamedata.platforms[i].box.intersecting(&check) {
if(gamedata.platforms[i].type == PLATFORM_TYPE_BOUNCY){
this.vspeed = -5.0f
gamedata.resources_ref.bounce.play()
return false
} else if(gamedata.platforms[i].type == PLATFORM_TYPE_DESTROY){
this.gone = true
gamedata.resources_ref.destroy.play()
} else {
if gamedata.platforms[i].type == PLATFORM_TYPE_HIDDEN and gamedata.platforms[i].triggered == false {
gamedata.platforms[i].triggered = true; gamedata.resources_ref.discover.play()
}
return true
}
}
i += 1
}
// Test to see if the box is on another box
i = 0; while i != gamedata.boxes_length {
box *Box = &gamedata.boxes[i]
if box.gone == false and box.box.intersecting(&check) and this.box.equals(&box.box) == false, return true
i += 1
}
// Test to see if the box is on a jumper
i = 0; while i != gamedata.jumpers_length {
jumper *Jumper = &gamedata.jumpers[i]
if jumper.gone == false and jumper.box.intersecting(&check) and this.box.equals(&jumper.box) == false, return true
i += 1
}
return false
}
func isColliding(this *Box, gamedata *GameData) bool {
// Test to see if the box is colliding with a platform
i usize = 0; while i != gamedata.platforms_length {
if gamedata.platforms[i].box.intersecting(&this.box), return true
i += 1
}
// Test to see if the box is colliding with another block
i = 0; while i != gamedata.boxes_length {
box *Box = &gamedata.boxes[i]
if box.gone == false and box.box.intersecting(&this.box) and this.box.equals(&box.box) == false, return true
i += 1
}
// Test to see if the box is colliding with a jumper
i = 0; while i != gamedata.jumpers_length {
jumper *Jumper = &gamedata.jumpers[i]
if jumper.gone == false and jumper.box.intersecting(&this.box) and this.box.equals(&jumper.box) == false, return true
i += 1
}
return false
}
func isPlayerColliding(gamedata *GameData) bool {
// Test to see if the player is colliding with a platform
i usize = 0; while i != gamedata.platforms_length {
if gamedata.platforms[i].box.intersecting(gamedata.player_x + 48.0f, gamedata.player_y + 20.0f, 32.0f, 108.0f), return true
i += 1
}
// Test to see if the player is colliding with a box
i = 0; while i != gamedata.boxes_length {
box *Box = &gamedata.boxes[i]
if box.gone == false and box.box.intersecting(gamedata.player_x + 48.0f, gamedata.player_y + 20.0f, 32.0f, 108.0f), return true
i += 1
}
// Test to see if the player is colliding with a jumper
i = 0; while i != gamedata.jumpers_length {
jumper *Jumper = &gamedata.jumpers[i]
if jumper.gone == false and jumper.box.intersecting(gamedata.player_x + 48.0f, gamedata.player_y + 20.0f, 32.0f, 108.0f), return true
i += 1
}
return false
}
func playerOnTopOf(this *Box, gamedata *GameData) bool {
return this.box.intersecting(gamedata.player_x + 48.0f, gamedata.player_y + 20.0f + 2.0f, 32.0f, 108.0f)
}
func playerJumpCollide(gamedata *GameData, by_y float) bool {
// Returns whether snapping occured
player_box AABB = gamedata.getPlayerBox()
i usize = 0; while i != gamedata.platforms_length {
platform *Platform = &gamedata.platforms[i]
if platform.box.intersecting(&player_box) {
if platform.type == PLATFORM_TYPE_HIDDEN and platform.triggered == false {
platform.triggered = true; gamedata.resources_ref.discover.play()
}
if gamedata.player_y - by_y + 64.0f > platform.box.y {
gamedata.player_y -= by_y; gamedata.player_vspeed = 0.0f
} else {
gamedata.player_y = platform.box.y - 128.0f; gamedata.player_vspeed = 0.0f
return true
}
}
i += 1
}
i = 0; while i != gamedata.boxes_length {
box *Box = &gamedata.boxes[i]
if box.gone == false and box.box.intersecting(&player_box) {
if gamedata.player_y - gamedata.player_vspeed + 64.0f > box.box.y {
gamedata.player_y -= by_y; gamedata.player_vspeed = 0.0f
} else {
gamedata.player_y = box.box.y - 128.0f; gamedata.player_vspeed = 0.0f
return true
}
}
i += 1
}
i = 0; while i != gamedata.jumpers_length {
jumper *Jumper = &gamedata.jumpers[i]
if jumper.gone == false and jumper.box.intersecting(&player_box) {
if gamedata.player_y - gamedata.player_vspeed + 64.0f > jumper.box.y {
gamedata.player_y -= by_y; gamedata.player_vspeed = 0.0f
} else {
gamedata.player_y = jumper.box.y - 128.0f; gamedata.player_vspeed = 0.0f
return true
}
}
i += 1
}
gamedata.player_vspeed += 0.9f
return false
}
func playerHandlePunch(gamedata *GameData, resources *Resources) void {
player_hit_offset float
if gamedata.player_anim == gamedata.player_punch_r_anim, player_hit_offset = 32.0f
else player_hit_offset = -32.0f
i usize = 0; while i != gamedata.boxes_length {
box *Box = &gamedata.boxes[i]
if box.gone == false and box.box.intersecting(gamedata.player_x + 48.0f + player_hit_offset, gamedata.player_y + 20.0f, 32.0f, 108.0f) {
if player_hit_offset > 0.0, box.hspeed = 5.0
else box.hspeed = -5.0
}
i += 1
}
i = 0; while i != gamedata.jumpers_length {
jumper *Jumper = &gamedata.jumpers[i]
if jumper.gone == false and jumper.box.intersecting(gamedata.player_x + 48.0f + player_hit_offset, gamedata.player_y + 20.0f, 32.0f, 108.0f) {
if player_hit_offset > 0.0, jumper.hspeed = 5.0
else jumper.hspeed = -5.0
jumper.jumping = false
}
i += 1
}
}
func distance(x1 float, y1 float, x2 float, y2 float) float {
xdiff float = x2 - x1
ydiff float = y2 - y1
return cast float sqrt(cast double (xdiff * xdiff + ydiff * ydiff))
}