mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 04:25:00 +01:00
Add player entity
This commit is contained in:
parent
6ca737f36c
commit
5a6fe33e1e
7 changed files with 150 additions and 31 deletions
18
src/game.rs
18
src/game.rs
|
|
@ -1,4 +1,6 @@
|
|||
use sfml::graphics::{Rect, RenderTarget, RenderWindow, Sprite, Transformable};
|
||||
mod player;
|
||||
|
||||
use sfml::graphics::{Rect, RectangleShape, RenderTarget, RenderWindow, Sprite, Transformable};
|
||||
|
||||
use crate::{
|
||||
graphics::{ScreenPos, ScreenPosScalar, NATIVE_RESOLUTION},
|
||||
|
|
@ -7,9 +9,12 @@ use crate::{
|
|||
world::{Tile, TilePos, World},
|
||||
};
|
||||
|
||||
use self::player::Player;
|
||||
|
||||
pub struct GameState {
|
||||
pub camera_offset: WorldPos,
|
||||
pub world: World,
|
||||
pub player: Player,
|
||||
}
|
||||
impl GameState {
|
||||
pub(crate) fn draw_world(&mut self, rw: &mut RenderWindow, res: &Res) {
|
||||
|
|
@ -24,6 +29,16 @@ impl GameState {
|
|||
rw.draw(&s);
|
||||
});
|
||||
}
|
||||
pub fn draw_entities(&mut self, rw: &mut RenderWindow) {
|
||||
let (x, y, w, h) = self.player.col_en.en.xywh();
|
||||
let mut rs = RectangleShape::new();
|
||||
rs.set_position((
|
||||
(x - self.camera_offset.x as i32) as f32,
|
||||
(y - self.camera_offset.y as i32) as f32,
|
||||
));
|
||||
rs.set_size((w as f32, h as f32));
|
||||
rw.draw(&rs);
|
||||
}
|
||||
}
|
||||
|
||||
fn for_each_tile_on_screen(camera_offset: WorldPos, mut f: impl FnMut(TilePos, ScreenPos)) {
|
||||
|
|
@ -48,6 +63,7 @@ impl Default for GameState {
|
|||
Self {
|
||||
camera_offset: WorldPos::SURFACE_CENTER,
|
||||
world: Default::default(),
|
||||
player: Player::new_at(WorldPos::SURFACE_CENTER),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue