From: Skullheadx <704277@pdsb.net> Date: Mon, 11 Jul 2022 21:05:58 +0000 (-0400) Subject: fixed more bugs + added anim for skele X-Git-Url: http://git.skullheadx.com/nixos/static/index.html?a=commitdiff_plain;h=a8a46571b2a670da3c402e8cefd32d8fa8957115;p=Pygame-Jam.git fixed more bugs + added anim for skele --- diff --git a/Actors.py b/Actors.py index 1a24e16..27634b0 100644 --- a/Actors.py +++ b/Actors.py @@ -39,7 +39,7 @@ class Actor: self.jumping = False self.coyote_time = datetime.utcnow() self.hold_jump = datetime.utcnow() - self.stun_time = 0 + self.stun_time = 750 self.attacked = False self.invincibility_frames = 0 @@ -50,6 +50,7 @@ class Actor: self.stun_time -= delta self.stun_time = max(self.stun_time, 0) + self.invincibility_frames -= delta self.invincibility_frames = max(self.invincibility_frames, 0) if self.invincibility_frames == 0 and self.on_ground: @@ -91,7 +92,6 @@ class Actor: self.invincibility_frames = self.invincibility_time def follow_target(self, node, follow_range=100000, stop_dist=115): - return # if stop_dist is None: # stop_dist = max(self.height, self.width) * 1.5 @@ -110,13 +110,13 @@ class Actor: self.move_left() elif target.x > self.position.x: self.move_right() - if not (target.y - node.height/2< self.position.y < target.y + node.height/2): self.jump() def jump(self): - if self.stun_time == 0: - pass + # print(self) + if self.stun_time > 0: + return if (self.on_ground and not self.jumping) or (datetime.utcnow() - self.hold_jump <= self.variable_jump_time): self.velocity.y = -self.jump_strength if not self.jumping: @@ -130,17 +130,13 @@ class Actor: def dash_right(self): pass - def move_left(self, customSpeed=None): - if customSpeed is None: - customSpeed = self.speed + def move_left(self): if self.stun_time == 0: - self.velocity.x = -customSpeed + self.velocity.x = -self.speed - def move_right(self, customSpeed=None): - if customSpeed is None: - customSpeed = self.speed + def move_right(self): if self.stun_time == 0: - self.velocity.x = customSpeed + self.velocity.x = self.speed def push(self, direction, strength=1, y=-1): self.velocity += pg.Vector2(direction * strength, y) @@ -153,6 +149,7 @@ class Actor: if thing == self: continue if collision_rect.colliderect(thing.get_collision_rect()): + # print(self, self.position.x, self.velocity.x) # if thing.movable: # if vel.x > 0: # thing.position.x = pos.x + self.width @@ -160,10 +157,11 @@ class Actor: # thing.position.x = pos.x - thing.width if vel.x > 0: pos.x = thing.position.x - self.width - # vel.x = min(vel.x, 0) + vel.x = min(vel.x, 0) elif vel.x < 0: pos.x = thing.position.x + thing.width - # vel.x = max(vel.x, 0) + vel.x = max(vel.x, 0) + # print(pos.x, vel.x) collision_rect = self.get_collision_rect(pos) if datetime.utcnow() - self.coyote_time >= self.coyote_time_amount or self.jumping: diff --git a/Assets/skeleton/skeleton_run.gif b/Assets/skeleton/skeleton_run.gif new file mode 100644 index 0000000..68e4073 Binary files /dev/null and b/Assets/skeleton/skeleton_run.gif differ diff --git a/Assets/world/VOID.png b/Assets/world/VOID.png new file mode 100644 index 0000000..4f8c5a6 Binary files /dev/null and b/Assets/world/VOID.png differ diff --git a/Enemy.py b/Enemy.py index c6a3df4..045d777 100644 --- a/Enemy.py +++ b/Enemy.py @@ -6,11 +6,14 @@ from Weapon import Melee class Enemy(Actor): - speed = Actor.speed * 0.5 - # jump_strength = Actor.jump_strength * 0.5 + speed = Actor.speed * 0.33 + jump_strength = Actor.jump_strength * 0.5 colour = (235, 64, 52) friction = 0.9 - + run_gif = Image.open("Assets/skeleton/skeleton_run.gif") + run_frames = [] + for i in range(run_gif.n_frames): + run_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(run_gif, i)), (125, 125))) def __init__(self, pos, collision_layer, collision_mask): super().__init__(pos, collision_layer, collision_mask) @@ -18,7 +21,6 @@ class Enemy(Actor): "head": Area(self.position, pg.Vector2(self.width * 1 / 3 * 1 / 2, -2), self.width * 2 / 3, 25, Player, self.knockout)} self.movable = False - self.dizzy_time = 0 self.direction = -1 @@ -29,15 +31,20 @@ class Enemy(Actor): self.buffer = [] + self.display_offsets = {"enemy":pg.Vector2(0,0)} + + self.current_frame = 0 + self.display = self.run_frames[math.floor(self.current_frame)] + self.state = "RUN" + def update(self, delta, target=None): super().update(delta) - if not self.attacked and target is not None and self.dizzy_time == 0: + if not self.attacked and target is not None and self.stun_time == 0: + # print('a') self.follow_target(target) - if random.random() < 2/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()): - target.attack(self, self.weapon, self.direction) - print('attack') - self.dizzy_time -= delta - self.dizzy_time = max(0, self.dizzy_time) + # if random.random() < 2/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()): + # target.attack(self, self.weapon, self.direction) + # print('attack') # Deals with collision and applying velocity self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta) @@ -47,11 +54,23 @@ class Enemy(Actor): else: self.direction = math.copysign(1, self.velocity.x) self.weapon.update(delta, self.position, self.direction) + + if self.state == "RUN": + frame = math.floor(self.current_frame) + if self.velocity.x > 0: + self.display = self.run_frames[math.floor(frame)] + self.display_offsets["enemy"] = pg.Vector2(-40, -35) + elif self.velocity.x <= 0: + self.display = pg.transform.flip(self.run_frames[math.floor(frame)], True, False) + self.display_offsets["enemy"] = pg.Vector2(-55, -35) + + self.current_frame = (self.current_frame + 0.5) % self.run_gif.n_frames + # print(self.velocity) def knockout(self, node): - self.dizzy_time = 100 + self.stun_time = 100 self.modify_health(-25, None) node.on_ground = False node.push(math.copysign(1, node.velocity.x), 0.25, -2.25) @@ -59,9 +78,10 @@ class Enemy(Actor): def draw(self, surf): self.weapon.draw(surf) - super(Enemy, self).draw(surf) + # super(Enemy, self).draw(surf) + surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + self.display_offsets["enemy"]) # for b in self.buffer: - # pg.draw.rect(surf,(0,0,255),b,3) - # self.buffer.append(get_display_rect(self.get_collision_rect())) + # pg.draw.rect(surf,(0,0,255),get_display_rect(b),3) + # self.buffer.append(self.get_collision_rect()) # pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2) diff --git a/Game.py b/Game.py index 569e984..3eaee72 100644 --- a/Game.py +++ b/Game.py @@ -77,7 +77,7 @@ class Game: # screen.fill((0, 191, 255)) # screen.fill((255,255,255)) - sky = pg.image.load("Assets/world/SKY.png") + sky = pg.image.load("Assets/world/VOID.png") surf.blit(sky,(0,0)) if (self.level == 1): diff --git a/Player.py b/Player.py index 6d52800..d945aaf 100644 --- a/Player.py +++ b/Player.py @@ -71,6 +71,8 @@ class Player(Actor): self.display = self.idle_frames[0] self.display_offsets = {"weapon": pg.Vector2(0, 0), "player": pg.Vector2(0, 0)} + self.buffer = [] + # def attack(self, enemy, weapon): # super(Player, self).attack(enemy, weapon) @@ -87,7 +89,7 @@ class Player(Actor): if len(self.potion_bag) > 0: self.potion_bag[0].get_input(self) - print(self.state, self.previous_state) + # print(self.state, self.previous_state) # Deals with collision and applying velocity self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta) @@ -167,6 +169,9 @@ class Player(Actor): return self.position - center def handle_input(self): + if self.stun_time > 0: + return + pressed = pygame.key.get_pressed() if pressed[pg.K_w] or pressed[pg.K_UP] or pressed[pg.K_SPACE]: @@ -251,6 +256,11 @@ class Player(Actor): get_display_rect(self.get_collision_rect()).topleft + pg.Vector2(0, 55) + self.display_offsets["weapon"]) surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + self.display_offsets["player"]) + # + # for b in self.buffer: + # pg.draw.rect(surf,(0,0,255),get_display_rect(b),3) + # self.buffer.append(self.get_collision_rect()) + # print(self, self.position) # super().draw(surf) # print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset) diff --git a/main.py b/main.py index 6a9d093..f807de5 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ is_running = True # scene = TransitionScene() scene = DevLevelSelect() old_level = 0 -level = 0 +level = 5 next_level = 0 while is_running: