create new sprites class for holding sprite paths

This commit is contained in:
Xevion
2020-04-19 23:45:01 -05:00
parent d4b5a1b799
commit 7d9efa4da1
3 changed files with 24 additions and 8 deletions

View File

@@ -3,7 +3,11 @@ config.py
Holds all constants used for setting up the game.
May later hold functions for loading/saving configuration files.
"""
import os
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
RESOURCES = os.path.join(BASE_PATH, "resources")
IMAGES = os.path.join(RESOURCES, "images")
class Config(object):
"""
@@ -23,9 +27,22 @@ class Config(object):
# Movement speed of player, in pixels per frame
PLAYER_MOVEMENT_SPEED = 7
# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
# How many pixels to keep as a minimum margin between the character and the edge of the screen.
LEFT_VIEWPORT_MARGIN = 250
RIGHT_VIEWPORT_MARGIN = 250
BOTTOM_VIEWPORT_MARGIN = 50
TOP_VIEWPORT_MARGIN = 100
class Sprites(object):
"""
Simple class for holding sprite paths.
"""
__MONSTERS = os.path.join(IMAGES, "monsters")
SKELETON = os.path.join(__MONSTERS, "skeleton.png")
GHOST = os.path.join(__MONSTERS, "ghost", "ghost1.png")
FROG = os.path.join(__MONSTERS, "frog", "frog1.png")
print(SKELETON, GHOST, FROG)

View File

@@ -6,9 +6,9 @@ Holds the main game window, as well as manages basic functions for organizing th
import arcade
from config import Config
from map import Dungeon
from mobs import Player, Enemy
from config import Config, Sprites
class Game(arcade.Window):
@@ -59,8 +59,8 @@ class Game(arcade.Window):
# Create monsters
self.enemy_list.extend([
Enemy("resources/images/monsters/ghost/ghost1.png", 200, 200).get_enemy(),
Enemy("resources/images/monsters/frog/frog1.png", 200, 1000).get_enemy()
Enemy(Sprites.GHOST, 200, 200).get_enemy(),
Enemy(Sprites.FROG, 200, 1000).get_enemy()
])
# Create the 'physics engine'

View File

@@ -5,7 +5,7 @@ Organizes all classes related to Mobs, Entities, Enemies, Players and Items.
import arcade
from config import Config
from config import Config, Sprites
class Mob(object):
@@ -37,8 +37,7 @@ class Player(Mob):
super(Player, self).__init__(*args, **kwargs)
def setup(self):
image_source = "resources/images/monsters/skeleton.png"
self.player_sprite = arcade.Sprite(image_source, Config.CHARACTER_SCALING)
self.player_sprite = arcade.Sprite(Sprites.SKELETON, Config.CHARACTER_SCALING)
self.player_sprite.center_x = Config.SCREEN_WIDTH / 2
self.player_sprite.center_y = Config.SCREEN_HEIGHT / 2
self.player_sprite.scale = 4