Funny slippery guyy

This commit is contained in:
Silas Bartha 2022-04-02 12:29:26 -04:00
parent 166e83ad06
commit fc1a3d5f29
No known key found for this signature in database
GPG Key ID: 9323054A4EA1EA6C
3 changed files with 62 additions and 10 deletions

View File

@ -44,5 +44,5 @@ pub struct ProjectConstants {
pub target_fps: u32, pub target_fps: u32,
/// The size of the game tiles /// The size of the game tiles
pub tile_size: u8, pub tile_size: u32,
} }

View File

@ -68,6 +68,9 @@ impl SceneRenderDelegate {
self.scene_playable self.scene_playable
.render_frame(raylib, rl_thread, &discord, global_resources, constants) .render_frame(raylib, rl_thread, &discord, global_resources, constants)
.await; .await;
self.scene_playable
.update_physics(raylib)
.await;
} }
MenuStateSignal::QuitGame => unimplemented!(), MenuStateSignal::QuitGame => unimplemented!(),
MenuStateSignal::DoMainMenu => { MenuStateSignal::DoMainMenu => {

View File

@ -2,6 +2,7 @@
use nalgebra as na; use nalgebra as na;
use raylib::prelude::*; use raylib::prelude::*;
use std::time::SystemTime;
use crate::{ use crate::{
discord::{DiscordChannel, DiscordRpcSignal}, discord::{DiscordChannel, DiscordRpcSignal},
@ -15,26 +16,41 @@ use crate::{
pub struct PlayableScene { pub struct PlayableScene {
has_updated_discord_rpc: bool, has_updated_discord_rpc: bool,
player: Player, player: Player,
camera: raylib::camera::Camera2D,
last_update: SystemTime,
} }
impl PlayableScene { impl PlayableScene {
/// Construct a new `PlayableScene` /// Construct a new `PlayableScene`
pub fn new( pub fn new(
raylib_handle: &mut RaylibHandle, raylib_handle: &mut raylib::RaylibHandle,
thread: &RaylibThread, thread: & raylib::RaylibThread,
constants: &ProjectConstants, constants: &ProjectConstants,
) -> Self { ) -> Self {
Self { Self {
has_updated_discord_rpc: false, has_updated_discord_rpc: false,
player: Player::new(na::Vector2::new(10.0, 10.0)), player: Player::new(na::Vector2::new(10.0, 10.0)),
camera: raylib::camera::Camera2D {
target: raylib::math::Vector2 {
x: 0.0,
y: 0.0,
},
offset: raylib::math::Vector2 {
x: (constants.base_window_size.0 as f32 / 2.0),
y: (constants.base_window_size.1 as f32 / 2.0)
},
rotation: 0.0,
zoom: 1.0
},
last_update: SystemTime::UNIX_EPOCH
} }
} }
/// Handler for each frame /// Handler for each frame
pub async fn render_frame( pub async fn render_frame(
&mut self, &mut self,
raylib: &mut RaylibHandle, raylib: &mut raylib::RaylibHandle,
rl_thread: &RaylibThread, rl_thread: &raylib::RaylibThread,
discord: &DiscordChannel, discord: &DiscordChannel,
global_resources: &GlobalResources, global_resources: &GlobalResources,
constants: &ProjectConstants, constants: &ProjectConstants,
@ -61,16 +77,49 @@ impl PlayableScene {
// Clear the screen // Clear the screen
draw.clear_background(Color::WHITE); draw.clear_background(Color::WHITE);
draw.draw_rectangle_lines( for i in 0..100 {
0, for j in 0..100 {
0, draw.draw_rectangle(
constants.tile_size as i32 * (i * 2),
constants.tile_size as i32 * (j * 2) * -1,
constants.tile_size as i32,
constants.tile_size as i32,
Color::RED
)
}
}
draw.draw_rectangle(
self.player.position[0] as i32,
self.player.position[1] as i32 * -1,
(constants.tile_size as f32 * self.player.size) as i32, (constants.tile_size as f32 * self.player.size) as i32,
(constants.tile_size as f32 * self.player.size) as i32, (constants.tile_size as f32 * self.player.size) as i32,
Color::GREEN Color::GREEN
); );
}
// Physics
pub async fn update_physics(
&mut self,
raylib: & raylib::RaylibHandle,
) {
let time = SystemTime::now();
if time
.duration_since(self.last_update)
.expect("Time Appears to Have Moved Backwards!")
.as_millis() < 16
{
return
}
self.last_update = time;
// TODO: Render stuff let player = &mut self.player;
// self.player. <whatever> let h_axis = raylib.is_key_down(KeyboardKey::KEY_D) as i8 - raylib.is_key_down(KeyboardKey::KEY_A) as i8;
let v_axis = raylib.is_key_down(KeyboardKey::KEY_W) as i8 - raylib.is_key_down(KeyboardKey::KEY_S) as i8;
let direction = na::Vector2::new(h_axis as f32, v_axis as f32);
player.velocity += &direction;
player.position += &player.velocity;
} }
} }