working on aoe
This commit is contained in:
parent
79bae68f71
commit
b51de3b815
src
10
src/items.rs
10
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)
|
||||
}
|
||||
Flashlight { power: u8 },
|
||||
Flippers { speed_increase: u8 },
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -21,6 +21,8 @@ pub struct Player {
|
||||
pub is_boosting: bool,
|
||||
pub is_boost_charging: bool,
|
||||
pub inventory: Vec<ShopItems>,
|
||||
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(
|
||||
|
Reference in New Issue
Block a user