From b51de3b81553e5986df32fc5a202fde12773e696 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 24 Apr 2021 16:03:07 -0400 Subject: [PATCH] working on aoe --- src/items.rs | 10 +++++----- src/logic/ingame/playerlogic.rs | 8 +++++++- src/player.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/items.rs b/src/items.rs index b49d49b..f1559bb 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1,10 +1,10 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[serde(tag = "t", content = "c")] pub enum ShopItems { - StunGun(u8), + StunGun, AirBag, - Flashlight(u8), - Flippers(u8) -} \ No newline at end of file + Flashlight { power: u8 }, + Flippers { speed_increase: u8 }, +} diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index c1e5ec6..2bf695e 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -128,7 +128,8 @@ pub fn update_player_movement( // Only do this if the mouse is far enough away let player_real_movement = game_core.player.direction * speed_multiplier; - if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 { + let player_stunned = game_core.player.stun_timer > 0.0; + if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 || player_stunned{ game_core.player.is_moving = true; game_core.player.position += player_real_movement; @@ -145,6 +146,11 @@ pub fn update_player_movement( } } else { game_core.player.is_moving = false; + + // Handle updating the stun timer + if player_stunned { + game_core.player.stun_timer -= dt; + } } // Move the camera to follow the player diff --git a/src/player.rs b/src/player.rs index 6daddf1..f7850ab 100644 --- a/src/player.rs +++ b/src/player.rs @@ -21,6 +21,8 @@ pub struct Player { pub is_boosting: bool, pub is_boost_charging: bool, pub inventory: Vec, + pub stun_timer: f64, + pub attacking_timer: f64, } impl Player { @@ -65,6 +67,18 @@ impl Player { return rectangle.check_collision_circle_rec(self.position, (self.size.y * 0.5) / 2.0); } + /// Stun the player + pub fn set_stun_seconds(&mut self, seconds: f64) { + self.stun_timer = seconds; + } + + /// Try to attack with the stun gun + pub fn begin_attack(&mut self) { + if self.inventory.contains(&ShopItems::StunGun) && self.stun_timer == 0.0 { + self.stun_timer = 2.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); @@ -114,6 +128,20 @@ impl Player { TRANSLUCENT_WHITE_96, ); + // Calculate AOE ring + let aoe_ring; + if self.attacking_timer <= 0.25 { + aoe_ring = self.attacking_timer; + } + + // Render attack AOE + context_2d.draw_circle_lines( + self.position.x as i32, + self.position.y as i32, + boost_ring_max_radius * self.boost_percent, + TRANSLUCENT_WHITE_64, + ); + // Render the player based on what is happening if self.is_boost_charging { resources.player_animation_boost_charge.draw(