Refactor entity and player classes to implement friction and velocity management
This commit is contained in:
+10
-5
@@ -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):...
|
||||
Reference in New Issue
Block a user