From 22e9eda97c7f47b37fd769fed3cbb5cb1c262894 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 24 Apr 2021 16:21:48 -0400 Subject: [PATCH] aoe ring math --- src/lib/utils/mod.rs | 12 +++++++++++- src/logic/ingame/mod.rs | 2 +- src/logic/ingame/playerlogic.rs | 4 ++++ src/logic/loadingscreen.rs | 14 ++------------ src/player.rs | 24 +++++++++--------------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/lib/utils/mod.rs b/src/lib/utils/mod.rs index 9d6dd04..baba8af 100644 --- a/src/lib/utils/mod.rs +++ b/src/lib/utils/mod.rs @@ -1,2 +1,12 @@ pub mod profiler; -pub mod triangles; \ No newline at end of file +pub mod triangles; + +pub fn calculate_linear_slide(playthrough_percent: f64) -> f64 { + if playthrough_percent < 0.25 { + return playthrough_percent / 0.25; + } else if playthrough_percent > 0.75 { + return 1.0 - ((playthrough_percent - 0.75) / 0.25); + } else { + return 1.0; + } +} \ No newline at end of file diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index e58c92e..50fe9d7 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -127,7 +127,7 @@ impl Screen for InGameScreen { // Render Player // playerlogic::render_player(&mut context_2d, game_core); - game_core.player.render(&mut context_2d, &mut game_core.resources); + game_core.player.render(&mut context_2d, &mut game_core.resources, dt); } // Render the hud diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 2bf695e..afd21f5 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -76,6 +76,10 @@ pub fn update_player_movement( let user_request_boost = draw_handle.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); let user_request_action = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON); + if user_request_action { + game_core.player.begin_attack(); + } + // Move the player in their direction let speed_multiplier; if user_request_boost && game_core.player.boost_percent >= 0.0 { diff --git a/src/logic/loadingscreen.rs b/src/logic/loadingscreen.rs index 184322b..06056c1 100644 --- a/src/logic/loadingscreen.rs +++ b/src/logic/loadingscreen.rs @@ -1,9 +1,6 @@ use raylib::prelude::*; -use crate::{ - gamecore::{GameCore, GameState}, - lib::wrappers::audio::player::AudioPlayer, -}; +use crate::{gamecore::{GameCore, GameState}, lib::{utils::calculate_linear_slide, wrappers::audio::player::AudioPlayer}}; use super::screen::Screen; @@ -32,14 +29,7 @@ impl LoadingScreen { fn get_logo_mask(&self, playthrough_percent: f64) -> Color { // Determine the alpha - let alpha; - if playthrough_percent < 0.25 { - alpha = playthrough_percent / 0.25 - } else if playthrough_percent > 0.75 { - alpha = 1.0 - ((playthrough_percent - 0.75) / 0.25); - } else { - alpha = 1.0; - } + let alpha = calculate_linear_slide(playthrough_percent); // Build a color mask Color { diff --git a/src/player.rs b/src/player.rs index f7850ab..e284f9e 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,13 +1,8 @@ use raylib::prelude::*; -use crate::{ - gamecore::{GameCore, GameProgress}, - items::ShopItems, - lib::utils::triangles::rotate_vector, - pallette::{TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96}, - resources::GlobalResources, - world::World, -}; +use crate::{gamecore::{GameCore, GameProgress}, items::ShopItems, lib::utils::{calculate_linear_slide, triangles::rotate_vector}, pallette::{TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96}, resources::GlobalResources, world::World}; + +const AOE_RING_MAX_RADIUS: f32 = 40.0; #[derive(Debug, Default)] pub struct Player { @@ -74,7 +69,7 @@ impl Player { /// Try to attack with the stun gun pub fn begin_attack(&mut self) { - if self.inventory.contains(&ShopItems::StunGun) && self.stun_timer == 0.0 { + if true || self.inventory.contains(&ShopItems::StunGun) && self.stun_timer == 0.0 { self.stun_timer = 2.0; } } @@ -99,9 +94,10 @@ impl Player { /// Render the player pub fn render( - &self, + &mut self, context_2d: &mut RaylibMode2D, resources: &mut GlobalResources, + dt: f64 ) { // Convert the player direction to a rotation let player_rotation = Vector2::zero().angle_to(self.direction); @@ -129,16 +125,14 @@ impl Player { ); // Calculate AOE ring - let aoe_ring; - if self.attacking_timer <= 0.25 { - aoe_ring = self.attacking_timer; - } + let aoe_ring = calculate_linear_slide(self.attacking_timer) as f32; + self.stun_timer = (self.stun_timer - dt).max(0.0); // 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, + AOE_RING_MAX_RADIUS * aoe_ring, TRANSLUCENT_WHITE_64, );