create new enums class, move out constants from mobs.py

This commit is contained in:
Xevion
2020-04-20 01:44:21 -05:00
parent 290942aa0d
commit 3d9a6d3eb4
2 changed files with 20 additions and 13 deletions

View File

@@ -3,8 +3,11 @@ config.py
Holds all constants used for setting up the game. Holds all constants used for setting up the game.
May later hold functions for loading/saving configuration files. May later hold functions for loading/saving configuration files.
""" """
import os import os
from enum import Enum
BASE_PATH = os.path.dirname(os.path.abspath(__file__)) BASE_PATH = os.path.dirname(os.path.abspath(__file__))
RESOURCES = os.path.join(BASE_PATH, "resources") RESOURCES = os.path.join(BASE_PATH, "resources")
IMAGES = os.path.join(RESOURCES, "images") IMAGES = os.path.join(RESOURCES, "images")
@@ -37,6 +40,18 @@ class Config(object):
TOP_VIEWPORT_MARGIN = 100 TOP_VIEWPORT_MARGIN = 100
class Enums(Enum):
"""
A simple class used for tracking different simple
"""
# Play Direction Enums
RIGHT_FACING
LEFT_FACING
FRONT_FACING
UP_FACING
DOWN_FACING
class Sprites(object): class Sprites(object):
""" """
Simple class for holding sprite paths. Simple class for holding sprite paths.

View File

@@ -5,15 +5,7 @@ Organizes all classes related to Mobs, Entities, Enemies, Players and Items.
import arcade import arcade
from config import Config from config import Config, Enums
# Constants used to track if the player is facing left or right
RIGHT_FACING = 0
LEFT_FACING = 1
FRONT_FACING = 2
UP_FACING = 3
DOWN_FACING = 4
class Mob(arcade.Sprite): class Mob(arcade.Sprite):
""" """
@@ -51,7 +43,7 @@ class Player(Mob):
main_path = "resources/images/character/knight/" main_path = "resources/images/character/knight/"
# Default to face-front # Default to face-front
self.character_face_direction = FRONT_FACING self.character_face_direction = Enums.FRONT_FACING
# Load textures for idle standing # Load textures for idle standing
for i in range(4): for i in range(4):
@@ -80,11 +72,11 @@ class Player(Mob):
# Figure out if we need to flip face left, right, up, or down # Figure out if we need to flip face left, right, up, or down
if self.change_x > 0: if self.change_x > 0:
self.character_face_direction = LEFT_FACING self.character_face_direction = Enums.LEFT_FACING
elif self.change_x < 0: elif self.change_x < 0:
self.character_face_direction = RIGHT_FACING self.character_face_direction = Enums.RIGHT_FACING
elif self.change_x == 0 and self.change_y == 0: elif self.change_x == 0 and self.change_y == 0:
self.character_face_direction = FRONT_FACING self.character_face_direction = Enums.FRONT_FACING
# idle animation # idle animation
if self.change_x == 0 and self.change_y == 0: if self.change_x == 0 and self.change_y == 0: