]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
attack by itself done
authorSkullheadx <704277@pdsb.net>
Wed, 13 Jul 2022 03:59:25 +0000 (23:59 -0400)
committerSkullheadx <704277@pdsb.net>
Wed, 13 Jul 2022 03:59:25 +0000 (23:59 -0400)
Assets/ARROW.png
Enemy.py
Game.py
Player.py
RangedAttack.py [new file with mode: 0644]
Weapon.py

index d79c4e019d45ba8b8a8f5d92a982a36b634a8ca7..d0f2ac271e274fe4fb00fdba97648476d0b56c44 100644 (file)
Binary files a/Assets/ARROW.png and b/Assets/ARROW.png differ
index 2a24c1271441b3efe9261f4cbdae529263f9bb02..49ef9a8c192c33bee553b1a91bb26f2e17e8397c 100644 (file)
--- a/Enemy.py
+++ b/Enemy.py
@@ -214,6 +214,7 @@ class Skeleton(Actor):
         # self.buffer.append(self.get_collision_rect())
         # pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2)
 class King(Actor):
+    width, height = Actor.width * 2, Actor.height * 2
     speed = Actor.speed * 0.4
     jump_strength = Actor.jump_strength * 1.1
     colour = (235, 64, 52)
@@ -226,7 +227,7 @@ class King(Actor):
     attack_gif = Image.open("Assets/skeleton/skeleton_king_summon.gif")
     attack_frames = []
     for i in range(attack_gif.n_frames):
-        attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (180, 180)))
+        attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (120, 180)))
 
     def __init__(self, pos, collision_layer, collision_mask):
         super().__init__(pos, collision_layer, collision_mask)
@@ -241,9 +242,11 @@ class King(Actor):
 
         self.health = 1000 # for debugging without getting killed
 
-        self.weapon = Lightning(self.position, (-100 - self.width/2,0), self.width, -1)
+        self.weapon = Lightning(self.position, (-125 - self.width/2,0), self.width, -1)
         self.buffer = []
 
+        self.attack_cooldown = random.randint(2,5) * 1000
+
         self.display_offsets = {"enemy":pg.Vector2(0,0)}
 
         self.current_frame = 0
@@ -252,15 +255,20 @@ class King(Actor):
 
     def update(self, delta, target=None):
         super().update(delta)
-        if not self.attacked and target is not None and self.stun_time == 0:
+        self.attack_cooldown -= delta
+        self.attack_cooldown = max(0, self.attack_cooldown)
+
+        if self.attack_cooldown == 0 and not self.attacked and target is not None and self.stun_time == 0:
             # self.follow_target(target, follow_range=750,stop_dist=target.width/2+self.weapon.width)
             if not target.attacked and get_display_rect(self.weapon.get_collision_rect()).colliderect(
                     get_display_rect(target.get_collision_rect())):
                 if self.state != "ATTACK":
                     self.state = "ATTACK"
                     self.current_frame = 0
-                elif 4 < self.current_frame:
-                    target.attack(self, self.weapon, math.copysign(1, target.position.x - self.position.x))
+                    self.attack_cooldown = random.randint(2,5) * 1000
+        if (self.state == "ATTACK") and (4 < self.current_frame) and (not self.attacked) and (target is not None) and (self.stun_time == 0) and (not target.attacked) and get_display_rect(self.weapon.get_collision_rect()).colliderect(
+                    get_display_rect(target.get_collision_rect())):
+            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)
diff --git a/Game.py b/Game.py
index 763a14a0f65d17146241cfb10241aead8a02c881..48f90dad0b133713130d29b9283bcd30573cacb3 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -15,7 +15,7 @@ from UI.Dialogue import DialogueUI
 from UI.HealthBar import HealthBar
 from UI.PotionUI import PotionUI
 from World import World
-
+from RangedAttack import RangedAttack
 
 class Game:
     cloud_density = 1 / 100000
@@ -24,6 +24,7 @@ class Game:
         self.collision_layer = {"none": set(), "world": set(), "player": set(), "enemy": set(), "pet": set(),
                                 "body": set(), "potion": set(), "spike": set()}
 
+
         # self.load_world(level)
 
         self.levels = [[], [], [3, 4]]
@@ -109,10 +110,12 @@ class Game:
             pg.mixer.music.play(-1)
         except:
             pass;
+        self.test = RangedAttack((1650,1250),self.collision_layer["world"])
 
     # def load_world(self, level):
 
     def update(self, delta):
