mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-10 06:05:20 -06:00
@@ -42,6 +42,9 @@ class Config(object):
|
|||||||
BOTTOM_VIEWPORT_MARGIN = 50
|
BOTTOM_VIEWPORT_MARGIN = 50
|
||||||
TOP_VIEWPORT_MARGIN = 100
|
TOP_VIEWPORT_MARGIN = 100
|
||||||
|
|
||||||
|
# All debug statements and renderings should use this
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
class Enums(Enum):
|
class Enums(Enum):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ main.py
|
|||||||
The main class used to load the game.
|
The main class used to load the game.
|
||||||
Holds the main game window, as well as manages basic functions for organizing the game.
|
Holds the main game window, as well as manages basic functions for organizing the game.
|
||||||
"""
|
"""
|
||||||
|
import collections
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
import arcade
|
import arcade
|
||||||
import math
|
import math
|
||||||
@@ -15,6 +17,25 @@ from config import Config
|
|||||||
from projectiles import Temp
|
from projectiles import Temp
|
||||||
|
|
||||||
|
|
||||||
|
class FPSCounter:
|
||||||
|
def __init__(self):
|
||||||
|
self.time = time.perf_counter()
|
||||||
|
self.frame_times = collections.deque(maxlen=60)
|
||||||
|
|
||||||
|
def tick(self):
|
||||||
|
t1 = time.perf_counter()
|
||||||
|
dt = t1 - self.time
|
||||||
|
self.time = t1
|
||||||
|
self.frame_times.append(dt)
|
||||||
|
|
||||||
|
def get_fps(self):
|
||||||
|
total_time = sum(self.frame_times)
|
||||||
|
if total_time == 0:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return len(self.frame_times) / sum(self.frame_times)
|
||||||
|
|
||||||
|
|
||||||
class Game(arcade.Window):
|
class Game(arcade.Window):
|
||||||
"""
|
"""
|
||||||
Main application class.
|
Main application class.
|
||||||
@@ -49,10 +70,11 @@ class Game(arcade.Window):
|
|||||||
# Create the Sprite lists
|
# Create the Sprite lists
|
||||||
|
|
||||||
self.enemy_list = arcade.SpriteList()
|
self.enemy_list = arcade.SpriteList()
|
||||||
|
self.fps = FPSCounter()
|
||||||
self.bullet_list = arcade.SpriteList()
|
self.bullet_list = arcade.SpriteList()
|
||||||
|
|
||||||
# Create the dungeon
|
# Create the dungeon
|
||||||
self.dungeon = Dungeon(0, 3)
|
self.dungeon = Dungeon(0, 8)
|
||||||
|
|
||||||
# Set up the player, specifically placing it at these coordinates.
|
# Set up the player, specifically placing it at these coordinates.
|
||||||
self.player = Player()
|
self.player = Player()
|
||||||
@@ -79,7 +101,6 @@ class Game(arcade.Window):
|
|||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
""" Render the screen. """
|
""" Render the screen. """
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# Clear the screen to the background color
|
# Clear the screen to the background color
|
||||||
arcade.start_render()
|
arcade.start_render()
|
||||||
|
|
||||||
@@ -91,7 +112,10 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
self.player.draw_hit_box()
|
self.player.draw_hit_box()
|
||||||
x, y = self.player.center_x, self.player.center_y
|
x, y = self.player.center_x, self.player.center_y
|
||||||
arcade.draw_text(str((x, y)), x - 40, y + 50, arcade.color.WHITE, 15)
|
arcade.draw_text(str((x, y)), x - 40, y + 50, arcade.color.WHITE, 15, font_name='Arial')
|
||||||
|
arcade.draw_text(f"FPS: {self.fps.get_fps():3.0f}", self.view_left + 50, self.view_bottom + 30,
|
||||||
|
arcade.color.WHITE, 16, font_name='Arial')
|
||||||
|
self.fps.tick()
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ class Dungeon(object):
|
|||||||
self.level_count = level_count
|
self.level_count = level_count
|
||||||
self.size = size
|
self.size = size
|
||||||
|
|
||||||
self.floor_list = arcade.SpriteList()
|
self.floor_list = arcade.SpriteList(is_static=True)
|
||||||
self.wall_list = arcade.SpriteList()
|
self.wall_list = arcade.SpriteList(is_static=True)
|
||||||
|
|
||||||
# center = Level.load_file(1, 1, 'resources/levels/map1/center.json')
|
# center = Level.load_file(1, 1, 'resources/levels/map1/center.json')
|
||||||
# side = Level.load_file(2, 1, 'resources/levels/map1/room.json')
|
# side = Level.load_file(2, 1, 'resources/levels/map1/room.json')
|
||||||
@@ -48,10 +48,10 @@ class Dungeon(object):
|
|||||||
Simple one time function for getting all Wall sprites from all Levels.
|
Simple one time function for getting all Wall sprites from all Levels.
|
||||||
Used by the physics engine during game startup.
|
Used by the physics engine during game startup.
|
||||||
|
|
||||||
:return: A SpriteList containing all Sprites.
|
:return: A SpriteList containing all Wall (Collidable) Sprites.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
walls = arcade.SpriteList()
|
walls = arcade.SpriteList(is_static=True)
|
||||||
walls.extend(
|
walls.extend(
|
||||||
list(chain.from_iterable(
|
list(chain.from_iterable(
|
||||||
chain.from_iterable([level.wallSprites for level in column if level is not None]) for column in
|
chain.from_iterable([level.wallSprites for level in column if level is not None]) for column in
|
||||||
@@ -102,8 +102,8 @@ class Level:
|
|||||||
self.sprites = []
|
self.sprites = []
|
||||||
self.structure = []
|
self.structure = []
|
||||||
|
|
||||||
self.floorSprites = arcade.SpriteList()
|
self.floorSprites = arcade.SpriteList(is_static=True)
|
||||||
self.wallSprites = arcade.SpriteList()
|
self.wallSprites = arcade.SpriteList(is_static=True)
|
||||||
|
|
||||||
# Tuples containing the Node positions of where walls, floor and entrances are.
|
# Tuples containing the Node positions of where walls, floor and entrances are.
|
||||||
# All positions are generated based on the level's X and Y position, so that all points within
|
# All positions are generated based on the level's X and Y position, so that all points within
|
||||||
|
|||||||
Reference in New Issue
Block a user