From: Skullheadx <704277@pdsb.net> Date: Wed, 6 Jul 2022 17:28:22 +0000 (-0400) Subject: ? X-Git-Url: http://git.skullheadx.com/nixos/blog/static/gitweb.css?a=commitdiff_plain;h=bd244ad88ecb93625ceb1c783969d592b0dba5f4;p=Pygame-Jam.git ? --- diff --git a/Actors.py b/Actors.py index fd1c1d7..26b357e 100644 --- a/Actors.py +++ b/Actors.py @@ -1,10 +1,10 @@ from Setup import * class Actor: - width, height = 50, 100 + width, height = 25, 50 colour = (76, 82, 92) speed = 0.2 - jump_strength = 1 + jump_strength = 0.5 gravity = 0.098 friction = 0.9 @@ -20,10 +20,21 @@ class Actor: self.health = 100 + self.crouching = False + self.crouch_timer = None + 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) @@ -36,6 +47,7 @@ class Actor: + def follow_target(self, node): target = node.position @@ -51,6 +63,15 @@ 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 @@ -85,6 +106,7 @@ class Actor: 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 @@ -98,11 +120,14 @@ class Actor: def get_collision_rect(self, pos=None): if pos is None: pos = self.position - return pg.Rect(pos, (self.width, self.height)) + if self.crouching: + return pg.Rect(pos, (self.width, self.height/2)) + else: + return pg.Rect(pos, (self.width, self.height)) def draw(self, surf): - pg.draw.rect(surf, self.colour, self.get_collision_rect(), border_radius=15) + 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 2390548..b364813 100644 --- a/Area.py +++ b/Area.py @@ -22,8 +22,11 @@ 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 @@ -34,4 +37,4 @@ class Area: return pg.Rect(self.position + self.offset, (self.width, self.height)) def draw(self, surf): - pg.draw.rect(surf, (255,0,0),self.get_collision_rect()) \ No newline at end of file + pg.draw.rect(surf, (255,0,0),self.get_collision_rect()) diff --git a/Enemy.py b/Enemy.py index 6121458..ee7034d 100644 --- a/Enemy.py +++ b/Enemy.py @@ -4,10 +4,10 @@ from Player import Player from Actors import Actor class Enemy(Actor): - width, height = 50, 100 + width, height = 25, 50 colour = (235, 64, 52) speed = 0.2 - jump_strength = 1.1 + jump_strength = 0.75 gravity = 0.098 friction = 0.9 @@ -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,-15), self.width, 25, Player, self.knockout)} + self.areas = {"head":Area(self.position,pg.Vector2(0,-25), self.width, 25, Player, self.knockout)} self.dizzy_time = 0 @@ -30,5 +30,8 @@ class Enemy(Actor): self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta) def knockout(self, node): - self.dizzy_time = 10000 - + self.dizzy_time = 5000 + print(node) + node.on_ground = True + node.jump() + # self.crouch(1000) diff --git a/Game.py b/Game.py index 30fe35c..56fa62b 100644 --- a/Game.py +++ b/Game.py @@ -20,7 +20,7 @@ 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) @@ -37,4 +37,3 @@ class Game: self.player.draw(surf) self.pet.draw(surf) - diff --git a/Pet.py b/Pet.py index ca378e6..d779662 100644 --- a/Pet.py +++ b/Pet.py @@ -1,7 +1,8 @@ from Actors import Actor class Pet(Actor): - width,height = 75,50 + width,height = 35,25 + speed = 0.25 def __init__(self, pos, collision_layer, collision_mask): super().__init__(pos, collision_layer, collision_mask) @@ -12,4 +13,3 @@ class Pet(Actor): self.follow_target(target) self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta) - diff --git a/Player.py b/Player.py index 8c3f5d2..be950fa 100644 --- a/Player.py +++ b/Player.py @@ -4,17 +4,17 @@ from Setup import * from Actors import Actor class Player(Actor): - width, height = 50, 100 + width, height = 25, 50 colour = (52, 94, 235) - speed = 0.3 - jump_strength = 1.5 + speed = 0.2 + jump_strength = 0.9 gravity = 0.098 - friction = 0.9 + friction = 0.7 def __init__(self, pos, collision_layer, collision_mask): super().__init__(pos, collision_layer, collision_mask) - self.areas = {"body":Area(self.position, pg.Vector2(0, self.height/2),self.width, self.height/2,Actor)} + # self.areas = {"body":Area(self.position, pg.Vector2(0, self.height/2),self.width, self.height/2,Actor)} def update(self, delta): @@ -53,4 +53,3 @@ class Player(Actor): current_health = str(self.health) + "/100" current_health_display = font.render(current_health, True, (255, 255, 255)) surf.blit(current_health_display, foreground_rect) -