class Game: """run the whole game""" def __init__(self): self.display = pg.display.set_mode([640, 480]) self.next_screen = None self.running = True # menu = menu.Menu() self.screen = MainMenu() # screen = Lore() self.screen.bake() self.clock = pg.time.Clock() def main(self): """Run the main tickloop""" while self.running: #handle events events = pg.event.get() for event in events: if event.type == pg.QUIT: self.running = False if event.type == SCREEN_TRANSITION: if event.new_screen is not None: self.next_screen = event.new_screen self.screen = self.next_screen self.screen.handle_events(events) self.display.fill((0, 0, 0)) self.screen.draw(self.display) self.clock.tick(60) pg.display.update() print("goodbye!") pg.quit()
class Game: def __init__(self): self.gameover = False self.screen = pygame.display.set_mode(constants.SIZE) self.phase = 0 self.phases = [MainMenu, Play, GameOver] self.inter = Interactor() self.cur_phase = MainMenu(self.inter.get_top_5()) def process_drawing(self): self.cur_phase.draw(self.screen) pygame.display.flip() def process_logic(self): if self.cur_phase.is_changed: self.phase = (self.phase + 1) % 3 if self.phase == 1: self.cur_phase = self.phases[self.phase]( self.cur_phase.settings["speed"], self.cur_phase.settings["frequency"]) elif self.phase == 2: pygame.time.wait(10**3) self.inter.write(self.cur_phase.score * self.cur_phase.speed) self.cur_phase = self.phases[self.phase](self.cur_phase.score * self.cur_phase.speed) else: self.cur_phase = self.phases[self.phase]( self.inter.get_top_5()) self.cur_phase.logic() def process_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.gameover = True self.inter.close() self.cur_phase.event(event) def main_loop(self): clock = pygame.time.Clock() while not self.gameover: self.process_events() self.process_logic() self.process_drawing() clock.tick(constants.FPS)
def mainMenu(self): m = MainMenu(self.screen, self.screen_settings) clock = pygame.time.Clock() while True: clock.tick() action = m.checkEvents() if action == "singleplayer": self.runSinglePlayer() m.need_screen_changes = True m.need_draw_changes = True continue elif action == "multiplayer": self.runMultiPlayer() elif action == "settings": self.runSettings() m.need_screen_changes = True m.need_draw_changes = True continue elif action == "quit": pygame.quit() exit() if m.need_draw_changes: m.draw() m.need_draw_changes = False
from states import * pg.init() size = 1000, 1000 screen = pg.display.set_mode(size, pg.SRCALPHA, 32) pg.display.set_caption("Hyperion Annotation Tool (HAT)") state = IN_MENU menu = None annotation_screen = None done = False while not done: mouse_pos = pg.mouse.get_pos() for event in pg.event.get(): if event.type == pg.QUIT: done = True break elif state == IN_MENU and menu is not None: menu.handle_event(event) if state == IN_MENU: if menu is None: menu = MainMenu(screen) else: menu.draw(mouse_pos) elif state == IN_LABEL_SIMPLE: if annotation_screen is None: annotation_screen = pg.display.update()