finished stun system
This commit is contained in:
parent
0659780b3d
commit
54ff1c7931
@ -65,7 +65,9 @@ pub fn update_player_movement(
|
||||
}
|
||||
|
||||
// set angle
|
||||
game_core.player.direction = Vector2::new(f32::cos(player_angle), f32::sin(player_angle));
|
||||
if !game_core.player.is_stunned() {
|
||||
game_core.player.direction = Vector2::new(f32::cos(player_angle), f32::sin(player_angle));
|
||||
}
|
||||
|
||||
// In the case the player is in "null", just jump the camera to them
|
||||
if game_core.player.position == Vector2::zero() {
|
||||
@ -145,7 +147,9 @@ pub fn update_player_movement(
|
||||
// Only do this if the mouse is far enough away
|
||||
let player_stunned = game_core.player.stun_timer > 0.0;
|
||||
let mut player_real_movement = game_core.player.direction * speed_multiplier;
|
||||
if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 {
|
||||
if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0
|
||||
&& !game_core.player.is_stunned()
|
||||
{
|
||||
if game_core.player.is_moving {
|
||||
// move in x
|
||||
game_core.player.position.x += player_real_movement.x;
|
||||
|
@ -99,7 +99,7 @@ impl Player {
|
||||
|
||||
/// Try to attack with the stun gun
|
||||
pub fn begin_attack(&mut self, world: &mut World) {
|
||||
if self.inventory.stun_gun.is_some() && self.stun_timer == 0.0 {
|
||||
if self.inventory.stun_gun.is_some() && !self.is_stunned() {
|
||||
self.attacking_timer = self.inventory.stun_gun.as_ref().unwrap().duration;
|
||||
|
||||
// Stun everything in reach
|
||||
@ -117,6 +117,10 @@ impl Player {
|
||||
return self.attacking_timer != 0.0 && self.inventory.stun_gun.is_some();
|
||||
}
|
||||
|
||||
pub fn is_stunned(&self) -> bool {
|
||||
return self.stun_timer > 0.0;
|
||||
}
|
||||
|
||||
/// Calculate how far the player is
|
||||
pub fn calculate_depth_percent(&self, world: &World) -> f32 {
|
||||
let dist_from_player_to_end = self.position.distance_to(world.end_position);
|
||||
@ -193,7 +197,13 @@ impl Player {
|
||||
}
|
||||
|
||||
// Render the player based on what is happening
|
||||
if self.is_boost_charging {
|
||||
if self.is_stunned() {
|
||||
resources.player_animation_stunned.draw(
|
||||
context_2d,
|
||||
self.position,
|
||||
player_rotation.to_degrees() - 90.0,
|
||||
);
|
||||
} else if self.is_boost_charging {
|
||||
resources.player_animation_boost_charge.draw(
|
||||
context_2d,
|
||||
self.position,
|
||||
|
@ -16,6 +16,7 @@ pub struct GlobalResources {
|
||||
pub player_animation_regular: FrameAnimationWrapper,
|
||||
pub player_animation_boost_charge: FrameAnimationWrapper,
|
||||
pub player_animation_boost: FrameAnimationWrapper,
|
||||
pub player_animation_stunned: FrameAnimationWrapper,
|
||||
|
||||
// Cave
|
||||
pub cave_mid_layer: Texture2D,
|
||||
@ -63,6 +64,15 @@ impl GlobalResources {
|
||||
21,
|
||||
30,
|
||||
),
|
||||
player_animation_stunned: FrameAnimationWrapper::new(
|
||||
raylib.load_texture_from_image(
|
||||
&thread,
|
||||
&Image::load_image("./assets/img/character/stunned.png")?,
|
||||
)?,
|
||||
Vector2 { x: 12.0, y: 22.0 },
|
||||
4,
|
||||
100 / 8,
|
||||
),
|
||||
cave_mid_layer: raylib.load_texture_from_image(
|
||||
&thread,
|
||||
&Image::load_image("./assets/img/map/cave.png")?,
|
||||
|
Reference in New Issue
Block a user