From: Skullheadx <704277@pdsb.net> Date: Thu, 7 Jul 2022 21:09:52 +0000 (-0400) Subject: player now takes dmg X-Git-Url: http://git.skullheadx.com/nixos/static/pfp.webp?a=commitdiff_plain;h=ccb46b008f8a3fe8ba6f817cf6dcb5f863444378;p=Pygame-Jam.git player now takes dmg --- diff --git a/Actors.py b/Actors.py index 5151bda..4cfc5ff 100644 --- 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 b76abae..17a709a 100644 --- 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) diff --git a/Player.py b/Player.py index 0af9e6e..b93c991 100644 --- 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) diff --git a/Setup.py b/Setup.py index bce260c..93544b6 100644 --- 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 diff --git a/Weapon.py b/Weapon.py index 00455ef..823e239 100644 --- 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: