Make people say something

This commit is contained in:
akp 2025-03-23 11:20:17 +00:00
parent 9b364b9db9
commit 549f220081
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755
7 changed files with 129 additions and 4 deletions

View file

@ -69,6 +69,23 @@ def text_button(text, size, font=resources.FONT_SM) -> SurfaceButton:
return SurfaceButton(surface)
class Note:
surface: pygame.Surface
text: str
def __init__(self, base: pygame.Surface, text: str):
self.surface = pygame.Surface(base.get_size())
self.text = text
self.surface.blit(base, (0, 0))
util.render_text_centred_at(text, resources.FONT_SM, 0x000000, base.get_size()[0] / 2, 10, self.surface, base.get_size()[0] - 20)
def blit_onto(self, output_surface: pygame.Surface, pos: tuple[int, int]):
output_surface.blit(
self.surface,
pos
)
class Character:
torso: pygame.Surface
head: pygame.Surface
@ -76,14 +93,20 @@ class Character:
hair: pygame.Surface
headpos: int
text: str | None
text_hash: int | None
note: Note | None
def __init__(self):
def __init__(self, text: str | None = None):
self.torso = random.choice(resources.CHARACTER_TORSOS)
self.head = random.choice(resources.CHARACTER_HEADS)
self.glasses = random.choice(resources.CHARACTER_GLASSES)
self.hair = random.choice(resources.CHARACTER_HAIR)
self.headpos = self.head.get_size()[1] * random.randint(6, 9) / 10
self.text = text
self.note = None
def blit_onto(self, output_surface: pygame.SurfaceType, pos: tuple[int, int]):
output_surface.blit(self.torso, util.add_coord(pos, (0, self.headpos)))
torso_centerpoint = util.center_within(self.torso.get_size(), self.head.get_size())
@ -91,3 +114,10 @@ class Character:
if self.head not in resources.CHARACTER_HEADS[-2:]:
output_surface.blit(self.glasses, util.add_coord(pos, (torso_centerpoint[0], 50)))
output_surface.blit(self.hair, util.add_coord(pos, (torso_centerpoint[0], 0)))
if self.text is not None:
if self.note is None or hash(self.text) != self.text_hash:
self.text_hash = hash(self.text)
self.note = Note(resources.EMPTY_NOTE, self.text)
self.note.blit_onto(output_surface, util.add_coord(pos, (-200, 0)))

View file

@ -34,7 +34,7 @@ class GamePlay:
self.start = True
self.suspicion = 0
self.character = components.Character()
self.character = components.Character(random.choice(resources.SCRIPT_ASK_SANDWICH))
self.character_pos = (400 + random.randint(0, 100), 100 + random.randint(25, 100))
def displaysandwich(screen, sandwich):
@ -104,6 +104,7 @@ class GamePlay:
else:
if self.counter_button.blit_onto(self.surface, (1000, 5)):
self.surface.fill("lightgreen")
self.character = components.Character(random.choice(resources.SCRIPT_ASK_SANDWICH))
self.character.blit_onto(self.surface, self.character_pos)
self.surface.blit(resources.COUNTER_SCREEN_IMAGE, (0, 0))
self.status = "Counter"

View file

@ -71,4 +71,10 @@ CHARACTER_HAIR = [
pygame.image.load(RESOURCES_DIR / "sprites" / "character_hair_2.png"),
pygame.image.load(RESOURCES_DIR / "sprites" / "character_hair_3.png"),
pygame.image.load(RESOURCES_DIR / "sprites" / "character_hair_4.png"), # the bald one
]
]
EMPTY_NOTE = pygame.image.load(RESOURCES_DIR / "empty_note.png")
SCRIPT_ASK_SANDWICH = open(RESOURCES_DIR / "scripts" / "ask-sandwich.txt").read().strip().splitlines()
SCRIPT_TAKE_SANDWICH = open(RESOURCES_DIR / "scripts" / "take-sandwich.txt").read().strip().splitlines()
SCRIPT_TAKE_SANDWICH_RUDE = open(RESOURCES_DIR / "scripts" / "take-sandwich-rude.txt").read().strip().splitlines()

