Skip to content

Commit dcd6235

Browse files
Made blocks work better in platformer mode
you can hump them now
1 parent 066e8d3 commit dcd6235

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

src/game/playing/hitboxes.rs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn hitbox_collision(
1010
small_player: Rect,
1111
rotation: &mut f32,
1212
obj_grid: &Vec<ObjectStruct>,
13-
world_offset: f32,
13+
world_offset: &mut f32,
1414
player_cam_y: f32,
1515
velocity_y: &Cell<f32>,
1616
gravity: &Cell<f32>,
@@ -32,33 +32,52 @@ pub fn hitbox_collision(
3232
stars: &mut u32,
3333
main_levels: &mut Vec<MainLevel>,
3434
level_mode: u8,
35-
current_level: u8
35+
current_level: u8,
36+
current_mode: String
3637
) {
3738
for object in obj_grid {
3839
let obj_y = ((screen_height() / 1.15 - 25.0) + (object.y as f32 - 500.0)) + 6.0;
3940

4041
match object.id {
4142
1 => {
4243
*kill_player |= centered_player.overlaps(&Rect {
43-
x: object.x as f32 - world_offset + 15.0,
44+
x: object.x as f32 - *world_offset + 15.0,
4445
y: obj_y as f32 + 5.0,
4546
w: 10.0,
4647
h: 20.0
4748
});
4849
}
4950

5051
2 | 10 | 11 | 12 | 13 | 14 => {
51-
*kill_player |= small_player.overlaps(&Rect {
52-
x: object.x as f32 - world_offset,
53-
y: obj_y as f32 + 10.0 - player_cam_y as f32,
54-
w: 3.0,
55-
h: 20.0
56-
});
52+
if current_mode == "2" {
53+
if centered_player.overlaps(&Rect {
54+
x: object.x as f32 - *world_offset,
55+
y: obj_y as f32 + 20.0 - player_cam_y as f32,
56+
w: 3.0,
57+
h: 3.0
58+
}) {
59+
*world_offset = object.x as f32 - 220.0
60+
} else if centered_player.overlaps(&Rect {
61+
x: object.x as f32 + 40.0 - *world_offset,
62+
y: obj_y as f32 + 20.0 - player_cam_y as f32,
63+
w: 3.0,
64+
h: 3.0
65+
}) {
66+
*world_offset = object.x as f32 - 140.0
67+
}
68+
} else {
69+
*kill_player |= small_player.overlaps(&Rect {
70+
x: object.x as f32 - *world_offset,
71+
y: obj_y as f32 + 10.0 - player_cam_y as f32,
72+
w: 3.0,
73+
h: 20.0
74+
});
75+
}
5776

5877
if centered_player.overlaps(&Rect {
59-
x: object.x as f32 - world_offset + 3.0,
78+
x: object.x as f32 - *world_offset + 3.0,
6079
y: obj_y as f32 + 1.0 - player_cam_y as f32,
61-
w: 37.0,
80+
w: 35.0,
6281
h: 3.0
6382
}) {
6483
if velocity_y.get() >= 0.0 {
@@ -75,9 +94,9 @@ pub fn hitbox_collision(
7594
}
7695

7796
if centered_player.overlaps(&Rect {
78-
x: object.x as f32 - world_offset + 3.0,
97+
x: object.x as f32 - *world_offset + 3.0,
7998
y: obj_y as f32 + 38.0 - player_cam_y as f32,
80-
w: 37.0,
99+
w: 35.0,
81100
h: 3.0
82101
}) {
83102
if velocity_y.get() <= 0.0 {
@@ -97,7 +116,7 @@ pub fn hitbox_collision(
97116
}
98117

99118
if centered_player.overlaps(&Rect {
100-
x: object.x as f32 - world_offset + 80.0,
119+
x: object.x as f32 - *world_offset + 80.0,
101120
y: obj_y as f32 - player_cam_y as f32 + 10.0,
102121
w: 3.0,
103122
h: 20.0,
@@ -108,7 +127,7 @@ pub fn hitbox_collision(
108127

109128
3 | 21 => {
110129
if centered_player.overlaps( &Rect {
111-
x: object.x as f32 - world_offset,
130+
x: object.x as f32 - *world_offset,
112131
y: obj_y as f32 - player_cam_y as f32 + 35.0,
113132
w: 40.0,
114133
h: 5.0
@@ -142,7 +161,7 @@ pub fn hitbox_collision(
142161

143162
4 | 22 | 26 => {
144163
if centered_player.overlaps(&Rect {
145-
x: object.x as f32 - 10.0 - world_offset,
164+
x: object.x as f32 - 10.0 - *world_offset,
146165
y: obj_y as f32 - 10.0 - player_cam_y as f32,
147166
w: 60.0,
148167
h: 60.0
@@ -176,7 +195,7 @@ pub fn hitbox_collision(
176195

177196
5 | 6 | 8 | 9 | 24 | 25 | 17 | 18 | 19 | 20 => {
178197
if centered_player.overlaps(&Rect {
179-
x: object.x as f32 - world_offset + if object.rotation == 0 || object.rotation == 180 || object.rotation == -180 { 10.0 } else { -20.0 },
198+
x: object.x as f32 - *world_offset + if object.rotation == 0 || object.rotation == 180 || object.rotation == -180 { 10.0 } else { -20.0 },
180199
y: obj_y as f32 - if object.rotation == 0 || object.rotation == 180 || object.rotation == -180 { 0.0 } else { -31.0 } - player_cam_y as f32,
181200
w: if object.rotation == 0 || object.rotation == 180 || object.rotation == -180 { 20.0 } else { 80.0 },
182201
h: if object.rotation == 0 || object.rotation == 180 || object.rotation == -180 { 80.0 } else { 20.0 }
@@ -215,7 +234,7 @@ pub fn hitbox_collision(
215234

216235
7 => {
217236
*kill_player |= centered_player.overlaps(&Rect {
218-
x: object.x as f32 - world_offset + 20.0,
237+
x: object.x as f32 - *world_offset + 20.0,
219238
y: obj_y as f32 + if object.rotation > 145 || object.rotation < -145 { 5.0 } else { 25.0 } - player_cam_y as f32,
220239
w: 10.0,
221240
h: 10.0
@@ -224,7 +243,7 @@ pub fn hitbox_collision(
224243

225244
15 => {
226245
if centered_player.overlaps(&Rect {
227-
x: object.x as f32 - world_offset,
246+
x: object.x as f32 - *world_offset,
228247
y: obj_y,
229248
w: 40.0,
230249
h: 40.0
@@ -239,7 +258,7 @@ pub fn hitbox_collision(
239258

240259
23 => {
241260
if centered_player.overlaps(&Rect {
242-
x: object.x as f32 - world_offset,
261+
x: object.x as f32 - *world_offset,
243262
y: obj_y - player_cam_y,
244263
w: 40.0,
245264
h: 40.0
@@ -299,7 +318,7 @@ pub fn hitbox_draw(
299318
draw_rectangle_lines(
300319
object.x as f32 - world_offset + 3.0,
301320
obj_y as f32 + 1.0 - player_cam_y as f32,
302-
37.0,
321+
35.0,
303322
3.0,
304323
2.0,
305324
BLUE
@@ -308,7 +327,7 @@ pub fn hitbox_draw(
308327
draw_rectangle_lines(
309328
object.x as f32 - world_offset + 3.0,
310329
obj_y as f32 + 38.0 - player_cam_y as f32,
311-
37.0,
330+
35.0,
312331
3.0,
313332
2.0,
314333
BLUE

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ async fn main() {
722722
small_player,
723723
&mut rotation,
724724
&obj_grid,
725-
world_offset,
725+
&mut world_offset,
726726
player_cam_y,
727727
&velocity_y.0,
728728
&gravity.0,
@@ -744,7 +744,8 @@ async fn main() {
744744
&mut stars,
745745
&mut main_levels,
746746
level_mode,
747-
current_level
747+
current_level,
748+
current_mode.clone()
748749
);
749750

750751
match current_gamemode {

0 commit comments

Comments
 (0)