mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-18 00:10:07 -06:00
add docstrings and typehints to all functions
This commit is contained in:
@@ -13,11 +13,10 @@ from typing import Tuple, List
|
|||||||
import arcade
|
import arcade
|
||||||
from config import Config
|
from config import Config
|
||||||
from map import Dungeon
|
from map import Dungeon
|
||||||
from mobs import Player, MobHandler
|
from mobs import Player, MobHandler, Mob
|
||||||
from projectiles import Temp
|
from projectiles import Temp
|
||||||
from recipe import ActiveRecipe
|
from recipe import ActiveRecipe
|
||||||
|
|
||||||
|
|
||||||
class FPSCounter:
|
class FPSCounter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.time = time.perf_counter()
|
self.time = time.perf_counter()
|
||||||
@@ -56,7 +55,7 @@ class Game(arcade.Window):
|
|||||||
self.prev_keypress = [] # A list that assists with tracking keypress events
|
self.prev_keypress = [] # A list that assists with tracking keypress events
|
||||||
# Used to keep track of our scrolling
|
# Used to keep track of our scrolling
|
||||||
self.view_bottom = self.view_left = 0
|
self.view_bottom = self.view_left = 0
|
||||||
self.Recipe = []
|
self.recipe = []
|
||||||
self.enemies_in_range = []
|
self.enemies_in_range = []
|
||||||
|
|
||||||
arcade.set_background_color(arcade.color.BLACK)
|
arcade.set_background_color(arcade.color.BLACK)
|
||||||
@@ -71,15 +70,15 @@ class Game(arcade.Window):
|
|||||||
self.dungeon = Dungeon(0, 3)
|
self.dungeon = Dungeon(0, 3)
|
||||||
|
|
||||||
# Set up recipes
|
# Set up recipes
|
||||||
self.Recipe = ActiveRecipe()
|
self.recipe = ActiveRecipe()
|
||||||
self.Recipe.set_ghosts()
|
self.recipe.activateGhost()
|
||||||
|
|
||||||
# Set up the player, specifically placing it at these coordinates.
|
# Set up the player, specifically placing it at these coordinates.
|
||||||
self.player = Player(self.dungeon)
|
self.player = Player(self.dungeon)
|
||||||
self.player.scale = 1
|
self.player.scale = 1
|
||||||
level = random.choice(self.dungeon.levelList)
|
level = random.choice(self.dungeon.levelList)
|
||||||
self.player.center_x, self.player.center_y = level.center()
|
self.player.center_x, self.player.center_y = level.center()
|
||||||
self.player.cur_recipe = self.Recipe.active
|
self.player.cur_recipe = self.recipe.active
|
||||||
self.player.monster_collisions = arcade.PhysicsEngineSimple(self.player, self.dungeon.getWalls())
|
self.player.monster_collisions = arcade.PhysicsEngineSimple(self.player, self.dungeon.getWalls())
|
||||||
|
|
||||||
# Set up monsters
|
# Set up monsters
|
||||||
@@ -107,7 +106,7 @@ class Game(arcade.Window):
|
|||||||
self.Mobs.render()
|
self.Mobs.render()
|
||||||
self.active_enemies.draw()
|
self.active_enemies.draw()
|
||||||
self.bullet_list.draw()
|
self.bullet_list.draw()
|
||||||
self.Recipe.render()
|
self.recipe.render()
|
||||||
|
|
||||||
if Config.DEBUG:
|
if Config.DEBUG:
|
||||||
x, y = self.player.position
|
x, y = self.player.position
|
||||||
@@ -165,8 +164,8 @@ class Game(arcade.Window):
|
|||||||
elif key == 65307:
|
elif key == 65307:
|
||||||
self.close()
|
self.close()
|
||||||
elif key == 65505:
|
elif key == 65505:
|
||||||
self.Recipe.next_recipe()
|
self.recipe.next_recipe()
|
||||||
self.player.cur_recipe = self.Recipe.active
|
self.player.cur_recipe = self.recipe.active
|
||||||
|
|
||||||
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. """
|
||||||
@@ -273,13 +272,13 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
# Collision Checks
|
# Collision Checks
|
||||||
hit_list = arcade.check_for_collision_with_list(bullet, self.dungeon.getWalls())
|
hit_list = arcade.check_for_collision_with_list(bullet, self.dungeon.getWalls())
|
||||||
enemy_hit_list = arcade.check_for_collision_with_list(bullet, self.active_enemies)
|
enemy_hit_list: List[Mob] = arcade.check_for_collision_with_list(bullet, self.active_enemies)
|
||||||
# If it did, get rid of the bullet
|
# If it did, get rid of the bullet
|
||||||
if len(hit_list) > 0:
|
if len(hit_list) > 0:
|
||||||
bullet.remove_from_sprite_lists()
|
bullet.remove_from_sprite_lists()
|
||||||
if len(enemy_hit_list):
|
if len(enemy_hit_list) > 0:
|
||||||
self.player.add_kill(enemy_hit_list[0].monster_type)
|
self.player.add_kill(enemy_hit_list[0].monster_type)
|
||||||
self.Recipe.add_kill(enemy_hit_list[0].monster_type)
|
self.recipe.addKill(enemy_hit_list[0].monster_type)
|
||||||
enemy_hit_list[0].remove_from_sprite_lists()
|
enemy_hit_list[0].remove_from_sprite_lists()
|
||||||
bullet.remove_from_sprite_lists()
|
bullet.remove_from_sprite_lists()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Recipes are combinations of three monsters. When a player fills a recipe they get an updgrade
|
Recipes are combinations of three monsters. When a player fills a recipe they get an upgrade.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import arcade
|
import arcade
|
||||||
@@ -32,6 +32,9 @@ class ActiveRecipe(arcade.SpriteList):
|
|||||||
self.kill_num = 0
|
self.kill_num = 0
|
||||||
|
|
||||||
def render(self) -> None:
|
def render(self) -> None:
|
||||||
|
"""
|
||||||
|
Renders all current Recipe sprites at the top right of the screen in a row.
|
||||||
|
"""
|
||||||
x = 0
|
x = 0
|
||||||
for sprite in self.sprite_list:
|
for sprite in self.sprite_list:
|
||||||
screen_right = arcade.get_viewport()[1] - 100
|
screen_right = arcade.get_viewport()[1] - 100
|
||||||
@@ -43,13 +46,20 @@ class ActiveRecipe(arcade.SpriteList):
|
|||||||
x += 70
|
x += 70
|
||||||
sprite.draw()
|
sprite.draw()
|
||||||
|
|
||||||
def nextRecipe(self):
|
def nextRecipe(self) -> None:
|
||||||
|
"""
|
||||||
|
Iterates to the next recipe in the list.
|
||||||
|
"""
|
||||||
self.cycle_recipes[self.pos]()
|
self.cycle_recipes[self.pos]()
|
||||||
self.pos += 1
|
self.pos += 1
|
||||||
if self.pos == len(self.cycle_recipes):
|
if self.pos == len(self.cycle_recipes):
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
|
||||||
def addKill(self, monster_type):
|
def addKill(self, monster_type) -> None:
|
||||||
|
"""
|
||||||
|
Adds the kill and darkens the sprite if the monster type matches.
|
||||||
|
:param monster_type: The monster type.
|
||||||
|
"""
|
||||||
for sprite in self.sprite_list:
|
for sprite in self.sprite_list:
|
||||||
if monster_type == sprite:
|
if monster_type == sprite:
|
||||||
sprite.color = tuple(spectrum * 0.5 for spectrum in sprite.color)
|
sprite.color = tuple(spectrum * 0.5 for spectrum in sprite.color)
|
||||||
|
|||||||
Reference in New Issue
Block a user