# 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)
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)
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
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)
from UI.HealthBar import HealthBar
from UI.PotionUI import PotionUI
from World import World
-
+from RangedAttack import RangedAttack
class Game:
cloud_density = 1 / 100000
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]]
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
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)
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
--- /dev/null
+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))
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):