View file

@ -0,0 +1,30 @@
Can I get a sandwich, please?
Could you make me a sandwich?
Id like a sandwich, please.
Would you mind fixing me a sandwich?
Can you whip up a sandwich for me?
Is it possible to have a sandwich?
Could I trouble you for a sandwich?
Im craving a sandwich—could you help me out?
Would you be able to prepare a sandwich for me?
Can I order a sandwich, please?
Do you think I could have a sandwich?
Id love a sandwich if its not too much trouble.
Could you put together a sandwich for me?
Can you make me a sandwich, pretty please?
Would it be okay to ask for a sandwich?
Im in the mood for a sandwich—can you help?
Could I request a sandwich, please?
Can you rustle up a sandwich for me?
Id really appreciate it if you could make me a sandwich.
Is there any chance I could get a sandwich?
Hey, make me a sandwich, now!
What are you waiting for? Get me a sandwich already!
I dont have all day. Wheres my sandwich?
You call that a sandwich? Fix it and bring it to me!
Stop being useless and make me a sandwich!
Im starving, and youre just standing there. Sandwich. Now.
Do I have to do everything myself? Make me a sandwich!
If you were any good, youd have a sandwich in front of me by now.
I dont care how busy you are. Drop everything and make me a sandwich!
Ye scallywag! Fetch me a sandwich, or I'll make ye walk the plank! ARRR!

View file

@ -0,0 +1,10 @@
Finally! I was about to starve. Took you long enough.
About time you made yourself useful. Thanks, I guess.
Its not great, but Ill eat it. Thanks… if thats what you call this.
Wow, you actually did something right for once. Thanks.
Took you long enough to make a simple sandwich. But fine, thanks.
Ive had better, but Ill eat it. Dont get too proud of yourself.
Thanks, but next time, try not to mess it up.
I guess thisll do. Thanks… if thats what you were going for.
Took you long enough. Thanks, but dont expect a medal.
Well, its edible. Thanks… I think.

View file

@ -0,0 +1,10 @@
Thank you so much for the sandwich—its perfect!
I really appreciate you making this for me. Its delicious!
Youre the best! This sandwich is exactly what I needed.
Thanks a ton for the sandwich—its so thoughtful of you!
This sandwich is amazing! Thank you for taking the time to make it.
Im so grateful for this sandwich. Youve made my day!
Thank you! You really know how to make the perfect sandwich.
This is so kind of you. Thanks for the sandwich—its fantastic!
I cant thank you enough for this sandwich. Its absolutely delicious!
Youre a lifesaver! Thanks for the sandwich—its just what I needed.

View file

@ -22,4 +22,42 @@ def make_transition_event(to: str) -> pygame.event.Event:
return pygame.event.Event(
TRANSITION_EVENT_TYPE,
{"to": to}
)
)
def render_text_centred_at(text, font, colour, x, y, screen, allowed_width):
# first, split the text into words
words = text.split()
# now, construct lines out of these words
lines = []
while len(words) > 0:
# get as many words as will fit within allowed_width
line_words = []
while len(words) > 0:
line_words.append(words.pop(0))
fw, fh = font.size(' '.join(line_words + words[:1]))
if fw > allowed_width:
break
# add a line consisting of those words
line = ' '.join(line_words)
lines.append(line)
# now we've split our text into lines that fit into the width, actually
# render them
# we'll render each line below the last, so we need to keep track of
# the culmative height of the lines we've rendered so far
y_offset = 0
for line in lines:
fw, fh = font.size(line)
# (tx, ty) is the top-left of the font surface
tx = x - fw / 2
ty = y + y_offset
font_surface = font.render(line, True, colour)
screen.blit(font_surface, (tx, ty))
y_offset += fh