From: 711215 <711215@pdsb.net> Date: Thu, 7 Jul 2022 23:32:56 +0000 (-0400) Subject: added potions X-Git-Url: http://git.skullheadx.com/projects/static/git-logo.png?a=commitdiff_plain;h=e6271038d8b07f5530dd5d634ffb6854ab85452f;p=Pygame-Jam.git added potions --- diff --git a/Player.py b/Player.py index 24d58f7..caa206b 100644 --- a/Player.py +++ b/Player.py @@ -1,9 +1,12 @@ import pygame.key import Setup +import time +import threading from Setup import * from Actors import Actor from datetime import datetime, timedelta +from Potion import Potion class Player(Actor): width, height = 25, 50 @@ -28,16 +31,30 @@ class Player(Actor): self.lastValueR = False # self.areas = {"body":Area(self.position, pg.Vector2(0, self.height/2),self.width, self.height/2,Actor)} + self.potion_cooldown = 0 + self.starting_potions = 999 + self.potion_bag = [Potion(self)] + for i in range(self.starting_potions): + self.potion_bag.append(Potion(self)) + def update(self, delta): super().update(delta) # Get and handle input self.handle_input() + #if self.potion_cooldown > 0: + #threading.Thread(Potion.cooldown) + + if len(self.potion_bag) > 0: + self.potion_bag[0].get_input(self) + # Deals with collision and applying velocity self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta) return self.position - self.initial_position + + def handle_input(self): pressed = pygame.key.get_pressed() if pressed[pg.K_w] or pressed[pg.K_UP] or pressed[pg.K_SPACE]: diff --git a/Potion.py b/Potion.py new file mode 100644 index 0000000..ae65869 --- /dev/null +++ b/Potion.py @@ -0,0 +1,21 @@ +from Setup import * + +class Potion: + + def __init__(self, player, heal_amount = 25): + self.heal = heal_amount + self.player = player + + def get_input(self, player): + pressed_key = pygame.key.get_pressed() + if pressed_key[pg.K_1] and player.potion_cooldown == 0: + self.consume_potion(player) + + def consume_potion(self, player): + player.health += self.heal + del player.potion_bag[0] + player.potion_cooldown = 5 + + #def cooldown(self, player): + +