def reset_state(self) -> None:
        """Check if state needs to be reset to "idle" due to inactivity."""

        current_time = timestamp_now()

        if (current_time - self.clock) >= ANIM_RESET:
            self.state = "idle"
            self.clock = current_time
Beispiel #2
0
    def __init__(self, sprite_group: str, speed: int = 1):
        super().__init__(sprite_group)

        # multiplier for pixel displacement
        self.speed: int = speed

        # internal clock for state reset
        self.clock = timestamp_now()

        # movement mapper
        self.movements = {"up": self.move_up,
                          "down": self.move_down,
                          "left": self.move_left,
                          "right": self.move_right}
    def __init__(self, sprite_group: str, speed: int = 1):
        # load initial animation frame and "idle" anims via parent class
        super().__init__(sprite_group)

        # collection for animations per state
        self.anim_groups: dict = {state: [] for state in ANIM_GROUPS}

        # reload animations for all states
        self.load_animations()

        # multiplier for pixel displacement
        self.speed: int = speed

        # internal clock for state reset
        self.clock = timestamp_now()

        # movement mapper
        self.movements = {
            "up": self.move_up,
            "down": self.move_down,
            "left": self.move_left,
            "right": self.move_right
        }
 def move_right(self) -> None:
     self.rect.x += self.speed
     self.state = "right"
     self.animate()  # jump to next anim frame
     self.clock = timestamp_now()  # reset clock after movement
 def move_down(self) -> None:
     self.rect.y += self.speed
     self.state = "down"
     self.animate()  # jump to next anim frame
     self.clock = timestamp_now()  # reset clock after movement
Beispiel #6
0
 def move_right(self) -> None:
     self.rect.x += self.speed
     self.state = "right"
     self.clock = timestamp_now()    # reset clock after movement
Beispiel #7
0
 def move_left(self) -> None:
     self.rect.x -= self.speed
     self.state = "left"
     self.clock = timestamp_now()    # reset clock after movement
Beispiel #8
0
 def move_down(self) -> None:
     self.rect.y += self.speed
     self.state = "down"
     self.clock = timestamp_now()    # reset clock after movement
Beispiel #9
0
 def move_up(self) -> None:
     self.rect.y -= self.speed
     self.state = "up"
     self.clock = timestamp_now()    # reset clock after movement