the boss has now abilitys

they can heal and spawn adds and are probably doing it every time they can
the boss has only one ability atm (plus the add spawning)

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
This commit is contained in:
SpagettiFisch 2024-03-29 09:38:23 +01:00
parent 7199e7f72f
commit baa592d921
2 changed files with 95 additions and 13 deletions

View file

@ -138,10 +138,12 @@ class HealthBar(Label):
self.box[i] = pygame.image.load(tb)
if not self.filling_is <= self.filling_should:
self.filling_is -= 1.5
if self.filling_should >= self.filling_is:
self.filling_is += 1.5
self.box[i] = pygame.transform.scale(self.box[i], (self.filling_is, self.height))
self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height)
self.labelSurf = self.font.render(f'{self.text}: {self.percentage}%', True, self.font_color)
self.labelSurf = self.font.render(f'{self.text}: {round(self.percentage, 1)}%', True, self.font_color)
self.box[-1].blit(self.labelSurf, [
self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2,
self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2
@ -536,7 +538,7 @@ class Convo(Label):
objects[0][0].talking = False
class Drops():
def __init__(self, type, level, objects) -> None:
def __init__(self, type, level, mult) -> None:
table = {
'boss': {
'xp': 150,
@ -551,7 +553,7 @@ class Drops():
],
'will': 5
},
'normal': {
'mob': {
'xp': 5,
'gold': 20,
'artifacts': [
@ -564,7 +566,7 @@ class Drops():
],
'will': 0.1
},
'ad': {
'add': {
'xp': 0,
'gold': 3,
'artifacts': [
@ -578,6 +580,12 @@ class Drops():
'will': 0
}
}
self.table = table[type]
self.multiplicator = level * mult
def drop(self, main):
main.skill_xp += self.table['xp'] * self.multiplicator
main.gold += self.table['gold'] * self.multiplicator
class Fighter(Objects):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None:
@ -855,7 +863,7 @@ class Level(Label):
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
self.level = level
def draw(self, screen):
self.text = f'will to live: {self.level}%'
self.text = f'will to live: {round(self.level)}%'
super().draw(screen)
class Thinks(Label):
@ -944,14 +952,14 @@ class Book():
class Mobs(Fighter):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
self.drops = drops * (self.level / 2)
self.drops = Drops('mob', self.level, drops)
def chase(self, obj):
x = obj[0][0].x
y = obj[0][0].y
moveto = vec(x, y) - vec(self.x, self.y)
if not (moveto).length() <= self.attack_range:
moveto.scale_to_length(self.speed)
moveto.scale_to_length(int(self.speed))
self.x += moveto[0] / fps
self.y += moveto[1] / fps
touches = pygame.sprite.spritecollideany(self, obj[4])
@ -980,15 +988,15 @@ class Mobs(Fighter):
if self.health <= 0:
objects[0][0].killed.append(self.name)
self.hidden = True
self.drops.drop(objects[0][0])
objects[1].remove(self)
def update(self, obj):
self.chase(obj)
class Skeleton(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite = 'people/skeleton.png', drops=0) -> None:
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite = 'people/skeleton.png', drops=2) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
def attack(self, moveto, obj):
@ -1001,7 +1009,7 @@ class Skeleton(Mobs):
class Zombie(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite_sheet='people/zombiewalk.png', drops=0) -> None:
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite_sheet='people/zombiewalk.png', drops=1) -> None:
super().__init__(name, ms, sprite_sheet, x, y, health, damage, level, asp, atr, drops)
self.load_frames(f'art/images/{sprite_sheet}')
self.current_frame = 0
@ -1045,7 +1053,7 @@ class Zombie(Mobs):
self.lastAttack = pygame.time.get_ticks()
class Rat(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/rat.png', drops=0) -> None:
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/rat.png', drops=1) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
def attack(self, moveto, obj):
@ -1053,9 +1061,22 @@ class Rat(Mobs):
obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter))
self.lastAttack = pygame.time.get_ticks()
class Boss(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/reddy.png', drops=0) -> None:
class Adds(Mobs):
def __init__(self, name, ms, sprite, health, damage, level, asp, atr, drops, x, y) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
self.drops = Drops('add', self.level, drops)
def attack(self, moveto, obj):
pass
class Boss(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/reddy.png', drops=1) -> None:
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
self.max_hp = health
self.drops = Drops('boss', self.level, drops)
self.adds = SpawnAdds(15, ['add', '125', sprite, 3, 0.5, 1, 1.5, 250, 1], [3, 7])
self.ability = Heal(10, 25, 5)
self.adds.last_used = pygame.time.get_ticks() - 12500
def attack(self, moveto, obj):
reddyattack_sound = mixer.Sound('audio/soundeffects/reddyattack.mp3')
@ -1073,7 +1094,63 @@ class Boss(Mobs):
objects[0][0].killed.append(self.name)
self.hidden = True
objects[1].remove(self)
def update(self, obj):
super().update(obj)
self.adds.spawn(obj)
event = self.ability.cast(obj)
if event.type == 'heal':
self.health += event.num
if self.health > self.max_hp:
self.health = self.max_hp
elif self.health < 0:
self.health = 0
class Event():
def __init__(self, _type: str, num: int) -> None:
self.type = _type
self.num = num
class Ability():
def __init__(self, cd, stage = 0) -> None:
self.cooldown = cd
self.stage = stage
self.last_used = 0
def cast(self, objects):
if self.last_used + self.cooldown * 1000 <= pygame.time.get_ticks():
self.last_used = pygame.time.get_ticks()
class SpawnAdds(Ability):
def __init__(self, cd, add:list, count:list, stage=0) -> None:
super().__init__(cd, stage)
self.add = add
self.count = count
def spawn(self, objects):
if self.last_used + self.cooldown * 1000 <= pygame.time.get_ticks():
for i in range(random.randint(*self.count)):
objects[1].append(Adds(*self.add, random.randint(32, 1888), random.randint(32, 1048)))
self.last_used = pygame.time.get_ticks()
class Heal(Ability):
def __init__(self, cd, amount, time, stage=0) -> None:
super().__init__(cd, stage)
self.amount = amount
self.time = time
def cast(self, objects):
if self.time * 1000 + self.last_used > pygame.time.get_ticks():
return Event('heal', (self.amount / self.time / 1000))
elif self.time * 1000 + self.last_used == pygame.time.get_ticks():
self.last_used = pygame.time.get_ticks()
return Event('heal', (self.amount / self.time / 1000))
elif random.randint(0, 88) % 5 == 0:
if self.last_used + self.cooldown * 1000 <= pygame.time.get_ticks():
self.last_used = pygame.time.get_ticks()
# else:
# self.last_used
return Event('None', 0)
class Weapons(Objects):
def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None:
@ -1162,6 +1239,9 @@ class Punch(Weapons):
def __init__(self, name, ms, x, y, moveto, damage, kills, sprite = 'weapons/empty.png', life_ticks=100) -> None:
super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
self.kills = kills
# if self.kills == Mobs:
# self.rect.width *= 2
# self.rect.height *= 2
def update(self, objects):
self.move(objects)

View file

@ -41,6 +41,7 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list):
Room(type, 'normal', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, 0)] for _ in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, j)
for j in range(random.randint(5, 10))
]
print(objects)
rooms.append(Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88))
#rooms = [Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88)]
#rooms =Room(type, 'normal', room_backgrounds[random.randint(0, 4)], [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j)
@ -105,6 +106,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
if objects[0][0].level.level >= 100:
isblack = True
if isinstance(result, str):
print(result)
if result == 'village':
village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
elif result == 'play':