aoe ring math

This commit is contained in:
Evan Pratten 2021-04-24 16:21:48 -04:00
parent b51de3b815
commit 22e9eda97c
5 changed files with 27 additions and 29 deletions

View File

@ -1,2 +1,12 @@
pub mod profiler;
pub mod triangles;
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;
}
}

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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<RaylibDrawHandle>,
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,
);