Merge pull request #41 from n0remac/stats-upgrades

Stats upgrades
This commit is contained in:
Cameron
2020-04-25 23:00:25 -07:00
committed by GitHub
4 changed files with 69 additions and 43 deletions

View File

@@ -34,11 +34,16 @@ class Config(object):
# The number of pixels across the level
LEVEL_SIZE = 10 * TILE_SCALING * TILE_WIDTH
# Movement speed of player, in pixels per frame
# Movement speeds, in pixels per frame
PLAYER_MOVEMENT_SPEED = 14
MONSTER_MOVEMENT_SPEED = 11
# Boon and Recipe constants
BOON_LIST = ["heal", "harden", "hurry"]
HEAL_AMOUNT = 20
ARMOR_AMOUNT = 1
SPEED_AMOUNT = 2
# How many pixels to keep as a minimum margin between the characters and the edge of the screen.
LEFT_VIEWPORT_MARGIN = 700
RIGHT_VIEWPORT_MARGIN = 700

View File

@@ -106,6 +106,11 @@ class Game(arcade.Window):
self.bullet_list.draw()
self.Recipe.render()
# Draw stats
arcade.draw_text("Health:"+str(self.player.health)+"/"+str(self.player.max_health), self.view_left+100, self.view_bottom+60, arcade.color.RED, 15, font_name='Arial')
arcade.draw_text("Armor:"+str(self.player.armor), self.view_left+100, self.view_bottom+90, arcade.color.BLUE, 15, font_name='Arial')
arcade.draw_text("Speed:"+str(self.player.speed), self.view_left+100, self.view_bottom+120, arcade.color.YELLOW, 15, font_name='Arial')
if Config.DEBUG:
x, y = self.player.position
arcade.draw_rectangle_outline(round(x / Config.TILE_SIZE) * Config.TILE_SIZE,
@@ -148,16 +153,16 @@ class Game(arcade.Window):
"""Called whenever a key is pressed. """
if key == arcade.key.UP or key == arcade.key.W:
self.player.change_y = Config.PLAYER_MOVEMENT_SPEED
self.player.change_y = self.player.speed
self.prev_keypress.append(key)
elif key == arcade.key.DOWN or key == arcade.key.S:
self.player.change_y = -Config.PLAYER_MOVEMENT_SPEED
self.player.change_y = -self.player.speed
self.prev_keypress.append(key)
elif key == arcade.key.LEFT or key == arcade.key.A:
self.player.change_x = -Config.PLAYER_MOVEMENT_SPEED
self.player.change_x = -self.player.speed
self.prev_keypress.append(key)
elif key == arcade.key.RIGHT or key == arcade.key.D:
self.player.change_x = Config.PLAYER_MOVEMENT_SPEED
self.player.change_x = self.player.speed
self.prev_keypress.append(key)
elif key == 65307:
self.close()
@@ -239,8 +244,9 @@ class Game(arcade.Window):
if len(hit_list) > 0:
bullet.remove_from_sprite_lists()
if len(enemy_hit_list):
self.player.add_kill(enemy_hit_list[0].monster_type)
self.Recipe.add_kill(enemy_hit_list[0].monster_type)
boon = self.Recipe.add_kill(enemy_hit_list[0].monster_type)
if boon >= 0:
getattr(self.player, Config.BOON_LIST[boon])();
enemy_hit_list[0].remove_from_sprite_lists()
bullet.remove_from_sprite_lists()

View File

@@ -130,7 +130,7 @@ class Mob(arcade.Sprite):
super(Mob, self).__init__(*args, **kwargs)
self.max_health, self.max_armor = max_health, max_armor
self.health, self.armor = max_health, max_armor
self.health, self.armor = 60, max_armor
self.idle_textures = []
self.walking_textures = []
self.up_textures = []
@@ -164,20 +164,19 @@ class Player(Mob):
self.refreshIndex = 0
self.prev = Enums.IDLE
self.texture = next(self.map[self.prev])
self.kill_list = []
self.cur_recipe = None
self.speed = 14
def add_kill(self, creature):
# Adds a kill to kill_list. If 3 or more check the recipe then give a power up if it matches.
self.kill_list.append(creature)
print(self.kill_list)
print(self.cur_recipe)
if self.cur_recipe == self.kill_list:
print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++")
self.kill_list = []
elif len(self.kill_list) >= 3:
self.kill_list = []
def heal(self):
self.health+=Config.HEAL_AMOUNT
if self.health > self.max_health:
self.health = self.max_health
def harden(self):
self.armor+=Config.ARMOR_AMOUNT
def hurry(self):
self.speed+=Config.SPEED_AMOUNT
def update_animation(self, delta_time: float = 1 / 60) -> None:
"""
@@ -258,8 +257,6 @@ class Enemy(Mob):
else:
self.change_y = 0
def get_path(self, end: Tuple[int, int] = None) -> List[Tuple[int, int]]:
"""
Returns the path to get to the Mob's target in absolute integer positions.

View File

@@ -24,9 +24,11 @@ class ActiveRecipe(arcade.SpriteList):
def __init__(self):
super().__init__()
self.active = Recipe.GHOSTS
self.cycle_recipes = [self.set_frogs, self.set_ghosts]
self.cycle_recipes = [self.set_ghosts, self.set_frogs, self.set_ggf]
self.ghost = arcade.Sprite(filename="resources/images/monsters/ghost/ghost1.png")
self.frog = arcade.Sprite(filename="resources/images/monsters/frog/frog1.png")
self.pos = 0
self.kill_num = 0
self.kill_list = []
def render(self) -> None:
@@ -37,38 +39,54 @@ class ActiveRecipe(arcade.SpriteList):
sprite.scale = 4
sprite.center_x = screen_right - x
sprite.center_y = screen_top
x += 70
sprite.draw()
x = 0
for kill in self.kill_list:
sprite = getattr(self, kill)
screen_right = arcade.get_viewport()[1] - 240
screen_top = arcade.get_viewport()[3] - 150
sprite.scale = 4
sprite.center_x = screen_right + x
sprite.center_y = screen_top
x += 70
sprite.draw()
def next_recipe(self):
self.cycle_recipes[self.pos]()
self.pos += 1
if self.pos == len(self.cycle_recipes):
self.pos = 0
self.cycle_recipes[self.pos]()
def add_kill(self, monster_type):
for sprite in self.sprite_list:
if monster_type in "ghost":
r, g, b = sprite.color
darken = lambda c, s: c * (1 - s)
r = darken(r, .5)
g = darken(g, .5)
b = darken(b, .5)
sprite.color = (r, g, b)
return
def add_kill(self, monster_type) -> int:
# Adds a kill to kill_list. If 3 or more check the recipe then give a power up if it matches.
self.kill_list.append(monster_type)
ret_val = -1
if len(self.kill_list) >= 3:
if self.active == self.kill_list:
print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++")
self.kill_list = []
ret_val = self.pos
self.kill_list = []
return ret_val
def set_ghosts(self) -> None:
self.active = Recipe.GHOSTS
self.sprite_list = []
self.sprite_list.append(arcade.Sprite(filename="resources/images/monsters/ghost/ghost1.png"))
self.sprite_list.append(arcade.Sprite(filename="resources/images/monsters/ghost/ghost1.png"))
self.sprite_list.append(arcade.Sprite(filename="resources/images/monsters/ghost/ghost1.png"))
self.sprite_list.append(self.ghost)
self.sprite_list.append(self.ghost)
self.sprite_list.append(self.ghost)
def set_frogs(self) -> None:
self.active = Recipe.FROGS
self.sprite_list = []
self.sprite_list.append(arcade.Sprite(filename="resources/images/monsters/frog/frog1.png"))
self.sprite_list.append(arcade.Sprite(filename="resources/images/monsters/frog/frog1.png"))
self.sprite_list.append(arcade.Sprite(filename="resources/images/monsters/frog/frog1.png"))
self.sprite_list.append(self.frog)
self.sprite_list.append(self.frog)
self.sprite_list.append(self.frog)
def set_ggf(self) -> None:
self.active = Recipe.GHOST_FROG
self.sprite_list = []
self.sprite_list.append(self.frog)
self.sprite_list.append(self.ghost)
self.sprite_list.append(self.ghost)