Real boost logic
This commit is contained in:
parent
fa9bc120e3
commit
6469a36c56
@ -17,7 +17,7 @@ pub enum GameState {
|
|||||||
MainMenu,
|
MainMenu,
|
||||||
PauseMenu,
|
PauseMenu,
|
||||||
GameQuit,
|
GameQuit,
|
||||||
InGame
|
InGame,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for GameState {
|
impl fmt::Display for GameState {
|
||||||
@ -32,6 +32,7 @@ pub struct GameCore {
|
|||||||
pub state: GameState,
|
pub state: GameState,
|
||||||
pub last_state: GameState,
|
pub last_state: GameState,
|
||||||
pub last_state_change_time: f64,
|
pub last_state_change_time: f64,
|
||||||
|
pub last_frame_time: f64,
|
||||||
pub has_rendered_first_frame: bool,
|
pub has_rendered_first_frame: bool,
|
||||||
|
|
||||||
/// Resources
|
/// Resources
|
||||||
@ -56,6 +57,7 @@ impl GameCore {
|
|||||||
state: GameState::Loading,
|
state: GameState::Loading,
|
||||||
last_state: GameState::Loading,
|
last_state: GameState::Loading,
|
||||||
last_state_change_time: 0.0,
|
last_state_change_time: 0.0,
|
||||||
|
last_frame_time: 0.0,
|
||||||
has_rendered_first_frame: false,
|
has_rendered_first_frame: false,
|
||||||
resources: GlobalResources::load_all(raylib, thread)
|
resources: GlobalResources::load_all(raylib, thread)
|
||||||
.expect("Failed to load game assets. Can not launch!"),
|
.expect("Failed to load game assets. Can not launch!"),
|
||||||
@ -67,7 +69,7 @@ impl GameCore {
|
|||||||
},
|
},
|
||||||
show_simple_debug_info: false,
|
show_simple_debug_info: false,
|
||||||
world: world,
|
world: world,
|
||||||
player: Player::new()
|
player: Player::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{gamecore::GameCore, pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96}};
|
||||||
gamecore::GameCore,
|
|
||||||
pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64},
|
|
||||||
};
|
|
||||||
|
|
||||||
const NORMAL_PLAYER_SPEED: i32 = 4;
|
const NORMAL_PLAYER_SPEED: i32 = 4;
|
||||||
const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2;
|
const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2;
|
||||||
const CAMERA_FOLLOW_SPEED: f32 = 0.7;
|
const CAMERA_FOLLOW_SPEED: f32 = 0.7;
|
||||||
|
const BOOST_DECREASE_PER_SECOND: f32 = 0.75;
|
||||||
|
const BOOST_REGEN_PER_SECOND: f32 = 0.25;
|
||||||
|
const BREATH_DECREASE_PER_SECOND: f32 = 0.01;
|
||||||
|
|
||||||
pub fn update_player_movement(
|
pub fn update_player_movement(
|
||||||
draw_handle: &mut RaylibDrawHandle,
|
draw_handle: &mut RaylibDrawHandle,
|
||||||
game_core: &mut GameCore,
|
game_core: &mut GameCore,
|
||||||
window_center: Vector2,
|
window_center: Vector2,
|
||||||
) {
|
) {
|
||||||
|
// Calculate DT
|
||||||
|
let dt = draw_handle.get_time() - game_core.last_frame_time;
|
||||||
|
|
||||||
// Handle player movement
|
// Handle player movement
|
||||||
let mouse_pose = draw_handle.get_mouse_position();
|
let mouse_pose = draw_handle.get_mouse_position();
|
||||||
let mouse_world_pose = draw_handle.get_screen_to_world2D(mouse_pose, game_core.master_camera);
|
let mouse_world_pose = draw_handle.get_screen_to_world2D(mouse_pose, game_core.master_camera);
|
||||||
@ -32,10 +35,21 @@ pub fn update_player_movement(
|
|||||||
let user_request_action = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON);
|
let user_request_action = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON);
|
||||||
|
|
||||||
// Move the player in their direction
|
// Move the player in their direction
|
||||||
let speed_multiplier = match user_request_boost && game_core.player.boost_percent >= 0.0 {
|
let speed_multiplier;
|
||||||
true => BOOST_PLAYER_SPEED as f32,
|
if user_request_boost && game_core.player.boost_percent >= 0.0 {
|
||||||
false => NORMAL_PLAYER_SPEED as f32,
|
// Set the speed multiplier
|
||||||
};
|
speed_multiplier = BOOST_PLAYER_SPEED as f32;
|
||||||
|
|
||||||
|
// Decrease the boost
|
||||||
|
game_core.player.boost_percent -= BOOST_DECREASE_PER_SECOND * dt as f32;
|
||||||
|
} else {
|
||||||
|
// Set the speed multiplier
|
||||||
|
speed_multiplier = NORMAL_PLAYER_SPEED as f32;
|
||||||
|
|
||||||
|
// Handle boost regen
|
||||||
|
game_core.player.boost_percent =
|
||||||
|
(game_core.player.boost_percent + BOOST_REGEN_PER_SECOND * dt as f32).clamp(0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
// Only do this if the mouse is far enough away
|
// Only do this if the mouse is far enough away
|
||||||
let player_real_movement = game_core.player.direction * speed_multiplier;
|
let player_real_movement = game_core.player.direction * speed_multiplier;
|
||||||
@ -78,7 +92,7 @@ pub fn render_player(context_2d: &mut RaylibMode2D<RaylibDrawHandle>, game_core:
|
|||||||
0,
|
0,
|
||||||
(360.0 * player.breath_percent) as i32,
|
(360.0 * player.breath_percent) as i32,
|
||||||
0,
|
0,
|
||||||
TRANSLUCENT_WHITE_128,
|
TRANSLUCENT_WHITE_96,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: tmp rect
|
// TODO: tmp rect
|
||||||
|
@ -149,6 +149,9 @@ fn main() {
|
|||||||
|
|
||||||
// Set the first frame flag
|
// Set the first frame flag
|
||||||
game_core.has_rendered_first_frame = true;
|
game_core.has_rendered_first_frame = true;
|
||||||
|
|
||||||
|
// Update the frame time
|
||||||
|
game_core.last_frame_time = draw_handle.get_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
@ -7,6 +7,13 @@ pub const TRANSLUCENT_WHITE_128: Color = Color {
|
|||||||
a: 128,
|
a: 128,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const TRANSLUCENT_WHITE_96: Color = Color {
|
||||||
|
r: 255,
|
||||||
|
g: 255,
|
||||||
|
b: 255,
|
||||||
|
a: 96,
|
||||||
|
};
|
||||||
|
|
||||||
pub const TRANSLUCENT_WHITE_64: Color = Color {
|
pub const TRANSLUCENT_WHITE_64: Color = Color {
|
||||||
r: 255,
|
r: 255,
|
||||||
g: 255,
|
g: 255,
|
||||||
|
Reference in New Issue
Block a user