Added the floor
This commit is contained in:
parent
26406b97ba
commit
fa452c8350
@ -16,8 +16,8 @@ serde_json = "1.0.64"
|
|||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
rust-embed = "6.2.0"
|
rust-embed = "6.2.0"
|
||||||
raylib = { version = "3.5", git = "https://github.com/ewpratten/raylib-rs", rev = "2399e17d7bf299f34c8e618a9ab140b274639cfb", features = [
|
raylib = { version = "3.5", git = "https://github.com/ewpratten/raylib-rs", rev = "2ae949cb3488dd1bb052ece71d61021c8dd6e910", features = [
|
||||||
"with_serde"
|
"serde"
|
||||||
] }
|
] }
|
||||||
puffin = "0.9"
|
puffin = "0.9"
|
||||||
puffin_http = "0.6"
|
puffin_http = "0.6"
|
||||||
|
@ -5,12 +5,15 @@ use raylib::math::Vector2;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MainCharacter {
|
pub struct MainCharacter {
|
||||||
pub position: Vector2,
|
pub position: Vector2,
|
||||||
|
pub size: Vector2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainCharacter {
|
impl MainCharacter {
|
||||||
|
|
||||||
pub fn new(position: Vector2) -> Self {
|
pub fn new(position: Vector2) -> Self {
|
||||||
Self { position }
|
Self {
|
||||||
|
position,
|
||||||
|
size: Vector2::new(60.0, 80.0),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_force(&mut self, force: Vector2) {
|
pub fn apply_force(&mut self, force: Vector2) {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::ops::{Div, Sub};
|
||||||
|
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::utilities::non_ref_raylib::HackedRaylibHandle;
|
use crate::utilities::non_ref_raylib::HackedRaylibHandle;
|
||||||
@ -9,5 +11,5 @@ pub fn render_character_in_camera_space(
|
|||||||
player: &MainCharacter,
|
player: &MainCharacter,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
raylib.draw_rectangle_v(player.position, Vector2::new(10.0, 20.0), Color::WHITE);
|
raylib.draw_rectangle_v(player.position.sub(player.size.div(2.0)), player.size, Color::WHITE);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
use dirty_fsm::{Action, ActionFlag};
|
use dirty_fsm::{Action, ActionFlag};
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{character::MainCharacter, context::GameContext, utilities::render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender}};
|
use crate::{
|
||||||
|
character::MainCharacter,
|
||||||
|
context::GameContext,
|
||||||
|
utilities::render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender},
|
||||||
|
};
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
use super::{Scenes, ScreenError};
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
@ -13,7 +17,7 @@ mod world;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct InGameScreen {
|
pub struct InGameScreen {
|
||||||
camera: Camera2D,
|
camera: Camera2D,
|
||||||
player: MainCharacter
|
player: MainCharacter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InGameScreen {
|
impl InGameScreen {
|
||||||
@ -26,7 +30,7 @@ impl InGameScreen {
|
|||||||
rotation: 0.0,
|
rotation: 0.0,
|
||||||
zoom: 1.0,
|
zoom: 1.0,
|
||||||
},
|
},
|
||||||
player: MainCharacter::new(Vector2::zero()),
|
player: MainCharacter::new(Vector2::new(0.0, -45.0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,11 @@ use raylib::prelude::*;
|
|||||||
impl FrameUpdate for InGameScreen {
|
impl FrameUpdate for InGameScreen {
|
||||||
fn update(&mut self, raylib: &HackedRaylibHandle, delta_seconds: &Duration) {
|
fn update(&mut self, raylib: &HackedRaylibHandle, delta_seconds: &Duration) {
|
||||||
// Set the camera's offset based on screen size
|
// Set the camera's offset based on screen size
|
||||||
self.camera.offset = raylib.get_screen_size().div(2.0);
|
self.camera.offset = raylib.get_screen_size().div(Vector2::new(2.0, 1.25));
|
||||||
|
self.camera.target = Vector2::new(
|
||||||
|
self.player.position.x,
|
||||||
|
self.camera.target.y,
|
||||||
|
);
|
||||||
|
|
||||||
// Check the only possible keyboard inputs
|
// Check the only possible keyboard inputs
|
||||||
let is_jump = raylib.is_key_down(KeyboardKey::KEY_SPACE);
|
let is_jump = raylib.is_key_down(KeyboardKey::KEY_SPACE);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::ops::Mul;
|
||||||
|
|
||||||
use super::InGameScreen;
|
use super::InGameScreen;
|
||||||
use crate::{
|
use crate::{
|
||||||
character::render::render_character_in_camera_space,
|
character::render::render_character_in_camera_space,
|
||||||
@ -9,5 +11,17 @@ impl WorldSpaceRender for InGameScreen {
|
|||||||
fn render_world_space(&self, raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>) {
|
fn render_world_space(&self, raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>) {
|
||||||
// Render the player
|
// Render the player
|
||||||
render_character_in_camera_space(raylib, &self.player);
|
render_character_in_camera_space(raylib, &self.player);
|
||||||
|
|
||||||
|
// Render the floor as a line
|
||||||
|
let screen_world_zero = raylib.get_screen_to_world2D(Vector2::zero(), self.camera);
|
||||||
|
let screen_world_size = raylib.get_screen_to_world2D(raylib.get_screen_size().mul(2.0), self.camera);
|
||||||
|
|
||||||
|
raylib.draw_rectangle(
|
||||||
|
screen_world_zero.x as i32,
|
||||||
|
0,
|
||||||
|
screen_world_size.x as i32,
|
||||||
|
5,
|
||||||
|
Color::WHITE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user