feat: restructure draw and movement

This commit is contained in:
uttarayan21
2024-06-19 20:24:26 +05:30
parent 046724c860
commit 39c1096b87
7 changed files with 138 additions and 62 deletions
+31
View File
@@ -0,0 +1,31 @@
use macroquad::prelude::*;
#[derive(Debug, Clone, Copy)]
pub enum MovementType {
Speed(f32),
Acceleration(Vec2),
}
#[derive(Debug, Clone, Copy)]
pub struct Movement {
pub pos: Vec2,
pub direction: Vec2, // Direction of the movement normalized to 1
pub type_: MovementType,
}
impl Movement {
pub fn tick(&mut self) {
match self.type_ {
MovementType::Speed(speed) => {
self.pos += self.direction * speed;
}
MovementType::Acceleration(acceleration) => {
self.direction += acceleration;
self.direction = self.direction.normalize();
self.pos += self.direction;
}
}
}
pub fn pos(&self) -> Vec2 {
self.pos
}
}