From 3f4f1863241bcb5dbf5f44271f376022407106d3 Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 01:18:12 -0700 Subject: [PATCH 01/13] Added Pathfinding dependency, started on path.py --- triple-dungeon/Pipfile | 1 + triple-dungeon/Pipfile.lock | 54 +++++++++++++++++++++---------------- triple-dungeon/path.py | 28 +++++++++++++++++++ 3 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 triple-dungeon/path.py diff --git a/triple-dungeon/Pipfile b/triple-dungeon/Pipfile index 4b6f851..2c24668 100644 --- a/triple-dungeon/Pipfile +++ b/triple-dungeon/Pipfile @@ -8,6 +8,7 @@ verify_ssl = true [packages] arcade = "*" networkx = "*" +pathfinding = "*" [requires] python_version = "3.7" diff --git a/triple-dungeon/Pipfile.lock b/triple-dungeon/Pipfile.lock index 6d6b49e..2c2ea7a 100644 --- a/triple-dungeon/Pipfile.lock +++ b/triple-dungeon/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "800f10e10ab907fd0589f880f7c7bbf82acfb39f3450331a1f3bdcdabc8e561d" + "sha256": "072e8938371eb0a39830868ce97961536e15f31d82fcdf3019e870522684c661" }, "pipfile-spec": 6, "requires": { @@ -47,29 +47,37 @@ }, "numpy": { "hashes": [ - "sha256:1598a6de323508cfeed6b7cd6c4efb43324f4692e20d1f76e1feec7f59013448", - "sha256:1b0ece94018ae21163d1f651b527156e1f03943b986188dd81bc7e066eae9d1c", - "sha256:2e40be731ad618cb4974d5ba60d373cdf4f1b8dcbf1dcf4d9dff5e212baf69c5", - "sha256:4ba59db1fcc27ea31368af524dcf874d9277f21fd2e1f7f1e2e0c75ee61419ed", - "sha256:59ca9c6592da581a03d42cc4e270732552243dc45e87248aa8d636d53812f6a5", - "sha256:5e0feb76849ca3e83dd396254e47c7dba65b3fa9ed3df67c2556293ae3e16de3", - "sha256:6d205249a0293e62bbb3898c4c2e1ff8a22f98375a34775a259a0523111a8f6c", - "sha256:6fcc5a3990e269f86d388f165a089259893851437b904f422d301cdce4ff25c8", - "sha256:82847f2765835c8e5308f136bc34018d09b49037ec23ecc42b246424c767056b", - "sha256:87902e5c03355335fc5992a74ba0247a70d937f326d852fc613b7f53516c0963", - "sha256:9ab21d1cb156a620d3999dd92f7d1c86824c622873841d6b080ca5495fa10fef", - "sha256:a1baa1dc8ecd88fb2d2a651671a84b9938461e8a8eed13e2f0a812a94084d1fa", - "sha256:a244f7af80dacf21054386539699ce29bcc64796ed9850c99a34b41305630286", - "sha256:a35af656a7ba1d3decdd4fae5322b87277de8ac98b7d9da657d9e212ece76a61", - "sha256:b1fe1a6f3a6f355f6c29789b5927f8bd4f134a4bd9a781099a7c4f66af8850f5", - "sha256:b5ad0adb51b2dee7d0ee75a69e9871e2ddfb061c73ea8bc439376298141f77f5", - "sha256:ba3c7a2814ec8a176bb71f91478293d633c08582119e713a0c5351c0f77698da", - "sha256:cd77d58fb2acf57c1d1ee2835567cd70e6f1835e32090538f17f8a3a99e5e34b", - "sha256:cdb3a70285e8220875e4d2bc394e49b4988bdb1298ffa4e0bd81b2f613be397c", - "sha256:deb529c40c3f1e38d53d5ae6cd077c21f1d49e13afc7936f7f868455e16b64a0", - "sha256:e7894793e6e8540dbeac77c87b489e331947813511108ae097f1715c018b8f3d" + "sha256:0aa2b318cf81eb1693fcfcbb8007e95e231d7e1aa24288137f3b19905736c3ee", + "sha256:163c78c04f47f26ca1b21068cea25ed7c5ecafe5f5ab2ea4895656a750582b56", + "sha256:1e37626bcb8895c4b3873fcfd54e9bfc5ffec8d0f525651d6985fcc5c6b6003c", + "sha256:264fd15590b3f02a1fbc095e7e1f37cdac698ff3829e12ffdcffdce3772f9d44", + "sha256:3d9e1554cd9b5999070c467b18e5ae3ebd7369f02706a8850816f576a954295f", + "sha256:40c24960cd5cec55222963f255858a1c47c6fa50a65a5b03fd7de75e3700eaaa", + "sha256:46f404314dbec78cb342904f9596f25f9b16e7cf304030f1339e553c8e77f51c", + "sha256:4847f0c993298b82fad809ea2916d857d0073dc17b0510fbbced663b3265929d", + "sha256:48e15612a8357393d176638c8f68a19273676877caea983f8baf188bad430379", + "sha256:6725d2797c65598778409aba8cd67077bb089d5b7d3d87c2719b206dc84ec05e", + "sha256:99f0ba97e369f02a21bb95faa3a0de55991fd5f0ece2e30a9e2eaebeac238921", + "sha256:a41f303b3f9157a31ce7203e3ca757a0c40c96669e72d9b6ee1bce8507638970", + "sha256:a4305564e93f5c4584f6758149fd446df39fd1e0a8c89ca0deb3cce56106a027", + "sha256:a551d8cc267c634774830086da42e4ba157fa41dd3b93982bc9501b284b0c689", + "sha256:a6bc9432c2640b008d5f29bad737714eb3e14bb8854878eacf3d7955c4e91c36", + "sha256:c60175d011a2e551a2f74c84e21e7c982489b96b6a5e4b030ecdeacf2914da68", + "sha256:e46e2384209c91996d5ec16744234d1c906ab79a701ce1a26155c9ec890b8dc8", + "sha256:e607b8cdc2ae5d5a63cd1bec30a15b5ed583ac6a39f04b7ba0f03fcfbf29c05b", + "sha256:e94a39d5c40fffe7696009dbd11bc14a349b377e03a384ed011e03d698787dd3", + "sha256:eb2286249ebfe8fcb5b425e5ec77e4736d53ee56d3ad296f8947f67150f495e3", + "sha256:fdee7540d12519865b423af411bd60ddb513d2eb2cd921149b732854995bbf8b" ], - "version": "==1.18.2" + "version": "==1.18.3" + }, + "pathfinding": { + "hashes": [ + "sha256:3e3809abada1fdb292ced85cd7f63700c4f28a20f10eae68168a760be52ca746", + "sha256:e71ac5e1d933d67a3b402600f3dfb766da8c0113a0df328661c89a24bd5f21a5" + ], + "index": "pypi", + "version": "==0.0.4" }, "pillow": { "hashes": [ diff --git a/triple-dungeon/path.py b/triple-dungeon/path.py new file mode 100644 index 0000000..2d91ecd --- /dev/null +++ b/triple-dungeon/path.py @@ -0,0 +1,28 @@ +from pathfinding.core.diagonal_movement import DiagonalMovement +from pathfinding.core.grid import Grid +from pathfinding.finder.a_star import AStarFinder + +# 0 is an unwalkable block. Numbers larger than 0 are walkable. +# The higher the number the harder it is to walk on. +matrix = [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], + [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + ] + +grid = Grid(matrix=matrix) +start = grid.node(1, 1) +end = grid.node(8, 8) + +finder = AStarFinder(diagonal_movement=DiagonalMovement.always) +path, runs = finder.find_path(start, end, grid) + +print('operations:', runs, 'path length:', len(path)) +print(grid.grid_str(path=path, start=start, end=end)) From de72eed2c73ddf96e8a670b95b38da188ed30691 Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 01:21:24 -0700 Subject: [PATCH 02/13] removed tabs --- triple-dungeon/path.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/triple-dungeon/path.py b/triple-dungeon/path.py index 2d91ecd..489a258 100644 --- a/triple-dungeon/path.py +++ b/triple-dungeon/path.py @@ -5,16 +5,16 @@ from pathfinding.finder.a_star import AStarFinder # 0 is an unwalkable block. Numbers larger than 0 are walkable. # The higher the number the harder it is to walk on. matrix = [ - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], - [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], + [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] grid = Grid(matrix=matrix) From 6561469351cfd2bf7f2ad0d53cc723e2c21e615a Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 02:27:28 -0700 Subject: [PATCH 03/13] route function takes start, stop, and matrixs, returns path --- triple-dungeon/path.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/triple-dungeon/path.py b/triple-dungeon/path.py index 489a258..46a7eea 100644 --- a/triple-dungeon/path.py +++ b/triple-dungeon/path.py @@ -2,27 +2,20 @@ from pathfinding.core.diagonal_movement import DiagonalMovement from pathfinding.core.grid import Grid from pathfinding.finder.a_star import AStarFinder -# 0 is an unwalkable block. Numbers larger than 0 are walkable. -# The higher the number the harder it is to walk on. -matrix = [ - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], - [0, 1, 1, 1, 0, 0, 1, 1, 1, 1], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - ] +def route(start, end, matrix) -> path: + """ + Take a matrix of the level in the form wighted numbers, a start and stop point, and return a path between them. -grid = Grid(matrix=matrix) -start = grid.node(1, 1) -end = grid.node(8, 8) + param: start: (x, y) location of the monster + param: end: (x, y) location of the player + param: matrix: a 2d list of the level. 0s are walls, numbers greater than 0 are weighted + """ + grid = Grid(matrix=matrix) + start = grid.node(start[0],start[1]) + end = grid.node(end[0], end[1]) -finder = AStarFinder(diagonal_movement=DiagonalMovement.always) -path, runs = finder.find_path(start, end, grid) + finder = AStarFinder(diagonal_movement=DiagonalMovement.always) + path, runs = finder.find_path(start, end, grid) -print('operations:', runs, 'path length:', len(path)) -print(grid.grid_str(path=path, start=start, end=end)) + #grid.grid_str(path=path, start=start, end=end) + return path From ba8459797c667cfa7fb016f72d6f6d0597657e6d Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 02:34:19 -0700 Subject: [PATCH 04/13] Removed tabs and training white space. --- triple-dungeon/path.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/triple-dungeon/path.py b/triple-dungeon/path.py index 46a7eea..6a062fd 100644 --- a/triple-dungeon/path.py +++ b/triple-dungeon/path.py @@ -2,20 +2,23 @@ from pathfinding.core.diagonal_movement import DiagonalMovement from pathfinding.core.grid import Grid from pathfinding.finder.a_star import AStarFinder + def route(start, end, matrix) -> path: - """ - Take a matrix of the level in the form wighted numbers, a start and stop point, and return a path between them. + """ + Take a matrix of the level in the form wighted numbers, a start and stop point, and return a path between them. + + param: start: (x, y) location of the monster + param: end: (x, y) location of the player + param: matrix: a 2d list of the level. 0s are walls, numbers greater than 0 are weighted + """ + + grid = Grid(matrix=matrix) + start = grid.node(start[0], start[1]) + end = grid.node(end[0], end[1]) + finder = AStarFinder(diagonal_movement=DiagonalMovement.always) + path, runs = finder.find_path(start, end, grid) + + return path - param: start: (x, y) location of the monster - param: end: (x, y) location of the player - param: matrix: a 2d list of the level. 0s are walls, numbers greater than 0 are weighted - """ - grid = Grid(matrix=matrix) - start = grid.node(start[0],start[1]) - end = grid.node(end[0], end[1]) - finder = AStarFinder(diagonal_movement=DiagonalMovement.always) - path, runs = finder.find_path(start, end, grid) - #grid.grid_str(path=path, start=start, end=end) - return path From 882ce349d87fbdfca19897e476d440bc7b50d950 Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 02:37:39 -0700 Subject: [PATCH 05/13] got rid of last bit of whitespace --- triple-dungeon/path.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/triple-dungeon/path.py b/triple-dungeon/path.py index 6a062fd..98b0ca1 100644 --- a/triple-dungeon/path.py +++ b/triple-dungeon/path.py @@ -6,7 +6,7 @@ from pathfinding.finder.a_star import AStarFinder def route(start, end, matrix) -> path: """ Take a matrix of the level in the form wighted numbers, a start and stop point, and return a path between them. - + param: start: (x, y) location of the monster param: end: (x, y) location of the player param: matrix: a 2d list of the level. 0s are walls, numbers greater than 0 are weighted @@ -19,6 +19,3 @@ def route(start, end, matrix) -> path: path, runs = finder.find_path(start, end, grid) return path - - - From 6769cceed4ab4215f67d4c401d5c1ff5aa243c4d Mon Sep 17 00:00:00 2001 From: Lief9100 Date: Mon, 20 Apr 2020 00:37:46 -0700 Subject: [PATCH 06/13] add constants to config --- triple-dungeon/config.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index a291911..01caa3f 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -41,6 +41,10 @@ class Config(object): RIGHT_VIEWPORT_MARGIN = 250 BOTTOM_VIEWPORT_MARGIN = 50 TOP_VIEWPORT_MARGIN = 100 + + #Bullet constants + BULLET_SPEED = 5 + SPRITE_SCALING_BULLET = 0.8 class Enums(Enum): From cc83bab11cdbb89f2a33b589365d89d6bf9ae5a2 Mon Sep 17 00:00:00 2001 From: Lief9100 Date: Mon, 20 Apr 2020 00:40:47 -0700 Subject: [PATCH 07/13] indentation and positioning correction in config for constants --- triple-dungeon/config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 01caa3f..0023f51 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -17,7 +17,7 @@ class Config(object): """ A simple class dedicated to loading, storing and organizing constants. """ - + # Constants SCREEN_WIDTH = 1650 SCREEN_HEIGHT = 1000 @@ -29,6 +29,7 @@ class Config(object): # Constants used to scale our sprites from their original size CHARACTER_SCALING = 1 TILE_SCALING = 2 + BULLET_SCALING = 0.8 # The number of pixels across the level LEVEL_SIZE = 10 * TILE_SCALING * TILE_WIDTH @@ -42,9 +43,9 @@ class Config(object): BOTTOM_VIEWPORT_MARGIN = 50 TOP_VIEWPORT_MARGIN = 100 - #Bullet constants - BULLET_SPEED = 5 - SPRITE_SCALING_BULLET = 0.8 + #Bullet constants + BULLET_SPEED = 5 + class Enums(Enum): From 3034d96ab7a2f5347a53dee5e3c8e51af43bd4f2 Mon Sep 17 00:00:00 2001 From: Lief9100 Date: Mon, 20 Apr 2020 01:27:26 -0700 Subject: [PATCH 08/13] main.py busy edit, works but simplistic --- triple-dungeon/main.py | 55 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 48bc7af..a7fe982 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -6,6 +6,7 @@ Holds the main game window, as well as manages basic functions for organizing th import random import arcade +import math from config import Config from map import Dungeon @@ -26,6 +27,7 @@ class Game(arcade.Window): self.wall_list = None self.floor_list = None self.enemy_list = None + self.bullet_list = None self.player = None self.dungeon = None @@ -47,6 +49,7 @@ class Game(arcade.Window): # Create the Sprite lists self.enemy_list = arcade.SpriteList() + self.bullet_list = arcade.SpriteList() # Set up the player, specifically placing it at these coordinates. self.player = Player() @@ -76,6 +79,7 @@ class Game(arcade.Window): self.player.draw() self.enemy_list.draw() self.wall_list.draw() + self.bullet_list.draw() x, y = self.player.center_x, self.player.center_y + 100 arcade.draw_text(f"({x}, {y})", x, y, arcade.color.WHITE, 15) @@ -116,13 +120,48 @@ class Game(arcade.Window): if self.prev_keypress: self.on_key_press(self.prev_keypress.pop(0), 0) + def on_mouse_press(self, x, y, button, modifiers): + """ + Called whenever the mouse is clicked. + """ + # Create a bullet NEED SPRITE, currently wielding frog slingshot + bullet = arcade.Sprite("resources/images/monsters/frog/frog1.png", Config.BULLET_SCALING) + + # Position the bullet at the player's current location + start_x = self.player_list.center_x + start_y = self.player_list.center_y + bullet.center_x = start_x + bullet.center_y = start_y + + # Get from the mouse the destination location for the bullet + dest_x = x+self.view_left + dest_y = y+self.view_bottom + + # Do math to calculate how to get the bullet to the destination. + # Calculation the angle in radians between the start points + # and end points. This is the angle the bullet will travel. + x_diff = dest_x - start_x + y_diff = dest_y - start_y + angle = math.atan2(y_diff, x_diff) + + # Angle the bullet sprite so it doesn't look like it is flying sideways. + bullet.angle = math.degrees(angle) + + # Taking into account the angle, calculate our change_x + # and change_y. Velocity is how fast the bullet travels. + bullet.change_x = math.cos(angle) * Config.BULLET_SPEED + bullet.change_y = math.sin(angle) * Config.BULLET_SPEED + + # Add the bullet to the appropriate lists + self.bullet_list.append(bullet) + def on_update(self, delta_time): """ Movement and game logic """ # Move the player with the physics engine self.physics_engine.update() - self.player.update_animation() + changed = False # Track if we need to change the viewport # Below manages all scrolling mechanics @@ -159,6 +198,20 @@ class Game(arcade.Window): self.view_bottom, Config.SCREEN_HEIGHT + self.view_bottom) + #Projectile updates + self.bullet_list.update() + for bullet in self.bullet_list: + # Collision Checks + hit_list = arcade.check_for_collision_with_list(bullet, self.wall_list) + + # If it did, get rid of the bullet + if len(hit_list) > 0: + bullet.remove_from_sprite_lists() + + # If the bullet flies off-screen, remove it. + if bullet.bottom > self.width or bullet.top < 0 or bullet.right < 0 or bullet.left > self.width: + bullet.remove_from_sprite_lists() + def main() -> None: """ From b06fcaf0f899bf8c227b8084db84a8a8de204d9a Mon Sep 17 00:00:00 2001 From: Lief9100 Date: Mon, 20 Apr 2020 01:47:48 -0700 Subject: [PATCH 09/13] screen-projectile deletion fix, comment updates to note TEMP features --- triple-dungeon/config.py | 2 +- triple-dungeon/main.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 0023f51..6c2e710 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -43,7 +43,7 @@ class Config(object): BOTTOM_VIEWPORT_MARGIN = 50 TOP_VIEWPORT_MARGIN = 100 - #Bullet constants + #Bullet constants TEMP change to speed factor in projectiles.py BULLET_SPEED = 5 diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index a7fe982..69604b1 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -124,7 +124,7 @@ class Game(arcade.Window): """ Called whenever the mouse is clicked. """ - # Create a bullet NEED SPRITE, currently wielding frog slingshot + # Create a bullet TEMP SPRITE, currently wielding frog slingshot bullet = arcade.Sprite("resources/images/monsters/frog/frog1.png", Config.BULLET_SCALING) # Position the bullet at the player's current location @@ -208,8 +208,8 @@ class Game(arcade.Window): if len(hit_list) > 0: bullet.remove_from_sprite_lists() - # If the bullet flies off-screen, remove it. - if bullet.bottom > self.width or bullet.top < 0 or bullet.right < 0 or bullet.left > self.width: + # If the bullet flies off-screen, remove it. TEMP change to range calc + if bullet.bottom < self.view_bottom or bullet.top > self.view_bottom+Config.SCREEN_HEIGHT or bullet.right > self.view_left+Config.SCREEN_WIDTH or bullet.left < self.view_left: bullet.remove_from_sprite_lists() From c051414870a7367b964f9488267de2f80d3819a3 Mon Sep 17 00:00:00 2001 From: Lief9100 Date: Mon, 20 Apr 2020 02:58:32 -0700 Subject: [PATCH 10/13] remove config excess, add projectiles folder and temp classes --- triple-dungeon/config.py | 4 ---- triple-dungeon/main.py | 12 ++++++------ triple-dungeon/projectiles.py | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 triple-dungeon/projectiles.py diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 6c2e710..c68c5b5 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -29,7 +29,6 @@ class Config(object): # Constants used to scale our sprites from their original size CHARACTER_SCALING = 1 TILE_SCALING = 2 - BULLET_SCALING = 0.8 # The number of pixels across the level LEVEL_SIZE = 10 * TILE_SCALING * TILE_WIDTH @@ -42,9 +41,6 @@ class Config(object): RIGHT_VIEWPORT_MARGIN = 250 BOTTOM_VIEWPORT_MARGIN = 50 TOP_VIEWPORT_MARGIN = 100 - - #Bullet constants TEMP change to speed factor in projectiles.py - BULLET_SPEED = 5 diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 69604b1..177c2cc 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -10,8 +10,9 @@ import math from config import Config from map import Dungeon -from mobs import Player - +from mobs import Player, Enemy +from config import Config, Sprites +from projectiles import Temp class Game(arcade.Window): """ @@ -125,8 +126,7 @@ class Game(arcade.Window): Called whenever the mouse is clicked. """ # Create a bullet TEMP SPRITE, currently wielding frog slingshot - bullet = arcade.Sprite("resources/images/monsters/frog/frog1.png", Config.BULLET_SCALING) - + bullet = Temp() # Position the bullet at the player's current location start_x = self.player_list.center_x start_y = self.player_list.center_y @@ -149,8 +149,8 @@ class Game(arcade.Window): # Taking into account the angle, calculate our change_x # and change_y. Velocity is how fast the bullet travels. - bullet.change_x = math.cos(angle) * Config.BULLET_SPEED - bullet.change_y = math.sin(angle) * Config.BULLET_SPEED + bullet.change_x = math.cos(angle) * bullet.speed + bullet.change_y = math.sin(angle) * bullet.speed # Add the bullet to the appropriate lists self.bullet_list.append(bullet) diff --git a/triple-dungeon/projectiles.py b/triple-dungeon/projectiles.py new file mode 100644 index 0000000..288875a --- /dev/null +++ b/triple-dungeon/projectiles.py @@ -0,0 +1,37 @@ +""" +projectiles.py +Organizes classes related to projectiles +""" + +import arcade + +from config import Config, Sprites + + +class Projectile(arcade.Sprite): + """ + Represents a Projectile. Damage, sprite, speed, range, collision list? + """ + def __init__(self, speed=7, damage=0, range=100, *args, **kwargs) -> None: + # Set up parent class + super().__init__() + + self.speed = speed + self.damage = damage #unimplemented + self.texture = None + self.range = range #unimplemented + self.collision_list = [] + + +class Temp(Projectile): + """ + Temporary extension of projectile to demonstrate usage + """ + def __init__(self, *args, **kwargs) -> None: + super(Temp, self).__init__(*args, **kwargs) + self.texture = arcade.load_texture("resources/images/monsters/frog/frog1.png") + self.speed = 12 + self.scale = 2 + #collision list for who/what to collide with: wall, player, enemy + + #Can place function for starting on player or enemy From dff882770d67e4cbb3578fec69693b3f03204db8 Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 13:45:49 -0700 Subject: [PATCH 11/13] removed whitespace and other formatting. --- triple-dungeon/config.py | 3 +-- triple-dungeon/main.py | 18 +++++++++--------- triple-dungeon/projectiles.py | 14 ++++++-------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index c68c5b5..a291911 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -17,7 +17,7 @@ class Config(object): """ A simple class dedicated to loading, storing and organizing constants. """ - + # Constants SCREEN_WIDTH = 1650 SCREEN_HEIGHT = 1000 @@ -41,7 +41,6 @@ class Config(object): RIGHT_VIEWPORT_MARGIN = 250 BOTTOM_VIEWPORT_MARGIN = 50 TOP_VIEWPORT_MARGIN = 100 - class Enums(Enum): diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 177c2cc..a4170f8 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -11,9 +11,10 @@ import math from config import Config from map import Dungeon from mobs import Player, Enemy -from config import Config, Sprites +from config import Config from projectiles import Temp + class Game(arcade.Window): """ Main application class. @@ -79,11 +80,10 @@ class Game(arcade.Window): self.dungeon.render() self.player.draw() self.enemy_list.draw() - self.wall_list.draw() self.bullet_list.draw() x, y = self.player.center_x, self.player.center_y + 100 - arcade.draw_text(f"({x}, {y})", x, y, arcade.color.WHITE, 15) + # arcade.draw_text(f"({x}, {y})", x, y, arcade.color.WHITE, 15) def on_key_press(self, key, modifiers): """Called whenever a key is pressed. """ @@ -128,8 +128,8 @@ class Game(arcade.Window): # Create a bullet TEMP SPRITE, currently wielding frog slingshot bullet = Temp() # Position the bullet at the player's current location - start_x = self.player_list.center_x - start_y = self.player_list.center_y + start_x = self.player.center_x + start_y = self.player.center_y bullet.center_x = start_x bullet.center_y = start_y @@ -198,21 +198,21 @@ class Game(arcade.Window): self.view_bottom, Config.SCREEN_HEIGHT + self.view_bottom) - #Projectile updates + # Projectile updates self.bullet_list.update() for bullet in self.bullet_list: # Collision Checks - hit_list = arcade.check_for_collision_with_list(bullet, self.wall_list) + hit_list = arcade.check_for_collision_with_list(bullet, self.dungeon.getWalls()) # If it did, get rid of the bullet if len(hit_list) > 0: bullet.remove_from_sprite_lists() # If the bullet flies off-screen, remove it. TEMP change to range calc - if bullet.bottom < self.view_bottom or bullet.top > self.view_bottom+Config.SCREEN_HEIGHT or bullet.right > self.view_left+Config.SCREEN_WIDTH or bullet.left < self.view_left: + if (bullet.bottom < self.view_bottom or bullet.top > self.view_bottom+Config.SCREEN_HEIGHT + or bullet.right > self.view_left+Config.SCREEN_WIDTH or bullet.left < self.view_left): bullet.remove_from_sprite_lists() - def main() -> None: """ Setups up window classes and runs the game. diff --git a/triple-dungeon/projectiles.py b/triple-dungeon/projectiles.py index 288875a..39010e5 100644 --- a/triple-dungeon/projectiles.py +++ b/triple-dungeon/projectiles.py @@ -5,8 +5,6 @@ Organizes classes related to projectiles import arcade -from config import Config, Sprites - class Projectile(arcade.Sprite): """ @@ -15,11 +13,11 @@ class Projectile(arcade.Sprite): def __init__(self, speed=7, damage=0, range=100, *args, **kwargs) -> None: # Set up parent class super().__init__() - + self.speed = speed - self.damage = damage #unimplemented + self.damage = damage # unimplemented self.texture = None - self.range = range #unimplemented + self.range = range # unimplemented self.collision_list = [] @@ -31,7 +29,7 @@ class Temp(Projectile): super(Temp, self).__init__(*args, **kwargs) self.texture = arcade.load_texture("resources/images/monsters/frog/frog1.png") self.speed = 12 - self.scale = 2 - #collision list for who/what to collide with: wall, player, enemy + self.scale = 4 + # collision list for who/what to collide with: wall, player, enemy - #Can place function for starting on player or enemy + # Can place function for starting on player or enemy From 6b74629a5767f570cd4f8b066d701bec311f26cb Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 13:50:05 -0700 Subject: [PATCH 12/13] changed bullet speed and size, final format check --- triple-dungeon/main.py | 3 ++- triple-dungeon/projectiles.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index a4170f8..46df4a9 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -211,7 +211,8 @@ class Game(arcade.Window): # If the bullet flies off-screen, remove it. TEMP change to range calc if (bullet.bottom < self.view_bottom or bullet.top > self.view_bottom+Config.SCREEN_HEIGHT or bullet.right > self.view_left+Config.SCREEN_WIDTH or bullet.left < self.view_left): - bullet.remove_from_sprite_lists() + bullet.remove_from_sprite_lists() + def main() -> None: """ diff --git a/triple-dungeon/projectiles.py b/triple-dungeon/projectiles.py index 39010e5..8cfa101 100644 --- a/triple-dungeon/projectiles.py +++ b/triple-dungeon/projectiles.py @@ -28,8 +28,8 @@ class Temp(Projectile): def __init__(self, *args, **kwargs) -> None: super(Temp, self).__init__(*args, **kwargs) self.texture = arcade.load_texture("resources/images/monsters/frog/frog1.png") - self.speed = 12 - self.scale = 4 + self.speed = 20 + self.scale = 1 # collision list for who/what to collide with: wall, player, enemy # Can place function for starting on player or enemy From 03d4cd774315d10fc006d375e5188430d2740bd2 Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Mon, 20 Apr 2020 14:03:59 -0700 Subject: [PATCH 13/13] Fix formatting on condition main:212 --- triple-dungeon/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 46df4a9..3945523 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -209,9 +209,13 @@ class Game(arcade.Window): bullet.remove_from_sprite_lists() # If the bullet flies off-screen, remove it. TEMP change to range calc - if (bullet.bottom < self.view_bottom or bullet.top > self.view_bottom+Config.SCREEN_HEIGHT - or bullet.right > self.view_left+Config.SCREEN_WIDTH or bullet.left < self.view_left): - bullet.remove_from_sprite_lists() + if ( + bullet.bottom < self.view_bottom or + bullet.top > self.view_bottom+Config.SCREEN_HEIGHT or + bullet.right > self.view_left+Config.SCREEN_WIDTH or + bullet.left < self.view_left + ): + bullet.remove_from_sprite_lists() def main() -> None: