2023-03-26 15:00:29 +02:00
|
|
|
from sprite.BoundingBox import BoundingBox
|
2023-03-25 15:41:32 +01:00
|
|
|
from sprite.Spritesheet import Spritesheet
|
|
|
|
from sprite.StaticSprite import StaticSprite
|
2023-03-26 12:46:41 +02:00
|
|
|
from physics.TickData import TickData
|
2023-03-25 15:41:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DynamicSprite(StaticSprite):
|
|
|
|
def __init__(self, spritesheet: Spritesheet):
|
|
|
|
super().__init__(spritesheet)
|
|
|
|
|
|
|
|
self.motion = (0, 0)
|
2023-03-25 18:14:47 +01:00
|
|
|
|
|
|
|
self.deceleration_horizontal_air = 0.02
|
|
|
|
self.deceleration_horizontal_ground = 0.3
|
2023-03-25 17:18:43 +01:00
|
|
|
self.gravity = 9.81 / 10
|
2023-03-25 15:41:32 +01:00
|
|
|
|
2023-03-25 18:14:47 +01:00
|
|
|
# up, right, down, left
|
|
|
|
self.touches_bounding = (False, False, False, False)
|
|
|
|
|
2023-03-26 12:46:41 +02:00
|
|
|
def tick(self, tick_data: TickData):
|
|
|
|
super().tick(tick_data)
|
|
|
|
|
|
|
|
deceleration_horizontal = 0
|
|
|
|
if abs(self.motion[0]) > 0:
|
|
|
|
if self.touches_bounding[2]:
|
|
|
|
deceleration_horizontal = self.deceleration_horizontal_ground
|
|
|
|
else:
|
|
|
|
deceleration_horizontal = self.deceleration_horizontal_air
|
|
|
|
|
|
|
|
self.motion = (
|
|
|
|
self.motion[0] - deceleration_horizontal * self.motion[0] * tick_data.dt,
|
|
|
|
self.motion[1] + self.gravity * tick_data.dt
|
|
|
|
)
|
|
|
|
|
2023-03-25 18:14:47 +01:00
|
|
|
def set_touches_bottom(self, value: bool):
|
|
|
|
self.touches_bounding = (self.touches_bounding[0], self.touches_bounding[1], value, self.touches_bounding[3])
|
|
|
|
|
|
|
|
def set_touches_right(self, value: bool):
|
|
|
|
self.touches_bounding = (self.touches_bounding[0], value, self.touches_bounding[2], self.touches_bounding[3])
|
|
|
|
|
|
|
|
def set_touches_left(self, value: bool):
|
|
|
|
self.touches_bounding = (self.touches_bounding[0], self.touches_bounding[1], self.touches_bounding[2], value)
|
|
|
|
|
|
|
|
def set_touches_top(self, value: bool):
|
|
|
|
self.touches_bounding = (value, self.touches_bounding[1], self.touches_bounding[2], self.touches_bounding[3])
|
|
|
|
|
|
|
|
def reset_touches(self):
|
|
|
|
self.touches_bounding = (False, False, False, False)
|