Prepare to flip player.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use sdl2::rect::Rect;
|
||||
|
||||
pub enum PlayerFacing {
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
pub struct Player {
|
||||
pub x: f32,
|
||||
@@ -9,7 +13,8 @@ pub struct Player {
|
||||
pub dx: f32,
|
||||
pub dy: f32,
|
||||
pub gravity: f32,
|
||||
pub on_ground: bool
|
||||
pub on_ground: bool,
|
||||
pub facing: PlayerFacing
|
||||
}
|
||||
|
||||
impl Player {
|
||||
@@ -22,11 +27,25 @@ impl Player {
|
||||
dx: 0.0,
|
||||
dy: 0.0,
|
||||
gravity: 0.3,
|
||||
on_ground: false
|
||||
on_ground: false,
|
||||
facing: PlayerFacing::Right
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
match self.facing {
|
||||
PlayerFacing::Right => {
|
||||
if self.dx < 0.0 {
|
||||
self.facing = PlayerFacing::Left;
|
||||
}
|
||||
},
|
||||
PlayerFacing::Left => {
|
||||
if self.dx > 0.0 {
|
||||
self.facing = PlayerFacing::Right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.dy += self.gravity;
|
||||
|
||||
if self.dy > 8.0 {
|
||||
|
||||
Reference in New Issue
Block a user