Add player entity

This commit is contained in:
crumblingstatue 2023-04-03 15:37:14 +02:00
parent 6ca737f36c
commit 5a6fe33e1e
7 changed files with 150 additions and 31 deletions

24
src/game/player.rs Normal file
View file

@ -0,0 +1,24 @@
use s2dc::{vec2, MobileEntity};
use crate::{
math::{WorldPos, TILE_SIZE},
world::{TilePos, TilePosScalar},
};
pub struct Player {
pub col_en: MobileEntity,
}
impl Player {
pub fn new_at(pos: WorldPos) -> Self {
Self {
col_en: MobileEntity::from_pos_and_bb(vec2(pos.x as i32, pos.y as i32), vec2(15, 24)),
}
}
pub fn center_tp(&self) -> TilePos {
TilePos {
x: (self.col_en.en.pos.x / TILE_SIZE as i32) as TilePosScalar,
y: (self.col_en.en.pos.y / TILE_SIZE as i32) as TilePosScalar,
}
}
}