From: Skullheadx <704277@pdsb.net> Date: Wed, 6 Jul 2022 17:53:53 +0000 (-0400) Subject: changed stuff X-Git-Url: http://git.skullheadx.com/nixos/README?a=commitdiff_plain;h=5208a912458fb142382a5b7deb72b114bb109c09;p=Pygame-Jam.git changed stuff --- diff --git a/Actors.py b/Actors.py index 26b357e..c27570a 100644 --- a/Actors.py +++ b/Actors.py @@ -1,10 +1,10 @@ from Setup import * class Actor: - width, height = 25, 50 + width, height = 50, 100 colour = (76, 82, 92) speed = 0.2 - jump_strength = 0.5 + jump_strength = 1 gravity = 0.098 friction = 0.9 @@ -19,25 +19,19 @@ class Actor: self.collision_mask = collision_mask # the layer the actor detects collisions against self.health = 100 - - self.crouching = False - self.crouch_timer = None + self.dead = False self.areas = dict() def update(self, delta): - - if self.crouching and self.crouch_timer == 0: - self.position.y -= self.height/2 - self.crouching = False - if self.crouch_timer is not None: - self.crouch_timer -= delta - self.crouch_timer = max(0, self.crouch_timer) - for area in self.areas.values(): 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 @@ -45,14 +39,22 @@ class Actor: # Apply gravity self.velocity.y += self.gravity + def is_dead(self): + if self.health <= 0: + self.dead = True + def modify_health(self): - def follow_target(self, node): + + def follow_target(self, node, follow_range=None, stop_dist=None): + if stop_dist is None: + stop_dist = max(self.height, self.width) * 1.5 + target = node.position # So that actor doesn't come up and hug u lol - if (self.position - target).length_squared() < pow(max(self.height, self.width) * 1.5,2): + if (self.position - target).length_squared() < pow(stop_dist,2): return if target.x < self.position.x: @@ -63,15 +65,6 @@ class Actor: if target.y < self.position.y: self.jump() - def crouch(self, time=None): - self.crouching = True - self.position.y += self.height/2 - if time is not None: - self.crouch_timer = time - else: - self.crouch_timer = None - - def jump(self): if self.on_ground: self.velocity.y = -self.jump_strength @@ -103,11 +96,10 @@ class Actor: for thing in mask: if thing == self: continue + for area in self.areas.values(): + if area.is_colliding(thing): + area.signal(thing) if collision_rect.colliderect(thing.get_collision_rect()): - for area in self.areas.values(): - if area.is_colliding(thing): - print('b') - area.signal(thing) if vel.y > 0: pos.y = thing.position.y - self.height vel.y = min(vel.y + thing.velocity.y, 0) @@ -120,14 +112,11 @@ class Actor: def get_collision_rect(self, pos=None): if pos is None: pos = self.position - if self.crouching: - return pg.Rect(pos, (self.width, self.height/2)) - else: - return pg.Rect(pos, (self.width, self.height)) + return pg.Rect(pos, (self.width, self.height)) def draw(self, surf): pg.draw.rect(surf, self.colour, self.get_collision_rect(), border_radius=8) # 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/Area.py b/Area.py index b364813..8babd5b 100644 --- a/Area.py +++ b/Area.py @@ -22,14 +22,14 @@ class Area: self.position = pos def is_colliding(self,node): - print("a", node) if isinstance(node, self.target): - print('c') if self.get_collision_rect().colliderect(node.get_collision_rect()): - print('d') return True return False + def set_func(self, func): + self.func = func + def signal(self, node): self.func(node) diff --git a/Enemy.py b/Enemy.py index ee7034d..e7a5e8f 100644 --- a/Enemy.py +++ b/Enemy.py @@ -15,7 +15,7 @@ class Enemy(Actor): def __init__(self, pos, collision_layer, collision_mask): super().__init__(pos, collision_layer, collision_mask) - self.areas = {"head":Area(self.position,pg.Vector2(0,-25), self.width, 25, Player, self.knockout)} + self.areas = {"head":Area(self.position,pg.Vector2(self.width * 1/3 * 1/2,-5), self.width * 2/3, 25, Player, self.knockout)} self.dizzy_time = 0 @@ -31,7 +31,7 @@ class Enemy(Actor): def knockout(self, node): self.dizzy_time = 5000 - print(node) + self.health -= 50 node.on_ground = True node.jump() # self.crouch(1000) diff --git a/Game.py b/Game.py index 56fa62b..ffc32ae 100644 --- a/Game.py +++ b/Game.py @@ -20,10 +20,12 @@ class Game: def update(self, delta): self.player.update(delta) - # self.pet.update(delta, self.player) + self.pet.update(delta, self.player) for enemy in self.enemies: enemy.update(delta, self.player) + if enemy.dead: + print('a') for block in self.blocks: block.update(delta) diff --git a/Pet.py b/Pet.py index d779662..e669837 100644 --- a/Pet.py +++ b/Pet.py @@ -1,8 +1,10 @@ from Actors import Actor +from Player import Player class Pet(Actor): width,height = 35,25 - speed = 0.25 + speed = Player.speed * 0.75 + jump_strength = Player.jump_strength / 2 def __init__(self, pos, collision_layer, collision_mask): super().__init__(pos, collision_layer, collision_mask) @@ -10,6 +12,6 @@ class Pet(Actor): def update(self, delta, target): super().update(delta) - self.follow_target(target) + self.follow_target(target, stop_dist=70) self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta)