Refactor entity and player classes to implement friction and velocity management

This commit is contained in:
2026-06-22 16:37:30 +02:00
parent 04a83c5cc2
commit 40306d9441
3 changed files with 61 additions and 16 deletions
+10 -5
View File
@@ -13,12 +13,19 @@ class Pos:
class Velocity:
x: float
y: float
max: float = 50
@dataclass
class Friction: # les forces de frottement
x: float
y: float
@dataclass
class Entity:
name: str
pos: Pos
velocity: Velocity
friction: Friction
image: pygame.Surface
screen_manager: Screen
@@ -28,14 +35,12 @@ class Entity:
self.name:str = name
self.pos = Pos(*origin)
self.velocity = Velocity(0, 0)
self.friction = Friction(0, 0) # Par defaut on est dans le vide
self.image: pygame.Surface = image
self.screen_manager = screen_manager
self.screen: pygame.Surface = screen_manager.get_screen()
def apply_move(self):
self.pos.x += int(self.velocity.x)
self.pos.y += int(self.velocity.y)
def draw(self):...
def move(self, event:pygame.event.Event):...
def move(self, deltatime: float):...
def apply_friction(self, deltatime: float):...