mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-14 14:09:55 -06:00
fix the enum mapping, fully implement the animations mapping, lower run updates per frame, fix hyperspeed animations
This commit is contained in:
@@ -24,7 +24,7 @@ class Config(object):
|
|||||||
SCREEN_TITLE = "Triple Dungeon"
|
SCREEN_TITLE = "Triple Dungeon"
|
||||||
TILE_WIDTH = 63
|
TILE_WIDTH = 63
|
||||||
IDLE_UPDATES_PER_FRAME = 20
|
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
|
# Constants used to scale our sprites from their original size
|
||||||
CHARACTER_SCALING = 1
|
CHARACTER_SCALING = 1
|
||||||
@@ -46,11 +46,11 @@ class Enums(Enum):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Play Direction Enums
|
# Play Direction Enums
|
||||||
RIGHT_FACING = 0
|
RIGHT = 0
|
||||||
LEFT_FACING = 1
|
LEFT = 1
|
||||||
FRONT_FACING = 2
|
UP = 2
|
||||||
UP_FACING = 3
|
DOWN = 3
|
||||||
DOWN_FACING = 4
|
IDLE = 4
|
||||||
|
|
||||||
|
|
||||||
class SpritePaths(object):
|
class SpritePaths(object):
|
||||||
|
|||||||
@@ -26,16 +26,6 @@ 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.
|
||||||
@@ -53,7 +43,18 @@ 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)
|
||||||
|
# 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.refreshIndex = 0
|
||||||
|
self.prev = Enums.IDLE
|
||||||
|
self.texture = next(self.map[self.prev])
|
||||||
|
|
||||||
def update_animation(self, delta_time: float = 1 / 60) -> None:
|
def update_animation(self, delta_time: float = 1 / 60) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -61,21 +62,28 @@ class Player(Mob):
|
|||||||
:param delta_time: No idea.
|
:param delta_time: No idea.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Increase the refresh index according
|
||||||
self.refreshIndex = (self.refreshIndex + 1) % Config.RUN_UPDATES_PER_FRAME
|
self.refreshIndex = (self.refreshIndex + 1) % Config.RUN_UPDATES_PER_FRAME
|
||||||
|
|
||||||
if self.change_x == 0 and self.change_y == 0: # Idle
|
# Logic to determine what direction we're in.
|
||||||
dir = Enums.IDLE
|
if self.change_x == 0 and self.change_y == 0:
|
||||||
|
cur = Enums.IDLE
|
||||||
elif self.change_y > 0: # Up
|
elif self.change_y > 0: # Up
|
||||||
dir = Enums.UP
|
cur = Enums.UP
|
||||||
elif self.change_y < 0: # Down
|
elif self.change_y < 0: # Down
|
||||||
dir = Enums.DOWN
|
cur = Enums.DOWN
|
||||||
elif self.change_x > 0: # Left
|
elif self.change_x > 0: # Left
|
||||||
dir = Enums.LEFT
|
cur = Enums.RIGHT
|
||||||
elif self.change_x < 0: # 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:
|
# If we're in a new direction or the refresh index has reset
|
||||||
self.texture = next(self.map[dir])
|
if self.prev is not cur or self.refreshIndex == 0:
|
||||||
|
self.texture = next(self.map[cur])
|
||||||
|
|
||||||
|
self.prev = cur
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user