From 276d584db405b719a041515b635873ccc8390ce1 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:09:31 -0500 Subject: [PATCH 1/9] add IDEA workspace folder to .gitignore --- triple-dungeon/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 triple-dungeon/.gitignore diff --git a/triple-dungeon/.gitignore b/triple-dungeon/.gitignore new file mode 100644 index 0000000..d19812c --- /dev/null +++ b/triple-dungeon/.gitignore @@ -0,0 +1 @@ +.idea/** \ No newline at end of file From 24d77714a5654297b2fd12676ff5335e276d788e Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:09:48 -0500 Subject: [PATCH 2/9] create basic Dungeon and Level skeleton classes --- triple-dungeon/map.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 triple-dungeon/map.py diff --git a/triple-dungeon/map.py b/triple-dungeon/map.py new file mode 100644 index 0000000..52d593b --- /dev/null +++ b/triple-dungeon/map.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +class Dungeon(object): + """ + Organizes Level objects into an easy to render and path through object. + """ + + def __init__(self, level_count: int = 3, size: int = 3) -> None: + """ + Initializes the Dungeon object. + + :param level_count: The number of Active Levels that should be stored within the Dungeon. + :param size: The diameter of the dungeon. Allows for a total of size^2 slots for levels. + """ + + self.levels, self.size = level_count, size + + +class Level(object): + """ + A 10x10 space holding wall and background sprites, enemies, items and so forth. + Should be loaded from + + """ + + def __init__(self,) -> None: + self.wallGrid = [] + + @staticmethod + def load_file(path: str) -> Level: + """ + Builds a Level from a given file path. + + :param path: Path to the Level file. + :return: The new generated Level file. + """ + pass From 240a3707038c039eec362b877951f1f846eccd7a Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:15:58 -0500 Subject: [PATCH 3/9] create basic mob class skeletons --- triple-dungeon/mobs.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 triple-dungeon/mobs.py diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py new file mode 100644 index 0000000..20ac557 --- /dev/null +++ b/triple-dungeon/mobs.py @@ -0,0 +1,22 @@ +import arcade + +class Mob(object): + def __init__(self, sprite, max_health=100, max_armor=0) -> None: + self.sprite_path = sprite + self.max_health, self.max_armor = max_health, max_armor + self.health, self.armor = max_health, max_armor + + def tick(self) -> None: + pass + +class Player(Mob): + def __init__(self, *args, **kwargs) -> None: + super(Player, self).__init__(*args, **kwargs) + +class Enemy(Mob): + def __init__(self, *args, **kwargs) -> None: + super(Enemy, self).__init__(*args, **kwargs) + + def tick(self) -> None: + + def path(self) -> None: From b4903ae8bb25f30d192ce1523fb53629e92bc869 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:22:04 -0500 Subject: [PATCH 4/9] basic docstrings/typehints for classes and functions --- triple-dungeon/mobs.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index 20ac557..dda7f5e 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -1,22 +1,55 @@ import arcade class Mob(object): + """ + Represents a Mob. No defined behaviour, it has no intelligence. + """ def __init__(self, sprite, max_health=100, max_armor=0) -> None: self.sprite_path = sprite self.max_health, self.max_armor = max_health, max_armor self.health, self.armor = max_health, max_armor def tick(self) -> None: + """ + A on_update function, the Mob should decide it's next actions here. + """ pass + class Player(Mob): + """ + Represents a Player. + While this is a instance, there should only be one in the world at any given time. + """ def __init__(self, *args, **kwargs) -> None: super(Player, self).__init__(*args, **kwargs) + def tick(self): + """ + While Player objects do not have any AI (they are controlled by the user), + the tick function can keep track of statistics that progress over time, like + regenerating health/armor or status effects like poison. + """ + + class Enemy(Mob): + """ + Represents an Enemy Mob. + Will take basic offensive actions against Player objects. + """ def __init__(self, *args, **kwargs) -> None: super(Enemy, self).__init__(*args, **kwargs) def tick(self) -> None: + """ + A on_update function, the Enemy Mob should scan for the player, decide how to path to it, and + decide how to take offensive action. + """ + pass def path(self) -> None: + """ + Not yet decided how this function should work. + Basically, most pathfinding decisions should be kept within this function. + """ + pass From a22b472392104d55be070950d8e6ecce123ff4ea Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:25:36 -0500 Subject: [PATCH 5/9] create new config class for organizing constants --- triple-dungeon/config.py | 23 +++++++++++++++++++++++ triple-dungeon/main.py | 24 ------------------------ 2 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 triple-dungeon/config.py diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py new file mode 100644 index 0000000..052abe1 --- /dev/null +++ b/triple-dungeon/config.py @@ -0,0 +1,23 @@ +class Config(object): + """ + A simple class dedicated to loading, storing and organizing constants. + """ + + # Constants + SCREEN_WIDTH = 1000 + SCREEN_HEIGHT = 650 + SCREEN_TITLE = "Triple Dungeon" + + # Constants used to scale our sprites from their original size + CHARACTER_SCALING = 1 + TILE_SCALING = 2 + + # Movement speed of player, in pixels per frame + PLAYER_MOVEMENT_SPEED = 5 + + # 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 diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index f85d015..3ded8ac 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -1,29 +1,5 @@ -""" -Platformer Game -""" import arcade -# Constants -SCREEN_WIDTH = 1000 -SCREEN_HEIGHT = 650 -SCREEN_TITLE = "Triple Dungeon!!!" - -# Constants used to scale our sprites from their original size -CHARACTER_SCALING = 1 -TILE_SCALING = 2 - -# Movement speed of player, in pixels per frame -PLAYER_MOVEMENT_SPEED = 5 - - -# 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 MyGame(arcade.Window): """ Main application class. From 814996497e54e8f09a49572f401a93889600648a Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:27:01 -0500 Subject: [PATCH 6/9] change all constants to use new config class, rename MyGame to just Game --- triple-dungeon/main.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 3ded8ac..be1fad2 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -1,13 +1,15 @@ import arcade -class MyGame(arcade.Window): +from config import Config + +class Game(arcade.Window): """ Main application class. """ def __init__(self): # Call the parent class and set up the window - super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) + super().__init__(Config.SCREEN_WIDTH, Config.SCREEN_HEIGHT, Config.SCREEN_TITLE) # These are 'lists' that keep track of our sprites. Each sprite should # go into a list. @@ -39,17 +41,17 @@ class MyGame(arcade.Window): # Set up the player, specifically placing it at these coordinates. image_source = "images/monsters/skeleton.png" - self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING) - self.player_sprite.center_x = SCREEN_WIDTH / 2 - self.player_sprite.center_y = SCREEN_HEIGHT / 2 + self.player_sprite = arcade.Sprite(image_source, 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 self.player_list.append(self.player_sprite) # Create the floor # This shows using a loop to place multiple sprites horizontally and vertically - for y in range(0, 1250, 63 * TILE_SCALING): - for x in range(0, 1250, 63 * TILE_SCALING): - floor = arcade.Sprite("images/tiles/floor_tile.png", TILE_SCALING) + for y in range(0, 1250, 63 * Config.TILE_SCALING): + for x in range(0, 1250, 63 * Config.TILE_SCALING): + floor = arcade.Sprite("images/tiles/floor_tile.png", Config.TILE_SCALING) floor.center_x = x floor.center_y = y self.floor_list.append(floor) @@ -71,16 +73,16 @@ class MyGame(arcade.Window): """Called whenever a key is pressed. """ if key == arcade.key.UP or key == arcade.key.W: - self.player_sprite.change_y = PLAYER_MOVEMENT_SPEED + self.player_sprite.change_y = Config.PLAYER_MOVEMENT_SPEED self.prev_keypress.append(key) elif key == arcade.key.DOWN or key == arcade.key.S: - self.player_sprite.change_y = -PLAYER_MOVEMENT_SPEED + self.player_sprite.change_y = -Config.PLAYER_MOVEMENT_SPEED self.prev_keypress.append(key) elif key == arcade.key.LEFT or key == arcade.key.A: - self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED + self.player_sprite.change_x = -Config.PLAYER_MOVEMENT_SPEED self.prev_keypress.append(key) elif key == arcade.key.RIGHT or key == arcade.key.D: - self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED + self.player_sprite.change_x = Config.PLAYER_MOVEMENT_SPEED self.prev_keypress.append(key) def on_key_release(self, key, modifiers): @@ -115,25 +117,25 @@ class MyGame(arcade.Window): changed = False # Scroll left - left_boundary = self.view_left + LEFT_VIEWPORT_MARGIN + left_boundary = self.view_left + Config.LEFT_VIEWPORT_MARGIN if self.player_sprite.left < left_boundary: self.view_left -= left_boundary - self.player_sprite.left changed = True # Scroll right - right_boundary = self.view_left + SCREEN_WIDTH - RIGHT_VIEWPORT_MARGIN + right_boundary = self.view_left + Config.SCREEN_WIDTH - Config.RIGHT_VIEWPORT_MARGIN if self.player_sprite.right > right_boundary: self.view_left += self.player_sprite.right - right_boundary changed = True # Scroll up - top_boundary = self.view_bottom + SCREEN_HEIGHT - TOP_VIEWPORT_MARGIN + top_boundary = self.view_bottom + Config.SCREEN_HEIGHT - Config.TOP_VIEWPORT_MARGIN if self.player_sprite.top > top_boundary: self.view_bottom += self.player_sprite.top - top_boundary changed = True # Scroll down - bottom_boundary = self.view_bottom + BOTTOM_VIEWPORT_MARGIN + bottom_boundary = self.view_bottom + Config.BOTTOM_VIEWPORT_MARGIN if self.player_sprite.bottom < bottom_boundary: self.view_bottom -= bottom_boundary - self.player_sprite.bottom changed = True @@ -146,14 +148,14 @@ class MyGame(arcade.Window): # Do the scrolling arcade.set_viewport(self.view_left, - SCREEN_WIDTH + self.view_left, + Config.SCREEN_WIDTH + self.view_left, self.view_bottom, - SCREEN_HEIGHT + self.view_bottom) + Config.SCREEN_HEIGHT + self.view_bottom) def main(): """ Main method """ - window = MyGame() + window = Game() window.setup() arcade.run() From bb4a6cd8e714b4a2f3c4d8ec0e11e17623de9a72 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:29:27 -0500 Subject: [PATCH 7/9] use Config class in mobs.py --- triple-dungeon/mobs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index dda7f5e..6856ed1 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -1,11 +1,14 @@ import arcade +from config import Config + class Mob(object): """ Represents a Mob. No defined behaviour, it has no intelligence. """ def __init__(self, sprite, max_health=100, max_armor=0) -> None: self.sprite_path = sprite + self.sprite = arcade.Sprite(self.sprite_path, Config.CHARACTER_SCALING) self.max_health, self.max_armor = max_health, max_armor self.health, self.armor = max_health, max_armor From d24e166e729f467601fa682d0ee68f0cdc781502 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:32:29 -0500 Subject: [PATCH 8/9] add file level docstrings to all files --- triple-dungeon/config.py | 6 ++++++ triple-dungeon/main.py | 6 ++++++ triple-dungeon/mobs.py | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 052abe1..44bd4ac 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -1,3 +1,9 @@ +""" +config.py +Holds all constants used for setting up the game. +May later hold functions for loading/saving configuration files. +""" + class Config(object): """ A simple class dedicated to loading, storing and organizing constants. diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index be1fad2..932d82f 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -1,3 +1,9 @@ +""" +main.py +The main class used to load the game. +Holds the main game window, as well as manages basic functions for organizing the game. +""" + import arcade from config import Config diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index 6856ed1..5242641 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -1,3 +1,8 @@ +""" +mobs.py +Organizes all classes related to Mobs, Entities, Enemies, Players and Items. +""" + import arcade from config import Config From 396141427902b4a681c0b73434a791a87e1053f8 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 18 Apr 2020 01:36:13 -0500 Subject: [PATCH 9/9] basic reformatting work for PEP8 guidelines --- triple-dungeon/config.py | 1 + triple-dungeon/main.py | 23 ++++++++++------------- triple-dungeon/mobs.py | 1 + 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 44bd4ac..933abaf 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -4,6 +4,7 @@ Holds all constants used for setting up the game. May later hold functions for loading/saving configuration files. """ + class Config(object): """ A simple class dedicated to loading, storing and organizing constants. diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 932d82f..0b13d56 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -8,6 +8,7 @@ import arcade from config import Config + class Game(arcade.Window): """ Main application class. @@ -29,7 +30,7 @@ class Game(arcade.Window): # Our physics engine self.physics_engine = None - #list to keep track of keypresses + # list to keep track of keypresses self.prev_keypress = [] # Used to keep track of our scrolling @@ -108,38 +109,31 @@ class Game(arcade.Window): self.prev_keypress.remove(key) if self.prev_keypress: - self.on_key_press(self.prev_keypress.pop(0), '') + self.on_key_press(self.prev_keypress.pop(0), 0) def on_update(self, delta_time): """ Movement and game logic """ # Move the player with the physics engine self.physics_engine.update() + changed = False # Track if we need to change the viewport - # --- Manage Scrolling --- - - # Track if we need to change the viewport - - changed = False - + # Below manages all scrolling mechanics # Scroll left left_boundary = self.view_left + Config.LEFT_VIEWPORT_MARGIN if self.player_sprite.left < left_boundary: self.view_left -= left_boundary - self.player_sprite.left changed = True - # Scroll right right_boundary = self.view_left + Config.SCREEN_WIDTH - Config.RIGHT_VIEWPORT_MARGIN if self.player_sprite.right > right_boundary: self.view_left += self.player_sprite.right - right_boundary changed = True - # Scroll up top_boundary = self.view_bottom + Config.SCREEN_HEIGHT - Config.TOP_VIEWPORT_MARGIN if self.player_sprite.top > top_boundary: self.view_bottom += self.player_sprite.top - top_boundary changed = True - # Scroll down bottom_boundary = self.view_bottom + Config.BOTTOM_VIEWPORT_MARGIN if self.player_sprite.bottom < bottom_boundary: @@ -159,8 +153,11 @@ class Game(arcade.Window): Config.SCREEN_HEIGHT + self.view_bottom) -def main(): - """ Main method """ +def main() -> None: + """ + Setups up window classes and runs the game. + """ + window = Game() window.setup() arcade.run() diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index 5242641..97b7ff7 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -7,6 +7,7 @@ import arcade from config import Config + class Mob(object): """ Represents a Mob. No defined behaviour, it has no intelligence.