diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 0cab7fd..2b13ade 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -24,7 +24,7 @@ class Config(object): SCREEN_TITLE = "Triple Dungeon" TILE_WIDTH = 63 IDLE_UPDATES_PER_FRAME = 20 - RUN_UPDATES_PER_FRAME = 10 + RUN_UPDATES_PER_FRAME = 8 # Constants used to scale our sprites from their original size CHARACTER_SCALING = 1 @@ -46,11 +46,11 @@ class Enums(Enum): """ # Play Direction Enums - RIGHT_FACING = 0 - LEFT_FACING = 1 - FRONT_FACING = 2 - UP_FACING = 3 - DOWN_FACING = 4 + RIGHT = 0 + LEFT = 1 + UP = 2 + DOWN = 3 + IDLE = 4 class SpritePaths(object): diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index 5d72d86..9b9906b 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -26,16 +26,6 @@ class Mob(arcade.Sprite): self.down_textures = [] self.cur_texture = 0 - - # Used for mapping directions to animations - self.map = { - Enums.IDLE : self.animations.idles, - Enums.UP : self.animations.up, - Enums.DOWN : self.animations.down, - Enums.RIGHT : self.animations.right, - Enums.LEFT : self.animations.left - } - def tick(self) -> None: """ A on_update function, the Mob should decide it's next actions here. @@ -53,7 +43,18 @@ class Player(Mob): super(Player, self).__init__(*args, **kwargs) self.animations = PlayerAnimations(SpritePaths.KNIGHT) + # Used for mapping directions to animations + self.map = { + Enums.IDLE: self.animations.idles, + Enums.UP: self.animations.up, + Enums.DOWN: self.animations.down, + Enums.RIGHT: self.animations.right, + Enums.LEFT: self.animations.left + } + self.refreshIndex = 0 + self.prev = Enums.IDLE + self.texture = next(self.map[self.prev]) def update_animation(self, delta_time: float = 1 / 60) -> None: """ @@ -61,21 +62,28 @@ class Player(Mob): :param delta_time: No idea. """ + # Increase the refresh index according self.refreshIndex = (self.refreshIndex + 1) % Config.RUN_UPDATES_PER_FRAME - if self.change_x == 0 and self.change_y == 0: # Idle - dir = Enums.IDLE + # Logic to determine what direction we're in. + if self.change_x == 0 and self.change_y == 0: + cur = Enums.IDLE elif self.change_y > 0: # Up - dir = Enums.UP + cur = Enums.UP elif self.change_y < 0: # Down - dir = Enums.DOWN + cur = Enums.DOWN elif self.change_x > 0: # Left - dir = Enums.LEFT + cur = Enums.RIGHT elif self.change_x < 0: # Right - dir = Enums.RIGHT + cur = Enums.LEFT + else: # Idle + cur = Enums.IDLE - if self.prev != dir or not wait: - self.texture = next(self.map[dir]) + # If we're in a new direction or the refresh index has reset + if self.prev is not cur or self.refreshIndex == 0: + self.texture = next(self.map[cur]) + + self.prev = cur def tick(self): """