commit
5879f55b68
@ -26,6 +26,9 @@
|
|||||||
"width": 56,
|
"width": 56,
|
||||||
"height": 313
|
"height": 313
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"kill":[
|
||||||
|
|
||||||
],
|
],
|
||||||
"win": {
|
"win": {
|
||||||
"x": 12000,
|
"x": 12000,
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
"width": 704,
|
"width": 704,
|
||||||
"height": 64
|
"height": 64
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"kill":[
|
||||||
|
|
||||||
],
|
],
|
||||||
"win": {
|
"win": {
|
||||||
"x": 12000,
|
"x": 12000,
|
||||||
|
@ -13,6 +13,7 @@ pub const GRAVITY_PPS: f32 = 2.0;
|
|||||||
pub fn modify_player_based_on_forces(
|
pub fn modify_player_based_on_forces(
|
||||||
player: &mut MainCharacter,
|
player: &mut MainCharacter,
|
||||||
colliders: &Vec<Rectangle>,
|
colliders: &Vec<Rectangle>,
|
||||||
|
killers: &Vec<Rectangle>,
|
||||||
level_height_offset: f32,
|
level_height_offset: f32,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
trace!("Player state: {:?}", player.current_state);
|
trace!("Player state: {:?}", player.current_state);
|
||||||
@ -25,7 +26,7 @@ pub fn modify_player_based_on_forces(
|
|||||||
let predicted_player_position = player.position + player.velocity;
|
let predicted_player_position = player.position + player.velocity;
|
||||||
|
|
||||||
// Calculate a bounding rect around the player both now, and one frame in the future
|
// Calculate a bounding rect around the player both now, and one frame in the future
|
||||||
let mut player_rect = Rectangle::new(
|
let player_rect = Rectangle::new(
|
||||||
predicted_player_position.x - (player.size.x / 2.0),
|
predicted_player_position.x - (player.size.x / 2.0),
|
||||||
predicted_player_position.y - (player.size.x / 2.0),
|
predicted_player_position.y - (player.size.x / 2.0),
|
||||||
player.size.x,
|
player.size.x,
|
||||||
@ -48,6 +49,15 @@ pub fn modify_player_based_on_forces(
|
|||||||
|| translated_rect.check_collision_recs(&predicted_player_rect)
|
|| translated_rect.check_collision_recs(&predicted_player_rect)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
let check_player_colliding_with_killers = || {
|
||||||
|
killers.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(&player_rect.clone())
|
||||||
|
|| translated_rect.check_collision_recs(&predicted_player_rect)
|
||||||
|
})
|
||||||
|
};
|
||||||
let check_player_colliding_with_colliders_forwards = || {
|
let check_player_colliding_with_colliders_forwards = || {
|
||||||
colliders.iter().any(|rect| {
|
colliders.iter().any(|rect| {
|
||||||
let mut translated_rect = rect.clone();
|
let mut translated_rect = rect.clone();
|
||||||
@ -76,10 +86,11 @@ pub fn modify_player_based_on_forces(
|
|||||||
return player.update_player(
|
return player.update_player(
|
||||||
Some(CharacterState::Running),
|
Some(CharacterState::Running),
|
||||||
colliders,
|
colliders,
|
||||||
|
killers,
|
||||||
level_height_offset,
|
level_height_offset,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}else if player.current_state == CharacterState::Running {
|
} else if player.current_state == CharacterState::Running {
|
||||||
player.override_state(CharacterState::Jumping);
|
player.override_state(CharacterState::Jumping);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,22 +98,27 @@ pub fn modify_player_based_on_forces(
|
|||||||
player.position += player.velocity;
|
player.position += player.velocity;
|
||||||
|
|
||||||
// Re-calculate the player rect
|
// Re-calculate the player rect
|
||||||
player_rect = Rectangle::new(
|
let player_rect = Rectangle::new(
|
||||||
player.position.x - (player.size.x / 2.0),
|
player.position.x - (player.size.x / 2.0),
|
||||||
player.position.y - (player.size.x / 2.0),
|
player.position.y - (player.size.x / 2.0),
|
||||||
player.size.x,
|
player.size.x,
|
||||||
player.size.y,
|
player.size.y,
|
||||||
);
|
);
|
||||||
|
|
||||||
if player.position.y > 50.0 || colliders.iter().any(|rect| {
|
if player.position.y > 50.0
|
||||||
let mut translated_rect = rect.clone();
|
|| colliders.iter().any(|rect| {
|
||||||
translated_rect.y += level_height_offset;
|
let mut translated_rect = rect.clone();
|
||||||
translated_rect.x += WORLD_LEVEL_X_OFFSET;
|
translated_rect.y += level_height_offset;
|
||||||
translated_rect.check_collision_recs(&player_rect)
|
translated_rect.x += WORLD_LEVEL_X_OFFSET;
|
||||||
}) {
|
translated_rect.check_collision_recs(&player_rect)
|
||||||
|
})
|
||||||
|
{
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if check_player_colliding_with_killers() {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ impl MainCharacter {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state: Option<CharacterState>,
|
state: Option<CharacterState>,
|
||||||
colliders: &Vec<Rectangle>,
|
colliders: &Vec<Rectangle>,
|
||||||
|
killers: &Vec<Rectangle>,
|
||||||
level_height_offset: f32,
|
level_height_offset: f32,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
if let Some(state) = state {
|
if let Some(state) = state {
|
||||||
@ -81,7 +82,7 @@ impl MainCharacter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the player based on the new velocity
|
// Update the player based on the new velocity
|
||||||
modify_player_based_on_forces(self, colliders, level_height_offset)
|
modify_player_based_on_forces(self, colliders, killers, level_height_offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
|
@ -8,6 +8,7 @@ pub mod loader;
|
|||||||
pub struct LevelZones {
|
pub struct LevelZones {
|
||||||
pub appear: Vec<Rectangle>,
|
pub appear: Vec<Rectangle>,
|
||||||
pub disappear: Vec<Rectangle>,
|
pub disappear: Vec<Rectangle>,
|
||||||
|
pub kill: Vec<Rectangle>,
|
||||||
pub win: Rectangle,
|
pub win: Rectangle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
|
|||||||
let _ = self.player.update_player(
|
let _ = self.player.update_player(
|
||||||
Some(CharacterState::Running),
|
Some(CharacterState::Running),
|
||||||
&cur_level.colliders,
|
&cur_level.colliders,
|
||||||
|
&cur_level.zones.kill,
|
||||||
-cur_level.platform_tex.height as f32,
|
-cur_level.platform_tex.height as f32,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -133,7 +134,6 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
|
|||||||
// Render the HUD
|
// Render the HUD
|
||||||
self.render_screen_space(&mut renderer, &context.config);
|
self.render_screen_space(&mut renderer, &context.config);
|
||||||
|
|
||||||
|
|
||||||
// Check if the player won
|
// Check if the player won
|
||||||
let cur_level = self.levels.get(context.current_level).unwrap();
|
let cur_level = self.levels.get(context.current_level).unwrap();
|
||||||
if self.player.position.x > cur_level.zones.win.x {
|
if self.player.position.x > cur_level.zones.win.x {
|
||||||
|
@ -35,12 +35,14 @@ impl FrameUpdate for InGameScreen {
|
|||||||
self.player.update_player(
|
self.player.update_player(
|
||||||
Some(CharacterState::Jumping),
|
Some(CharacterState::Jumping),
|
||||||
&cur_level.colliders,
|
&cur_level.colliders,
|
||||||
|
&cur_level.zones.kill,
|
||||||
-cur_level.platform_tex.height as f32,
|
-cur_level.platform_tex.height as f32,
|
||||||
)
|
)
|
||||||
} else if is_dash {
|
} else if is_dash {
|
||||||
self.player.update_player(
|
self.player.update_player(
|
||||||
Some(CharacterState::Dashing),
|
Some(CharacterState::Dashing),
|
||||||
&cur_level.colliders,
|
&cur_level.colliders,
|
||||||
|
&cur_level.zones.kill,
|
||||||
-cur_level.platform_tex.height as f32,
|
-cur_level.platform_tex.height as f32,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -50,12 +52,14 @@ impl FrameUpdate for InGameScreen {
|
|||||||
self.player.update_player(
|
self.player.update_player(
|
||||||
Some(CharacterState::Running),
|
Some(CharacterState::Running),
|
||||||
&cur_level.colliders,
|
&cur_level.colliders,
|
||||||
|
&cur_level.zones.kill,
|
||||||
-cur_level.platform_tex.height as f32,
|
-cur_level.platform_tex.height as f32,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.player.update_player(
|
self.player.update_player(
|
||||||
None,
|
None,
|
||||||
&cur_level.colliders,
|
&cur_level.colliders,
|
||||||
|
&cur_level.zones.kill,
|
||||||
-cur_level.platform_tex.height as f32,
|
-cur_level.platform_tex.height as f32,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user