def displayScreen(self): self.timer = 4.0 * FRAMES_PER_SECOND sequence = 1 * FRAMES_PER_SECOND while self.timer: self.handleEvents() self.screen.fill(FILL_COLOR) if self.music: utility.playMusic(self.music) self.timer -= 1 self.image.draw(self.screen) if self.timer >= 3 * FRAMES_PER_SECOND: utility.dim((sequence / (1.0 * FRAMES_PER_SECOND)) * 255) sequence -= 1 if self.timer <= 1 * FRAMES_PER_SECOND: if self.fadeImage: utility.dim((sequence / (1.0 * FRAMES_PER_SECOND)) * 255) sequence += 1 pygame.display.flip() self.clock.tick(FRAMES_PER_SECOND)
def actorUpdate(self): utility.playMusic(self.music, True) self.placeEye() if self.lifeTimer <= 30 * FRAMES_PER_SECOND and self.health == self.world.level+ 2: if self.lifeTimer == 30 * FRAMES_PER_SECOND: tempImage = self.howToKill helpBubble = infoBubble.infoBubble(tempImage, self.target,5 * FRAMES_PER_SECOND) helpBubble.offSet = vector.vector2d(0.0, -100.0) self.textGroup.add(helpBubble) self.lifeTimer += 1 if not self.active and self.health > 0: self.active = True if self.active: if self.stunned: if self.charging: self.speed -= 0.2 if self.speed <= 1.75: self.speed = 1.75 self.charging = False self.timeUntilCharge = 6 * FRAMES_PER_SECOND self.velocity.makeNormal() self.velocity *= self.speed self.currentSequence = 1 self.stunned -= 1 if not self.stunned: self.textGroup.add(self.eye) self.animationList.play("idle") if not self.stunned % 4: puffsToCreate = 4 while puffsToCreate and settingList[PARTICLES]: puffsToCreate -= 1 tempPuff = particle.smokeParticle(self.position, [1,0]) tempPuff.velocity.setAngle(359 * random.random()) self.effectsGroup.add(tempPuff) else: self.currentSequence = 0 self.processAI() if self.health <= 0: self.active = False self.die() if not self.gaveBonus: self.world.giveBonus() self.gaveBonus = True
def actorUpdate(self): if not self.stunned: try: self.emitter.update() except: pass utility.playMusic(self.music, True) if not self.active and self.health > 0: self.active = True if self.lifeTimer <= 30 * FRAMES_PER_SECOND and self.health == self.world.level + 2: if self.lifeTimer == 30 * FRAMES_PER_SECOND: tempImage = self.howToKill helpBubble = infoBubble.infoBubble(tempImage, self.target,5 * FRAMES_PER_SECOND) helpBubble.offSet = vector.vector2d(0.0, -100.0) self.textGroup.add(helpBubble) self.lifeTimer += 1 if self.active: if self.stunned: self.stunned -= 1 if not self.stunned % 4: puffsToCreate = 4 while puffsToCreate and settingList[PARTICLES]: puffsToCreate -= 1 tempPuff = particle.smokeParticle(self.position, [1,0]) tempPuff.velocity.setAngle(359 * random.random()) self.effectsGroup.add(tempPuff) if not self.stunned: self.animationList.play("idle") else: self.currentSequence = 0 self.processAI() if self.health <= 0: self.active = False self.die() if not self.gaveBonus and self.world.worldName != "Tutorial": self.world.giveBonus() self.gaveBonus = True
def actorUpdate(self): utility.playMusic(self.music, True) if not self.active and self.health > 0: self.active = True if self.lifeTimer <= 30 * FRAMES_PER_SECOND and self.health == (self.world.level + 1) * 25: if self.lifeTimer == 30 * FRAMES_PER_SECOND: tempImage = self.howToKill helpBubble = infoBubble.infoBubble(tempImage, self.target,5 * FRAMES_PER_SECOND) helpBubble.offSet = vector.vector2d(0.0, -100.0) self.textGroup.add(helpBubble) self.lifeTimer += 1 if self.active: if self.stunned: if self.charging: self.speed -= 0.2 if self.speed <= 1.75: self.speed = 1.75 self.charging = False self.timeUntilCharge = 10 * FRAMES_PER_SECOND self.velocity.makeNormal() self.velocity *= self.speed self.stunned -= 1 self.animationList.play("vulnerable") if not self.stunned: utility.playSound(self.shieldRestore, PICKUP_CHANNEL) self.animationList.play("idle") else: self.currentSequence = 0 self.processAI() if self.health <= 0: self.active = False self.die() if not self.gaveBonus: self.world.giveBonus() self.gaveBonus = True
def rollCredits(self): creditGroup = pygame.sprite.Group() """ Create Text Labels """ titleCredit = text.Text(FONT_PATH,48,FONT_COLOR,"Credits") titleCredit.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT)) bigJony = text.Text(FONT_PATH,36,FONT_COLOR,"Jony Fries") bigJony.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 100)) jonyCredit0 = text.Text(FONT_PATH,24,FONT_COLOR,"Game Programming") jonyCredit0.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 150)) jonyCredit1 = text.Text(FONT_PATH,24,FONT_COLOR,"Sound Design") jonyCredit1.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 200)) jonyCredit2 = text.Text(FONT_PATH,24,FONT_COLOR,"Voice Acting") jonyCredit2.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 250)) bigJosh = text.Text(FONT_PATH,36,FONT_COLOR,"Joshua Skelton") bigJosh.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 350)) joshCredit0 = text.Text(FONT_PATH,24,FONT_COLOR,"Game Programming") joshCredit0.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 400)) joshCredit1 = text.Text(FONT_PATH,24,FONT_COLOR,"Graphic Design") joshCredit1.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 450)) bigSpecial = text.Text(FONT_PATH,36,FONT_COLOR,"Special Thanks To:") bigSpecial.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 550)) specialCredit0 = text.Text(FONT_PATH,24,FONT_COLOR,"Python Software Foundation") specialCredit0.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 600)) specialCredit1 = text.Text(FONT_PATH,24,FONT_COLOR,"PyGame") specialCredit1.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 650)) specialCredit2 = text.Text(FONT_PATH,24,FONT_COLOR,"ShyFonts Type Foundry") specialCredit2.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 700)) thankYou = text.Text(FONT_PATH,64,FONT_COLOR,"Thank You For Playing!") thankYou.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 800)) """ Add Labels to Group """ creditGroup.add(titleCredit) creditGroup.add(bigJony) creditGroup.add(jonyCredit0) creditGroup.add(jonyCredit1) creditGroup.add(jonyCredit2) creditGroup.add(bigJosh) creditGroup.add(joshCredit0) creditGroup.add(joshCredit1) creditGroup.add(bigSpecial) creditGroup.add(specialCredit0) creditGroup.add(specialCredit1) creditGroup.add(specialCredit2) creditGroup.add(thankYou) self.rollingCredits = True timer = 5 * FRAMES_PER_SECOND for credit in creditGroup: credit.setAlign(CENTER_MIDDLE) while self.rollingCredits: utility.playMusic(self.musicList) for credit in creditGroup: creditPosition = credit.getPosition() credit.setPosition((creditPosition[0],creditPosition[1] + self.scrollRate)) creditGroup.update() self.newScene.draw(self.screen) creditGroup.draw(self.screen) pygame.display.flip() self.handleEvents() if specialCredit2.getPosition()[1] < 0: if self.finished: self.rollingCredits = False if thankYou.getPosition()[1] < (SCREEN_HEIGHT / 2): thankYou.setPosition((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
bokko.loadData() pygame.event.pump() hakta.loadData() raayu.loadData() paajo.loadData() pygame.event.pump() boss.loadData() particle.loadData() menu.loadData() for event in pygame.event.get(): pass splashScreen.SplashScreen(screen,"pygamesplash") utility.playMusic(musicList[MENU_MUSIC]) splashScreen.SplashScreen(screen,"gameSplash") if settingList[WORLD_UNLOCKED] == 0: newScene = scene.tutorialScene() elif settingList[WORLD_UNLOCKED] == 1: newScene = scene.forestScene() elif settingList[WORLD_UNLOCKED] == 2: newScene = scene.rockyScene() elif settingList[WORLD_UNLOCKED] == 3: newScene = scene.pinkScene() try: import psyco psyco.full() except:
def handleEvents(self): for event in pygame.event.get(): if (event.type == KEYDOWN and event.key == K_ESCAPE) or (event.type == MOUSEBUTTONDOWN and event.button == 3) or (event.type == ACTIVEEVENT and event.gain == 0): utility.dim(128,FILL_COLOR) """takingScreenShot = True while takingScreenShot: for shotEvent in pygame.event.get(): if (event.type == pygame.MOUSEBUTTONDOWN): takingScreenShot = False""" screenGrab = self.screen.copy() pauseMenuRunning = True while pauseMenuRunning: pauseMenu = menu.Menu(self.screen, self.musicList[self.worldNumber], screenGrab, [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ["Pause",128,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], pauseMenuDictionary).displayMenu() if pauseMenu == OPTION_MENU: optionResult = True lastHighlighted = 0 while optionResult: optionMenuDictionary = {SOUND_MENU:["Sound Options", "Change Sound Options"], DISPLAY_MENU:["Video Options" ,"Change Video Options"], CHANGE_SENSITIVITY:["Mouse Sensitivity: " + getSensitivity(settingList[SENSITIVITY]), "Change Mouse Sensitivity"], EXIT_OPTIONS:["Back","Go Back to the Main Menu"]} sensitivityMenuDictionary = {0:["Very Low", "Change Sensitivty to Very Low"], 1:["Low", "Change Sensitivty to Low"], 2:["Normal", "Change Sensitivty to Normal"], 3:["High", "Change Sensitivty to High"], 4:["Very High", "Change Sensitivty to Very High"],} soundMenuDictionary = {TOGGLE_SFX:["Sound Effects: " + on(settingList[SFX]), "Turn " + on(not settingList[SFX]) + " Sound Effects"], TOGGLE_MUSIC:["Music: " + on(settingList[MUSIC]),"Turn " + on(not settingList[MUSIC]) + " Music"], EXIT_OPTIONS:["Back","Go Back to the Option Menu"]} displayMenuDictionary = {TOGGLE_PARTICLES:["Particles: " + able(settingList[PARTICLES]), "Turn " + on(not settingList[PARTICLES]) + " Particle Effects"], TOGGLE_FULLSCREEN:["Video Mode: " + getScreenMode(settingList[SETTING_FULLSCREEN]), "Switch To " + getScreenMode(not settingList[SETTING_FULLSCREEN]) + " Mode"], EXIT_OPTIONS:["Back","Go Back to the Main Menu"]} optionResult = menu.Menu(self.screen, self.musicList[self.worldNumber], screenGrab, [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ["Options",96,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], optionMenuDictionary, lastHighlighted).displayMenu() if optionResult == SOUND_MENU: soundResult = True lastHighLighted = 0 while soundResult: soundResult = menu.Menu(self.screen, self.musicList[self.worldNumber], screenGrab, [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ["Sound Options",96,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], soundMenuDictionary, lastHighlighted).displayMenu() if soundResult == TOGGLE_SFX: settingList[SFX] = not settingList[SFX] lastHighlighted = 0 elif soundResult == TOGGLE_MUSIC: settingList[MUSIC] = not settingList[MUSIC] if not settingList[MUSIC]: pygame.mixer.Channel(MUSIC_CHANNEL).stop() lastHighlighted = 1 elif soundResult == EXIT_OPTIONS: soundResult = False soundMenuDictionary = {TOGGLE_SFX:["Sound Effects: " + on(settingList[SFX]), "Turn " + on(not settingList[SFX]) + " Sound Effects"], TOGGLE_MUSIC:["Music: " + on(settingList[MUSIC]),"Turn " + on(not settingList[MUSIC]) + " Music"], EXIT_OPTIONS:["Back","Go Back to the Option Menu"]} if optionResult == DISPLAY_MENU: displayResult = True lastHighlighted = 0 while displayResult: displayResult = menu.Menu(self.screen, self.musicList[self.worldNumber], screenGrab, [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ["Video Options",96,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], displayMenuDictionary, lastHighlighted).displayMenu() if displayResult == TOGGLE_PARTICLES: settingList[PARTICLES] = not settingList[PARTICLES] lastHighlighted = 0 elif displayResult == TOGGLE_FULLSCREEN: settingList[SETTING_FULLSCREEN] = not settingList[SETTING_FULLSCREEN] lastHighlighted = 1 pygame.mixer.quit() pygame.mixer.init() if settingList[SETTING_FULLSCREEN]: utility.setFullscreen() else: utility.setFullscreen(False) pygame.mouse.set_visible(False) elif displayResult == EXIT_OPTIONS: displayResult = False displayMenuDictionary = {TOGGLE_PARTICLES:["Particles: " + able(settingList[PARTICLES]), "Turn " + on(not settingList[PARTICLES]) + " Particle Effects"], TOGGLE_FULLSCREEN:["Video Mode: " + getScreenMode(settingList[SETTING_FULLSCREEN]), "Switch To " + getScreenMode(not settingList[SETTING_FULLSCREEN]) + " Mode"], EXIT_OPTIONS:["Back","Go Back to the Main Menu"]} elif optionResult == EXIT_OPTIONS: optionResult = False elif optionResult == CHANGE_SENSITIVITY: sensitivityResult = True lastHighlighted = 0 while sensitivityResult: sensitivityResult = menu.Menu(self.screen, self.musicList[self.worldNumber], screenGrab, [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ["Mouse Sensitivity",96,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], sensitivityMenuDictionary, lastHighlighted).displayMenu() if sensitivityResult == 0: settingList[SENSITIVITY] = .5 elif sensitivityResult == 1: settingList[SENSITIVITY] = .75 sensitivityResult = False elif sensitivityResult == 2: settingList[SENSITIVITY] = 1 sensitivityResult = False elif sensitivityResult == 3: settingList[SENSITIVITY] = 1.25 sensitivityResult = False elif sensitivityResult == 4: settingList[SENSITIVITY] = 1.5 sensitivityResult = False elif pauseMenu == RESUME_GAME or pauseMenu == False: pauseMenuRunning = False pygame.mouse.get_rel() elif pauseMenu == EXIT_GAME: utility.fadeMusic() utility.playMusic(self.musicList[MENU_MUSIC], True) self.done = True pauseMenuRunning = False elif event.type == MOUSEMOTION and self.player.lives: mousein = [pygame.mouse.get_pos()[0] - 512.0, pygame.mouse.get_pos()[1] - 384.0] if mousein[0] != 0 and mousein[1] != 0: self.player.fire() self.player.velocity = (self.player.velocity + mousein) / 1.5 * settingList[SENSITIVITY]
def run(self): while not self.done: if self.worldDone: if self.worldNumber < MAX_WORLD: self.worldBeat() """Resetting player lives so that it isn't in their best interest to play easier worlds just to have extra lives.""" self.player.lives = 3 self.player.lifeBoard.setText('x' + str(self.player.lives)) self.player.score = 0 self.player.nextBonus = 50000 """Loading the new world""" self.worldNumber += 1 if self.worldNumber == 0: self.newScene = scene.tutorialScene() elif self.worldNumber == 1: self.newScene = scene.forestScene() elif self.worldNumber == 2: self.newScene = scene.rockyScene() elif self.worldNumber == 3: self.newScene = scene.pinkScene() if self.worldNumber > settingList[WORLD_UNLOCKED]: settingList[WORLD_UNLOCKED] = self.worldNumber utility.playMusic(self.musicList[self.worldNumber],True) self.currentWorld = world.World(self.worldList[self.worldNumber], self.musicList[self.worldNumber]) self.currentWorld.load() self.worldDone = False else: self.gameBeat() self.checkCollision() self.update() self.draw() self.handleEvents() pygame.mouse.set_pos(MOUSE_DEFAULT_POSITION) pygame.mouse.get_rel() self.mouseLastMove = pygame.mouse.get_pos() self.timer.tick(FRAMES_PER_SECOND) if self.player.dead: highScore = readHighScores() if self.player.score < highScore[self.worldNumber]: endGameDictionary = {HIGH_SCORE:["High Score For This World: " + str(highScore[self.worldNumber]), "You would need to score " + str(highScore[self.worldNumber] - self.player.score) + " more to beat it!"], NEXT_WORLD:["Exit","Return To The Menu"]} elif self.player.score == highScore[self.worldNumber]: endGameDictionary = {HIGH_SCORE:["High Score For This World: " + str(highScore[self.worldNumber]), "You Tied the High Score!"], NEXT_WORLD:["Exit","Return To The Menu"]} else: endGameDictionary = {HIGH_SCORE:["High Score For This World: " + str(highScore[self.worldNumber]), "You Beat the High Score!"], NEXT_WORLD:["Exit","Return To The Menu"]} highScore[self.worldNumber] = self.player.score writeHighScores(highScore) utility.dim(128,FILL_COLOR) endGameMenu = menu.Menu(self.screen, self.musicList[self.worldNumber], self.screen.convert(), [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ["Game Over",128,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], endGameDictionary).displayMenu() self.done = True utility.fadeMusic() utility.playMusic(self.musicList[MENU_MUSIC], True)
def displayMenu(self): self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) pygame.mouse.get_rel() mouseTimeout = 10 sampleMouse = True while True: """Music Stuff""" utility.playMusic(self.musicList) """Drawing Stuff""" self.screen.fill(FILL_COLOR) self.menuGroup.update() self.menuTooltipGroup.update() self.cursorGroup.update() try: self.screen.blit(self.backgroundImage, self.backgroundImage.get_rect()) except: self.backgroundImage.draw(self.screen) self.menuGroup.draw(self.screen) self.menuTooltipPointer[self.currentSelection].draw(self.screen) self.cursorGroup.draw(self.screen) pygame.display.flip() self.cursor.position = vector.vector2d(pygame.mouse.get_pos()) + vector.vector2d(32,32) """Event Handling Stuff""" for event in pygame.event.get(): if event.type == pygame.KEYDOWN and (event.key == pygame.K_SPACE or event.key == pygame.K_RETURN): utility.playSound(self.menuForward) return self.menuDictionary.keys()[self.currentSelection] elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: utility.playSound(self.menuForward) return self.menuDictionary.keys()[self.currentSelection] elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: utility.playSound(self.menuBack) return False elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3: utility.playSound(self.menuBack) return False elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection -= 1 if self.currentSelection < 0: self.currentSelection = len(self.menuDictionary) - 1 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) utility.playSound(self.menuBeep) elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection += 1 if self.currentSelection > len(self.menuDictionary) - 1: self.currentSelection = 0 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) utility.playSound(self.menuBeep) elif event.type == pygame.MOUSEMOTION: for element in self.menuGroup: if element.mouseOver(): if (element.textIndex != self.currentSelection): self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) mouseSelection = element.textIndex self.currentSelection = mouseSelection self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) utility.playSound(self.menuBeep) # """elif event.type == pygame.KEYDOWN and event.key == pygame.K_q: for element in self.menuTooltipGroup: print "ELEMENT: ", element.textIndex element.mouseOverDump()""" """elif event.type == pygame.MOUSEMOTION: mouseInput = list(pygame.mouse.get_rel()) if sampleMouse: if mouseInput[1] < -10: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection -= 1 if self.currentSelection < 0: self.currentSelection = len(self.menuDictionary) - 1 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) sampleMouse = False utility.playSound(self.menuBeep) elif mouseInput[1] > 10: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection += 1 if self.currentSelection > len(self.menuDictionary) - 1: self.currentSelection = 0 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) sampleMouse = False utility.playSound(self.menuBeep) """ if not sampleMouse: mouseTimeout -= 1 if mouseTimeout == 0: sampleMouse = True mouseTimeout = 3 self.timer.tick(30)