def main(): #pygame init pygame.mixer.pre_init(SAMPLE_RATE, BIT, CHANNELS, BUFFER_SIZE) pygame.init() pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('PyTone') #make background background = Gradient((WIDTH, HEIGHT), GRAD_START, GRAD_END) #path to medias path = 'media/' pygame.display.set_icon(pygame.image.load(path + 'petrol.png')) #intro duration in milliseconds duration = 4000 #states intro = Intro(background, path, duration) menu = Menu(background, path) game = Game(background, path) instructions = Instructions(background, path) intro.run() #storing return value from menu running = True while running: option = menu.run() if option == NEW_GAME: option = game.run() elif option == INSTRUCTIONS: instructions.run() elif option == PRACTICE: #intro.run() game.set_practise(True) game.run() game.set_practise(False) #no elif here to make different states be able to quit as well if option == pygame.locals.QUIT: pygame.quit() running = False
class ScreamingBird(object): def __init__(self): self.screen = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT)) pygame.display.set_caption('Screaming Bird') self.pipegap = 120 self.intro = Intro(self.screen) self.highScore = HighScore(self.screen) self.settings = Setting(self.screen) def run(self): playing = True mode = 'intro' count = 0 while playing: # print(self.pipegap) if mode == 'intro' or mode[0] == 'intro': if count > 0: self.__init__() if mode != 'intro': print(mode[1]) self.pipegap = mode[1] mode = self.intro.run() elif mode == 'game': self.game = Game(self.screen, self.pipegap) print(self.pipegap) mode = self.game.run() elif mode == 'highscore': mode = self.highScore.run() elif mode[0] == 'gameover': count += 1 self.scoreAppend = True self.gameOver = GameOver(self.screen, mode[1]) mode = self.gameOver.run() elif mode == 'settings': mode = self.settings.run() elif mode == 'quit': playing = False pygame.quit()