mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-14 16:09:54 -06:00
change statements to use Enums with dictionary mapping
This commit is contained in:
@@ -26,6 +26,16 @@ class Mob(arcade.Sprite):
|
|||||||
self.down_textures = []
|
self.down_textures = []
|
||||||
self.cur_texture = 0
|
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:
|
def tick(self) -> None:
|
||||||
"""
|
"""
|
||||||
A on_update function, the Mob should decide it's next actions here.
|
A on_update function, the Mob should decide it's next actions here.
|
||||||
@@ -43,6 +53,7 @@ class Player(Mob):
|
|||||||
super(Player, self).__init__(*args, **kwargs)
|
super(Player, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.animations = PlayerAnimations(SpritePaths.KNIGHT)
|
self.animations = PlayerAnimations(SpritePaths.KNIGHT)
|
||||||
|
self.refreshIndex = 0
|
||||||
|
|
||||||
def update_animation(self, delta_time: float = 1 / 60) -> None:
|
def update_animation(self, delta_time: float = 1 / 60) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -50,16 +61,21 @@ class Player(Mob):
|
|||||||
:param delta_time: No idea.
|
:param delta_time: No idea.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.change_x == 0 and self.change_y == 0:
|
self.refreshIndex = (self.refreshIndex + 1) % Config.RUN_UPDATES_PER_FRAME
|
||||||
self.texture = next(self.animations.idles)
|
|
||||||
|
if self.change_x == 0 and self.change_y == 0: # Idle
|
||||||
|
dir = Enums.IDLE
|
||||||
elif self.change_y > 0: # Up
|
elif self.change_y > 0: # Up
|
||||||
self.texture = next(self.animations.up)
|
dir = Enums.UP
|
||||||
elif self.change_y < 0: # Down
|
elif self.change_y < 0: # Down
|
||||||
self.texture = next(self.animations.down)
|
dir = Enums.DOWN
|
||||||
elif self.change_x > 0: # Left
|
elif self.change_x > 0: # Left
|
||||||
self.texture = next(self.animations.right)
|
dir = Enums.LEFT
|
||||||
elif self.change_x < 0: # Right
|
elif self.change_x < 0: # Right
|
||||||
self.texture = next(self.animations.left)
|
dir = Enums.RIGHT
|
||||||
|
|
||||||
|
if self.prev != dir or not wait:
|
||||||
|
self.texture = next(self.map[dir])
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user