From 7d9efa4da131f6346971568070688c6995d03e28 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 19 Apr 2020 23:45:01 -0500 Subject: [PATCH] create new sprites class for holding sprite paths --- triple-dungeon/config.py | 21 +++++++++++++++++++-- triple-dungeon/main.py | 6 +++--- triple-dungeon/mobs.py | 5 ++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 313b102..2c00dfb 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -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) \ No newline at end of file diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 56e6a5b..7d7e4db 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -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' diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index d6656ab..bf72e6c 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -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