From: Skullheadx <704277@pdsb.net> Date: Wed, 13 Jul 2022 19:02:39 +0000 (-0400) Subject: boss death effect X-Git-Url: http://git.skullheadx.com/life/phil/static/gitweb.css?a=commitdiff_plain;h=6dd2abd28a90f8ee4e80abbc886e8cd52fb0e1da;p=Pygame-Jam.git boss death effect --- diff --git a/Enemy.py b/Enemy.py index c3d0fcc..b326856 100644 --- a/Enemy.py +++ b/Enemy.py @@ -148,7 +148,8 @@ class Skeleton(Actor): self.direction = -1 self.prev_direction = self.direction - self.health = 75 # for debugging without getting killed + self.health = 75 + self.health = 0 # for debugging without getting killed self.weapon = Sword(self.position, (0, 0), self.width, -1) @@ -255,7 +256,7 @@ class King(Actor): self.direction = -1 self.prev_direction = self.direction - self.health = 1000 # for debugging without getting killed + self.health = 100 # for debugging without getting killed self.weapon = Lightning(self.position, (-125 - self.width/2,0), self.width, -1) self.buffer = [] diff --git a/Game.py b/Game.py index 10f5ea9..caf2496 100644 --- a/Game.py +++ b/Game.py @@ -1,3 +1,5 @@ +import random + import Setup from EndScreen import EndScreen from Enemy import Enemy, Skeleton, King @@ -5,7 +7,7 @@ from Function.Fade import fade from Function.Portal import Transition from Item import PotionItem from Object import Object -from Particle import Cloud +from Particle import Cloud, Treasure from PauseMenu import PauseMenu from PhysicsBody import PhysicsBody from Player import Player @@ -17,13 +19,13 @@ from UI.PotionUI import PotionUI from World import World from RangedAttack import RangedAttack + class Game: cloud_density = 1 / 100000 def __init__(self, level): self.collision_layer = {"none": set(), "world": set(), "player": set(), "enemy": set(), "pet": set(), - "body": set(), "potion": set(), "spike": set(), "arrow":set()} - + "body": set(), "potion": set(), "spike": set(), "arrow": set()} # self.load_world(level) @@ -38,7 +40,16 @@ class Game: PotionItem(i, self.collision_layer["potion"]) for i in spike_positions: Spike(i, self.collision_layer["spike"]) - + if king_position is not None: + self.king = King(king_position, self.collision_layer["enemy"], + [self.collision_layer["player"], self.collision_layer["world"], + self.collision_layer["enemy"]], + (self.collision_layer["world"], self.collision_layer["arrow"])) + self.treasure = [Treasure(self.king.position - pg.Vector2(0, 50),pg.Vector2((random.random() -0.5) * 2, random.random() -2.5), self.collision_layer["body"], + [self.collision_layer["world"]]) for i in range(15)] + else: + self.king = None + self.treasure = None self.player = Player(player_position, self.collision_layer["player"], [self.collision_layer["enemy"], self.collision_layer["world"]], [self.collision_layer["enemy"], self.collision_layer["body"]], @@ -54,12 +65,7 @@ class Game: [self.collision_layer["player"], self.collision_layer["world"], self.collision_layer["enemy"]]) for pos in self.skele_positions] - if king_position is not None: - self.king = King(king_position, self.collision_layer["enemy"], - [self.collision_layer["player"], self.collision_layer["world"], - self.collision_layer["enemy"]],(self.collision_layer["world"], self.collision_layer["arrow"])) - else: - self.king = None + self.scene = EndScreen() # self.dashMeter = DashMeter(self.player.dashCooldown) @@ -75,15 +81,15 @@ class Game: # self.hints = [(Object((270, 640)), "Hello")] self.dialogue = DialogueUI() - - self.skeleton_spawn_frame = pg.transform.scale(pil_to_game(get_gif_frame(Image.open("Assets/skeleton/skeleton_attack.gif"), 0)), (170, 138)) + + self.skeleton_spawn_frame = pg.transform.scale( + pil_to_game(get_gif_frame(Image.open("Assets/skeleton/skeleton_attack.gif"), 0)), (170, 138)) self.skeleton_spawn_coords = [] skeleton_portal_gif = Image.open("Assets/skeleton/portal.gif") self.skeleton_portal_gif = [] for i in range(skeleton_portal_gif.n_frames): - self.skeleton_portal_gif.append(pg.transform.scale(pil_to_game(get_gif_frame(skeleton_portal_gif, i)), (96, 64))) - - + self.skeleton_portal_gif.append( + pg.transform.scale(pil_to_game(get_gif_frame(skeleton_portal_gif, i)), (96, 64))) self.paused = False self.PauseMenu = PauseMenu(self.level) @@ -117,7 +123,6 @@ class Game: else: pg.mixer.music.load("Assets/Music/Overworld_Music.ogg") - pg.mixer.music.play(-1) except: pass; @@ -137,7 +142,7 @@ class Game: Setup.camera_offset = self.player.update(delta) Setup.camera_offset.x = max(0, min(Setup.camera_offset.x, MAP_WIDTH - SCREEN_WIDTH)) Setup.camera_offset.y = max(0, min(Setup.camera_offset.y, MAP_HEIGHT - SCREEN_HEIGHT)) - + for i, enemy in enumerate(self.enemies): enemy.update(delta, self.player) if enemy.dead: @@ -145,28 +150,43 @@ class Game: enemy.colour, self.collision_layer["body"], [self.collision_layer["world"], self.collision_layer["body"]]) - self.collision_layer["enemy"].remove(enemy) + if enemy in self.collision_layer["enemy"]: + self.collision_layer["enemy"].remove(enemy) self.collision_layer["body"].add(self.enemies[i]) for i, enemy in enumerate(self.skeletons): enemy.update(delta, self.player) if enemy.dead: - self.skeletons[i] = PhysicsBody(enemy.position, enemy.velocity, enemy.width, enemy.height, - enemy.colour, - self.collision_layer["body"], - [self.collision_layer["world"], self.collision_layer["body"]], goon_skin=False) - self.collision_layer["enemy"].remove(enemy) + self.skeletons[i] = PhysicsBody(enemy.position, enemy.velocity, enemy.width, enemy.height / 2, + enemy.colour, + self.collision_layer["body"], + [self.collision_layer["world"], self.collision_layer["body"]], + goon_skin=False) + if enemy in self.collision_layer["enemy"]: + self.collision_layer["enemy"].remove(enemy) self.collision_layer["body"].add(self.skeletons[i]) if self.king is not None: self.king.update(delta, self.player) + if isinstance(self.king, PhysicsBody): + for t in self.treasure: + t.update(delta) if self.king.dead: self.collision_layer["enemy"].remove(self.king) - self.king = PhysicsBody(self.king.position, self.king.velocity, self.king.width/2, self.king.height/2, - self.king.colour, - self.collision_layer["body"], - [self.collision_layer["world"], self.collision_layer["body"]], goon_skin=False) + self.king = PhysicsBody(self.king.position, self.king.velocity, self.king.width / 2, + self.king.height / 4, + self.king.colour, + self.collision_layer["body"], + [self.collision_layer["world"], self.collision_layer["body"]], + goon_skin=False) self.collision_layer["body"].add(self.king) - for enemy in self.skeletons: - enemy.dead = True + for i, enemy in enumerate(self.skeletons): + if enemy in self.collision_layer["enemy"]: + self.collision_layer["enemy"].remove(enemy) + self.skeletons[i] = PhysicsBody(enemy.position, enemy.velocity, enemy.width, enemy.height, + enemy.colour, + self.collision_layer["body"], + [self.collision_layer["world"], self.collision_layer["body"]], + goon_skin=False) + self.collision_layer["body"].add(self.skeletons[i]) for particle in particles: particle.update(delta) @@ -188,29 +208,37 @@ class Game: def draw(self, surf): - - # screen.fill((0, 191, 255)) # screen.fill((0, 191, 255)) # screen.fill((255,255,255)) surf.blit(self.sky, (0, 0)) - + for particle in particles: + particle.draw(surf) + self.world.draw(surf) if (self.level == 4): # print(get_camera_offset()) if self.king is not None and isinstance(self.king, King): if self.king.skeleton_attack == True: for i in range(random.randint(1, 2)): - if(len(self.skeleton_spawn_coords) < 2): - self.skeleton_spawn_coords.append([(random.randint(4000, 5200), random.randint(3250, 3350)), 0]) + if (len(self.skeleton_spawn_coords) < 2): + self.skeleton_spawn_coords.append( + [(random.randint(4000, 5200), random.randint(3250, 3350)), 0]) self.king.skeleton_attack = False + if isinstance(self.king, PhysicsBody): + for t in self.treasure: + t.draw(surf) + for i in range(len(self.skeleton_spawn_coords)): try: - surf.blit(self.skeleton_portal_gif[self.skeleton_spawn_coords[i][1]], get_display_point((self.skeleton_spawn_coords[i][0][0] + 40, 3150))) + surf.blit(self.skeleton_portal_gif[self.skeleton_spawn_coords[i][1]], + get_display_point((self.skeleton_spawn_coords[i][0][0] + 40, 3150))) - if(self.skeleton_spawn_coords[i][0][1] <= 3050): - skele = Skeleton(self.skeleton_spawn_coords[i][0], self.collision_layer["enemy"], [self.collision_layer["player"],self.collision_layer["world"],self.collision_layer["enemy"]]) + if (self.skeleton_spawn_coords[i][0][1] <= 3050): + skele = Skeleton(self.skeleton_spawn_coords[i][0], self.collision_layer["enemy"], + [self.collision_layer["player"], self.collision_layer["world"], + self.collision_layer["enemy"]]) self.skeletons.append(skele) self.skeleton_spawn_coords[i][0] = (100000, 100000) else: @@ -218,25 +246,23 @@ class Game: lst[1] -= 2 self.skeleton_spawn_coords[i][0] = tuple(lst) surf.blit(self.skeleton_spawn_frame, get_display_point(self.skeleton_spawn_coords[i][0])) - if(self.skeleton_spawn_coords[i][1] <= 5): + if (self.skeleton_spawn_coords[i][1] <= 5): self.skeleton_spawn_coords[i][1] += 1 - - if(self.skeleton_spawn_coords[i][0][0] > 50000 and self.skeleton_spawn_coords[i][0][1] > 50000): + + if (self.skeleton_spawn_coords[i][0][0] > 50000 and self.skeleton_spawn_coords[i][0][1] > 50000): self.skeleton_spawn_coords[i][1] -= 1 - if(self.skeleton_spawn_coords[i][1] >= 0): + if (self.skeleton_spawn_coords[i][1] >= 0): self.skeleton_spawn_coords.pop(i) except IndexError: pass; - + if (self.player.position[1] > 10000): self.player.dead = True # if (self.level in self.levels[2]): # self.sky = pg.image.load("Assets/world/sky_level_background.png").convert() - for particle in particles: - particle.draw(surf) - self.world.draw(surf) + for potion in self.collision_layer["potion"]: potion.draw(surf) diff --git a/Particle.py b/Particle.py index ab7c4bd..46baef9 100644 --- a/Particle.py +++ b/Particle.py @@ -1,5 +1,9 @@ +import random + import Setup from Setup import * +from datetime import datetime, timedelta + class Dust: dust_gif = Image.open("Assets/player/DUSTCLOUD.gif") @@ -42,3 +46,88 @@ class Cloud: def draw(self, surf): surf.blit(self.display_img, self.position - Setup.camera_offset * 0.25) + +class Treasure: + imgs = [pg.image.load("Assets/world/decor/GOLDCOIN.png"), + pg.image.load("Assets/world/decor/SILVERCOIN.png"), + pg.image.load("Assets/world/decor/BRONZECOIN.png"), + pg.image.load("Assets/world/decor/JEWEL.png"), + ] + for i, val in enumerate(imgs): + imgs[i] = pg.transform.scale(val, (50, 50)) + width, height = imgs[0].get_size() + gravity = 0.098 + friction = 0.9 + + def __init__(self, pos,vel, collision_layer, collision_mask): + self.position = pg.Vector2(pos) + self.velocity = pg.Vector2(vel) + collision_layer.add(self) + self.collision_mask = collision_mask + self.display = random.choice(self.imgs) + self.attacked = False + self.health = 1000 + self.invincibility_frames = 250 + self.on_ground = False + + def update(self, delta): + if self.on_ground: + self.velocity.x *= self.friction + self.velocity.y += self.gravity + + self.position, self.velocity = self.move_and_collide(self.position, self.velocity,delta) + def attack(self, enemy, weapon, direction): + if not self.attacked and self.invincibility_frames == 0: + self.push(direction, 3, -5) + self.attacked = True + self.invincibility_frames = 250 + def push(self, direction, strength=1, y=-1): + self.velocity += pg.Vector2(direction * strength, y) + def move_and_collide(self, pos, vel, delta): + pos.x += vel.x * delta + collision_rect = self.get_collision_rect(pos) + for mask in self.collision_mask: + for thing in mask: + 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 + # elif vel.x < 0: + # thing.position.x = pos.x - thing.width + if vel.x > 0: + pos.x = thing.position.x - self.width + vel.x = min(vel.x, 0) + elif vel.x < 0: + pos.x = thing.position.x + thing.width + vel.x = max(vel.x, 0) + # print(pos.x, vel.x) + collision_rect = self.get_collision_rect(pos) + + self.on_ground = False + pos.y += vel.y * delta + collision_rect = self.get_collision_rect(pos) + for mask in self.collision_mask: + for thing in mask: + if thing == self: + continue + if collision_rect.colliderect(thing.get_collision_rect()): + if vel.y >= 0: + pos.y = thing.position.y - self.height + vel.y = min(vel.y, 0) + self.on_ground = True + elif vel.y < 0: + pos.y = thing.position.y + thing.height + vel.y = max(vel.y, 0) + collision_rect = self.get_collision_rect(pos) + return pos, vel + + def get_collision_rect(self, pos=None): + if pos is None: + pos = self.position + return pg.Rect(pos, (self.width, self.height)) + + def draw(self, surf): + surf.blit(self.display, get_display_rect(self.get_collision_rect())) diff --git a/Player.py b/Player.py index 06b4bd6..3ad4922 100644 --- a/Player.py +++ b/Player.py @@ -300,7 +300,7 @@ class Player(Actor): if not enemy.attacked and get_display_rect(self.weapon.get_collision_rect()).colliderect( get_display_rect(enemy.get_collision_rect())): enemy_type = str(type(enemy)) - print(enemy_type) + # print(enemy_type) if enemy.health > 0: if enemy_type == "": pg.mixer.Sound.play(self.grunt_sound)