-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPOBC tutorial code.txt
More file actions
43 lines (39 loc) · 1.24 KB
/
PPOBC tutorial code.txt
File metadata and controls
43 lines (39 loc) · 1.24 KB
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
var sprite_bbox_top = sprite_get_bbox_top(sprite_index)-sprite_get_yoffset(sprite_index);
var sprite_bbox_bottom = sprite_get_bbox_bottom(sprite_index)-sprite_get_yoffset(sprite_index)+1;
var sprite_bbox_left = sprite_get_bbox_left(sprite_index)-sprite_get_xoffset(sprite_index);
var sprite_bbox_right = sprite_get_bbox_right(sprite_index)-sprite_get_xoffset(sprite_index)+1;
//Snap coordinates
snap_x = 0;
snap_y = 0;
//Horizontal
for(var h=0;h<=ceil(abs(hspd));h++) {
var wall_x = collision_real_id(h*sign(hspd),0,oWall);
if wall_x != noone {
var wall_left = wall_x.bbox_left;
var wall_right = wall_x.bbox_right;
if x < wall_left {//right
snap_x = wall_left-sprite_bbox_right;
} else if x > wall_right {//left
snap_x = wall_right-sprite_bbox_left;
}
hspd = 0;
}
}
//Vertical
for(var v=0;v<=ceil(abs(vspd));v++) {
var wall_y = collision_real_id(0,v*sign(vspd),oWall);
if wall_y != noone {
var wall_top = wall_y.bbox_top;
var wall_bottom = wall_y.bbox_bottom;
if y < wall_top {//down
snap_y = wall_top-sprite_bbox_bottom;
} else if y > wall_bottom {//up
snap_y = wall_bottom-sprite_bbox_top;
}
vspd = 0;
}
}
x += hspd;
y += vspd;
if snap_x != 0 x = snap_x;
if snap_y != 0 y = snap_y;