]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
collectable potions, combat done
authorSkullheadx <704277@pdsb.net>
Tue, 12 Jul 2022 06:04:39 +0000 (02:04 -0400)
committerSkullheadx <704277@pdsb.net>
Tue, 12 Jul 2022 06:04:39 +0000 (02:04 -0400)
Actors.py
Assets/skeleton/skeleton_attack.gif [moved from Assets/skeleton/skele_ATTAK.gif with 100% similarity]
Assets/world/decor/HEALTHPOTION.png [new file with mode: 0644]
Enemy.py
Game.py
Item.py [new file with mode: 0644]
Levels/Level5.txt
Player.py
Potion.py
World.py

index 49dd46a97a04f4aea07be78de4b91240d171fa75..389f000529f7ba98412c6f1b820e6e73d07d9b1c 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -88,7 +88,7 @@ class Actor:
         self.is_dead(reason)
 
     def attack(self, enemy, weapon, direction):
-        if not self.attacked:
+        if not self.attacked and self.invincibility_frames == 0:
             self.push(direction, 2, -1)
             self.modify_health(weapon.damage, "enemy")
             self.attacked = True
@@ -200,5 +200,5 @@ class Actor:
         # pg.draw.rect(surf, (0,0,0), self.get_collision_rect(), border_radius=8, width=2)
 
         # Uncomment for debugging area hitboxes
-        for area in self.areas.values():
-            area.draw(surf)
+        for area in self.areas.values():
+            area.draw(surf)
diff --git a/Assets/world/decor/HEALTHPOTION.png b/Assets/world/decor/HEALTHPOTION.png
new file mode 100644 (file)
index 0000000..4ea4031
Binary files /dev/null and b/Assets/world/decor/HEALTHPOTION.png differ
index 4b43d64176efc1bf70fe4473f3a6975d01f74df9..8e27b1343333ef13828bf5da82803cd2a19db247 100644 (file)
--- a/Enemy.py
+++ b/Enemy.py
@@ -1,3 +1,4 @@
+import math
 from argparse import Action
 from Setup import *
 from Player import Player
@@ -14,6 +15,12 @@ class Enemy(Actor):
     run_frames = []
     for i in range(run_gif.n_frames):
         run_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(run_gif, i)), (180, 180)))
+
+    attack_gif = Image.open("Assets/skeleton/skeleton_attack.gif")
+    attack_frames = []
+    for i in range(attack_gif.n_frames):
+        attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (180, 180)))
+
     def __init__(self, pos, collision_layer, collision_mask):
         super().__init__(pos, collision_layer, collision_mask)
 
@@ -43,7 +50,11 @@ class Enemy(Actor):
             self.follow_target(target, stop_dist=target.width/2+self.weapon.width)
             if not target.attacked and get_display_rect(self.weapon.get_collision_rect()).colliderect(
                     get_display_rect(target.get_collision_rect())):
-                target.attack(self, self.weapon, self.direction)
+                if self.state != "ATTACK":
+                    self.state = "ATTACK"
+                    self.current_frame = 0
+                elif 4 < self.current_frame:
+                    target.attack(self, self.weapon, math.copysign(1, -self.velocity.x))
 
         # Deals with collision and applying velocity
         self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
@@ -64,8 +75,18 @@ class Enemy(Actor):
                 self.display_offsets["enemy"] = pg.Vector2(-60, -35)
             if frame % 4 == 0 and self.on_ground:
                 Dust(pg.Vector2(self.get_collision_rect().midbottom) + pg.Vector2(math.copysign(1, self.velocity.x) * -self.width/2,-15), 16, self.direction)
-            self.current_frame = (self.current_frame + 0.5) % self.run_gif.n_frames
-            
+            self.current_frame = (self.current_frame + 0.25) % self.run_gif.n_frames
+        elif self.state == "ATTACK":
+            frame = math.floor(self.current_frame)
+            if self.velocity.x > 0:
+                self.display = self.attack_frames[math.floor(frame)]
+                self.display_offsets["enemy"] = pg.Vector2(-50, -50)
+            else:
+                self.display = pg.transform.flip(self.attack_frames[math.floor(frame)], True, False)
+                self.display_offsets["enemy"] = pg.Vector2(-100, -50)
+            self.current_frame += 0.4
+            if math.floor(self.current_frame) >= self.attack_gif.n_frames-1:
+                self.state = "RUN"
 
         # print(self.velocity)
 
