add player
This commit is contained in:
parent
d7b0ec9a52
commit
c5a3e9ad6b
@ -39,6 +39,7 @@ pub(crate) mod persistent;
|
||||
pub(crate) mod project_constants;
|
||||
pub(crate) mod rendering;
|
||||
pub(crate) mod scenes;
|
||||
pub(crate) mod model;
|
||||
|
||||
/// This is the game logic entrypoint. Despite being async,
|
||||
/// this is expected to block the main thread for rendering and stuff.
|
||||
|
1
game/game_logic/src/model/mod.rs
Normal file
1
game/game_logic/src/model/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod player;
|
20
game/game_logic/src/model/player.rs
Normal file
20
game/game_logic/src/model/player.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use nalgebra as na;
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Player {
|
||||
pub position: na::Vector2<f32>,
|
||||
pub velocity: na::Vector2<f32>,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
|
||||
/// Construct a new player.
|
||||
pub fn new(position: na::Vector2<f32>) -> Self {
|
||||
Self {
|
||||
position,
|
||||
velocity: na::Vector2::zeros(),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -107,7 +107,7 @@ pub async fn handle_graphics_blocking<ConfigBuilder>(
|
||||
&raylib_thread,
|
||||
&discord_signaling,
|
||||
&global_resources,
|
||||
);
|
||||
).await;
|
||||
}
|
||||
_ => backend_sm = RenderBackendStates::sm_failed(),
|
||||
};
|
||||
|
@ -7,7 +7,8 @@ use raylib::prelude::*;
|
||||
|
||||
use crate::{discord::DiscordChannel, global_resource_package::GlobalResources};
|
||||
|
||||
use self::test_fox::TestFoxScene;
|
||||
use self::{player_interaction::PlayableScene, test_fox::TestFoxScene};
|
||||
mod player_interaction;
|
||||
mod test_fox;
|
||||
|
||||
/// Delegate for handling rendering.
|
||||
@ -15,6 +16,7 @@ mod test_fox;
|
||||
pub struct SceneRenderDelegate {
|
||||
/* Scenes */
|
||||
scene_test_fox: TestFoxScene,
|
||||
scene_playable: PlayableScene,
|
||||
}
|
||||
|
||||
impl SceneRenderDelegate {
|
||||
@ -24,23 +26,27 @@ impl SceneRenderDelegate {
|
||||
|
||||
// Init some scenes
|
||||
let scene_test_fox = TestFoxScene::new(raylib, rl_thread);
|
||||
let scene_playable = PlayableScene::new(raylib, rl_thread);
|
||||
|
||||
Self { scene_test_fox }
|
||||
Self {
|
||||
scene_test_fox,
|
||||
scene_playable,
|
||||
}
|
||||
}
|
||||
|
||||
/// This is called every frame once the game has started.
|
||||
///
|
||||
/// Keep in mind everything you do here will block the main thread (no loading files plz)
|
||||
pub fn process_ingame_frame(
|
||||
pub async fn process_ingame_frame(
|
||||
&mut self,
|
||||
raylib: &mut RaylibHandle,
|
||||
rl_thread: &RaylibThread,
|
||||
discord: &DiscordChannel,
|
||||
global_resources: &GlobalResources,
|
||||
) {
|
||||
// For now, we will just render the test fox scene
|
||||
self.scene_test_fox
|
||||
.render_frame(raylib, rl_thread, &discord, global_resources);
|
||||
// For now, we will just render the game scene
|
||||
self.scene_playable
|
||||
.render_frame(raylib, rl_thread, &discord, global_resources).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
51
game/game_logic/src/scenes/player_interaction.rs
Normal file
51
game/game_logic/src/scenes/player_interaction.rs
Normal file
@ -0,0 +1,51 @@
|
||||
//! This scene encompasses all of the game where the player can walk around.
|
||||
|
||||
use nalgebra as na;
|
||||
use raylib::prelude::*;
|
||||
|
||||
use crate::{
|
||||
discord::{DiscordChannel, DiscordRpcSignal}, global_resource_package::GlobalResources,
|
||||
rendering::utilities::anim_texture::AnimatedTexture, model::player::Player,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PlayableScene {
|
||||
has_updated_discord_rpc: bool,
|
||||
player: Player
|
||||
}
|
||||
|
||||
impl PlayableScene {
|
||||
/// Construct a new `PlayableScene`
|
||||
pub fn new(raylib_handle: &mut RaylibHandle, thread: &RaylibThread) -> Self {
|
||||
Self {
|
||||
has_updated_discord_rpc: false,
|
||||
player: Player::new(na::Vector2::new(10.0, 10.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler for each frame
|
||||
pub async fn render_frame(
|
||||
&mut self,
|
||||
raylib: &mut RaylibHandle,
|
||||
rl_thread: &RaylibThread,
|
||||
discord: &DiscordChannel,
|
||||
global_resources: &GlobalResources,
|
||||
) {
|
||||
|
||||
// Handle updating discord RPC
|
||||
if !self.has_updated_discord_rpc {
|
||||
discord.send(DiscordRpcSignal::BeginGameTimer).await.unwrap();
|
||||
discord.send(DiscordRpcSignal::ChangeDetails { details: "Playing the game".to_string(), party_status: None }).await.unwrap();
|
||||
self.has_updated_discord_rpc = true;
|
||||
}
|
||||
|
||||
// Get a drawing handle
|
||||
let mut draw = raylib.begin_drawing(rl_thread);
|
||||
|
||||
// Clear the screen
|
||||
draw.clear_background(Color::WHITE);
|
||||
|
||||
// TODO: Render stuff
|
||||
// self.player. <whatever>
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user