mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-10 12:05:22 -06:00
fix the enum mapping, fully implement the animations mapping, lower run updates per frame, fix hyperspeed animations
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user