Compare commits

...
Sign in to create a new pull request.

2 commits
main ... main

Author SHA1 Message Date
SpagettiFisch
baa592d921 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>
2024-03-29 09:38:23 +01:00
SpagettiFisch
7199e7f72f added a Drops class 2024-03-13 16:21:40 +01:00
2 changed files with 142 additions and 15 deletions

View file

@ -138,10 +138,12 @@ class HealthBar(Label):
self.box[i] = pygame.image.load(tb) self.box[i] = pygame.image.load(tb)
if not self.filling_is <= self.filling_should: if not self.filling_is <= self.filling_should:
self.filling_is -= 1.5 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.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.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.box[-1].blit(self.labelSurf, [
self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2, self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2,
self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2 self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2
@ -379,13 +381,14 @@ class Room(GameObjects):
def update(self, objects): def update(self, objects):
if objects is not None: if objects is not None:
self.objects = objects self.objects = objects
if not self.objects[1]: if self.type == 'boss' and not self.objects:
if self.type == 'boss':
print('yeahhh, you killed the boss') print('yeahhh, you killed the boss')
self.objects[0][0].level.level = 100 self.objects[0][0].level.level = 100
if len(self.objects[1]) <= 3:
self.locked = False self.locked = False
for door in self.doors: for door in self.doors:
door.update(False) door.update(False)
#Tür Sound
return return
def draw(self, screen): def draw(self, screen):
@ -534,6 +537,55 @@ class Convo(Label):
self.npc.talking = False self.npc.talking = False
objects[0][0].talking = False objects[0][0].talking = False
class Drops():
def __init__(self, type, level, mult) -> None:
table = {
'boss': {
'xp': 150,
'gold': 500,
'artifacts': [
100, #drop-chance
20, #common
30, #uncommon
35, #rare
14, #epic
1 #legendary
],
'will': 5
},
'mob': {
'xp': 5,
'gold': 20,
'artifacts': [
10, #drop-chance
65, #common
25, #uncommon
7.5, #rare
2.25, #epic
0.25 #legendary
],
'will': 0.1
},
'add': {
'xp': 0,
'gold': 3,
'artifacts': [
1, #drop-chance
90, #common
9.9, #uncommon
0.1, #rare
0, #epic
0 #legendary
],
'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): class Fighter(Objects):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None:
@ -553,7 +605,7 @@ class MainCharacter(Fighter):
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
self.book = Book(0, 0, [], None, None) self.book = Book(0, 0, [], None, None)
self.talking = False self.talking = False
self.level = Level(1000, 38, 150, 40, level, f'will to live: {level}%', 'simple', 20) self.level = Level(1000, 38, 150, 40, level, f'will to live: {round(level, 1)}%', 'simple', 20)
self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y=50, hurtCooldown=self.hurtCooldown) self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y=50, hurtCooldown=self.hurtCooldown)
self.thinks = Thinks(self.x + 20, self.y - 50, 150, 100, 'brr I\'m freezing') self.thinks = Thinks(self.x + 20, self.y - 50, 150, 100, 'brr I\'m freezing')
self.freezing = True self.freezing = True
@ -564,6 +616,8 @@ class MainCharacter(Fighter):
self.last_frame_update = pygame.time.get_ticks() self.last_frame_update = pygame.time.get_ticks()
self.rect = pygame.Rect(x, y, self.walk_frames[0].get_width(), self.walk_frames[0].get_height()) self.rect = pygame.Rect(x, y, self.walk_frames[0].get_width(), self.walk_frames[0].get_height())
self.is_attacking = False self.is_attacking = False
self.skill_xp = 0
self.gold = 0
def load_frames(self, walk_sprite_sheet, attack_sprite_sheet): def load_frames(self, walk_sprite_sheet, attack_sprite_sheet):
self.walk_frames = self.load_animation_frames(walk_sprite_sheet, frame_width=40, frame_height=66) self.walk_frames = self.load_animation_frames(walk_sprite_sheet, frame_width=40, frame_height=66)
@ -574,7 +628,7 @@ class MainCharacter(Fighter):
animation_frames = [] animation_frames = []
if frame_width == 40: if frame_width == 40:
frames_coordinates = [ frames_coordinates = [
(frame_width, 0), (frame_width, 0),
(frame_width*2, 0), (frame_width*2, 0),
(frame_width*3, 0), (frame_width*3, 0),
(frame_width*4, 0), (frame_width*4, 0),
@ -598,7 +652,6 @@ class MainCharacter(Fighter):
animation_frames.append(frame) animation_frames.append(frame)
return animation_frames return animation_frames
def draw(self, screen): def draw(self, screen):
if self.hidden: if self.hidden:
return return
@ -810,7 +863,7 @@ class Level(Label):
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite) super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
self.level = level self.level = level
def draw(self, screen): def draw(self, screen):
self.text = f'will to live: {self.level}%' self.text = f'will to live: {round(self.level)}%'
super().draw(screen) super().draw(screen)
class Thinks(Label): class Thinks(Label):
@ -899,14 +952,14 @@ class Book():
class Mobs(Fighter): class Mobs(Fighter):
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None: 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) 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): def chase(self, obj):
x = obj[0][0].x x = obj[0][0].x
y = obj[0][0].y y = obj[0][0].y
moveto = vec(x, y) - vec(self.x, self.y) moveto = vec(x, y) - vec(self.x, self.y)
if not (moveto).length() <= self.attack_range: 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.x += moveto[0] / fps
self.y += moveto[1] / fps self.y += moveto[1] / fps
touches = pygame.sprite.spritecollideany(self, obj[4]) touches = pygame.sprite.spritecollideany(self, obj[4])
@ -935,15 +988,15 @@ class Mobs(Fighter):
if self.health <= 0: if self.health <= 0:
objects[0][0].killed.append(self.name) objects[0][0].killed.append(self.name)
self.hidden = True self.hidden = True
self.drops.drop(objects[0][0])
objects[1].remove(self) objects[1].remove(self)
def update(self, obj): def update(self, obj):
self.chase(obj) self.chase(obj)
class Skeleton(Mobs): 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) super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
def attack(self, moveto, obj): def attack(self, moveto, obj):
@ -956,7 +1009,7 @@ class Skeleton(Mobs):
class Zombie(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) super().__init__(name, ms, sprite_sheet, x, y, health, damage, level, asp, atr, drops)
self.load_frames(f'art/images/{sprite_sheet}') self.load_frames(f'art/images/{sprite_sheet}')
self.current_frame = 0 self.current_frame = 0
@ -1000,7 +1053,7 @@ class Zombie(Mobs):
self.lastAttack = pygame.time.get_ticks() self.lastAttack = pygame.time.get_ticks()
class Rat(Mobs): 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) super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops)
def attack(self, moveto, obj): def attack(self, moveto, obj):
@ -1008,9 +1061,22 @@ class Rat(Mobs):
obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter)) obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter))
self.lastAttack = pygame.time.get_ticks() self.lastAttack = pygame.time.get_ticks()
class Boss(Mobs): class Adds(Mobs):
def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/reddy.png', drops=0) -> None: 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) 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): def attack(self, moveto, obj):
reddyattack_sound = mixer.Sound('audio/soundeffects/reddyattack.mp3') reddyattack_sound = mixer.Sound('audio/soundeffects/reddyattack.mp3')
@ -1028,7 +1094,63 @@ class Boss(Mobs):
objects[0][0].killed.append(self.name) objects[0][0].killed.append(self.name)
self.hidden = True self.hidden = True
objects[1].remove(self) 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): class Weapons(Objects):
def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None: def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None:
@ -1117,6 +1239,9 @@ class Punch(Weapons):
def __init__(self, name, ms, x, y, moveto, damage, kills, sprite = 'weapons/empty.png', life_ticks=100) -> None: 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) super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks)
self.kills = kills self.kills = kills
# if self.kills == Mobs:
# self.rect.width *= 2
# self.rect.height *= 2
def update(self, objects): def update(self, objects):
self.move(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) 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)) 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.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, '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) #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: if objects[0][0].level.level >= 100:
isblack = True isblack = True
if isinstance(result, str): if isinstance(result, str):
print(result)
if result == 'village': if result == 'village':
village(screen, clock, running, background, isblack, WIDTH, HEIGHT) village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
elif result == 'play': elif result == 'play':