@@ -77,8 +98,8 @@ class Enemy(Actor):
         # self.crouch(1000)
 
     def draw(self, surf):
-        self.weapon.draw(surf)
-        super(Enemy, self).draw(surf)
+        self.weapon.draw(surf)
+        super(Enemy, self).draw(surf)
         surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + self.display_offsets["enemy"])
 
         # for b in self.buffer:
diff --git a/Game.py b/Game.py
index 8b811b521b4f48ad505fdf62412ad41c9ab21571..fd6884b5d6550dc1f2ebf5f598b4be954802ab09 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -18,12 +18,13 @@ from UI.Dialogue import DialogueUI
 from UI.HealthBar import HealthBar
 from UI.PotionUI import PotionUI
 from World import World
+from Item import PotionItem
 
 
 class Game:
 
     def __init__(self, level):
-        self.collision_layer = {"none": set(), "world": set(), "player": set(), "enemy": set(), "pet": set(), "body":set()}
+        self.collision_layer = {"none": set(), "world": set(), "player": set(), "enemy": set(), "pet": set(), "body":set(), "potion":set()}
 
         # self.load_world(level)
 
@@ -32,11 +33,15 @@ class Game:
 
         self.world = World(self.collision_layer)
 
-        enemy_positions, player_position, self.portal_position = self.world.load_world(level)
+        enemy_positions, player_position, self.portal_position, heal_positions = self.world.load_world(level)
+
+        for i in heal_positions:
+            PotionItem(i, self.collision_layer["potion"])
 
         self.player = Player(player_position, self.collision_layer["player"],
                              [self.collision_layer["enemy"], self.collision_layer["world"]],
-                             [self.collision_layer["enemy"], self.collision_layer["body"]])
+                             [self.collision_layer["enemy"], self.collision_layer["body"]],
+                             self.collision_layer["potion"])
         # self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
         self.enemies = [Enemy(pos, self.collision_layer["enemy"],
                               [self.collision_layer["player"], self.collision_layer["world"]]) for pos in
@@ -98,6 +103,9 @@ class Game:
 
         self.world.draw(surf)
 
+        for potion in self.collision_layer["potion"]:
+            potion.draw(surf)
+
         for particle in particles:
             particle.draw(surf)
 
diff --git a/Item.py b/Item.py
new file mode 100644 (file)
index 0000000..b45af4e
--- /dev/null
+++ b/Item.py
@@ -0,0 +1,20 @@
+from Setup import *
+
+
+class PotionItem:
+    width, height = 50, 50
+    img = pg.transform.scale(pg.image.load("Assets/world/decor/HEALTHPOTION.png"), (50, 50))
+
+    def __init__(self, pos, collision_layer):
+        self.position = pg.Vector2(pos)
+        collision_layer.add(self)
+
+    def update(self, delta):
+        pass
+
+    def get_collision_rect(self):
+        return pg.Rect(self.position, (self.width, self.height))
+
+    def draw(self, surf):
+        surf.blit(self.img, get_display_rect(self.get_collision_rect()))
+        # pg.draw.rect(surf,(255,0,0),get_display_rect(self.get_collision_rect()))
index 1695f1cae754e7750758c13412b4c8c837e07c92..0bf6b0b3cebb890215ccde58c85665e0e283d733 100644 (file)
@@ -1,6 +1,6 @@
-none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world
-1250.0,750.0|1200.0,750.0|1350.0,750.0|1350.0,700.0|1450.0,750.0|1450.0,700.0|1450.0,650.0|1450.0,600.0|1450.0,550.0|1250.0,700.0|1900.0,550.0|1900.0,600.0|1900.0,650.0|1900.0,700.0|1900.0,750.0|50.0,800.0|100.0,800.0|150.0,800.0|200.0,800.0|250.0,800.0|300.0,800.0|350.0,800.0|400.0,800.0|450.0,800.0|500.0,800.0|550.0,800.0|600.0,800.0|650.0,800.0|700.0,800.0|750.0,800.0|800.0,800.0|850.0,800.0|900.0,800.0|950.0,800.0|1000.0,800.0|1050.0,800.0|1100.0,800.0|1150.0,800.0|1200.0,800.0|1250.0,800.0|1300.0,800.0|1350.0,800.0|1400.0,800.0|1450.0,800.0|1500.0,800.0|1550.0,800.0|1600.0,800.0|1650.0,800.0|1700.0,800.0|1750.0,800.0|1800.0,800.0|1850.0,800.0|1900.0,800.0|1950.0,800.0|2000.0,800.0|2050.0,800.0|2100.0,800.0|2150.0,850.0|2100.0,850.0|2050.0,850.0|2000.0,850.0|1950.0,850.0|1900.0,850.0|1850.0,850.0|1800.0,850.0|1750.0,850.0|1700.0,850.0|1650.0,850.0|1600.0,850.0|1550.0,850.0|1500.0,850.0|1450.0,850.0|1400.0,850.0|1350.0,850.0|1300.0,850.0|1250.0,850.0|1200.0,850.0|1150.0,850.0|1100.0,850.0|1050.0,850.0|1000.0,850.0|950.0,850.0|900.0,850.0|850.0,850.0|800.0,850.0|750.0,850.0|700.0,850.0|650.0,850.0|600.0,850.0|550.0,850.0|500.0,850.0|450.0,850.0|400.0,850.0|350.0,850.0|300.0,850.0|250.0,850.0|200.0,850.0|150.0,850.0|100.0,850.0|50.0,850.0|0.0,850.0|0.0,800.0|0.0,750.0|0.0,700.0|0.0,650.0|0.0,600.0|0.0,550.0|0.0,400.0|0.0,350.0|0.0,300.0|0.0,250.0|0.0,200.0|0.0,150.0|0.0,100.0|0.0,50.0|0.0,0.0|2200.0,850.0|2200.0,800.0|2200.0,750.0|2200.0,700.0|2200.0,650.0|2200.0,600.0|2150.0,400.0|2200.0,200.0|2200.0,150.0|2200.0,100.0|2200.0,50.0|2200.0,0.0|2150.0,0.0|2150.0,50.0|2150.0,100.0|2150.0,150.0|2150.0,200.0|2150.0,250.0|2150.0,350.0|2150.0,300.0|2200.0,250.0|2200.0,300.0|2200.0,350.0|2200.0,400.0|2200.0,550.0|2150.0,550.0|2150.0,600.0|2150.0,650.0|2150.0,700.0|2150.0,750.0|2150.0,800.0|300.0,600.0|0.0,450.0|2200.0,450.0|2150.0,450.0|2150.0,500.0|2200.0,500.0|0.0,500.0|2050.0,700.0
-GOLDCOIN|BRONZECOIN|PEDESTAL|INTERDIMENSIONALPOWDER|PILLAR_|PILLAR_|PILLAR_|PILLAR_|PILLAR_|SILVERCOIN|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLAYER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|ENEMY
+none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world
+1250.0,750.0|1200.0,750.0|1350.0,750.0|1350.0,700.0|1450.0,750.0|1450.0,700.0|1450.0,650.0|1450.0,600.0|1450.0,550.0|1250.0,700.0|1900.0,550.0|1900.0,600.0|1900.0,650.0|1900.0,700.0|1900.0,750.0|50.0,800.0|100.0,800.0|150.0,800.0|200.0,800.0|250.0,800.0|300.0,800.0|350.0,800.0|400.0,800.0|450.0,800.0|500.0,800.0|550.0,800.0|600.0,800.0|650.0,800.0|700.0,800.0|750.0,800.0|800.0,800.0|850.0,800.0|900.0,800.0|950.0,800.0|1000.0,800.0|1050.0,800.0|1100.0,800.0|1150.0,800.0|1200.0,800.0|1250.0,800.0|1300.0,800.0|1350.0,800.0|1400.0,800.0|1450.0,800.0|1500.0,800.0|1550.0,800.0|1600.0,800.0|1650.0,800.0|1700.0,800.0|1750.0,800.0|1800.0,800.0|1850.0,800.0|1900.0,800.0|1950.0,800.0|2000.0,800.0|2050.0,800.0|2100.0,800.0|2150.0,850.0|2100.0,850.0|2050.0,850.0|2000.0,850.0|1950.0,850.0|1900.0,850.0|1850.0,850.0|1800.0,850.0|1750.0,850.0|1700.0,850.0|1650.0,850.0|1600.0,850.0|1550.0,850.0|1500.0,850.0|1450.0,850.0|1400.0,850.0|1350.0,850.0|1300.0,850.0|1250.0,850.0|1200.0,850.0|1150.0,850.0|1100.0,850.0|1050.0,850.0|1000.0,850.0|950.0,850.0|900.0,850.0|850.0,850.0|800.0,850.0|750.0,850.0|700.0,850.0|650.0,850.0|600.0,850.0|550.0,850.0|500.0,850.0|450.0,850.0|400.0,850.0|350.0,850.0|300.0,850.0|250.0,850.0|200.0,850.0|150.0,850.0|100.0,850.0|50.0,850.0|0.0,850.0|0.0,800.0|0.0,750.0|0.0,700.0|0.0,650.0|0.0,600.0|0.0,550.0|0.0,400.0|0.0,350.0|0.0,300.0|0.0,250.0|0.0,200.0|0.0,150.0|0.0,100.0|0.0,50.0|0.0,0.0|2200.0,850.0|2200.0,800.0|2200.0,750.0|2200.0,700.0|2200.0,650.0|2200.0,600.0|2150.0,400.0|2200.0,200.0|2200.0,150.0|2200.0,100.0|2200.0,50.0|2200.0,0.0|2150.0,0.0|2150.0,50.0|2150.0,100.0|2150.0,150.0|2150.0,200.0|2150.0,250.0|2150.0,350.0|2150.0,300.0|2200.0,250.0|2200.0,300.0|2200.0,350.0|2200.0,400.0|2200.0,550.0|2150.0,550.0|2150.0,600.0|2150.0,650.0|2150.0,700.0|2150.0,750.0|2150.0,800.0|300.0,600.0|0.0,450.0|2200.0,450.0|2150.0,450.0|2150.0,500.0|2200.0,500.0|0.0,500.0|2050.0,700.0|1050.0,750.0|1100.0,750.0|1050.0,700.0|1000.0,750.0|700.0,750.0
+GOLDCOIN|BRONZECOIN|PEDESTAL|INTERDIMENSIONALPOWDER|PILLAR_|PILLAR_|PILLAR_|PILLAR_|PILLAR_|SILVERCOIN|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLAYER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|ENEMY|HEALTHPOTION|HEALTHPOTION|HEALTHPOTION|HEALTHPOTION|HEALTHPOTION
 
 
 
index 1251c9cc4537f3a98bda0aaed2aef3bc8ff533ff..3651f76f2a102fbcc0e53b9f532e4abcb7f2cd9a 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -6,6 +6,7 @@ import time
 from Actors import Actor
 from datetime import datetime, timedelta
 from Potion import Potion
+from Item import PotionItem
 from Weapon import Sword
 from Particle import Dust
 
@@ -40,12 +41,12 @@ class Player(Actor):
 
     colour = (52, 94, 235)
 
-    def __init__(self, pos, collision_layer, collision_mask, can_hurt):
+    def __init__(self, pos, collision_layer, collision_mask, can_hurt, heals):
         super().__init__(pos, collision_layer, collision_mask)
         # self.initial_position = pg.Vector2(pos)
-        self.dashCooldown = timedelta(seconds=2, microseconds=500000)
-        self.timeBetweenDoublePress = timedelta(seconds=0, microseconds=500000)
-        self.dashSpeed = 5
+        self.dashCooldown = timedelta(seconds=2, microseconds=500000)
+        self.timeBetweenDoublePress = timedelta(seconds=0, microseconds=500000)
+        self.dashSpeed = 5
 
         # self.dashPossible = False
         # self.lastDash = datetime.utcnow()
@@ -53,14 +54,14 @@ class Player(Actor):
         # self.lastValueL = False
         # self.lastPressedRight = datetime.utcnow()
         # self.lastValueR = False
-        self.areas = {"body": Area(self.position, pg.Vector2(0, self.height / 2), self.width, self.height / 2, Actor),
-                      "head": Area(self.position, pg.Vector2(self.width * 1 / 3 * 1 / 2, -2), self.width * 2 / 3, 25,
-                                   Actor)}
+        self.areas = {"head": Area(self.position, pg.Vector2(0, self.height / 2), self.width, self.height / 2, Actor),
+                      "body": Area(self.position,(0,0),self.width,self.height,PotionItem, self.add_potion)}
 
+        self.heal_layer = heals
         self.potion_cooldown = 0
-        self.starting_potions = 999
+        self.starting_potions = 3
         self.potion_bag = [Potion(self)]
-        for i in range(self.starting_potions):
+        for i in range(self.starting_potions - 1):
             self.potion_bag.append(Potion(self))  # use one liner
 
         self.weapon = Sword(self.position, (0, 0), self.width, -1)
@@ -78,12 +79,21 @@ class Player(Actor):
         self.buffer = []
 
 
+    def add_potion(self):
+        if len(self.potion_bag) < 3:
+            self.potion_bag.append(Potion(self))
+
     # def attack(self, enemy, weapon):
     #     super(Player, self).attack(enemy, weapon)
     #     self.current_frame = 0
     #     self.state = "ATTACK"
     #     print('a')
 
+    def attack(self, enemy, weapon, direction):
+        self.friction = 0.9
+
+        super().attack(enemy,weapon,direction)
+
     def update(self, delta):
 
         if self.attacked:
@@ -96,6 +106,12 @@ class Player(Actor):
         # Get and handle input
         self.handle_input()
 
+        for i,heal in enumerate(self.heal_layer):
+            if len(self.potion_bag) < 3 and self.areas["body"].is_colliding(heal):
+                self.add_potion()
+                self.heal_layer.remove(heal)
+                break
+
         if len(self.potion_bag) > 0:
             self.potion_bag[0].get_input(self)
 
@@ -262,6 +278,7 @@ class Player(Actor):
                             enemy.attack(self, self.weapon, self.direction)
 
     def draw(self, surf):
+        # super().draw(surf)
         if self.state == "IDLE":
             # self.weapon.draw(surf, self.display_offsets["weapon"])
             if self.direction == 1:
index ed5fb19147920abc4a8dea3981bbf64c07fd1fed..c3131ccc9935cbf7e90ab8b764496d743186d70f 100644 (file)
--- a/Potion.py
+++ b/Potion.py
@@ -17,11 +17,6 @@ class Potion:
         if player.health > 100:
             player.health = 100
             
-        del player.potion_bag[0]
-        player.potion_cooldown = 30
-        threading.Thread(target = player.potion_cooldown_timer).start()
-
-
-
-
-
+        del self.player.potion_bag[0]
+        self.player.potion_cooldown = 4
+        threading.Thread(target = self.player.potion_cooldown_timer).start()
index 1c3f108ee7c1abd236d1d571f1623b7a039bcc22..15bf15f2f8657d8f354096c8d292ed66b49d4015 100644 (file)
--- a/World.py
+++ b/World.py
@@ -1,5 +1,6 @@
 from Setup import *
 from Block import Block
+from Item import PotionItem
 from os import path, listdir
 
 
@@ -13,7 +14,7 @@ class World:
         with open(path.join("Levels", f'Level{level}.txt'), 'r') as f:
             file_contents = f.read().split("\n")
 
-        out = [[], center, "a"]
+        out = [[], center, "a", []]
         for i in range(0, len(file_contents) - 1, 3):
             layer = file_contents[i].split("|")
             pos = file_contents[i + 1].split("|")
@@ -31,6 +32,8 @@ class World:
                     out[0].append((x, y))
                 elif t == "PORTAL":
                     out[2] = (x, y)
+                elif t == "HEALTHPOTION":
+                    out[3].append((x,y))
                 elif f"{t}.png" in listdir("Assets/world/decor"):
                     self.blocks.append(Decor((x,y),self.collision_layer["none"],t))
                 else:
@@ -48,9 +51,13 @@ class World:
 
 class Decor:
     textures = dict()
+    # for file in listdir("Assets/world/decor"):
+    #     textures[file[:file.index(".")]] = pg.transform.scale(
+    #     pg.image.load(path.join("Assets/world/decor", file)), (50, 50))
     for file in listdir("Assets/world/decor"):
-        textures[file[:file.index(".")]] = pg.transform.scale(
-        pg.image.load(path.join("Assets/world/decor", file)), (50, 50))
+        img = pg.image.load(path.join("Assets/world/decor", file))
+
+        textures[file[:file.index(".")]] = pg.transform.scale(pg.image.load(path.join("Assets/world/decor", file)),(img.get_width() * 50/16, img.get_height() * 50/16))
     def __init__(self, pos, collision_layer, img):
         self.position = pg.Vector2(pos)
         self.img = img