From d4c45c02890143fb8cfbc60be9d2b79240d9ad8e Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 14 Jul 2024 15:49:48 -0500 Subject: Initial commit --- main.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 main.py (limited to 'main.py') diff --git a/main.py b/main.py new file mode 100644 index 0000000..f24f4c6 --- /dev/null +++ b/main.py @@ -0,0 +1,79 @@ +import random +import states +import string +import pyxel +from rounds import ROUNDS, END_DIALOG + + +class App: + def __init__(self): + pyxel.init(64, 64) + pyxel.load("my_resource.pyxres") + + self.guessed = set() + self.frame = 0 + self.round = -1 + + # Generate a random mix of fake letters + self.glyph_map = {} + for key in list(string.ascii_uppercase): + if random.random() < 0.4: + self.glyph_map[key] = 1 + else: + self.glyph_map[key] = 0 + + self.set_state(states.TitleScreen) + + pyxel.run(self.update, self.draw) + + + def next_round(self, winner=None): + self.guessed = set() + self.round += 1 + pyxel.stop() + if self.round == 5: + pyxel.playm(3, loop=True) + # TODO special for grand prize. + self.set_state( + states.Dialog, dialog=END_DIALOG, + is_end=True, next=states.Credits + ) + else: + current_round = ROUNDS[self.round] + phrase_obj = random.choice(current_round["phrases"]) + self.outcomes = current_round["wheel_outcomes"] + self.phrase = phrase_obj["phrase"] + self.category = phrase_obj["category"] + if winner: + current_round["dialog"].insert(0, + { + "who": "camera", + "text": f"Congrats, {winner}!", + }, + ) + + current_round["dialog"].append( + { + "who": "camera", + "text": f"The category is: {self.category}.", + }, + ) + self.set_state(states.Dialog, dialog=current_round["dialog"]) + song = 2 if self.round < 2 else 1 + pyxel.playm(song, loop=True) + + def set_state(self, new_state_class, **kwargs): + self.state_change_at = self.frame + kwargs["app"] = self + self.state = new_state_class(**kwargs) + + def update(self): + self.frame += 1 + self.state.update(self) + + def draw(self): + pyxel.cls(0) + self.state.draw(self) + + +App() -- cgit v1.2.3