changed Book and Convo, renamed Speech

This commit is contained in:
Lyzzy 2024-03-09 11:11:28 +01:00
parent 1f38a04004
commit 614654692f
3 changed files with 39 additions and 19 deletions

View file

Before

Width:  |  Height:  |  Size: 329 B

After

Width:  |  Height:  |  Size: 329 B

View file

@ -52,7 +52,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
rooms = genRooms(WIDTH, HEIGHT, 'grass', objects)
level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms))
scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level)
freeze = False #Gameplay is freezed in certain situations
freeze = True #Gameplay is freezed in certain situations
while running:
screen.fill('#000000')

View file

@ -63,6 +63,7 @@ class NPC(Objects):
self.talking = False
self.hidden = False
self.conversation = Convo('Hello, you can shoot fireballs with f now.', convo_act, 'person')
self.lastUpdate = pg.time.get_ticks()
def talk(self, objects):
self.talking = True
@ -74,9 +75,16 @@ class NPC(Objects):
if self.talking:
self.conversation.draw(screen)
def update(self, keys, objects):
if self.talking:
self.conversation.update(keys, objects)
def update(self, keys, objects):
if self.lastUpdate + 200 < pg.time.get_ticks():
if self.talking:
self.conversation.update(keys, objects)
else:
touches = pg.sprite.spritecollideany(self, objects[0])
if touches is not None and keys[pg.K_SPACE] and isinstance(touches, MainCharacter):
self.talk(objects)
self.lastUpdate = pg.time.get_ticks()
class Convo(Label):
def __init__(self, text, convo_act, person, x = 140, y = 600, width = 1000, height = 100, font='simple', font_size = 20) -> None:
@ -112,7 +120,7 @@ class MainCharacter(Fighter):
self.talking = False
self.level = Level(1000, 38, 150, 40, f'will to live: {level}%', '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.speech = Speech(self.x+20, self.y-50, 150, 100, 'brr Im freezing')
self.thinks = Thinks(self.x+20, self.y-50, 150, 100, 'brr Im freezing')
self.freezing = True
def draw(self, screen):
@ -124,8 +132,8 @@ class MainCharacter(Fighter):
self.level.draw(screen)
self.book.draw(screen)
pg.draw.rect(screen, '#e900fa', self.rect, 2)
if self.speech.hidden == False:
self.speech.draw(screen, self.x+20, self.y-100)
if self.thinks.hidden == False:
self.thinks.draw(screen, self.x+20, self.y-100)
def hurt(self, damage, objects):
if not self.talking:
@ -204,7 +212,7 @@ class MainCharacter(Fighter):
self.walk(keys, objects)
if pg.mouse.get_pressed()[0]:
self.attack(objects, vec(mouse))
self.speech.update(self)
self.thinks.update(self)
if self.health.health <= 0:
return False
else:
@ -262,8 +270,8 @@ class Level(Label):
def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color='#1e90ff', sprite='label.png') -> None:
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
class Speech(Label):
def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color='#000000', sprite='speech.png') -> None:
class Thinks(Label):
def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color='#000000', sprite='thinks.png') -> None:
super().__init__(x, y, width, height, text, font, font_size, font_color, sprite)
def draw(self, screen, x, y):
@ -285,24 +293,36 @@ class Book():
self.sprite = pg.transform.scale(self.sprite, (1280, 720))
self.x = x
self.y = y
self.hidden = True
self.hidden = False
self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
self.sp_list = spells
self.current_sp = current_spell
self.labels = [Label(100, 100, 500, 50, "Dear User, ", font_color='#000000', sprite='empty.png'),
Label(100, 150, 500, 50, "this book will help you to survive.", font_color='#000000', sprite='empty.png'),
Label(100, 200, 500, 50, "Click on a picture to choose your spell.", font_color='#000000', sprite='empty.png'),
Label(100, 250, 500, 50, "Talk to fairies to unlock new spells!", font_color='#000000', sprite='empty.png')]
self.text_left = ["Dear User, ", "in case you fell on the ground too hard,", "here is a quick reminder:",
"You are a homeless person.","One cold day you went to the library to get warm.",
"There you saw and opened me out of boedom.", "This lead to you being thrown in this world.",
"But you can find a way out of here again."]
self.text_right = ["This book will help you to survive.", "Click on a picture to choose your spell.",
"Talk to fairies to unlock new spells!"]
self.buttons=[]
self.buttons_height = 400
self.buttons_y = 400
self.buttons_x = 800
def draw(self, screen):
if self.hidden:
return
self.rect.x, self.rect.y = self.x, self.y
screen.blit(self.sprite, self.rect)
for label in self.labels:
text_left_y = 100
text_right_y = 100
for text in self.text_left:
label = Label(100, text_left_y, 500, 50, text, font_color='#000000', sprite='empty.png')
label.draw(screen)
text_left_y += 50
for text in self.text_right:
label = Label(680, text_right_y, 500, 50, text, font_color='#000000', sprite='empty.png')
label.draw(screen)
text_right_y += 50
for button in self.buttons:
button.update(screen)
@ -310,8 +330,8 @@ class Book():
if spell not in self.sp_list:
self.sp_list.append(spell)
self.current_sp = spell
self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}_icon.png', 'medieval', 23, attributes=[spell], onclickFunction=self.update_spell))
self.buttons_height += 100
self.buttons.append(Button(self.buttons_x, self.buttons_y, 58, 50, f'{spell}_icon.png', 'medieval', 23, attributes=[spell], onclickFunction=self.update_spell))
self.buttons_y += 100
def update_spell(self, spell):
self.current_sp = spell