Make people say something
This commit is contained in:
parent
9b364b9db9
commit
549f220081
7 changed files with 129 additions and 4 deletions
|
@ -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)))
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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()
|
||||
|
|
30
game/resources/scripts/ask-sandwich.txt
Normal file
30
game/resources/scripts/ask-sandwich.txt
Normal file
|
@ -0,0 +1,30 @@
|
|||
Can I get a sandwich, please?
|
||||
Could you make me a sandwich?
|
||||
I’d 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?
|
||||
I’m 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?
|
||||
I’d love a sandwich if it’s 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?
|
||||
I’m in the mood for a sandwich—can you help?
|
||||
Could I request a sandwich, please?
|
||||
Can you rustle up a sandwich for me?
|
||||
I’d 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 don’t have all day. Where’s my sandwich?
|
||||
You call that a sandwich? Fix it and bring it to me!
|
||||
Stop being useless and make me a sandwich!
|
||||
I’m starving, and you’re just standing there. Sandwich. Now.
|
||||
Do I have to do everything myself? Make me a sandwich!
|
||||
If you were any good, you’d have a sandwich in front of me by now.
|
||||
I don’t 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!
|
10
game/resources/scripts/take-sandwich-rude.txt
Normal file
10
game/resources/scripts/take-sandwich-rude.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
Finally! I was about to starve. Took you long enough.
|
||||
About time you made yourself useful. Thanks, I guess.
|
||||
It’s not great, but I’ll eat it. Thanks… if that’s 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.
|
||||
I’ve had better, but I’ll eat it. Don’t get too proud of yourself.
|
||||
Thanks, but next time, try not to mess it up.
|
||||
I guess this’ll do. Thanks… if that’s what you were going for.
|
||||
Took you long enough. Thanks, but don’t expect a medal.
|
||||
Well, it’s edible. Thanks… I think.
|
10
game/resources/scripts/take-sandwich.txt
Normal file
10
game/resources/scripts/take-sandwich.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
Thank you so much for the sandwich—it’s perfect!
|
||||
I really appreciate you making this for me. It’s delicious!
|
||||
You’re the best! This sandwich is exactly what I needed.
|
||||
Thanks a ton for the sandwich—it’s so thoughtful of you!
|
||||
This sandwich is amazing! Thank you for taking the time to make it.
|
||||
I’m so grateful for this sandwich. You’ve made my day!
|
||||
Thank you! You really know how to make the perfect sandwich.
|
||||
This is so kind of you. Thanks for the sandwich—it’s fantastic!
|
||||
I can’t thank you enough for this sandwich. It’s absolutely delicious!
|
||||
You’re a lifesaver! Thanks for the sandwich—it’s just what I needed.
|
40
game/util.py
40
game/util.py
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue