From 6769cceed4ab4215f67d4c401d5c1ff5aa243c4d Mon Sep 17 00:00:00 2001 From: Lief9100 Date: Mon, 20 Apr 2020 00:37:46 -0700 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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: