mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2026-01-31 10:22:11 -06:00
@@ -3,7 +3,11 @@ config.py
|
|||||||
Holds all constants used for setting up the game.
|
Holds all constants used for setting up the game.
|
||||||
May later hold functions for loading/saving configuration files.
|
May later hold functions for loading/saving configuration files.
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
|
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
RESOURCES = os.path.join(BASE_PATH, "resources")
|
||||||
|
IMAGES = os.path.join(RESOURCES, "images")
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
"""
|
"""
|
||||||
@@ -25,9 +29,20 @@ class Config(object):
|
|||||||
# Movement speed of player, in pixels per frame
|
# Movement speed of player, in pixels per frame
|
||||||
PLAYER_MOVEMENT_SPEED = 7
|
PLAYER_MOVEMENT_SPEED = 7
|
||||||
|
|
||||||
# How many pixels to keep as a minimum margin between the character
|
# How many pixels to keep as a minimum margin between the character and the edge of the screen.
|
||||||
# and the edge of the screen.
|
|
||||||
LEFT_VIEWPORT_MARGIN = 250
|
LEFT_VIEWPORT_MARGIN = 250
|
||||||
RIGHT_VIEWPORT_MARGIN = 250
|
RIGHT_VIEWPORT_MARGIN = 250
|
||||||
BOTTOM_VIEWPORT_MARGIN = 50
|
BOTTOM_VIEWPORT_MARGIN = 50
|
||||||
TOP_VIEWPORT_MARGIN = 100
|
TOP_VIEWPORT_MARGIN = 100
|
||||||
|
|
||||||
|
|
||||||
|
class Sprites(object):
|
||||||
|
"""
|
||||||
|
Simple class for holding sprite paths.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__MONSTERS = os.path.join(IMAGES, "monsters")
|
||||||
|
|
||||||
|
SKELETON = os.path.join(__MONSTERS, "skeleton.png")
|
||||||
|
GHOST = os.path.join(__MONSTERS, "ghost", "ghost1.png")
|
||||||
|
FROG = os.path.join(__MONSTERS, "frog", "frog1.png")
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ Holds the main game window, as well as manages basic functions for organizing th
|
|||||||
|
|
||||||
import arcade
|
import arcade
|
||||||
|
|
||||||
from config import Config
|
|
||||||
from map import Dungeon
|
from map import Dungeon
|
||||||
from mobs import Player, Enemy
|
from mobs import Player, Enemy
|
||||||
|
from config import Config, Sprites
|
||||||
|
|
||||||
|
|
||||||
class Game(arcade.Window):
|
class Game(arcade.Window):
|
||||||
@@ -35,7 +35,7 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
# Our physics engine
|
# Our physics engine
|
||||||
self.physics_engine = None
|
self.physics_engine = None
|
||||||
|
|
||||||
# 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
|
||||||
@@ -61,6 +61,7 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
# Create the dungeon
|
# Create the dungeon
|
||||||
dungeon = Dungeon()
|
dungeon = Dungeon()
|
||||||
|
|
||||||
self.floor_list = dungeon.floor_list
|
self.floor_list = dungeon.floor_list
|
||||||
self.wall_list = dungeon.wall_list
|
self.wall_list = dungeon.wall_list
|
||||||
|
|
||||||
|
|||||||
+10
-15
@@ -11,6 +11,7 @@ import arcade
|
|||||||
import json
|
import json
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class Dungeon(object):
|
class Dungeon(object):
|
||||||
"""
|
"""
|
||||||
Organizes Level objects into an easy to render and path through object.
|
Organizes Level objects into an easy to render and path through object.
|
||||||
@@ -33,11 +34,10 @@ class Dungeon(object):
|
|||||||
center = Level()
|
center = Level()
|
||||||
center.load_file('resources/levels/map1/center.json')
|
center.load_file('resources/levels/map1/center.json')
|
||||||
center.render()
|
center.render()
|
||||||
center_floor, center_wall = center.get_lists()
|
center_floor, center_wall = center.floor_list, center.wall_list
|
||||||
self.floor_list.extend(center_floor)
|
self.floor_list.extend(center_floor)
|
||||||
self.wall_list.extend(center_wall)
|
self.wall_list.extend(center_wall)
|
||||||
|
|
||||||
|
|
||||||
# get a side room
|
# get a side room
|
||||||
room = Level()
|
room = Level()
|
||||||
room.load_file('resources/levels/map1/room.json')
|
room.load_file('resources/levels/map1/room.json')
|
||||||
@@ -59,10 +59,6 @@ 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
|
|
||||||
#self.levels = [[None for y in range(size)] for x in range(size)] # array[x][y] style access
|
|
||||||
|
|
||||||
def add_level(self, sprit_list):
|
def add_level(self, sprit_list):
|
||||||
for x in sprit_list:
|
for x in sprit_list:
|
||||||
self.levels.append(x)
|
self.levels.append(x)
|
||||||
@@ -102,10 +98,9 @@ class Level:
|
|||||||
# the dungeon can be mapped by a proper pathfinding system.
|
# the dungeon can be mapped by a proper pathfinding system.
|
||||||
self.floor_list = []
|
self.floor_list = []
|
||||||
self.wall_list = []
|
self.wall_list = []
|
||||||
#self.entrances = []
|
# self.entrances = []
|
||||||
|
|
||||||
#@staticmethod
|
def load_file(self, path: str):
|
||||||
def load_file(self, path: str) -> Level:
|
|
||||||
"""
|
"""
|
||||||
Builds a Level from a given file path.
|
Builds a Level from a given file path.
|
||||||
|
|
||||||
@@ -114,10 +109,10 @@ class Level:
|
|||||||
"""
|
"""
|
||||||
self.floor_list = arcade.SpriteList()
|
self.floor_list = arcade.SpriteList()
|
||||||
self.wall_list = arcade.SpriteList()
|
self.wall_list = arcade.SpriteList()
|
||||||
|
|
||||||
|
|
||||||
with open(path) as file:
|
with open(path) as file:
|
||||||
level = json.load(file)
|
level = json.load(file)
|
||||||
|
|
||||||
self.sprites = level['elements']
|
self.sprites = level['elements']
|
||||||
self.level = level['structure']
|
self.level = level['structure']
|
||||||
|
|
||||||
@@ -138,19 +133,19 @@ class Level:
|
|||||||
floor = arcade.Sprite(sprite, Config.TILE_SCALING)
|
floor = arcade.Sprite(sprite, Config.TILE_SCALING)
|
||||||
floor.center_x = x_pos
|
floor.center_x = x_pos
|
||||||
floor.center_y = y_pos
|
floor.center_y = y_pos
|
||||||
if(cur_tile == ' '):
|
if cur_tile == ' ':
|
||||||
self.floor_list.append(floor)
|
self.floor_list.append(floor)
|
||||||
elif(cur_tile == 'w'):
|
elif cur_tile == 'w':
|
||||||
self.wall_list.append(floor)
|
self.wall_list.append(floor)
|
||||||
x += 1
|
x += 1
|
||||||
x = 0
|
x = 0
|
||||||
y += 1
|
y += 1
|
||||||
|
|
||||||
def get_lists(self):
|
def get_lists(self):
|
||||||
return (self.floor_list, self.wall_list)
|
return self.floor_list, self.wall_list
|
||||||
|
|
||||||
def rotate_level(self, times_rotated):
|
def rotate_level(self, times_rotated):
|
||||||
m = np.array(self.level)
|
m = np.array(self.level)
|
||||||
for i in range(0, times_rotated):
|
for i in range(0, times_rotated % 4):
|
||||||
m = np.rot90(m)
|
m = np.rot90(m)
|
||||||
self.level = m.tolist()
|
self.level = m.tolist()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Organizes all classes related to Mobs, Entities, Enemies, Players and Items.
|
|||||||
|
|
||||||
import arcade
|
import arcade
|
||||||
|
|
||||||
from config import Config
|
from config import Config, Sprites
|
||||||
|
|
||||||
# Constants used to track if the player is facing left or right
|
# Constants used to track if the player is facing left or right
|
||||||
RIGHT_FACING = 0
|
RIGHT_FACING = 0
|
||||||
@@ -107,7 +107,6 @@ class Player(Mob):
|
|||||||
self.cur_texture = 0
|
self.cur_texture = 0
|
||||||
self.texture = self.walking_textures[self.cur_texture // Config.RUN_UPDATES_PER_FRAME][self.character_face_direction]
|
self.texture = self.walking_textures[self.cur_texture // Config.RUN_UPDATES_PER_FRAME][self.character_face_direction]
|
||||||
|
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
"""
|
"""
|
||||||
While Player objects do not have any AI (they are controlled by the user),
|
While Player objects do not have any AI (they are controlled by the user),
|
||||||
|
|||||||
Reference in New Issue
Block a user