From 425c3b1413d10ee86856e0bb6da680489d6724cc Mon Sep 17 00:00:00 2001 From: Skullheadx <704277@pdsb.net> Date: Tue, 12 Jul 2022 22:35:17 -0400 Subject: [PATCH] boss melee atk --- Enemy.py | 32 +++++++++++++------------------- Game.py | 2 +- Weapon.py | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Enemy.py b/Enemy.py index 422daac..a44c77b 100644 --- a/Enemy.py +++ b/Enemy.py @@ -3,7 +3,7 @@ from argparse import Action from Setup import * from Player import Player from Actors import Actor -from Weapon import Sword +from Weapon import Sword, Lightning from Particle import Dust class Enemy(Actor): @@ -136,7 +136,7 @@ class Skeleton(Actor): self.direction = -1 self.prev_direction = self.direction - # self.health = 0 # for debugging without getting killed + self.health = 0 # for debugging without getting killed self.weapon = Sword(self.position, (0, 0), self.width, -1) @@ -221,7 +221,7 @@ class King(Actor): run_gif = Image.open("Assets/skeleton/skeleton_king_idle.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)), (160, 240))) + run_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(run_gif, i)), (120, 180))) attack_gif = Image.open("Assets/skeleton/skeleton_king_summon.gif") attack_frames = [] @@ -239,11 +239,9 @@ class King(Actor): self.direction = -1 self.prev_direction = self.direction - # self.health = 0 # for debugging without getting killed - - self.weapon = Sword(self.position, (0, 0), self.width, -1) - + self.health = 1000 # for debugging without getting killed + self.weapon = Lightning(self.position, (-100 - self.width/2,0), self.width, -1) self.buffer = [] self.display_offsets = {"enemy":pg.Vector2(0,0)} @@ -262,7 +260,7 @@ class King(Actor): self.state = "ATTACK" self.current_frame = 0 elif 4 < self.current_frame: - target.attack(self, self.weapon, self.direction) + target.attack(self, self.weapon, math.copysign(1, target.position.x - self.position.x)) # Deals with collision and applying velocity self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta) @@ -276,15 +274,10 @@ class King(Actor): 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(-30, -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(-90, -35) - if frame % 4 == 0 and self.on_ground: - Dust(pg.Vector2(self.get_collision_rect().midbottom) + pg.Vector2(math.copysign(1, self.velocity.x) * -self.width/2,-15), 16, self.direction) - self.current_frame = (self.current_frame + 0.25) % self.run_gif.n_frames + self.display = self.run_frames[math.floor(frame)] + self.display_offsets["enemy"] = pg.Vector2(0, -35) + self.current_frame = (self.current_frame + 0.025) % self.run_gif.n_frames + elif self.state == "ATTACK": frame = math.floor(self.current_frame) if self.direction == 1: @@ -296,6 +289,7 @@ class King(Actor): self.current_frame += 0.4 if math.floor(self.current_frame) >= self.attack_gif.n_frames-1: self.state = "RUN" + self.current_frame = 0 # print(self.velocity) @@ -308,10 +302,10 @@ class King(Actor): def draw(self, surf): # self.weapon.draw(surf) - # super(Enemy, self).draw(surf) + super(King, 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),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) + pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.weapon.get_collision_rect()), 2) diff --git a/Game.py b/Game.py index b19e001..763a14a 100644 --- a/Game.py +++ b/Game.py @@ -142,7 +142,7 @@ class Game: [self.collision_layer["world"], self.collision_layer["body"]], goon_skin=False) self.collision_layer["enemy"].remove(enemy) self.collision_layer["body"].add(self.skeletons[i]) - self.king.update(delta) + self.king.update(delta, self.player) if self.king.dead: print("You win!") diff --git a/Weapon.py b/Weapon.py index 0ecbfd3..74bedd4 100644 --- a/Weapon.py +++ b/Weapon.py @@ -93,3 +93,21 @@ class Sword: def draw(self, surf, display_offset = pg.Vector2(0,0)): surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + display_offset) +class Lightning: + width,height = (200,200) + damage = -35 + + def __init__(self, pos, offset, width,direction): + self.position = pg.Vector2(pos) + self.offset = pg.Vector2(offset) + + def update(self, delta, pos, direction): + self.position = pg.Vector2(pos) + + def get_collision_rect(self): + return pg.Rect(self.position - self.offset - pg.Vector2(self.width,self.height/4),(self.width, self.height)) + + + def draw(self, surf, display_offset = pg.Vector2(0,0)): + pass + # surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + display_offset) -- 2.54.0