+        self.test.update(delta)
         if self.paused == True:
             self.level = self.PauseMenu.level
             pass
@@ -237,6 +240,8 @@ class Game:
         self.healthBar.draw(surf, self.player.health)
         self.potionUI.draw(surf, self.player.potion_bag, self.player.potion_cooldown)
 
+        self.test.draw(surf)
+
         # print(self.player.get_collision_rect())s
         # Debug Lines. DO NOT CROSS THEM!
         # pg.draw.line(surf, (255, 0, 0), -Setup.camera_offset, pg.Vector2(SCREEN_WIDTH, -Setup.camera_offset.y), 10)
index 0fe06ebdfdee31051d17ac420e9f4655d18abc87..3ae919f75effe913ed6334d454907f5e715232fa 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -63,7 +63,7 @@ class Player(Actor):
 
         self.heal_layer = heals
         self.potion_cooldown = 0
-        self.starting_potions = 3
+        self.starting_potions = 1
         self.potion_bag = [Potion(self)]
         for i in range(self.starting_potions - 1):
             self.potion_bag.append(Potion(self))  # use one liner
diff --git a/RangedAttack.py b/RangedAttack.py
new file mode 100644 (file)
index 0000000..68a5bcb
--- /dev/null
@@ -0,0 +1,75 @@
+import random
+
+from Setup import *
+
+class RangedAttack:
+    attack_gif = Image.open("Assets/skeleton/portal.gif")
+    attack_frames = []
+    for i in range(attack_gif.n_frames):
+        attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (480, 320)))
+    def __init__(self, pos, ground):
+        self.position = pg.Vector2(pos)
+        self.timer = 0
+        self.ground = ground
+        self.arrows = []
+        self.anim_done = False
+        self.current_frame = 0
+        self.display = self.attack_frames[self.current_frame]
+
+    def update(self, delta):
+        self.timer += delta
+        if not self.anim_done:
+            self.display = self.attack_frames[math.floor(self.current_frame)]
+            self.current_frame = (self.current_frame + 0.1)
+            if math.floor(self.current_frame) >= self.attack_gif.n_frames - 1:
+                self.anim_done = True
+            if math.floor(self.current_frame) % 2 == 0 and random.random() < 0.5:
+                self.arrows.append(Arrow(self.position,(random.randint(-2,2),random.random() * 2), self.ground))
+
+        for arrow in self.arrows:
+            arrow.update(delta)
+    #     return True
+        # return False
+
+    def draw(self, surf):
+        # pg.draw.rect(surf, (255,0,0), pg.Rect(self.position, self.display.get_size()))
+        if not self.anim_done:
+            surf.blit(self.display, get_display_point(self.position - pg.Vector2(self.display.get_size()) / 2))
+
+        for arrow in self.arrows:
+            arrow.draw(surf)
+
+
+class Arrow:
+    gravity = 0.098
+    terminal_velocity = 1
+    arrow = pg.transform.scale(pg.image.load("Assets/ARROW.png"), (60,60))
+
+    def __init__(self, pos, vel, ground):
+        self.position = pg.Vector2(pos)
+        self.velocity = pg.Vector2(vel)
+        self.time = 0
+        self.display = self.arrow
+        self.ground = ground
+        self.in_ground = False
+
+    def update(self, delta):
+        if self.in_ground:
+            return
+        for block in self.ground:
+            if block.get_collision_rect().colliderect(pg.Rect(self.position, self.display.get_size())):
+                self.in_ground = True
+
+
+
+        self.velocity.y += self.gravity
+
+        self.position.x += self.velocity.x * delta / 5
+        self.position.y += self.velocity.y * delta / 5
+
+        self.time += delta
+
+        self.display = pg.transform.rotate(pg.transform.flip(self.arrow,bool(math.copysign(1,self.velocity.x)-1),False), -math.copysign(1,self.velocity.x) * min(90, round(90/(500 ** 2) * self.time * self.time)))
+
+    def draw(self, surf):
+        surf.blit(self.display, get_display_point(self.position))
index 74bedd49745bc4ba2c2aed85089c22dc38dbfb0c..c22ade916188f70297f0e9b60106d62f4549b0b3 100644 (file)
--- a/Weapon.py
+++ b/Weapon.py
@@ -94,7 +94,7 @@ 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)
+    width,height = (250,250)
     damage = -35
 
     def __init__(self, pos, offset, width,direction):