From 46c9270c19ff91248d6ea8a659cbc410591fc3eb Mon Sep 17 00:00:00 2001 From: Cameron Smart Date: Sat, 18 Apr 2020 22:47:27 -0700 Subject: [PATCH] Mobs now takes an x, y location and places the sprite there. --- triple-dungeon/main.py | 12 +++++++++--- triple-dungeon/mobs.py | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 8d80d0a..2fe1a86 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -8,6 +8,7 @@ import arcade from config import Config from map import Level +from mobs import Enemy class Game(arcade.Window): @@ -23,6 +24,7 @@ class Game(arcade.Window): # go into a list. self.wall_list = None self.floor_list = None + self.enemy_list = None self.player_list = None # Separate variable that holds the player sprite @@ -43,9 +45,8 @@ class Game(arcade.Window): def setup(self): """ Set up the game here. Call this function to restart the game. """ # Create the Sprite lists - self.wall_list = arcade.SpriteList() - self.floor_list = arcade.SpriteList() self.player_list = arcade.SpriteList() + self.enemy_list = arcade.SpriteList() # Set up the player, specifically placing it at these coordinates. image_source = "resources/images/monsters/skeleton.png" @@ -58,6 +59,10 @@ class Game(arcade.Window): # Create the level self.floor_list, self.wall_list = Level.load_file('resources/levels/box.json') + # Create monsters + self.enemy_list.append(Enemy(image_source, 100, 100).get_enemy()) + self.enemy_list.append(Enemy(image_source, Config.SCREEN_WIDTH / 2 + 10, Config.SCREEN_HEIGHT / 2 + 10).get_enemy()) + # Create the 'physics engine' self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list) @@ -66,10 +71,11 @@ class Game(arcade.Window): # Clear the screen to the background color arcade.start_render() - + # Draw our sprites self.floor_list.draw() self.player_list.draw() + self.enemy_list.draw() self.wall_list.draw() def on_key_press(self, key, modifiers): diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index 97b7ff7..770084c 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -12,11 +12,14 @@ class Mob(object): """ Represents a Mob. No defined behaviour, it has no intelligence. """ - def __init__(self, sprite, max_health=100, max_armor=0) -> None: + def __init__(self, sprite, x, y, 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 + self.sprite.scale = 4 + self.sprite.center_x = x + self.sprite.center_y = y def tick(self) -> None: """ @@ -49,6 +52,9 @@ class Enemy(Mob): def __init__(self, *args, **kwargs) -> None: super(Enemy, self).__init__(*args, **kwargs) + def get_enemy(self): + return self.sprite + def tick(self) -> None: """ A on_update function, the Enemy Mob should scan for the player, decide how to path to it, and