Merge branch 'master' into refactor
@@ -19,6 +19,8 @@ class Config(object):
|
|||||||
SCREEN_HEIGHT = 1000
|
SCREEN_HEIGHT = 1000
|
||||||
SCREEN_TITLE = "Triple Dungeon"
|
SCREEN_TITLE = "Triple Dungeon"
|
||||||
TILE_WIDTH = 63
|
TILE_WIDTH = 63
|
||||||
|
IDLE_UPDATES_PER_FRAME = 20
|
||||||
|
RUN_UPDATES_PER_FRAME = 10
|
||||||
|
|
||||||
# Constants used to scale our sprites from their original size
|
# Constants used to scale our sprites from their original size
|
||||||
CHARACTER_SCALING = 1
|
CHARACTER_SCALING = 1
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ class Game(arcade.Window):
|
|||||||
self.player_list = None
|
self.player_list = None
|
||||||
|
|
||||||
# Separate variable that holds the player sprite
|
# Separate variable that holds the player sprite
|
||||||
self.player_sprite = None
|
self.player = None
|
||||||
|
|
||||||
|
# list to keep track of keypresses
|
||||||
|
self.prev_keypress = []
|
||||||
|
|
||||||
# Our physics engine
|
# Our physics engine
|
||||||
self.physics_engine = None
|
self.physics_engine = None
|
||||||
|
|
||||||
# list to keep track of key presses
|
|
||||||
self.prev_keypress = []
|
|
||||||
|
|
||||||
# Used to keep track of our scrolling
|
# Used to keep track of our scrolling
|
||||||
self.view_bottom = 0
|
self.view_bottom = 0
|
||||||
self.view_left = 0
|
self.view_left = 0
|
||||||
@@ -46,25 +46,32 @@ class Game(arcade.Window):
|
|||||||
""" Set up the game here. Call this function to restart the game. """
|
""" Set up the game here. Call this function to restart the game. """
|
||||||
# Create the Sprite lists
|
# Create the Sprite lists
|
||||||
|
|
||||||
|
self.player_list = arcade.SpriteList()
|
||||||
self.wall_list = arcade.SpriteList()
|
self.wall_list = arcade.SpriteList()
|
||||||
self.floor_list = arcade.SpriteList()
|
self.floor_list = arcade.SpriteList()
|
||||||
self.enemy_list = arcade.SpriteList()
|
self.enemy_list = arcade.SpriteList()
|
||||||
|
|
||||||
# Set up the player, specifically placing it at these coordinates.
|
# Set up the player, specifically placing it at these coordinates.
|
||||||
Player.setup(self)
|
self.player = Player()
|
||||||
|
self.player.scale = 1
|
||||||
|
self.player.center_x = Config.SCREEN_WIDTH / 2
|
||||||
|
self.player.center_y = Config.SCREEN_HEIGHT / 2
|
||||||
|
self.player_list = self.player
|
||||||
|
|
||||||
|
|
||||||
# Create the dungeon
|
# Create the dungeon
|
||||||
dungeon = Dungeon()
|
dungeon = Dungeon()
|
||||||
self.floor_list, self.wall_list = dungeon.floor_list, dungeon.wall_list
|
|
||||||
|
self.floor_list = dungeon.floor_list
|
||||||
|
self.wall_list = dungeon.wall_list
|
||||||
|
|
||||||
# Create monsters
|
# Create monsters
|
||||||
self.enemy_list.extend([
|
# This needs to be updated to comply with the new mobs.py code
|
||||||
Enemy(Sprites.GHOST, 200, 200).sprite,
|
#self.enemy_list.append(Enemy("resources/images/monsters/ghost/ghost1.png", 200, 200, 4).get_enemy())
|
||||||
Enemy(Sprites.FROG, 200, 1000).sprite
|
#self.enemy_list.append(Enemy("resources/images/monsters/frog/frog1.png", 200, 1000, 4).get_enemy())
|
||||||
])
|
|
||||||
|
|
||||||
# Create the 'physics engine'
|
# Create the 'physics engine'
|
||||||
self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list)
|
self.physics_engine = arcade.PhysicsEngineSimple(self.player, self.wall_list)
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
""" Render the screen. """
|
""" Render the screen. """
|
||||||
@@ -74,7 +81,7 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
# Draw our sprites
|
# Draw our sprites
|
||||||
self.floor_list.draw()
|
self.floor_list.draw()
|
||||||
self.player_sprite.draw()
|
self.player_list.draw()
|
||||||
self.enemy_list.draw()
|
self.enemy_list.draw()
|
||||||
self.wall_list.draw()
|
self.wall_list.draw()
|
||||||
|
|
||||||
@@ -82,34 +89,35 @@ class Game(arcade.Window):
|
|||||||
"""Called whenever a key is pressed. """
|
"""Called whenever a key is pressed. """
|
||||||
|
|
||||||
if key == arcade.key.UP or key == arcade.key.W:
|
if key == arcade.key.UP or key == arcade.key.W:
|
||||||
self.player_sprite.change_y = Config.PLAYER_MOVEMENT_SPEED
|
self.player_list.change_y = Config.PLAYER_MOVEMENT_SPEED
|
||||||
self.prev_keypress.append(key)
|
self.prev_keypress.append(key)
|
||||||
elif key == arcade.key.DOWN or key == arcade.key.S:
|
elif key == arcade.key.DOWN or key == arcade.key.S:
|
||||||
self.player_sprite.change_y = -Config.PLAYER_MOVEMENT_SPEED
|
self.player_list.change_y = -Config.PLAYER_MOVEMENT_SPEED
|
||||||
self.prev_keypress.append(key)
|
self.prev_keypress.append(key)
|
||||||
elif key == arcade.key.LEFT or key == arcade.key.A:
|
elif key == arcade.key.LEFT or key == arcade.key.A:
|
||||||
self.player_sprite.change_x = -Config.PLAYER_MOVEMENT_SPEED
|
self.player_list.change_x = -Config.PLAYER_MOVEMENT_SPEED
|
||||||
self.prev_keypress.append(key)
|
self.prev_keypress.append(key)
|
||||||
elif key == arcade.key.RIGHT or key == arcade.key.D:
|
elif key == arcade.key.RIGHT or key == arcade.key.D:
|
||||||
self.player_sprite.change_x = Config.PLAYER_MOVEMENT_SPEED
|
self.player_list.change_x = Config.PLAYER_MOVEMENT_SPEED
|
||||||
self.prev_keypress.append(key)
|
self.prev_keypress.append(key)
|
||||||
|
elif key == 65307:
|
||||||
|
self.close()
|
||||||
|
|
||||||
def on_key_release(self, key, modifiers):
|
def on_key_release(self, key, modifiers):
|
||||||
"""Called when the user releases a key. """
|
"""Called when the user releases a key. """
|
||||||
|
|
||||||
if key == arcade.key.UP or key == arcade.key.W:
|
if key == arcade.key.UP or key == arcade.key.W:
|
||||||
self.player_sprite.change_y = 0
|
self.player_list.change_y = 0
|
||||||
self.prev_keypress.remove(key)
|
self.prev_keypress.remove(key)
|
||||||
elif key == arcade.key.DOWN or key == arcade.key.S:
|
elif key == arcade.key.DOWN or key == arcade.key.S:
|
||||||
self.player_sprite.change_y = 0
|
self.player_list.change_y = 0
|
||||||
self.prev_keypress.remove(key)
|
self.prev_keypress.remove(key)
|
||||||
elif key == arcade.key.LEFT or key == arcade.key.A:
|
elif key == arcade.key.LEFT or key == arcade.key.A:
|
||||||
self.player_sprite.change_x = 0
|
self.player_list.change_x = 0
|
||||||
self.prev_keypress.remove(key)
|
self.prev_keypress.remove(key)
|
||||||
elif key == arcade.key.RIGHT or key == arcade.key.D:
|
elif key == arcade.key.RIGHT or key == arcade.key.D:
|
||||||
self.player_sprite.change_x = 0
|
self.player_list.change_x = 0
|
||||||
self.prev_keypress.remove(key)
|
self.prev_keypress.remove(key)
|
||||||
|
|
||||||
if self.prev_keypress:
|
if self.prev_keypress:
|
||||||
self.on_key_press(self.prev_keypress.pop(0), 0)
|
self.on_key_press(self.prev_keypress.pop(0), 0)
|
||||||
|
|
||||||
@@ -118,28 +126,30 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
# Move the player with the physics engine
|
# Move the player with the physics engine
|
||||||
self.physics_engine.update()
|
self.physics_engine.update()
|
||||||
|
|
||||||
|
self.player_list.update_animation()
|
||||||
changed = False # Track if we need to change the viewport
|
changed = False # Track if we need to change the viewport
|
||||||
|
|
||||||
# Below manages all scrolling mechanics
|
# Below manages all scrolling mechanics
|
||||||
# Scroll left
|
# Scroll left
|
||||||
left_boundary = self.view_left + Config.LEFT_VIEWPORT_MARGIN
|
left_boundary = self.view_left + Config.LEFT_VIEWPORT_MARGIN
|
||||||
if self.player_sprite.left < left_boundary:
|
if self.player_list.left < left_boundary:
|
||||||
self.view_left -= left_boundary - self.player_sprite.left
|
self.view_left -= left_boundary - self.player_list.left
|
||||||
changed = True
|
changed = True
|
||||||
# Scroll right
|
# Scroll right
|
||||||
right_boundary = self.view_left + Config.SCREEN_WIDTH - Config.RIGHT_VIEWPORT_MARGIN
|
right_boundary = self.view_left + Config.SCREEN_WIDTH - Config.RIGHT_VIEWPORT_MARGIN
|
||||||
if self.player_sprite.right > right_boundary:
|
if self.player_list.right > right_boundary:
|
||||||
self.view_left += self.player_sprite.right - right_boundary
|
self.view_left += self.player_list.right - right_boundary
|
||||||
changed = True
|
changed = True
|
||||||
# Scroll up
|
# Scroll up
|
||||||
top_boundary = self.view_bottom + Config.SCREEN_HEIGHT - Config.TOP_VIEWPORT_MARGIN
|
top_boundary = self.view_bottom + Config.SCREEN_HEIGHT - Config.TOP_VIEWPORT_MARGIN
|
||||||
if self.player_sprite.top > top_boundary:
|
if self.player_list.top > top_boundary:
|
||||||
self.view_bottom += self.player_sprite.top - top_boundary
|
self.view_bottom += self.player_list.top - top_boundary
|
||||||
changed = True
|
changed = True
|
||||||
# Scroll down
|
# Scroll down
|
||||||
bottom_boundary = self.view_bottom + Config.BOTTOM_VIEWPORT_MARGIN
|
bottom_boundary = self.view_bottom + Config.BOTTOM_VIEWPORT_MARGIN
|
||||||
if self.player_sprite.bottom < bottom_boundary:
|
if self.player_list.bottom < bottom_boundary:
|
||||||
self.view_bottom -= bottom_boundary - self.player_sprite.bottom
|
self.view_bottom -= bottom_boundary - self.player_list.bottom
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ class Dungeon(object):
|
|||||||
self.floor_list.extend(room_floor)
|
self.floor_list.extend(room_floor)
|
||||||
self.wall_list.extend(room_wall)
|
self.wall_list.extend(room_wall)
|
||||||
|
|
||||||
# self.level_count, self.size = level_count, size
|
def add_level(self, sprit_list):
|
||||||
# self.levels = [[None for y in range(size)] for x in range(size)] # array[x][y] style access
|
for x in sprit_list:
|
||||||
|
self.levels.append(x)
|
||||||
|
|
||||||
def render(self) -> None:
|
def render(self) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -146,7 +147,6 @@ class Level:
|
|||||||
|
|
||||||
def rotate_level(self, times_rotated):
|
def rotate_level(self, times_rotated):
|
||||||
m = np.array(self.level)
|
m = np.array(self.level)
|
||||||
print(m)
|
for i in range(0, times_rotated % 4):
|
||||||
for _ in range(0, times_rotated % 4):
|
|
||||||
m = np.rot90(m)
|
m = np.rot90(m)
|
||||||
self.level = m.tolist()
|
self.level = m.tolist()
|
||||||
|
|||||||
@@ -7,19 +7,28 @@ import arcade
|
|||||||
|
|
||||||
from config import Config, Sprites
|
from config import Config, Sprites
|
||||||
|
|
||||||
|
# Constants used to track if the player is facing left or right
|
||||||
|
RIGHT_FACING = 0
|
||||||
|
LEFT_FACING = 1
|
||||||
|
FRONT_FACING = 2
|
||||||
|
UP_FACING = 3
|
||||||
|
DOWN_FACING = 4
|
||||||
|
|
||||||
class Mob(object):
|
class Mob(arcade.Sprite):
|
||||||
"""
|
"""
|
||||||
Represents a Mob. No defined behaviour, it has no intelligence.
|
Represents a Mob. No defined behaviour, it has no intelligence.
|
||||||
"""
|
"""
|
||||||
def __init__(self, sprite, x, y, max_health=100, max_armor=0) -> None:
|
def __init__(self, max_health=100, max_armor=0, *args, **kwargs) -> None:
|
||||||
self.sprite_path = sprite
|
# Set up parent class
|
||||||
self.sprite = arcade.Sprite(self.sprite_path, Config.CHARACTER_SCALING)
|
super().__init__()
|
||||||
|
|
||||||
self.max_health, self.max_armor = max_health, max_armor
|
self.max_health, self.max_armor = max_health, max_armor
|
||||||
self.health, self.armor = max_health, max_armor
|
self.health, self.armor = max_health, max_armor
|
||||||
self.sprite.scale = 4
|
self.idle_textures = []
|
||||||
self.sprite.center_x = x
|
self.walking_textures = []
|
||||||
self.sprite.center_y = y
|
self.up_textures = []
|
||||||
|
self.down_textures = []
|
||||||
|
self.cur_texture = 0
|
||||||
|
|
||||||
def tick(self) -> None:
|
def tick(self) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -36,11 +45,67 @@ class Player(Mob):
|
|||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super(Player, self).__init__(*args, **kwargs)
|
super(Player, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def setup(self):
|
main_path = "resources/images/character/knight/"
|
||||||
self.player_sprite = arcade.Sprite(Sprites.SKELETON, Config.CHARACTER_SCALING)
|
|
||||||
self.player_sprite.center_x = Config.SCREEN_WIDTH / 2
|
# Default to face-front
|
||||||
self.player_sprite.center_y = Config.SCREEN_HEIGHT / 2
|
self.character_face_direction = FRONT_FACING
|
||||||
self.player_sprite.scale = 4
|
|
||||||
|
# Load textures for idle standing
|
||||||
|
for i in range(4):
|
||||||
|
texture = arcade.load_texture(f"{main_path}knight iso char_idle_{i}.png")
|
||||||
|
self.idle_textures.append(texture)
|
||||||
|
|
||||||
|
# Load textures for running horizontally
|
||||||
|
for i in range(6):
|
||||||
|
self.walking_textures.append([arcade.load_texture(f"{main_path}knight iso char_run left_{i}.png"),arcade.load_texture(f"{main_path}knight iso char_run left_{i}.png", mirrored=True)])
|
||||||
|
|
||||||
|
# Load textures for running down
|
||||||
|
for i in range(5):
|
||||||
|
self.down_textures.append(arcade.load_texture(f"{main_path}knight iso char_run down_{i}.png"))
|
||||||
|
|
||||||
|
# Load textures for running up
|
||||||
|
for i in range(5):
|
||||||
|
self.up_textures.append(arcade.load_texture(f"{main_path}knight iso char_run up_{i}.png"))
|
||||||
|
|
||||||
|
def update_animation(self, delta_time: float = 1/60):
|
||||||
|
# Figure out if we need to flip face left, right, up, or down
|
||||||
|
if self.change_x > 0:
|
||||||
|
self.character_face_direction = LEFT_FACING
|
||||||
|
elif self.change_x < 0:
|
||||||
|
self.character_face_direction = RIGHT_FACING
|
||||||
|
elif self.change_x == 0 and self.change_y == 0:
|
||||||
|
self.character_face_direction = FRONT_FACING
|
||||||
|
|
||||||
|
|
||||||
|
# idle animation
|
||||||
|
if self.change_x == 0 and self.change_y == 0:
|
||||||
|
self.cur_texture += 1
|
||||||
|
if self.cur_texture > 3 * Config.IDLE_UPDATES_PER_FRAME:
|
||||||
|
self.cur_texture = 0
|
||||||
|
self.texture = self.idle_textures[self.cur_texture // Config.IDLE_UPDATES_PER_FRAME]
|
||||||
|
return
|
||||||
|
|
||||||
|
#walk up animation
|
||||||
|
if self.change_y > 0:
|
||||||
|
self.cur_texture += 1
|
||||||
|
if self.cur_texture > 4 * Config.RUN_UPDATES_PER_FRAME:
|
||||||
|
self.cur_texture = 0
|
||||||
|
self.texture = self.up_textures[self.cur_texture // Config.RUN_UPDATES_PER_FRAME]
|
||||||
|
return
|
||||||
|
|
||||||
|
#walk down animation
|
||||||
|
if self.change_y < 0:
|
||||||
|
self.cur_texture += 1
|
||||||
|
if self.cur_texture > 4 * Config.RUN_UPDATES_PER_FRAME:
|
||||||
|
self.cur_texture = 0
|
||||||
|
self.texture = self.down_textures[self.cur_texture // Config.RUN_UPDATES_PER_FRAME]
|
||||||
|
return
|
||||||
|
|
||||||
|
# Walking left/right animation
|
||||||
|
self.cur_texture += 1
|
||||||
|
if self.cur_texture > 5 * Config.RUN_UPDATES_PER_FRAME:
|
||||||
|
self.cur_texture = 0
|
||||||
|
self.texture = self.walking_textures[self.cur_texture // Config.RUN_UPDATES_PER_FRAME][self.character_face_direction]
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
"""
|
"""
|
||||||
@@ -58,6 +123,9 @@ class Enemy(Mob):
|
|||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super(Enemy, self).__init__(*args, **kwargs)
|
super(Enemy, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def get_enemy(self):
|
||||||
|
return self
|
||||||
|
|
||||||
def tick(self) -> None:
|
def tick(self) -> None:
|
||||||
"""
|
"""
|
||||||
A on_update function, the Enemy Mob should scan for the player, decide how to path to it, and
|
A on_update function, the Enemy Mob should scan for the player, decide how to path to it, and
|
||||||
|
|||||||
|
After Width: | Height: | Size: 597 B |
|
After Width: | Height: | Size: 597 B |
|
After Width: | Height: | Size: 621 B |
|
After Width: | Height: | Size: 621 B |
|
After Width: | Height: | Size: 547 B |
|
After Width: | Height: | Size: 566 B |
|
After Width: | Height: | Size: 545 B |
|
After Width: | Height: | Size: 570 B |
|
After Width: | Height: | Size: 583 B |
|
After Width: | Height: | Size: 438 B |
|
After Width: | Height: | Size: 498 B |
|
After Width: | Height: | Size: 508 B |
|
After Width: | Height: | Size: 444 B |
|
After Width: | Height: | Size: 476 B |
|
After Width: | Height: | Size: 488 B |
|
After Width: | Height: | Size: 441 B |
|
After Width: | Height: | Size: 499 B |
|
After Width: | Height: | Size: 509 B |
|
After Width: | Height: | Size: 451 B |
|
After Width: | Height: | Size: 480 B |
|
After Width: | Height: | Size: 498 B |
|
After Width: | Height: | Size: 409 B |
|
After Width: | Height: | Size: 429 B |
|
After Width: | Height: | Size: 435 B |
|
After Width: | Height: | Size: 449 B |
|
After Width: | Height: | Size: 498 B |
|
After Width: | Height: | Size: 547 B |
|
After Width: | Height: | Size: 552 B |
|
After Width: | Height: | Size: 767 B |
|
After Width: | Height: | Size: 441 B |
|
After Width: | Height: | Size: 569 B |
|
After Width: | Height: | Size: 481 B |
|
After Width: | Height: | Size: 438 B |
|
After Width: | Height: | Size: 563 B |
|
After Width: | Height: | Size: 486 B |
|
After Width: | Height: | Size: 383 B |
|
After Width: | Height: | Size: 396 B |
|
After Width: | Height: | Size: 633 B |