]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
player now takes dmg
authorSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 21:09:52 +0000 (17:09 -0400)
committerSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 21:09:52 +0000 (17:09 -0400)
Actors.py
Game.py
Player.py
Setup.py
Weapon.py

index 5151bdad84fc967ce15d1b60e132c1e12e34d1e7..4cfc5ffb1fdb370c666bb81270e1017c168eed50 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -2,6 +2,7 @@ from Setup import *
 from PhysicsBody import PhysicsBody
 from Block import Block
 
+
 class Actor:
     width, height = 50, 100
     colour = (76, 82, 92)
@@ -9,14 +10,13 @@ class Actor:
     jump_strength = 1
     gravity = 0.098
     friction = 0.9
-    
 
     def __init__(self, pos, collision_layer, collision_mask):
         self.position = pg.Vector2(pos)
         self.velocity = pg.Vector2(0, 0)
 
         self.on_ground = False
-        
+
         collision_layer.add(self)  # the layer the actor is on for collisions
         self.collision_layer = collision_layer
         self.collision_mask = collision_mask  # the layer the actor detects collisions against
@@ -28,28 +28,25 @@ class Actor:
 
         self.movable = False
 
-
     def update(self, delta):
         for area in self.areas.values():
-            area.update(delta,self.position)
+            area.update(delta, self.position)
 
         if self.is_dead():
             return
 
-
         # Apply friction so the enemy isn't walking on ice
         if self.on_ground:
-            self.velocity.x *= self.friction 
+            self.velocity.x *= self.friction
 
-        # Apply gravity
+            # Apply gravity
         self.velocity.y += self.gravity
 
-    def is_dead(self,reason=None):
+    def is_dead(self, reason=None):
         if self.health <= 0:
             self.dead = True
 
-
-    def modify_health(self,amount, reason):
+    def modify_health(self, amount, reason):
         self.health += amount
         self.is_dead(reason)
 
@@ -60,7 +57,7 @@ class Actor:
         target = node.position
 
         # So that actor doesn't come up and hug u lol
-        if (self.position - target).length_squared() < pow(stop_dist,2):
+        if (self.position - target).length_squared() < pow(stop_dist, 2):
             return
 
         if target.x < self.position.x:
@@ -89,7 +86,6 @@ class Actor:
                 if thing == self:
                     continue
                 if collision_rect.colliderect(thing.get_collision_rect()):
-                    print(self, vel, thing.velocity)
                     if thing.movable:
                         if vel.x > 0:
                             thing.position.x = pos.x + self.width
@@ -107,7 +103,7 @@ class Actor:
         self.on_ground = False
         pos.y += vel.y * delta
         collision_rect = self.get_collision_rect(pos)
-        for mask in self.collision_mask:        
+        for mask in self.collision_mask:
             for thing in mask:
                 if thing == self:
                     continue
diff --git a/Game.py b/Game.py
index b76abae4c2d8c3d075fbdead9c20ae7f98164aed..17a709af639d2954fb2a6794798724890a85cd4c 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -22,6 +22,8 @@ class Game:
 
     def update(self, delta):
         Setup.camera_offset = self.player.update(delta)
+        if self.player.dead:
+            print("You Died!")
 
         for i,enemy in enumerate(self.enemies):
             enemy.update(delta, self.player)
index 0af9e6e1ba2265f63ee272b679c5ec56037f9ea8..b93c991a55980d34310944ba52bdbb956cd18bb1 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -37,6 +37,9 @@ class Player(Actor):
         if pressed[pg.K_d] or pressed[pg.K_RIGHT]:
             self.move_right()
 
+    def attack(self, enemy, weapon):
+        self.modify_health(-10,"enemy")
+
     def draw(self, surf):
         super().draw(surf)
         # print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset)
index bce260cc83b25ae1785c96c3f19c4b9cd2d01458..93544b6109916caaecd6570a947f6b5819ea4027 100644 (file)
--- a/Setup.py
+++ b/Setup.py
@@ -29,6 +29,7 @@ def rotate(pos, img, angle, pivot):
 
 camera_offset = pg.Vector2(0,0)
 
+
 def get_display_rect(collision_rect):
     pos = collision_rect.topleft
     width, height = collision_rect.w, collision_rect.h
index 00455efec3cadeb941ff21f1046876b55447e697..823e239fdb7d3112d00e91e60eeaf4b2704fd658 100644 (file)
--- a/Weapon.py
+++ b/Weapon.py
@@ -19,6 +19,7 @@ class Melee:
         self.display = self.img
         self.display_rect = self.display.get_rect()
         self.swing_timer = 0
+        self.attacking = False
 
 
     def update(self, delta, pos, direction):
@@ -35,6 +36,10 @@ class Melee:
 
         self.swing_timer -= delta
         self.swing_timer = max(self.swing_timer, 0)
+        if self.swing_timer == 0:
+            self.attacking = False
+        else:
+            self.attacking = True
 
     def get_collision_rect(self):
         if self.direction == -1: