]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
player kb
authorSkullheadx <704277@pdsb.net>
Fri, 8 Jul 2022 01:43:00 +0000 (21:43 -0400)
committerSkullheadx <704277@pdsb.net>
Fri, 8 Jul 2022 01:43:00 +0000 (21:43 -0400)
no more no kb haxs. player gets launched away when enemy hits. Also player gets stunned when damaged

Actors.py
Game.py
Player.py

index 0e37724483bc67711428441688b876af6c6aa308..b1cb713f0e2a5c4510a65fb6287bfe686b645d82 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -27,8 +27,12 @@ class Actor:
         self.areas = dict()
 
         self.movable = False
+        self.stun_time = 0
 
     def update(self, delta):
+        self.stun_time -= delta
+        self.stun_time = max(self.stun_time, 0)
+
         for area in self.areas.values():
             area.update(delta, self.position)
 
@@ -48,6 +52,8 @@ class Actor:
 
     def modify_health(self, amount, reason):
         self.health += amount
+        if amount < 0:
+            self.stun_time = -amount * 50
         self.is_dead(reason)
 
     def follow_target(self, node, follow_range=None, stop_dist=None):
@@ -69,14 +75,24 @@ class Actor:
             self.jump()
 
     def jump(self):
-        if self.on_ground:
-            self.velocity.y = -self.jump_strength
+        if self.stun_time == 0:
+            if self.on_ground:
+                self.velocity.y = -self.jump_strength
 
     def move_left(self, customSpeed = speed):
-        self.velocity.x = -customSpeed
+        if self.stun_time == 0:
+            self.velocity.x = -customSpeed
 
     def move_right(self, customSpeed = speed):
-        self.velocity.x = customSpeed
+        if self.stun_time == 0:
+            self.velocity.x = customSpeed
+
+    def push(self, enemy):
+        v = pg.Vector2(0,0)
+        if enemy.velocity.x != v:
+            v = enemy.velocity.normalize().x
+
+        self.velocity += pg.Vector2(v, -1)
 
     def move_and_collide(self, pos, vel, delta):
         pos.x += vel.x * delta
diff --git a/Game.py b/Game.py
index 936e4f0433c7344e8fc1b8a8bcec8d36e4c5c404..0363447321e5f1dcde3d30da2b654fbb85fb9335 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -18,7 +18,7 @@ class Game:
                              [self.collision_layer["enemy"], self.collision_layer["world"]])
         # self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
 
-        self.enemies = [Enemy((SCREEN_WIDTH * 3 / 4, SCREEN_HEIGHT / 2), self.collision_layer["enemy"],
+        self.enemies = [Enemy((SCREEN_WIDTH / 4, SCREEN_HEIGHT / 2), self.collision_layer["enemy"],
                               [self.collision_layer["player"], self.collision_layer["world"]])]
         self.blocks = [Block((0, SCREEN_HEIGHT * 3 / 4), self.collision_layer["world"])]
 
index 49742dfe40341e394e7f27a82928f735a7011a0c..2f1fc418125feaa4574f85234b5a790d0784b27d 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -51,7 +51,6 @@ class Player(Actor):
 
         # Deals with collision and applying velocity
         self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
-        # print(self.velocity)
         return self.position - self.initial_position
 
         
@@ -91,6 +90,7 @@ class Player(Actor):
 
     def attack(self, enemy, weapon):
         self.modify_health(-10,"enemy")
+        self.push(enemy)
 
     def draw(self, surf):
         super().draw(surf)