def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key in self.input.leftKeys and self.currentMenu in self.interactiveMenus: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.rightKeys and self.currentMenu in self.interactiveMenus: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key == K_RETURN: self.select.play() if self.counter == 0: self.state = True if self.counter == 1: self.state = False if event.key == K_ESCAPE: self.running = False self.goBack.play()
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key in self.input.upKeys and self.currentMenu in self.interactiveMenus: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys and self.currentMenu in self.interactiveMenus: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key == K_RETURN and self.currentMenu == "Main menu": self.select.play() if self.counter == self.items.index("Play"): gameTypeScreen = GameTypeMenu() gameTypeScreen.main() self.soundSetup() if self.counter == self.items.index("Options"): optionsScreen = OptionsMenu() optionsScreen.main() self.soundSetup() if self.counter == self.items.index("High Scores"): hiScoreScreen = HighScoresMenu() hiScoreScreen.main() if self.counter == self.items.index("About"): aboutScreen = AboutMenu() aboutScreen.main() if self.counter == self.items.index("How to play"): howToPlayScreen = HowToPlayMenu() howToPlayScreen.main() if self.counter == self.items.index("Quit"): stop() if event.key == K_ESCAPE and self.currentMenu != "Main menu": self.running = False self.goBack.play()
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key in self.input.upKeys and self.currentMenu in self.interactiveMenus: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys and self.currentMenu in self.interactiveMenus: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key == K_RETURN: self.select.play() if self.counter == 0: self.running = False if self.counter == 1: optionsScreen = OptionsMenu() optionsScreen.main() self.soundSetup() if self.counter == 2: yesnoScreen = YesNoPrompt() yesnoScreen.main() if yesnoScreen.state: self.parentVal = True self.running = False if self.counter == 3: yesno = YesNoPrompt() yesno.main() if yesno.state: stop() if event.key == K_ESCAPE: self.running = False self.goBack.play()
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key in self.input.upKeys and self.currentMenu in self.interactiveMenus and len( self.items) > 1: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys and self.currentMenu in self.interactiveMenus and len( self.items) > 1: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key == K_RETURN: self.select.play() scoreDetailsScreen = ScoreDetails( self.items[self.counter], self.allNames[self.counter]) scoreDetailsScreen.main() if event.key == K_ESCAPE and self.currentMenu != "Main menu": self.running = False self.goBack.play() if event.key == K_x and len(self.allNames) != 0: self.select.play() yesNoScreen = YesNoPrompt() yesNoScreen.main() if yesNoScreen.state: del self.items[self.counter] del self.allNames[self.counter] with open("cfg/data.json", "w") as f: json.dump(self.items, f, indent=4)
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if len(self.result) < 8: if event.unicode in self.font.legalChars: self.result += event.unicode if event.key == K_RETURN: self.done = True if len(self.result) != 0: valid = self.result.isspace() if not valid: with open("cfg/data.json", "w") as f: scoreInput = {} scoreInput["Name"] = self.result scoreInput["Score"] = self.score scoreInput["Difficulty"] = self.dif scoreInput["Density"] = self.density scoreInput["Size"] = self.size scoreInput["Time limit"] = self.timer current = datetime.datetime.now() date = current.strftime("%Y-%m-%d") time = current.strftime("%H:%M:%S") scoreInput["Date"] = date scoreInput["Time"] = time self.scores.append(scoreInput) json.dump(self.scores, f, indent=4) if event.key == K_ESCAPE: self.done = True if event.key == K_BACKSPACE: if len(self.result) != 0: self.result = self.result[:-1]
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key == K_ESCAPE: self.goBack.play() self.running = False if event.key in self.input.upKeys: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key == K_RETURN: self.select.play() if self.counter == 0: gameConfigScreen = GameConfigMenu() gameConfigScreen.main() if gameConfigScreen.newGame: self.running = False if self.counter == 1: mpTypeScreen = MultiplayerTypeMenu() mpTypeScreen.main()
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key in self.input.upKeys: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key in self.input.leftKeys: if self.counter == 0: self.scroll.play() Const.filters = not Const.filters self.items[ 0] = "Filters: ON" if Const.filters else "Filters: OFF" Const.replaceConfig(8, "{:04x}".format(Const.filters)) elif self.counter == 1 and Const.filters: self.scroll.play() Const.crtEffect = not Const.crtEffect self.items[ 1] = "Scanlines: ON" if Const.crtEffect else "Scanlines: OFF" Const.replaceConfig(5, "{:04x}".format(Const.crtEffect)) elif self.counter == 2 and Const.filters: self.scroll.play() Const.inversion = (Const.inversion - 1) & 0xff self.items[2] = "Inversion: %d" % Const.inversion Const.replaceConfig(4, "{:04x}".format(Const.inversion)) elif self.counter == 3 and Const.filters: self.scroll.play() Const.redChannel = (Const.redChannel - 1) & 0xff self.items[3] = "Red channel: %d" % Const.redChannel Const.replaceConfig(6, "{:04x}".format(Const.redChannel)) elif self.counter == 4 and Const.filters: self.scroll.play() Const.greenChannel = (Const.greenChannel - 1) & 0xff self.items[ 4] = "Green channel: %d" % Const.greenChannel Const.replaceConfig( 9, "{:04x}".format(Const.greenChannel)) elif self.counter == 5 and Const.filters: self.scroll.play() Const.blueChannel = (Const.blueChannel - 1) & 0xff self.items[5] = "Blue channel: %d" % Const.blueChannel Const.replaceConfig(7, "{:04x}".format(Const.blueChannel)) if event.key in self.input.rightKeys: if self.counter == 0: self.scroll.play() Const.filters = not Const.filters self.items[ 0] = "Filters: ON" if Const.filters else "Filters: OFF" Const.replaceConfig(8, "{:04x}".format(Const.filters)) elif self.counter == 1 and Const.filters: self.scroll.play() Const.crtEffect = not Const.crtEffect self.items[ 1] = "Scanlines: ON" if Const.crtEffect else "Scanlines: OFF" Const.replaceConfig(5, "{:04x}".format(Const.crtEffect)) elif self.counter == 2 and Const.filters: self.scroll.play() Const.inversion = (Const.inversion + 1) & 0xff self.items[2] = "Inversion: %d" % Const.inversion Const.replaceConfig(4, "{:04x}".format(Const.inversion)) elif self.counter == 3 and Const.filters: self.scroll.play() Const.redChannel = (Const.redChannel + 1) & 0xff self.items[3] = "Red channel: %d" % Const.redChannel Const.replaceConfig(6, "{:04x}".format(Const.redChannel)) elif self.counter == 4 and Const.filters: self.scroll.play() Const.greenChannel = (Const.greenChannel + 1) & 0xff self.items[ 4] = "Green channel: %d" % Const.greenChannel Const.replaceConfig( 9, "{:04x}".format(Const.greenChannel)) elif self.counter == 5 and Const.filters: self.scroll.play() Const.blueChannel = (Const.blueChannel + 1) & 0xff self.items[5] = "Blue channel: %d" % Const.blueChannel Const.replaceConfig(7, "{:04x}".format(Const.blueChannel)) if event.key == K_ESCAPE: self.running = False self.goBack.play()
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key == K_ESCAPE: self.goBack.play() self.running = False if event.key == K_RETURN and self.counter == 4: with open("cfg/gameconfig.json", "w") as f: json.dump(self.data, f, indent=4) self.newGame = True game = Game() game.main() self.running = False if event.key in self.input.upKeys: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key in self.input.leftKeys: if self.counter == 0: self.difCounter -= 1 if self.difCounter == -1: self.difCounter = len(self.difficulties) - 1 self.difficulty = self.difficulties[self.difCounter] self.data["Difficulty"] = self.difficulty self.items[0] = "Difficulty: %s" % self.difficulty self.scroll.play() if self.counter == 1: self.denCounter -= 1 if self.denCounter == -1: self.denCounter = len(self.densities) - 1 self.density = self.densities[self.denCounter] self.data["Density"] = self.density self.items[1] = "Density: " + str( int(self.density * 100)) + "%" self.scroll.play() if self.counter == 2: self.sizeCounter -= 1 if self.sizeCounter == -1: self.sizeCounter = len(self.sizes) - 1 self.size = self.sizes[self.sizeCounter] self.data["Size"] = self.size self.items[2] = "Size: %dx%d" % (self.size[0], self.size[1]) self.scroll.play() if self.counter == 3: self.timer = (self.timer - 1) & 0xff self.data["Time limit"] = self.timer self.items[3] = "Time limit: %d s" % self.timer self.scroll.play() if event.key in self.input.rightKeys: if self.counter == 0: self.difCounter += 1 if self.difCounter == len(self.difficulties): self.difCounter = 0 self.difficulty = self.difficulties[self.difCounter] self.data["Difficulty"] = self.difficulty self.items[0] = "Difficulty: %s" % self.difficulty self.scroll.play() if self.counter == 1: self.denCounter += 1 if self.denCounter == len(self.densities): self.denCounter = 0 self.density = self.densities[self.denCounter] self.data["Density"] = self.density self.items[1] = "Density: " + str( int(self.density * 100)) + "%" self.scroll.play() if self.counter == 2: self.sizeCounter += 1 if self.sizeCounter == len(self.sizes): self.sizeCounter = 0 self.size = self.sizes[self.sizeCounter] self.data["Size"] = self.size self.items[2] = "Size: %dx%d" % (self.size[0], self.size[1]) self.scroll.play() if self.counter == 3: self.timer = (self.timer + 1) & 0xff self.data["Time limit"] = self.timer self.items[3] = "Time limit: %d s" % self.timer self.scroll.play()
def eventHandler(self): for event in pg.event.get(): if event.type == QUIT: stop() if event.type == KEYDOWN: if event.key == K_F12: self.takeScreenshot() if event.key in self.input.upKeys: self.counter -= 1 if self.counter == -1: self.counter = len(self.items) - 1 self.scroll.play() if event.key in self.input.downKeys: self.counter += 1 if self.counter == len(self.items): self.counter = 0 self.scroll.play() if event.key in self.input.leftKeys: if self.counter == 0: if Const.volume >= 1: Const.volume -= 1 self.scroll.play() self.items[0] = "Audio:" + str(int(Const.volume)) + "%" self.soundSetup() Const.replaceConfig( 0, "{:04x}".format((Const.volume << 8) + 86)) elif self.counter == 1: self.resSelected -= 1 if self.resSelected == -1: self.resSelected = len(self.resolutions) - 1 self.items[1] = "Window:%s" % self.resolutions[ self.resSelected] self.scroll.play() elif self.counter == 2: Const.fullscreen = not Const.fullscreen self.items[ 2] = "Fullscreen:ON" if Const.fullscreen else "Fullscreen:OFF" self.scroll.play() elif self.counter == 3: Const.playerColor -= 1 if Const.playerColor == -1: Const.playerColor = len(self.playerColors) - 1 Const.replaceConfig( 3, "{:04x}".format((Const.playerColor << 8) + 67)) self.scroll.play() if event.key in self.input.rightKeys: if self.counter == 0: if Const.volume <= 99: Const.volume += 1 self.scroll.play() self.items[0] = "Audio:" + str(int(Const.volume)) + "%" self.soundSetup() Const.replaceConfig( 0, "{:04x}".format((Const.volume << 8) + 86)) elif self.counter == 1: self.resSelected += 1 if self.resSelected == len(self.resolutions): self.resSelected = 0 self.items[1] = "Window:%s" % self.resolutions[ self.resSelected] self.scroll.play() elif self.counter == 2: Const.fullscreen = not Const.fullscreen self.items[ 2] = "Fullscreen:ON" if Const.fullscreen else "Fullscreen:OFF" self.scroll.play() elif self.counter == 3: Const.playerColor += 1 if Const.playerColor == len(self.playerColors): Const.playerColor = 0 Const.replaceConfig( 3, "{:04x}".format((Const.playerColor << 8) + 67)) self.scroll.play() # elif self.counter == 4: # Const.inversion = (Const.inversion + 1) & 0xff # self.items[4] = "Inversion: %d" % Const.inversion # Const.replaceConfig(4, "{:04x}".format(Const.inversion)) if event.key == K_ESCAPE: self.running = False self.goBack.play() if event.key == K_RETURN and self.counter == 4: self.select.play() advancedScreen = AdvancedOptionsMenu() advancedScreen.main() if event.key == K_RETURN and self.counter == len( self.items) - 1: Const.SCALE = self.resSelected + 3 Const.WINDOW_SIZE = (Const.WIDTH * Const.SCALE, Const.HEIGHT * Const.SCALE) if Const.fullscreen: Const.win = pg.display.set_mode( Const.WINDOW_SIZE, FULLSCREEN | DOUBLEBUF | HWSURFACE) else: Const.win = pg.display.set_mode( Const.WINDOW_SIZE, DOUBLEBUF | HWSURFACE) Const.replaceConfig( 2, "{:04x}".format((Const.fullscreen << 8) + 77)) Const.replaceConfig( 1, "{:04x}".format(((self.resSelected + 3) << 8) + 94)) self.select.play()