def __init__(self): os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() self.running = True self.screen = pygame.display.set_mode((WIDTH, HEIGHT + TILE_SIZE + 20)) self.clock = pygame.time.Clock() #---------------------------------------------------------------------------------------# self.stateDict = { "MENU": Menu(), "PATHFINDING": PathFinding(), "ABOUT": About() } self.loadState("MENU")
class Console(Gear): def __init__(self, display): super(Console, self).__init__(display) self.loadDefaultState() def loadDefaultState(self): self.state = Menu(self.display) self.state.kick() def tick(self): self.state.tick() if self.state.done: next = self.state.next if next is EXIT: self.done = True elif next is None: #print "no new state..." self.loadDefaultState() else: self.state = self.state.next #print "new state: %s" % self.state self.state.kick()
WIDTH = 600 HEIGHT = 400 pygame.mixer.init() pygame.font.init() pygame.display.set_caption('Pong') from states import Menu #https://www.dl-sounds.com/royalty-free/off-limits/ pygame.mixer.music.load('assets/Off_Limits.wav') pygame.mixer.music.play(loops=-1) screen = pygame.display.set_mode((WIDTH, HEIGHT)) surface = pygame.display.get_surface() state = Menu(WIDTH, HEIGHT) keys_pressed = set() done = False last = 0 while not done: # delay until 1/60th of second while time.time() - last < 1 / 60: pass last = time.time() # pump events for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if event.type == pygame.KEYDOWN:
def loadDefaultState(self): self.state = Menu(self.display) self.state.kick()