commit
ab2e64c111
@ -44,6 +44,19 @@ pub fn modify_player_based_on_forces(
|
|||||||
translated_rect.check_collision_recs(&player_rect)
|
translated_rect.check_collision_recs(&player_rect)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
let check_player_colliding_with_colliders_forwards = || {
|
||||||
|
colliders.iter().any(|rect| {
|
||||||
|
let mut translated_rect = rect.clone();
|
||||||
|
translated_rect.y += level_height_offset;
|
||||||
|
translated_rect.x += WORLD_LEVEL_X_OFFSET;
|
||||||
|
translated_rect.check_collision_recs(&Rectangle{
|
||||||
|
x: player_rect.x + 1.0,
|
||||||
|
y: player_rect.y - 1.0 ,
|
||||||
|
width: player_rect.width,
|
||||||
|
height: player_rect.height,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// If the player is colliding, only apply the x force
|
// If the player is colliding, only apply the x force
|
||||||
if (check_player_colliding_with_floor()
|
if (check_player_colliding_with_floor()
|
||||||
@ -66,7 +79,7 @@ pub fn modify_player_based_on_forces(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check sideways collisions
|
// Check sideways collisions
|
||||||
if player.velocity.y == 0.0 && check_player_colliding_with_colliders(){
|
if player.velocity.y == 0.0 && check_player_colliding_with_colliders_forwards(){
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ impl MainCharacter {
|
|||||||
movement_force: Vector2::zero(),
|
movement_force: Vector2::zero(),
|
||||||
velocity: Vector2::zero(),
|
velocity: Vector2::zero(),
|
||||||
base_velocity: Vector2::new(0.0, GRAVITY_PPS),
|
base_velocity: Vector2::new(0.0, GRAVITY_PPS),
|
||||||
size: Vector2::new(80.0, 100.0),
|
size: Vector2::new(60.0, 100.0),
|
||||||
sprite_sheet: AnimatedSpriteSheet::new(
|
sprite_sheet: AnimatedSpriteSheet::new(
|
||||||
sprite_sheet,
|
sprite_sheet,
|
||||||
Vector2::new(300.0, 300.0),
|
Vector2::new(300.0, 300.0),
|
||||||
@ -69,8 +69,8 @@ impl MainCharacter {
|
|||||||
|
|
||||||
// Handle extra external forces based on the character state
|
// Handle extra external forces based on the character state
|
||||||
self.movement_force = match state {
|
self.movement_force = match state {
|
||||||
CharacterState::Running => Vector2::new(12.0, 0.0),
|
CharacterState::Running => Vector2::new(10.0, 0.0),
|
||||||
CharacterState::Jumping => Vector2::new(12.0, -30.0),
|
CharacterState::Jumping => Vector2::new(10.0, -30.0),
|
||||||
CharacterState::Dashing => Vector2::new(30.0, -20.0),
|
CharacterState::Dashing => Vector2::new(30.0, -20.0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,20 +33,32 @@ pub fn render_character_in_camera_space(
|
|||||||
);
|
);
|
||||||
player.sprite_sheet.render(
|
player.sprite_sheet.render(
|
||||||
raylib,
|
raylib,
|
||||||
player.position.sub(player.size.div(2.0)),
|
player
|
||||||
|
.position
|
||||||
|
.sub(Vector2::new(player.size.y, player.size.y).div(4.0)),
|
||||||
Some(Vector2::new(player.size.y, player.size.y)),
|
Some(Vector2::new(player.size.y, player.size.y)),
|
||||||
Some(frame_id),
|
Some(frame_id),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Possibly render a debug vector
|
// Possibly render a debug vector
|
||||||
if config.debug_view {
|
// if config.debug_view {
|
||||||
raylib.draw_line_v(
|
raylib.draw_line_v(
|
||||||
player.position.sub(player.size.div(2.0)),
|
player.position.sub(player.size.div(2.0)),
|
||||||
player
|
player
|
||||||
.position
|
.position
|
||||||
.sub(player.size.div(2.0))
|
.sub(player.size.div(2.0))
|
||||||
.add(player.velocity.mul(10.0).add(Vector2::new(0.0, 100.0))),
|
.add(player.velocity.mul(10.0).add(Vector2::new(0.0, 100.0))),
|
||||||
Color::RED,
|
Color::RED,
|
||||||
);
|
);
|
||||||
}
|
raylib.draw_rectangle_lines_ex(
|
||||||
|
Rectangle::new(
|
||||||
|
player.position.x - (player.size.x / 2.0),
|
||||||
|
player.position.y - (player.size.x / 2.0),
|
||||||
|
player.size.x,
|
||||||
|
player.size.y,
|
||||||
|
),
|
||||||
|
2,
|
||||||
|
Color::RED,
|
||||||
|
);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user