From: Skullheadx <704277@pdsb.net> Date: Fri, 8 Jul 2022 01:43:00 +0000 (-0400) Subject: player kb X-Git-Url: http://git.skullheadx.com/nixos/blog/static/gitweb.css?a=commitdiff_plain;h=c7bd6194f33c66b84c7e82cef119e5179031cec3;p=Pygame-Jam.git player kb no more no kb haxs. player gets launched away when enemy hits. Also player gets stunned when damaged --- diff --git a/Actors.py b/Actors.py index 0e37724..b1cb713 100644 --- 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 936e4f0..0363447 100644 --- 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"])] diff --git a/Player.py b/Player.py index 49742df..2f1fc41 100644 --- 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)