sep-pm-platformer/project/physics/controllers/PlayerSprite.py

25 lines
957 B
Python

from physics.TickData import TickData
from sprite.DynamicSprite import DynamicSprite
from sprite.Spritesheet import Spritesheet
from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel
class PlayerSprite(DynamicSprite):
def __init__(self, spritesheet: Spritesheet):
super().__init__(spritesheet)
self.jump_time = -1
self.allowed_jump_time = 20
self.debug_label = TextLabel('', -1, -1)
def tick(self, tick_data: TickData):
super().tick(tick_data)
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT):
self.motion = (self.motion[0] + 2, self.motion[1])
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_LEFT):
self.motion = (self.motion[0] - 2, self.motion[1])
self.debug_label.set_text(f'jump: {self.jump_time}, x: {round(self.motion[0], 2)}, y: {round(self.motion[1], 2)}, touches: {self.touches_bounding}')