fix the enum mapping, fully implement the animations mapping, lower run updates per frame, fix hyperspeed animations

This commit is contained in:
Xevion
2020-04-20 03:35:51 -05:00
parent 8145c62090
commit e5c53fa7a0
2 changed files with 32 additions and 24 deletions

View File

@@ -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):
"""