def interact(game): # interaction entre l'utilisateur et le menu menu = Game.getMenu(game) win = Game.getWin(game) # deplacement du curseur menu['selectedItem'] = -1 key = win.getch() if key == ord('z'): if menu['cursor'] != 0: menu['cursor'] -= 1 if key == ord('s'): if menu['cursor'] != len(menu['items']) - 1: menu['cursor'] += 1 if key == ord('e'): menu['selectedItem'] = menu['cursor'] # action a effectuer en fonction de l'item selectionne if menu['selectedItem'] == 0: game = Game.setName(Game.askName(game), game) if menu['selectedItem'] == 1: game = Game.setDifficulty(Game.askDifficulty(game), game) if menu['selectedItem'] == 2: newLevel = Level.create(Level.askLevelNumber(game), 'levels.txt') logging.info("nouveau niveau : " + str(newLevel)) game = Game.setLevel(newLevel, game) if menu['selectedItem'] == 3: HighScores.show(HighScores.get(), win) if menu['selectedItem'] == 4: Game.setState('game', game) if menu['selectedItem'] == 5: Game.setState('quitProgram', game) return
def __init__(self,background): "Set up the HighScores menu" Menu.__init__(self,"MoleFusion HighScore Menu",background) self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse(open("languages/HighScoresMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"),(0.5,0.1),(27,22,24)) self.name_column = GW_Label(self.curHandler.getText("name"),(0.25,0.25),(212,224,130)) self.points_column = GW_Label(self.curHandler.getText("points"),(0.75,0.25),(212,224,130)) self.returnMain = GW_Button(self.curHandler.getText("returnMain"),(0.5,0.9),(255,255,255)) self.returnMain.add_eventhandler("onmouseclick",self.returnMain_onmouseclick) h = HighScores() highscorelist = h.get_HighScores() self.widgetlist = [self.title,self.name_column,self.points_column,self.returnMain] for val,i in enumerate(highscorelist[0:5]): self.widgetlist.append(GW_Label(i.get_name(),(0.25,0.35+val/10.0),(250,254,210))) self.widgetlist.append(GW_Label(str(i.get_points()),(0.75,0.35+val/10.0),(250,254,210))) self.widget_man = GuiWidgetManager(self.widgetlist) self.time_speed=pygame.time.Clock() self.exit=False self.on_enter()
def __init__(self): pygame.init() pygame.mixer.init() self.END_MUSIC = pygame.mixer.Sound('end.ogg') self.KILL_SOUND = pygame.mixer.Sound('lose.wav') self.ENEMY_DEAD_SOUND = pygame.mixer.Sound('scream.wav') self.ENEMY_DEAD_SOUND.set_volume(.4) self.WIN_SOUND = pygame.mixer.Sound("win.wav") pygame.display.set_caption(title) pygame.font.init() self.font = pygame.font.Font(FONTNAME, 20) self.fileName = "HighScore.json" # if there is no file then make one if not os.path.isfile(self.fileName): empty_score_file = open(self.fileName, "w") empty_score_file.write("[]") empty_score_file.close() self.running = True self.playerDead = False self.win = False self.highscore = HighScores() self.platformSpriteSheet = Spritesheet(spritesheetPlatformFile) self.enemiesSpriteSheet = Spritesheet(enemyspritesheetFile) self.coinSpriteSheet = Spritesheet(spritesheetPlatformFile) self.cloud_images = [] for cloud in range(1, 4): self.cloud_images.append( pygame.image.load("cloud{}.png".format(cloud)).convert())
def loadSprites(self): self.all_sprites = pygame.sprite.LayeredUpdates() self.platforms = pygame.sprite.Group() self.finalplatform = pygame.sprite.Group() self.coin = pygame.sprite.Group() self.enemyFly = pygame.sprite.Group() self.clouds = pygame.sprite.Group() self.spikeenemy = pygame.sprite.Group() self.brownmob = pygame.sprite.Group() self.skullmob = pygame.sprite.Group() self.digletmob = pygame.sprite.Group() self.EnemyFlyTimer = 0 from Player import Player self.player = Player(self) self.highscore = HighScores() self.playerDead = False # creates the enemy flys for fly in ENEMYFLY_LIST: EnemyFly(self, *fly) # creates the big grass platform for grassbigplatform in GRASS_BIG_PLATFORM_LIST: GrassBigPlatform(self, *grassbigplatform) # creates the small grass platform for grasssmallplatform in GRASS_SMALL_PLATFORM_LIST: GrassSmallPlatform(self, *grasssmallplatform) # creates the big brown cake platform for bcakebigplatform in BCAKE_BIG_PLATFORM_LIST: BCakeBigPlatform(self, *bcakebigplatform) # creates the small brown cake platform for bcakesmallplatform in BCAKE_SMALL_PLATFORM_LIST: BCakeSmallPlatform(self, *bcakesmallplatform) # creates the big sand platform for sandbigplatform in SAND_BIG_PLATFORM_LIST: SandBigPlatform(self, *sandbigplatform) # creates the small sand platform for sandsmallplatform in SAND_SMALL_PLATFORM_LIST: SandSmallPlatform(self, *sandsmallplatform) # creates the big snow platform for snowbigplatform in SNOW_BIG_PLATFORM_LIST: SnowBigPlatform(self, *snowbigplatform) # creates the small snow platform for snowsmallplatform in SNOW_SMALL_PLATFORM_LIST: SnowSmallPlatform(self, *snowsmallplatform) # creates the big stone platform for stonebigplatform in STONE_BIG_PLATFORM_LIST: StoneBigPlatform(self, *stonebigplatform) # creates the small stone platform for stonesmallplatform in STONE_SMALL_PLATFORM_LIST: StoneSmallPlatform(self, *stonesmallplatform) # final platform here for grassfinalplatform in GRASS_FINAL_PLATFORM_LIST: GrassFinalPlatform(self, *grassfinalplatform) # creates clouds on the map for i in range(8): from Cloud import Cloud cloud = Cloud(self) cloud.rect.y += 500
def run(self): while 1: self.time+=self.time_speed.tick(Constants.FPS) if self.gameover and (not self.pause): self.pause = True self.polygon.reset() self.timeclock.delete_timer() self.message = MessageBox(self,4000) self.display_items.add(self.message) if self.completed and (not self.pause): self.pause = True self.polygon.reset() self.timeclock.delete_timer() self.message = MessageBox(self,4000) self.display_items.add(self.message) self.polygon.set_alive(False) self.polygon.reset() if self.quit: self.on_exit() if self.gameover == True: h = HighScores() h.insert_HighScores(Constants.PLAYERNAME,str(self.score.get_score())) hlist = HighScores().get_HighScores() if len(hlist)<5 or self.score.get_score() > hlist[4].get_points(): h.flush() pygame.event.clear() highscores = HighScoresMenu("sprites/sky.jpg") highscores.run() return False else: return self.event_manager.run() self.screen.blit(self.background, (0, 0)) self.display_items.update() self.display_items.draw(self.screen) self.atoms.update() self.atoms.draw(self.screen) if self.start == True and self.pause == False: self.display_items.remove(self.message) self.message = None self.start = False self.polygon.set_alive(False) self.polygon.reset() self.timeclock.add_timer() if not self.pause: self.polygon.draw() pygame.display.flip()
def on_exit(self): Level.on_exit(self) h = HighScores() h.insert_HighScores(Constants.PLAYERNAME,str(self.score.get_score())) hlist = HighScores().get_HighScores() if len(hlist)<5 or self.score.get_score() > hlist[4].get_points(): h.flush() pygame.event.clear() highscores = HighScoresMenu("sprites/sky.jpg") highscores.run()
def interact(game): snake = getSnake(game) food = getFood(game) win = getWin(game) score = getScore(game) name = getName(game) key = win.getch() difficulty = game['difficulty'] win.timeout(200 - 30 * difficulty) # a ameliorer if key == 32: pause(win) try: newSnake = Snake.computeNextPos(key, snake, food, win) game = setSnake(newSnake, game) except ValueError: game = setHighScores(HighScores.log(score, name, difficulty), game) game = resetScore(game) game = setSnake(Snake.reset(), game) game = setState('menu', game) food = None if foodEaten(snake, food): game = setNewFood(game) game = addScore(1, game) return
def activeGameDisplay(self): #show the gameplay time on screen self.displayTimeActiveGame() # show some help statements for how to pause and restart the game while playing pauseTxt = Fonts.medSmall.render("(P)ause", False, Colors.white) restartTxt = Fonts.medSmall.render("(R)estart", False, Colors.white) self.gameWindow.blit( pauseTxt, (self.screen[0] * 0.95 - pauseTxt.get_width(), self.screen[1] * 0.1 * 0.5 - ((pauseTxt.get_height() + restartTxt.get_height()) / 2))) self.gameWindow.blit( restartTxt, (self.screen[0] * 0.95 - restartTxt.get_width(), self.screen[1] * 0.1 * 0.5 - ((pauseTxt.get_height() + restartTxt.get_height()) / 2) + pauseTxt.get_height())) if (HighScores.isHighScore(self.gameplay_time, self.difficulty_level)): newScoretxt = Fonts.standard.render("YOU GOT A NEW BEST SCORE!!", False, Colors.white) self.gameWindow.blit( newScoretxt, (self.screen[0] * 0.52 - newScoretxt.get_width() * 0.5, self.screen[1] * 0.1 * 0.5 - newScoretxt.get_height() * 0.5))
def __init__(self, background): "Set up the HighScores menu" Menu.__init__(self, "MoleFusion HighScore Menu", background) self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse( open("languages/HighScoresMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"), (0.5, 0.1), (27, 22, 24)) self.name_column = GW_Label(self.curHandler.getText("name"), (0.25, 0.25), (212, 224, 130)) self.points_column = GW_Label(self.curHandler.getText("points"), (0.75, 0.25), (212, 224, 130)) self.returnMain = GW_Button(self.curHandler.getText("returnMain"), (0.5, 0.9), (255, 255, 255)) self.returnMain.add_eventhandler("onmouseclick", self.returnMain_onmouseclick) h = HighScores() highscorelist = h.get_HighScores() self.widgetlist = [ self.title, self.name_column, self.points_column, self.returnMain ] for val, i in enumerate(highscorelist[0:5]): self.widgetlist.append( GW_Label(i.get_name(), (0.25, 0.35 + val / 10.0), (250, 254, 210))) self.widgetlist.append( GW_Label(str(i.get_points()), (0.75, 0.35 + val / 10.0), (250, 254, 210))) self.widget_man = GuiWidgetManager(self.widgetlist) self.time_speed = pygame.time.Clock() self.exit = False self.on_enter()
def run(self): while 1: self.time += self.time_speed.tick(Constants.FPS) if self.gameover and (not self.pause): self.pause = True self.polygon.reset() self.timeclock.delete_timer() self.message = MessageBox(self, 4000) self.display_items.add(self.message) if self.completed and (not self.pause): self.pause = True self.polygon.reset() self.timeclock.delete_timer() self.message = MessageBox(self, 4000) self.display_items.add(self.message) self.polygon.set_alive(False) self.polygon.reset() if self.quit: self.on_exit() if self.gameover == True: h = HighScores() h.insert_HighScores(Constants.PLAYERNAME, str(self.score.get_score())) hlist = HighScores().get_HighScores() if len(hlist) < 5 or self.score.get_score( ) > hlist[4].get_points(): h.flush() pygame.event.clear() highscores = HighScoresMenu("sprites/sky.jpg") highscores.run() return False else: return self.event_manager.run() self.screen.blit(self.background, (0, 0)) self.display_items.update() self.display_items.draw(self.screen) self.atoms.update() self.atoms.draw(self.screen) if self.start == True and self.pause == False: self.display_items.remove(self.message) self.message = None self.start = False self.polygon.set_alive(False) self.polygon.reset() self.timeclock.add_timer() if not self.pause: self.polygon.draw() pygame.display.flip()
def init(): # on initialise la fenetre curses curses.initscr() win = curses.newwin(30, 80, 0, 0) curses.noecho() curses.curs_set(0) win.nodelay(1) logging.basicConfig(filename='snake.log', level=logging.INFO) # creation du niveau level = Level.create(1, 'levels.txt') # creation du snake snake = Snake.create(35, 15, 1, 2) # creation du food food = None # creation du menu menu = Menu.create( 'Change name', 'Change difficulty', 'Select level', 'Show HighScores', 'Play', 'Quit game' ) # definition de l'etat du programme state = 'menu' # definition du nom du joueur name = 'player1' # definition de la difficulte difficulty = 2 score = -1 HighScoreTable = HighScores.get() # creation de la variable de type game game = Game.create( menu, level, snake, food, win, state, name, difficulty, score, HighScoreTable ) return game
def on_exit(self): Level.on_exit(self) h = HighScores() h.insert_HighScores(Constants.PLAYERNAME, str(self.score.get_score())) hlist = HighScores().get_HighScores() if len(hlist) < 5 or self.score.get_score() > hlist[4].get_points(): h.flush() pygame.event.clear() highscores = HighScoresMenu("sprites/sky.jpg") highscores.run()
def testEqualScore(self): HighScores.highscore('Frank', 789) observed = HighScores.highscore('Frank', 789) expected = 789 self.assertEqual(observed, expected, 'Results are not the expected, expected: {0}, actual: {1}'.format(expected,observed))
class Game: def __init__(self): pygame.init() pygame.mixer.init() self.END_MUSIC = pygame.mixer.Sound('end.ogg') self.KILL_SOUND = pygame.mixer.Sound('lose.wav') self.ENEMY_DEAD_SOUND = pygame.mixer.Sound('scream.wav') self.ENEMY_DEAD_SOUND.set_volume(.4) self.WIN_SOUND = pygame.mixer.Sound("win.wav") pygame.display.set_caption(title) pygame.font.init() self.font = pygame.font.Font(FONTNAME, 20) self.fileName = "HighScore.json" # if there is no file then make one if not os.path.isfile(self.fileName): empty_score_file = open(self.fileName, "w") empty_score_file.write("[]") empty_score_file.close() self.running = True self.playerDead = False self.win = False self.highscore = HighScores() self.platformSpriteSheet = Spritesheet(spritesheetPlatformFile) self.enemiesSpriteSheet = Spritesheet(enemyspritesheetFile) self.coinSpriteSheet = Spritesheet(spritesheetPlatformFile) self.cloud_images = [] for cloud in range(1, 4): self.cloud_images.append( pygame.image.load("cloud{}.png".format(cloud)).convert()) # used to refresh the games settings for when the player plays again def new(self): # start a new game, reset everything self.win = False self.loadSprites() self.gameLoop() # runs the game def gameLoop(self): self.GAME_MUSIC = pygame.mixer.Sound('gamemusic.ogg') self.GAME_MUSIC.set_volume(0.1) self.GAME_MUSIC.play(loops=-1) self.running = True while self.running: clock.tick(FPS) self.events() self.update() self.draw() pygame.display.update() pygame.quit() # updates the game actions def update(self): self.all_sprites.update() self.enemy_collisions() self.coin_collisions() self.moving_camera() self.player_death() def events(self): # if player clicks on X quit the game for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() # after the play presses the jump button, they will fall down at a realistic speed if event.type == pygame.KEYUP: if event.key == pygame.K_SPACE: self.player.jumpfall() # displays the images on the screen def draw(self): screen.fill(teal) self.all_sprites.draw(screen) scoreFont = pygame.font.Font(FONTNAME, 30) screen.blit( scoreFont.render("Score: {}".format(self.highscore.score), -1, black), (501, 11)) screen.blit( scoreFont.render("Score: {}".format(self.highscore.score), -1, white), (500, 10)) if self.win: self.GAME_MUSIC.fadeout(200) winchannel = self.WIN_SOUND.play() # Added sound here - Michael while winchannel.get_busy(): pygame.time.wait(100) highscore = 1 screen.blit( pygame.font.Font(FONTNAME, 100).render("YOU WON!", -1, white), (102, 72)) screen.blit( pygame.font.Font(FONTNAME, 100).render("YOU WON!", -1, red), (100, 70)) if highscore == 1: screen.blit( pygame.font.Font(FONTNAME, 33).render( "Enter your name for the HighScore List", -1, black), (10, 450)) screen.blit( pygame.font.Font(FONTNAME, 33).render( "Enter your name for the HighScore List", -1, white), (11, 452)) self.highscore.getUserName(self.highscore.score) self.highscore.addHighScores(self.highscore.score) highscore = 0 from MainMenu import MainMenu MainMenu().game_intro() if self.playerDead: self.GAME_MUSIC.fadeout(200) channel = self.KILL_SOUND.play() # Added sound here - Michael while channel.get_busy(): pygame.time.wait(100) self.END_MUSIC.play() highscore = 1 screen.blit( pygame.font.Font(FONTNAME, 100).render("Game Over", -1, white), (102, 72)) screen.blit( pygame.font.Font(FONTNAME, 100).render("Game Over", -1, red), (100, 70)) if highscore == 1: screen.blit( pygame.font.Font(FONTNAME, 33).render( "Enter your name for the HighScore List", -1, black), (10, 450)) screen.blit( pygame.font.Font(FONTNAME, 33).render( "Enter your name for the HighScore List", -1, white), (11, 452)) self.highscore.getUserName(self.highscore.score) self.highscore.addHighScores(self.highscore.score) highscore = 0 self.END_MUSIC.fadeout(500) from MainMenu import MainMenu MainMenu().game_intro() pygame.display.flip() def tutorialPage(self): seconds = 5 mainmenuSeconds = 0 key = pygame.key.get_pressed() clock = pygame.time.Clock() tutorialCount = 0 tutorialFPScount = 0 tutorialExit = False bigFont = pygame.font.Font(FONTNAME, 40) medFont = pygame.font.Font(FONTNAME, 30) self.loadSprites() while not tutorialExit: self.player.tutorial = True clock.tick(FPS) screen.fill(teal) self.all_sprites.update() self.enemy_collisions() self.coin_collisions() self.player_death() self.all_sprites.draw(screen) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() screen.blit(medFont.render("Type Q to exit tutorial", -1, white), (60, 8)) screen.blit(medFont.render("Type Q to exit tutorial", -1, red), (62, 6)) if not self.player.tutorialLEFT: screen.blit( medFont.render("Press A or Left Arrow to move left", -1, brightGreen), (12, 42)) screen.blit( medFont.render("Press A or Left Arrow to move left", -1, black), (10, 40)) if self.player.tutorialLEFT and not self.player.tutorialRIGHT and not self.player.tutorialJUMP \ and not self.player.tutorialPUNCH and not self.player.tutorialKICK: screen.blit( medFont.render("Press D or Right Arrow to move right", -1, brightGreen), (12, 42)) screen.blit( medFont.render("Press D or Right Arrow to move right", -1, black), (10, 40)) if self.player.tutorialLEFT and self.player.tutorialRIGHT and not self.player.tutorialJUMP \ and not self.player.tutorialPUNCH and not self.player.tutorialKICK: screen.blit( medFont.render("Press SpaceBar to jump", -1, brightGreen), (12, 42)) screen.blit( medFont.render("Press SpaceBar to jump", -1, black), (10, 40)) if self.player.tutorialLEFT and self.player.tutorialRIGHT and self.player.tutorialJUMP \ and not self.player.tutorialPUNCH and not self.player.tutorialKICK: screen.blit( medFont.render("Press F to punch", -1, brightGreen), (12, 42)) screen.blit(medFont.render("Press F to punch", -1, black), (10, 40)) if self.player.tutorialLEFT and self.player.tutorialRIGHT and self.player.tutorialJUMP \ and self.player.tutorialPUNCH and not self.player.tutorialKICK: screen.blit(medFont.render("Press G to kick", -1, brightGreen), (12, 42)) screen.blit(medFont.render("Press G to kick", -1, black), (10, 40)) if self.player.tutorialLEFT and self.player.tutorialRIGHT and self.player.tutorialJUMP \ and self.player.tutorialPUNCH and self.player.tutorialKICK and tutorialCount == 0: screen.blit( medFont.render("Avoid the Flies!", -1, brightGreen), (12, 42)) screen.blit(medFont.render("Avoid the Flies!", -1, black), (10, 40)) screen.blit( medFont.render("If you touch them you die!", -1, brightGreen), (12, 82)) screen.blit( medFont.render("If you touch them you die!", -1, black), (10, 80)) tutorialFPScount += 1 if tutorialFPScount == 700: tutorialCount += 1 if tutorialCount == 1: screen.blit( medFont.render("You gain points from killing mobs,", -1, brightGreen), (12, 42)) screen.blit( medFont.render("You gain points from killing mobs,", -1, black), (10, 40)) screen.blit( medFont.render("traveling, and collecting coins", -1, brightGreen), (12, 82)) screen.blit( medFont.render("traveling, and collecting coins", -1, black), (10, 80)) tutorialFPScount += 1 if tutorialFPScount == 1100: tutorialCount += 1 if tutorialCount == 2: screen.blit( medFont.render("You will lose if get killed or fall", -1, brightGreen), (12, 42)) screen.blit( medFont.render("You will lose if get killed or fall", -1, black), (10, 40)) screen.blit( medFont.render("You will win if you reach the top", -1, brightGreen), (12, 82)) screen.blit( medFont.render("You will win if you reach the top", -1, black), (10, 80)) tutorialFPScount += 1 if tutorialFPScount == 1500: tutorialCount += 1 if tutorialCount == 3: screen.blit( medFont.render("You can run across the screen and", -1, brightGreen), (12, 42)) screen.blit( medFont.render("You can run across the screen and", -1, black), (10, 40)) screen.blit( medFont.render("You will appear on the other side", -1, brightGreen), (12, 82)) screen.blit( medFont.render("You will appear on the other side", -1, black), (10, 80)) tutorialFPScount += 1 if tutorialFPScount == 1900: tutorialCount += 1 if tutorialCount == 4: screen.blit( bigFont.render("You have completed the Tutorial!", -1, brightGreen), (12, 42)) screen.blit( bigFont.render("You have completed the Tutorial!", -1, black), (10, 40)) screen.blit( bigFont.render( "Returning to MainMenu in {}".format(seconds), -1, brightGreen), (42, 82)) screen.blit( bigFont.render( "Returning to MainMenu in {}".format(seconds), -1, black), (40, 80)) mainmenuSeconds += 1 if mainmenuSeconds == 70: mainmenuSeconds = 0 seconds -= 1 if seconds == 0: from MainMenu import MainMenu MainMenu().game_intro() screen.blit( medFont.render("Score: {}".format(self.highscore.score), -1, black), (500, 8)) screen.blit( medFont.render("Score: {}".format(self.highscore.score), -1, white), (501, 6)) pygame.display.update() def loadSprites(self): self.all_sprites = pygame.sprite.LayeredUpdates() self.platforms = pygame.sprite.Group() self.finalplatform = pygame.sprite.Group() self.coin = pygame.sprite.Group() self.enemyFly = pygame.sprite.Group() self.clouds = pygame.sprite.Group() self.spikeenemy = pygame.sprite.Group() self.brownmob = pygame.sprite.Group() self.skullmob = pygame.sprite.Group() self.digletmob = pygame.sprite.Group() self.EnemyFlyTimer = 0 from Player import Player self.player = Player(self) self.highscore = HighScores() self.playerDead = False # creates the enemy flys for fly in ENEMYFLY_LIST: EnemyFly(self, *fly) # creates the big grass platform for grassbigplatform in GRASS_BIG_PLATFORM_LIST: GrassBigPlatform(self, *grassbigplatform) # creates the small grass platform for grasssmallplatform in GRASS_SMALL_PLATFORM_LIST: GrassSmallPlatform(self, *grasssmallplatform) # creates the big brown cake platform for bcakebigplatform in BCAKE_BIG_PLATFORM_LIST: BCakeBigPlatform(self, *bcakebigplatform) # creates the small brown cake platform for bcakesmallplatform in BCAKE_SMALL_PLATFORM_LIST: BCakeSmallPlatform(self, *bcakesmallplatform) # creates the big sand platform for sandbigplatform in SAND_BIG_PLATFORM_LIST: SandBigPlatform(self, *sandbigplatform) # creates the small sand platform for sandsmallplatform in SAND_SMALL_PLATFORM_LIST: SandSmallPlatform(self, *sandsmallplatform) # creates the big snow platform for snowbigplatform in SNOW_BIG_PLATFORM_LIST: SnowBigPlatform(self, *snowbigplatform) # creates the small snow platform for snowsmallplatform in SNOW_SMALL_PLATFORM_LIST: SnowSmallPlatform(self, *snowsmallplatform) # creates the big stone platform for stonebigplatform in STONE_BIG_PLATFORM_LIST: StoneBigPlatform(self, *stonebigplatform) # creates the small stone platform for stonesmallplatform in STONE_SMALL_PLATFORM_LIST: StoneSmallPlatform(self, *stonesmallplatform) # final platform here for grassfinalplatform in GRASS_FINAL_PLATFORM_LIST: GrassFinalPlatform(self, *grassfinalplatform) # creates clouds on the map for i in range(8): from Cloud import Cloud cloud = Cloud(self) cloud.rect.y += 500 def enemy_collisions(self): # template for killing enemies # enemyspike enemyspike_hits = pygame.sprite.spritecollide( self.player, self.spikeenemy, False, pygame.sprite.collide_mask) for spike in self.spikeenemy: if self.player.punching or self.player.kicking: if self.player.right: if enemyspike_hits and spike.rect.x >= self.player.rect.x and spike.rect.y >= self.player.rect.y: self.ENEMY_DEAD_SOUND.play() spike.kill() self.highscore.score += 100 if self.player.left: if enemyspike_hits and spike.rect.x <= self.player.rect.x and spike.rect.y >= self.player.rect.y: self.ENEMY_DEAD_SOUND.play() spike.kill() self.highscore.score += 100 elif enemyspike_hits: self.playerDead = True enemybrown_hits = pygame.sprite.spritecollide( self.player, self.brownmob, False, pygame.sprite.collide_mask) for brown in self.brownmob: if self.player.punching or self.player.kicking: if self.player.right: if enemybrown_hits and brown.rect.x >= self.player.rect.x and brown.rect.y >= self.player.rect.y: brown.kill() self.ENEMY_DEAD_SOUND.play() self.highscore.score += 150 if self.player.left: if enemybrown_hits and brown.rect.x <= self.player.rect.x and brown.rect.y >= self.player.rect.y: brown.kill() self.ENEMY_DEAD_SOUND.play() self.highscore.score += 150 elif enemybrown_hits: self.playerDead = True enemydig_hits = pygame.sprite.spritecollide(self.player, self.digletmob, False, pygame.sprite.collide_mask) for dig in self.digletmob: if self.player.punching or self.player.kicking: if self.player.right: if enemydig_hits and dig.rect.x >= self.player.rect.x and dig.rect.y >= self.player.rect.y: dig.kill() self.ENEMY_DEAD_SOUND.play() self.highscore.score += 175 if self.player.left: if enemydig_hits and dig.rect.x <= self.player.rect.x and dig.rect.y >= self.player.rect.y: dig.kill() self.ENEMY_DEAD_SOUND.play() self.highscore.score += 175 elif enemydig_hits: self.playerDead = True enemyskull_hits = pygame.sprite.spritecollide( self.player, self.skullmob, False, pygame.sprite.collide_mask) for skull in self.skullmob: if self.player.punching or self.player.kicking: if self.player.right: if enemyskull_hits and skull.rect.x >= self.player.rect.x and skull.rect.y >= self.player.rect.y: skull.kill() self.ENEMY_DEAD_SOUND.play() self.highscore.score += 250 if self.player.left: if enemyskull_hits and skull.rect.x <= self.player.rect.x and skull.rect.y >= self.player.rect.y: skull.kill() self.ENEMY_DEAD_SOUND.play() self.highscore.score += 250 elif enemyskull_hits: self.playerDead = True # check if hits enemyfly enemyfly_hits = pygame.sprite.spritecollide(self.player, self.enemyFly, False, pygame.sprite.collide_mask) if enemyfly_hits: self.playerDead = True # checks if a player hits a platform if self.player.velocity.y > 0: player_collision = pygame.sprite.spritecollide( self.player, self.platforms, False) if player_collision: lowest = player_collision[0] for hit in player_collision: if hit.rect.bottom > lowest.rect.bottom: lowest = hit # make sure the player falls off if leaves past the right or left of platform if self.player.position.x < lowest.rect.right + 10: if self.player.position.x > lowest.rect.left - 10: if self.player.position.y < lowest.rect.centery: self.player.position.y = lowest.rect.top self.player.velocity.y = 0 self.player.jumping = False def coin_collisions(self): # if player hits coin self.COIN_SOUND = pygame.mixer.Sound('coin.wav') self.COIN_SOUND.set_volume(.9) coin_hits = pygame.sprite.spritecollide(self.player, self.coin, True) for chits in coin_hits: self.COIN_SOUND.play() if chits.type == "goldcoin": self.highscore.score += 300 if chits.type == "silvercoin": self.highscore.score += 200 if chits.type == "bronzecoin": self.highscore.score += 100 if chits.type == "goalcoin": self.win = True def moving_camera(self): # if player reaches top of the screen move the camera if self.player.rect.top <= display_height / 3: from random import randrange if randrange(100) < 10: from Cloud import Cloud Cloud(self) self.player.position.y += max(abs(self.player.velocity.y), 3) # move clouds down half of the player speed for cloud in self.clouds: cloudspeed = randrange(1, 3) cloud.rect.y += max(abs(self.player.velocity.y / cloudspeed), 3) # move EnemyFly down based on player speed for enemyfly in self.enemyFly: enemyfly.rect.y += max(abs(self.player.velocity.y), 3) # move platforms down based on player speed for plat in self.platforms: plat.rect.y += max(abs(self.player.velocity.y), 3) if plat.rect.top >= display_height: plat.kill() self.highscore.score += 10 def player_death(self): # player death if not self.player.tutorial: if self.player.rect.bottom > display_height: for sprite in self.all_sprites: sprite.rect.y -= max(self.player.velocity.y, 7) if sprite.rect.bottom < 0: sprite.kill() self.playerDead = True elif self.player.tutorial: if self.player.rect.bottom > display_height: for sprite in self.all_sprites: if sprite.rect.bottom < 0: self.player.position = vector2(100, 530)
def show_high_scores(self): '''Will display the high scores''' HighScores.start()
def play_game(game_size, seed): game_color = Misc.BLACK game_exit = False game_over = False game_victory = False game_time = 0 global current_game print str(seed) if seed is "": current_game = Game.Game(game_size) else: current_game = Game.Game(game_size,seed) while not game_exit: # GAME OVER event while game_over is True: Misc.message_to_screen("Game Over", Misc.LIGHT_RED, -50, "L") Misc.message_to_screen("Press C to continue. Press Q to quit.", Misc.LIGHT_RED, 50) Misc.refresh() for event in pygame.event.get(): if event.type is pygame.QUIT: pygame.quit() quit() if event.type is pygame.KEYDOWN: if event.key is pygame.K_q: return endGame if event.key is pygame.K_c: return newGame # VICTORY event if game_victory is True: while game_victory is True: Misc.message_to_screen("YOU WIN", Misc.GREEN, -50, "L") Misc.message_to_screen("Press C to continue. Press Q to quit.", Misc.GREEN, 50) Misc.refresh() for event in pygame.event.get(): if event.type is pygame.QUIT: pygame.quit() quit() if event.type is pygame.KEYDOWN: if event.key is pygame.K_q: seed = current_game.get_seed_name() HighScores.enterName(str(game_time / 60), seed) return endGame if event.key is pygame.K_c: seed = current_game.get_seed_name() HighScores.enterName(str(game_time / 60), seed) return newGame # Input Handling pos_x = (pygame.mouse.get_pos()[0] - current_game.start_x) / Misc.pixel_size pos_y = (pygame.mouse.get_pos()[1] - current_game.start_y) / Misc.pixel_size pos = (pos_x, pos_y) for event in pygame.event.get(): if event.type is pygame.QUIT: pygame.quit() quit() if event.type is pygame.MOUSEBUTTONDOWN: if 0 <= pos_x < game_size[0] and 0 <= pos_y < game_size[1]: # LEFT CLICK if event.button is 1: game_over = Game.open_tile(current_game, pos) if not game_over: game_victory = current_game.check_win() # RIGHT CLICK elif event.button is 3: current_game.toggle_flag(pos) if event.type is pygame.KEYDOWN: if event.key is pygame.K_p: game_exit = game_pause() elif event.key is pygame.K_o: game_victory = True # EZ-SENSOR if Misc.EZ_SENSOR is True: if 0 <= pos_x < game_size[0] and 0 <= pos_y < game_size[1]: if pos in current_game.bomb.mines: game_color = Misc.ez_sensor('INCREASE', game_color) elif current_game.num.calculatepoint(current_game.num, pos, current_game.bomb) > 0: game_color = Misc.ez_sensor('increase', game_color) else: game_color = Misc.ez_sensor('decrease', game_color) else: game_color = Misc.ez_sensor('decrease', game_color) # GAME Handling Misc.gameDisplay.fill(game_color) current_game.display() Misc.timer(game_time, Misc.LIGHT_RED, timer_pos) pygame.display.update() game_time = Misc.tick(game_time)
def testNewScore(self): observed = HighScores.highscore('Roger', -50) expected = -50 self.assertEqual(observed, expected, 'Results are not the expected, expected: {0}, actual: {1}'.format(expected,observed))
def play_game(game_size, seed): game_exit = False game_over = False game_victory = False game_time = 0 global current_game print str(seed) if (seed == ""): current_game = Game.Game(game_size) else: current_game = Game.Game(game_size, seed) while not game_exit: # GAME OVER event while game_over is True: Misc.message_to_screen("Game Over", Misc.LIGHT_RED, -50, "L") Misc.message_to_screen("Press C to continue. Press Q to quit.", Misc.LIGHT_RED, 50) Misc.refresh() for event in pygame.event.get(): if event.type is pygame.QUIT: pygame.quit() quit() if event.type is pygame.KEYDOWN: if event.key is pygame.K_q: return endGame if event.key is pygame.K_c: return newGame # VICTORY event if game_victory is True: while game_victory is True: Misc.message_to_screen("YOU WIN", Misc.GREEN, -50, "L") Misc.message_to_screen("Press C to continue. Press Q to quit.", Misc.GREEN, 50) Misc.refresh() for event in pygame.event.get(): if event.type is pygame.QUIT: pygame.quit() quit() if event.type is pygame.KEYDOWN: if event.key is pygame.K_q: seed = current_game.get_seed_name() HighScores.enterName(str(game_time / 60), seed) return endGame if event.key is pygame.K_c: seed = current_game.get_seed_name() HighScores.enterName(str(game_time / 60), seed) return newGame # Input Handling for event in pygame.event.get(): if event.type is pygame.QUIT: pygame.quit() quit() if event.type is pygame.MOUSEBUTTONDOWN: pos_x = (pygame.mouse.get_pos()[0] - current_game.start_x) / Misc.pixel_size pos_y = (pygame.mouse.get_pos()[1] - current_game.start_y) / Misc.pixel_size pos = (pos_x, pos_y) if 0 <= pos_x < game_size[0] and 0 <= pos_y < game_size[1]: # LEFT CLICK if event.button is 1: game_over = Game.open_tile(current_game, pos) if not game_over: game_victory = current_game.check_win() # RIGHT CLICK elif event.button is 3: current_game.toggle_flag(pos) if event.type is pygame.KEYDOWN: if event.key is pygame.K_p: game_exit = game_pause() elif event.key is pygame.K_o: game_victory = True # gameOver = True # CHICKEN MODE # print (pygame.mouse.get_pos()[0]-Misc)/Misc.pixel_size # print [self.start_x + pos[0] * Misc.pixel_size, self.start_y + pos[1] * Misc.pixel_size] # GAME Handling Misc.gameDisplay.fill(Misc.BLACK) current_game.display() Misc.timer(game_time, Misc.LIGHT_RED, timer_pos) pygame.display.update() game_time = Misc.tick(game_time)
def run(self): self.fps = 30 self.gameClock.tick(self.fps) self.epilepsy_warning = EpilepsyWarning(self.screen) self.epilepsy_warning.run(self.gameWindow, self.fps, self.gameClock) while (self.restart): self.terminate = False while (not self.terminate): # counter variable to track the number of frames passed during game execution self.counter = 0 # the number of frames that pass between each tile iteration self.framesPerRound = self.difficulty_level.max_fpr # User is in the main menuif(self.game_state == self.game_states['Main Menu']): self.curr_song = self.title_song self.curr_song.play(self.fps / 2) while (self.game_state == self.game_states['Main Menu'] and not self.terminate): self.fps = 30 # make the mouse visible to the player pygame.mouse.set_visible(True) if (self.mainMenu.titleAnimationCreated): self.mainMenu.runTitleAnimation(self.gameWindow) else: self.mainMenu.startTitleAnimation(self.gameWindow) self.mainMenu.show(self.gameWindow, True) # event handling within the main menu for event in pygame.event.get(): if (event.type == pygame.QUIT): # user quits game self.endGame() if (event.type == pygame.MOUSEBUTTONDOWN): if (self.mainMenu.options[0].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user has clicked on the start game button self.difficulty_level = difficulties[0] self.prepNewGame() continue if (self.mainMenu.options[1].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user has clicked on the start game button self.difficulty_level = difficulties[1] self.prepNewGame() continue if (self.mainMenu.options[2].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user has clicked on the start game button self.difficulty_level = difficulties[2] self.prepNewGame() continue elif (self.mainMenu.options[3].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user has clicked the How to play button self.fps = 30 help = helpScreen(self.screen) helping = True while (helping): for event in pygame.event.get(): if (event.type == pygame.QUIT): self.terminate = True helping = False self.restart = False if (event.type == pygame.MOUSEBUTTONDOWN): if (help.returnBtn.inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]) ): helping = False help.update(self.gameWindow) pygame.display.update() self.gameClock.tick(self.fps) elif (self.mainMenu.options[4].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user has clicked the exit game button self.endGame() continue if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_ESCAPE): # user wants to exit game self.endGame() continue self.gameClock.tick(self.fps) pygame.display.update() if (self.game_state == self.game_states['Game Over'] and not self.terminate): self.curr_song.fadeout(100) HighScores.importScores("Assets/highscores.txt") while (self.game_state == self.game_states['Game Over'] and not self.terminate): # player is seeing the game over screen pygame.mouse.set_visible(True) diff_index = -1 for i in range(len(difficulties)): if self.difficulty_level == difficulties[i]: diff_index = i if (diff_index != -1): self.gameOverScreen.update(self.gameWindow, self.screen, self.gameplay_time, diff_index) else: raise Exception("Invalid difficulty index") while (HighScores.newHighScore): for event in pygame.event.get(): if (event.type == pygame.QUIT): terminate = True restart = False HighScores.newHighScore = False continue if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_RETURN): HighScores.newHighScore = False if (self.newHighScoreInput.nameIn == "(3 characters maximum)"): HighScores.newHighScoreInsert( self.gameplay_time, "-", self.difficulty_level) else: HighScores.newHighScoreInsert( self.gameplay_time, self.newHighScoreInput.nameIn[0:3], self.difficulty_level) if (event.key == pygame.K_ESCAPE): HighScores.newHighScore = False if (event.key == pygame.K_BACKSPACE): self.newHighScoreInput.nameIn = self.newHighScoreInput.nameIn[ 0:len(self.newHighScoreInput.nameIn) - 1] if (self.isAlphanumericKey(event)): if (self.newHighScoreInput.nameIn == "(3 characters maximum)"): self.newHighScoreInput.nameIn = self.getKeyVal( event).upper() else: if (len(self.newHighScoreInput.nameIn) < 3): self.newHighScoreInput.nameIn += self.getKeyVal( event).upper() self.newHighScoreInput.update(self.gameWindow) pygame.display.update() # event handling in the game over screen for event in pygame.event.get(): if (event.type == pygame.QUIT): self.endGame() continue if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_ESCAPE): # user wants to exit game self.restartGame() self.game_state = self.game_states['Main Menu'] continue if (event.key == pygame.K_SPACE): # user wants to play again self.newGameSession() self.prepNewGame() continue if (event.type == pygame.MOUSEBUTTONDOWN): if (self.gameOverScreen.options[0].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user selected the play again button self.newGameSession() self.prepNewGame() self.game_state = self.game_states[ 'Game Active'] continue if (self.gameOverScreen.options[1].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user selected to return to the main menu self.newGameSession() self.game_state = self.game_states['Main Menu'] continue self.fps = 120 self.gameClock.tick(self.fps) pygame.display.update() while (self.game_state == self.game_states['Game Paused'] and not self.terminate): self.curr_song.pause() pygame.mouse.set_visible(True) self.fps = 60 self.pauseMenu.show(self.gameWindow, True) # event handling for pause menu actions for event in pygame.event.get(): if (event.type == pygame.QUIT): self.endGame() continue if (event.type == pygame.MOUSEBUTTONDOWN): if (self.pauseMenu.options[0].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user selected the resume game button self.unpauseGame() if (self.pauseMenu.options[1].inBounds( pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])): # user selected the main menu button self.newGameSession() self.game_state = self.game_states['Main Menu'] continue if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_SPACE): # user wants to resume the game self.unpauseGame() if (event.key == pygame.K_ESCAPE): # user wants to return to the main menu self.game_state = self.game_states['Main Menu'] self.newGameSession() continue if (event.key == pygame.K_r): self.newGameSession() self.prepNewGame() self.game_state = self.game_states[ 'Game Active'] continue self.gameClock.tick(self.fps) pygame.display.update() while (self.game_state == self.game_states['Game Active'] and not self.terminate): # active gameplay for the user pygame.mouse.set_visible(False) self.fps = 30 self.iterateTime() if (self.gameClock.get_fps() < 20): print(self.gameClock.get_fps()) # event handling for active gameplay for event in pygame.event.get(): if (event.type == pygame.QUIT): self.endGame() continue if (event.type == pygame.MOUSEMOTION): if (not (pygame.mouse.get_pos()[0] < self.gameBoard.x or pygame.mouse.get_pos()[0] > self.gameBoard.x + self.gameBoard.width) and pygame.mouse.get_focused() != 0): self.playerXMove = pygame.mouse.get_pos()[0] if (not (pygame.mouse.get_pos()[1] < self.gameBoard.y or pygame.mouse.get_pos()[1] > self.gameBoard.y + self.gameBoard.height) and pygame.mouse.get_focused() != 0): self.playerYMove = pygame.mouse.get_pos()[1] if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_p): # user wants to pause the game self.pauseGame() self.terminate = False self.player.status = 1 continue if (event.key == pygame.K_r): self.newGameSession() self.prepNewGame() self.game_state = self.game_states[ 'Game Active'] continue if (event.key == pygame.K_ESCAPE): # user wants to return to the main menu self.newGameSession() self.game_state = self.game_states['Main Menu'] continue #check if the mouse is outside of the game board, and if it is, move them back inside the game board if (self.playerXMove < self.gameBoard.x + self.player.radius): self.playerXMove = self.gameBoard.x + self.player.radius elif (self.playerXMove > self.gameBoard.x + self.gameBoard.width - self.player.radius): self.playerXMove = self.gameBoard.x + self.gameBoard.width - self.player.radius if (self.playerYMove < self.gameBoard.y + self.player.radius): self.playerYMove = self.gameBoard.y + self.player.radius elif (self.playerYMove > self.gameBoard.y + self.gameBoard.height - self.player.radius): self.playerYMove = self.gameBoard.y + self.gameBoard.height - self.player.radius # move the player to their new position as specified by either mouse movement or "not-movement" self.player.move(self.playerXMove, self.playerYMove) # move the mouse to the center of the new player position pygame.mouse.set_pos(self.player.posX, self.player.posY) self.collisions = self.player.getTileCollisions( self.gameBoard.tiles) for tile in self.collisions: if (tile.value == 'x'): self.player.status = 0 self.terminate = True self.restart = True self.gameWindow.fill((10, 10, 10)) self.gameWindow.fill( Colors.black, pygame.Rect((0, 0), (self.screen[0], self.screen[1] * 0.1))) # update all non-board and non-player elements on the screen during active game state self.activeGameDisplay() if (self.counter % self.framesPerRound == 0 and self.counter != 0): # game board needs to iterate its tiles to the next set self.gameBoard.iterateTiles() # iterate tiles, increase speeds, etc. when the time is correct (as specified by the counter variable) if (self.counter % (int( self.fps * (self.secondsPerIdealGame / self.numTimesSpeedUp))) == 0 and self.counter != 0): # time to speed up the game if (self.framesPerRound > self.difficulty_level.min_fpr): self.framesPerRound -= self.frames_per_round_iter self.player.speed += self.player_speed_iter self.gameClock.tick(self.fps) self.boardPulseAnimation.iterate() self.boardPulseAnimation.update(self.gameWindow, 'center') self.gameBoard.update(self.gameWindow) self.player.update(self.gameWindow) pygame.display.update() self.counter += 1 # check if the player has "blacked out" and if they have, send them to the game over screen and let them choose what to do from there if (self.player.status == 0): self.game_state = self.game_states['Game Over'] # check if this player got a high score, and record it accordingly if (HighScores.isBestScore(self.gameplay_time, self.difficulty_level)): HighScores.newHighScore = True
from Gameplay import * from GameOver import * from HighScores import * from LevelScreen import * # load game resources big_font = pygame.font.Font("data/visitor.ttf", 64) small_font = pygame.font.Font("data/visitor.ttf", 48) mesh_list = loadMeshes("data/meshes.dsc", "data/sprites.png") # create & init subsystems screen = pygame.display.set_mode((800, 600)) mainMenu = MainMenu(big_font, (255, 0, 0), (0, 255, 0)) gameplay = Gameplay(mesh_list, big_font) gameOver = GameOver(big_font) highScores = HighScores(big_font) levelScreen = LevelScreen(big_font) mainMenu._gameplay = gameplay mainMenu._highScores = highScores gameplay._mainMenu = mainMenu gameplay._gameOver = gameOver gameOver._highScores = highScores highScores._mainMenu = mainMenu levelScreen._gameplay = gameplay gameplay._levelScreen = levelScreen mainMenu._levelScreen = levelScreen quit = False # game main loop gameState = mainMenu oldTime = pygame.time.get_ticks() * 0.001
print('=' * 20) import HighScores reload(HighScores) # This is a best practice high_scores = HighScores.HighScores() high_scores.print_scores() print('-' * 20) for score in (-99.6, -99.5, -99, -9, -1, -0, 0, 1, 9, 99, 99.5, 99.6): print('Input: {} ========'.format(score)) if high_scores.is_high_score('int', int(score)): print('Congratulations on your new high score!') #highscores.save_score('str_int', str(int(score))) # strings now raise an exception if high_scores.is_high_score('float', float(score)): print('Congratulations on your new high score!') #highscores.save_score('str_float', str(float(score))) # strings now raise an exception high_scores.print_scores() lessons_learned = '''==================== For positive values: int(n), str(int(n)), float(n), str(float(n)) all work correctly. For negative values: Only int(n) and float(n) work correctly. Recommendation: Always pass an int or float as the second value to highscores.is_high_score() Added a try / except block to reject nonnumeric scores''' print(lessons_learned)
optionParser = OptionParser() optionParser.add_option("-e", "--editlevel", help="Edit the level with a specified filename. If no such level exists, create a new one.") optionParser.add_option("-l", "--levellength", help="When editing a level, this is the length of the level") (options, args) = optionParser.parse_args() #### Kick off the graphics/window system kernel = GameKernel() screenSurface = kernel.InitializeDisplay((800, 600)) ticker = kernel.Ticker() #### Initialize game states gsm = GameStateManager() gsm.RegisterState(GS_MainMenu(kernel, gsm)) gsm.RegisterState(GS_EditorMenu(kernel, gsm)) gsm.RegisterState(GS_Game(kernel, gsm)) gsm.RegisterState(HighScores(kernel, gsm)) gsm.RegisterState(GS_LevelSelect(kernel, gsm)) gsm.RegisterState(GS_Tutorial(kernel, gsm)) if (options.editlevel): gsm.RegisterState(GS_Editor(kernel, gsm, options.editlevel)) gsm.SwitchState("Editor") else: gsm.SwitchState("MainMenu") font = pygame.font.SysFont("Helvetica", 12) ## Main Loop while (1): delta = ticker.get_time()