Exemplo n.º 1
0
    def replay(self):
        if time.clock() - self.timer > 2:
            node = self.first
            self.loadChar()
            self.getLevel(self.levelNumber)
            self.currLevel.setPlayer(self.char, 0, 0)
            self.currLevel.player.rect.x = int(self.x)
            self.currLevel.player.rect.y = int(self.y)
            self.currLevel.player.can_get_hurt = False
            self.currLevel.plotOver = True
            while node != None:
                milliStart = pygame.time.get_ticks()
                eventmanager.get().handleEvents(node.events)
                if self.currLevel.levelNumber == 0:
                    self.screen.fill(constants.LEVEL0_BGCOLOR)
                elif self.currLevel.levelNumber == 1:
                    self.screen.fill(constants.LEVEL1_BGCOLOR)
                else:
                    self.screen.fill(constants.DEFAULT_BGCOLOR)
                self.currLevel.draw(self.camera)
                self.currLevel.update()
                player_rect = self.currLevel.get_player_rect()
                self.camera.updatePosition(player_rect)
                pygame.display.flip()

                #Stop timer and sleep for remainder of time
                milliEnd = pygame.time.get_ticks()
                leftover = constants.mSPF - (milliEnd - milliStart)
                if leftover > 0: pygame.time.wait(int(leftover))
                node = node.next
            print("replay ran")
            self.timer = time.clock()
        else:
            print("false replay stopped")
Exemplo n.º 2
0
	def replay(self):
		if time.clock() - self.timer > 2 :
			node = self.first
			self.loadChar()			    
			self.getLevel(self.levelNumber)
			self.currLevel.setPlayer(self.char, 0, 0)
			self.currLevel.player.rect.x = int(self.x)
			self.currLevel.player.rect.y = int(self.y)
			self.currLevel.player.can_get_hurt = False
			self.currLevel.plotOver = True
			while node != None:
				milliStart = pygame.time.get_ticks()
				eventmanager.get().handleEvents(node.events)
				if self.currLevel.levelNumber == 0:
					self.screen.fill(constants.LEVEL0_BGCOLOR)
				elif self.currLevel.levelNumber == 1:
					self.screen.fill(constants.LEVEL1_BGCOLOR)
				else:
					self.screen.fill(constants.DEFAULT_BGCOLOR)
				self.currLevel.draw(self.camera)
				self.currLevel.update()
				player_rect = self.currLevel.get_player_rect()
				self.camera.updatePosition(player_rect)
				pygame.display.flip()

				#Stop timer and sleep for remainder of time
				milliEnd = pygame.time.get_ticks()
				leftover = constants.mSPF - (milliEnd - milliStart)
				if leftover > 0: pygame.time.wait(int(leftover))
				node = node.next
			print("replay ran")
			self.timer = time.clock()
		else:
			print("false replay stopped")
Exemplo n.º 3
0
    def handleCollision(self, a, b):
        #sentinel overlap values
        topOverlap = -500
        botOverlap = 500
        leftOverlap = -500
        rightOverlap = 500
        
        #If either object isn't solid we don't care
        if not a.solid or not b.solid: return


        #check for the actual overlaps
        #from the perspective of the player
        if(a.rect.top - b.rect.bottom < 0):
            topOverlap = a.rect.top - b.rect.bottom
        if(a.rect.bottom - b.rect.top > 0):
            botOverlap = a.rect.bottom- b.rect.top
        if(a.rect.left - b.rect.right < 0):
            leftOverlap = a.rect.left - b.rect.right
        if(a.rect.right - b.rect.left > 0):
            rightOverlap = a.rect.right - b.rect.left

        #correct only the smallest overlap
        #top overlap
        if min(abs(topOverlap), botOverlap, abs(leftOverlap), rightOverlap) == abs(topOverlap):
            if(topOverlap != -500):
                a.stallY()
                a.rect.top = b.rect.bottom
                if b.teleporter == True and b.teleportDir == UP and eventmanager.get().UPPRESSED:
                    #if a.rect.left > b.rect.left and a.rect.right < b.rect.right:
                    b.teleport()
        #bottom overlap
        elif min(abs(topOverlap), botOverlap, abs(leftOverlap), rightOverlap) == botOverlap:
            if(botOverlap != 500):
                a.stallY()
                a.isJumping = False
                a.rect.bottom = b.rect.top
                #check for teleporter
                if b.teleporter == True and b.teleportDir == DOWN and eventmanager.get().DOWNPRESSED:
                    #if a.rect.left > b.rect.left and a.rect.right < b.rect.right:
                    b.teleport()
        #left overlap
        elif min(abs(topOverlap), botOverlap, abs(leftOverlap), rightOverlap) == abs(leftOverlap):
            if(leftOverlap != -500):
                a.stallX()
                a.rect.left = b.rect.right
                if b.teleporter == True and b.teleportDir == LEFT and eventmanager.get().LEFTPRESSED:
                    b.teleport()
        #right overlap
        elif min(abs(topOverlap), botOverlap, abs(leftOverlap), rightOverlap) == rightOverlap:
            if(rightOverlap != 500):
                a.stallX()
                a.rect.right = b.rect.left
                if b.teleporter == True and b.teleportDir == RIGHT and eventmanager.get().RIGHTPRESSED:
                    b.teleport()

        b.try_hurt(a)
Exemplo n.º 4
0
    def update(self):

        evman = eventmanager.get()

        if evman.MOUSE1CLICK != False:
            event = evman.MOUSE1CLICK
            clickpoint = event.pos
            clickpoint = (self.camera.window.left+clickpoint[0],self.camera.window.top+clickpoint[1])
            if self.resumeIm.get_rect().collidepoint(clickpoint):
                eventmanager.get().togglePause()
            elif self.restartIm.get_rect().collidepoint(clickpoint):
                self.restartLevel = True
            elif self.quitIm.get_rect().collidepoint(clickpoint):
                self.showMainMenu = True
Exemplo n.º 5
0
	def update(self):

		evman = eventmanager.get()

		if evman.MOUSE1CLICK != False:
			event = evman.MOUSE1CLICK
			clickpoint = event.pos
			clickpoint = (self.camera.window.left+clickpoint[0],self.camera.window.top+clickpoint[1])
			if self.hulk.get_rect().collidepoint(clickpoint):
				self.setChar(1)

			elif self.thor.get_rect().collidepoint(clickpoint):
				self.setChar(2)

			elif self.america.get_rect().collidepoint(clickpoint):
				self.setChar(3)

			elif self.ironman.get_rect().collidepoint(clickpoint):
				self.setChar(4)

			elif self.hawkeye.get_rect().collidepoint(clickpoint):
				self.setChar(5)
				
			elif self.blackwidow.get_rect().collidepoint(clickpoint):
				self.setChar(6)
Exemplo n.º 6
0
    def update(self):

        evman = eventmanager.get()

        if evman.MOUSE1CLICK != False:
            event = evman.MOUSE1CLICK
            clickpoint = event.pos
            #clickpoint = (camera.window.left+clickpoint[0],camera.window.top+clickpoint[1])

            if self.volume_button.get_rect().collidepoint(clickpoint):
                self.vol = not self.vol
                if self.vol:
                    sound.set_bgm_vol(self.bgm_vol)
                    sound.set_sfx_vol(self.sfx_vol)
                else:
                    #update the volume before muting
                    self.bgm_vol = sound.get_bgm_vol()
                    self.sfx_vol = sound.get_sfx_vol()
                    sound.set_bgm_vol(0)
                    sound.set_sfx_vol(0)

#            else
#                self.playing = True
                  
            if self.plot_skip_button.get_rect().collidepoint(clickpoint):
                self.plotOver = True
            elif self.plot_next_button.get_rect().collidepoint(clickpoint) and self.currentPlot < self.maxPlot:
                self.currentPlot = self.currentPlot + 1
            elif self.plot_back_button.get_rect().collidepoint(clickpoint) and self.currentPlot > 1:
                self.currentPlot = self.currentPlot - 1
            elif self.plot_back_button.get_rect().collidepoint(clickpoint) and self.currentPlot == 1:
                pass
            elif self.plot_next_button.get_rect().collidepoint(clickpoint) and self.currentPlot == self.maxPlot:
                self.plotOver = True
Exemplo n.º 7
0
    def update(self):
        self.anim.update()
        #If we're not alive don't process anything
        if self.alive:
            #Do any updates pertaining to the child character class.
            #If the child class hasn't implemented the method, don't worry about it
            try:
                self.charSpecificUpdate()
            except AttributeError:
                pass
            evman = eventmanager.get()

            #replay
            #if evman.REPLAYPRESSED and logger.get().replayCanRun:
            #	logger.get().replay()
            #	logger.get().replayCanRun = True

        #update rect with new image
        #we use bottomleft so it doesn't mess with collision detection
        oldxy = self.rect.bottomleft
        self.rect = self.anim.get_rect()
        self.rect.bottomleft = oldxy

        #Oh snap gravity!
        self.velY += 1
        self.rect.move_ip(self.velX, self.velY)
Exemplo n.º 8
0
    def update(self):
        evman = eventmanager.get()
        if evman.MOUSE1CLICK != False:
            event = evman.MOUSE1CLICK
            clickpoint = event.pos

            if self.volume_button.get_rect().collidepoint(clickpoint):
                self.vol = not self.vol
                if self.vol:
                    sound.set_bgm_vol(self.bgm_vol)
                    sound.set_sfx_vol(self.sfx_vol)
                else:
                    #update the volume before muting
                    self.bgm_vol = sound.get_bgm_vol()
                    self.sfx_vol = sound.get_sfx_vol()
                    sound.set_bgm_vol(0)
                    sound.set_sfx_vol(0)
Exemplo n.º 9
0
    def update(self):
        evman = eventmanager.get()
        if evman.MOUSE1CLICK != False:
            event = evman.MOUSE1CLICK
            clickpoint = event.pos

            if self.volume_button.get_rect().collidepoint(clickpoint):
                self.vol = not self.vol
                if self.vol:
                    sound.set_bgm_vol(self.bgm_vol)
                    sound.set_sfx_vol(self.sfx_vol)
                else:
                    #update the volume before muting
                    self.bgm_vol = sound.get_bgm_vol()
                    self.sfx_vol = sound.get_sfx_vol()
                    sound.set_bgm_vol(0)
                    sound.set_sfx_vol(0)
Exemplo n.º 10
0
	def update(self):
		self.anim.update()
		#If we're not alive don't process anything
		if self.alive:
			#Do any updates pertaining to the child character class.
			#If the child class hasn't implemented the method, don't worry about it
			try: self.charSpecificUpdate()
			except AttributeError: pass
			evman = eventmanager.get()
			
			#replay
			#if evman.REPLAYPRESSED and logger.get().replayCanRun:
			#	logger.get().replay()
			#	logger.get().replayCanRun = True

		#update rect with new image
		#we use bottomleft so it doesn't mess with collision detection
		oldxy = self.rect.bottomleft
		self.rect = self.anim.get_rect()
		self.rect.bottomleft = oldxy

		#Oh snap gravity!
		self.velY += 1
		self.rect.move_ip(self.velX,self.velY)
Exemplo n.º 11
0
    def handleCollision(self, a, b):
        #sentinel overlap values
        topOverlap = -500
        botOverlap = 500
        leftOverlap = -500
        rightOverlap = 500

        #If either object isn't solid we don't care
        if not a.solid or not b.solid: return

        #check for the actual overlaps
        #from the perspective of the player
        if (a.rect.top - b.rect.bottom < 0):
            topOverlap = a.rect.top - b.rect.bottom
        if (a.rect.bottom - b.rect.top > 0):
            botOverlap = a.rect.bottom - b.rect.top
        if (a.rect.left - b.rect.right < 0):
            leftOverlap = a.rect.left - b.rect.right
        if (a.rect.right - b.rect.left > 0):
            rightOverlap = a.rect.right - b.rect.left

        #correct only the smallest overlap
        #top overlap
        if min(abs(topOverlap), botOverlap, abs(leftOverlap),
               rightOverlap) == abs(topOverlap):
            if (topOverlap != -500):
                a.stallY()
                a.rect.top = b.rect.bottom
                if b.teleporter == True and b.teleportDir == UP and eventmanager.get(
                ).UPPRESSED:
                    #if a.rect.left > b.rect.left and a.rect.right < b.rect.right:
                    b.teleport()
        #bottom overlap
        elif min(abs(topOverlap), botOverlap, abs(leftOverlap),
                 rightOverlap) == botOverlap:
            if (botOverlap != 500):
                a.stallY()
                a.isJumping = False
                a.rect.bottom = b.rect.top
                #check for teleporter
                if b.teleporter == True and b.teleportDir == DOWN and eventmanager.get(
                ).DOWNPRESSED:
                    #if a.rect.left > b.rect.left and a.rect.right < b.rect.right:
                    b.teleport()
        #left overlap
        elif min(abs(topOverlap), botOverlap, abs(leftOverlap),
                 rightOverlap) == abs(leftOverlap):
            if (leftOverlap != -500):
                a.stallX()
                a.rect.left = b.rect.right
                if b.teleporter == True and b.teleportDir == LEFT and eventmanager.get(
                ).LEFTPRESSED:
                    b.teleport()
        #right overlap
        elif min(abs(topOverlap), botOverlap, abs(leftOverlap),
                 rightOverlap) == rightOverlap:
            if (rightOverlap != 500):
                a.stallX()
                a.rect.right = b.rect.left
                if b.teleporter == True and b.teleportDir == RIGHT and eventmanager.get(
                ).RIGHTPRESSED:
                    b.teleport()

        b.try_hurt(a)
Exemplo n.º 12
0
    def update(self):
        #Game loop
        wasplaying = True  #Hack to figure out when we need to change sounds
        self.timer = 0
        self.frameCount = 0  #Timer logic: after 30 frames, increment hud timer

        self.didTeleport = False
        while True:

            #Start timer and handle events
            milliStart = pygame.time.get_ticks()
            events = pygame.event.get()
            logEvents = eventmanager.get().handleEvents(events)
            #if event = r or pause --> don't log
            if logEvents:
                logger.get().add(logger.LogNode(events))
                if (time.clock() - self.timer > 2) and self.invincible:
                    self.stopInvincibility()
            elif eventmanager.get().REPLAYPRESSED == True:
                #save game before hand
                self.saveState()
                logger.get().replay()
                self.saveCharSelection(
                )  # for some reason, replay resets the save file's char to 0
                self.loadLevel(0)
                #give temporary invincibility -> for 2 seconds
                self.tempInvincibility()

            #player is playing the game
            if self.startMenu.isPlaying():

                if not wasplaying: sound.play_bgm(self.currLevel.bgm)

                #player died
                if not self.currLevel.player_alive:
                    self.player_lives -= 1
                    #reset logger
                    logger.get().setStart(self.currLevel.player.rect.x,
                                          self.currLevel.player.rect.y)
                    logger.get().clear()
                    #reload level
                    self.loadLevel()
                    #check if died due to teleportation
                    if self.didTeleport:
                        sound.play_bgm(self.currLevel.bgm)
                        self.didTeleport = False

                    #game over
                    if self.player_lives < 1:
                        self.currLevel.charSelected = False
                        self.currLevel.charsel.char = 0
                        self.screen.fill(0)
                        gameover = StaticImage("images/gameover.jpg", 0, 0)
                        gameover.rect.topleft = self.camera.window.centerx - gameover.rect.width/2,\
                                                self.camera.window.centery - gameover.rect.width/2
                        gameover.draw(self.camera)
                        pygame.display.flip()
                        time.sleep(3)
                        self.player_lives = constants.PLAYER_LIVES
                        logger.get().setStart(0, 500)

                #select bg color depending on level
                #hopefully to cut down on image size
                if self.currLevel.levelNumber == -1:
                    self.screen.fill(constants.LEVELNEG1_BGCOLOR)
                elif self.currLevel.levelNumber == 0:
                    self.screen.fill(constants.LEVEL0_BGCOLOR)
                elif self.currLevel.levelNumber == 1:
                    self.screen.fill(constants.LEVEL1_BGCOLOR)
                elif self.currLevel.levelNumber == 3:
                    self.screen.fill(constants.LEVEL3_BGCOLOR)
                else:
                    self.screen.fill(constants.DEFAULT_BGCOLOR)
                self.currLevel.draw(self.camera)

                if self.currLevel.charSelected and self.currLevel.plotOver:
                    #Hud timer logic
                    self.frameCount = self.frameCount + 1
                    if self.frameCount > 30:
                        self.hud.incTime()
                        self.frameCount = 0
                    self.hud.draw(self.camera, self)

                #Update player and enemies positions/current actions
                if not eventmanager.get().isPaused():
                    self.currLevel.update()
                    if self.currLevel.charSelected:
                        self.hud.update()
                    #check for telportation
                    if constants.TELEPORT == True:
                        wasplaying = False
                        self.handleTeleport()
                        constants.TELEPORT = False
                    #check for level completion
                    if self.currLevel.levelCompleted:
                        wasplaying = False
                        self.levelNumber += 1
                        self.hud.resetTime()
                        self.currLevel = self.getCurrentLevel()
                        logger.get().clear()
                    else:
                        wasplaying = True

                else:
                    #show pause menu
                    self.pauseMenu.draw(self.camera)
                    self.pauseMenu.update()
                    #'quit to main' clicked
                    if self.pauseMenu.showMainMenu:
                        self.startMenu.playing = False
                        self.startMenu.show_level = False
                        self.currLevel = self.getCurrentLevel()
                        self.pauseMenu.showMainMenu = False
                        eventmanager.get().PAUSED = False
                    elif self.pauseMenu.restartLevel:
                        #'restart level' clicked
                        self.hud.resetTime()
                        self.currLevel = self.getCurrentLevel()
                        self.pauseMenu.restartLevel = False
                        eventmanager.get().PAUSED = False

                #Update camera position using player's
                player_rect = self.currLevel.get_player_rect()
                self.camera.updatePosition(player_rect)

            else:

                #update inputs from startMenu
                if wasplaying: sound.play_bgm(self.startMenu.bgm)
                self.startMenu.update()
                self.camera.zeroPosition()
                self.startMenu.draw(self.camera)
                wasplaying = False

                if self.startMenu.isPlaying():
                    self.levelNumber = self.startMenu.getLevel()
                    self.hud.resetTime()
                    self.currLevel = self.getCurrentLevel()
                    logger.get().clear()

                #'Load Game' clicked
                if self.startMenu.loadLevel:
                    self.loadLevel()

            #Fill the screen, draw level, flip the buffer
            pygame.display.flip()

            #Stop timer and sleep for remainder of time
            milliEnd = pygame.time.get_ticks()
            leftover = constants.mSPF - (milliEnd - milliStart)
            #sys.stdout.write('Time left in frame: %s\n' % leftover)
            if leftover > 0: pygame.time.wait(int(leftover))
Exemplo n.º 13
0
    def update(self):

        evman = eventmanager.get()

        if evman.MOUSE1CLICK != False:
            event = evman.MOUSE1CLICK
            clickpoint = event.pos

            #StartMenu
            if not self.show_instructions and not self.show_options and not self.show_level:
                #new game
                if self.newgame_button.get_rect().collidepoint(clickpoint):
                    #self.currentLevel = 0
                    self.show_level = True
                #load game
                elif self.loadgame_button.get_rect().collidepoint(clickpoint):
                    if os.path.isfile('save'):
                        self.loadLevel = True

                #options
                elif self.options_button.get_rect().collidepoint(clickpoint):
                    self.show_instructions = False
                    self.show_options = True
                #exit
                elif self.quit_button.get_rect().collidepoint(clickpoint):
                    print("Exiting....")
                    sys.exit(0)

                #isntructions
                elif self.instructions_button.get_rect().collidepoint(clickpoint):
                    self.show_options = False
                    self.show_instructions = True

            #Options Menu
            elif self.show_options:
                if self.volup_button.get_rect().collidepoint(clickpoint):
                    #clicked bgm vol up
                    sound.set_bgm_vol(sound.get_bgm_vol() + 10)
                    sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol()))
                elif self.voldown_button.get_rect().collidepoint(clickpoint):
                    #clicked bgm vol down
                    sound.set_bgm_vol(sound.get_bgm_vol() - 10)
                    sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol()))
                elif self.volupFX_button.get_rect().collidepoint(clickpoint):
                    #clicked sfx vol up
                    sound.set_sfx_vol(sound.get_sfx_vol() + 10)
                    sound.play_sfx('sounds/sfx/punch.wav')
                    sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol()))
                elif self.voldownFX_button.get_rect().collidepoint(clickpoint):
                    #clicked sfx vol down
                    sound.set_sfx_vol(sound.get_sfx_vol() - 10)
                    sound.play_sfx('sounds/sfx/punch.wav')
                    sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol()))
                elif self.gammaUp_button.get_rect().collidepoint(clickpoint):
                    #clicked gamma up
                    if self.gamma < 2.5:
                        self.gamma = self.gamma + .1
                    pygame.display.set_gamma(self.gamma)
                    sys.stdout.write('Gamma: %s\n' % (self.gamma))
                elif self.gammaDown_button.get_rect().collidepoint(clickpoint):
                    #clicked gamma down
                    if self.gamma > 0.2:
                        self.gamma = self.gamma - .1
                    pygame.display.set_gamma(self.gamma)
                    sys.stdout.write('Gamma: %s\n' % (self.gamma))
                elif self.options_back_button.get_rect().collidepoint(clickpoint):
                    #clicked back
                    self.show_options = False
            #Options Menu
            elif self.show_level:
                if self.lvltut.get_rect().collidepoint(clickpoint):
                    self.setLevel(0)
                elif self.lvl1.get_rect().collidepoint(clickpoint):
                    self.setLevel(1)
                elif self.lvl2.get_rect().collidepoint(clickpoint):
                    self.setLevel(2)
                elif self.lvl3.get_rect().collidepoint(clickpoint):
                    self.setLevel(3)
                elif self.lvl4.get_rect().collidepoint(clickpoint):
                    self.setLevel(4)
                elif self.lvl5.get_rect().collidepoint(clickpoint):
                    self.setLevel(5)
                
            #if on instructions go back to StartMenu
            else:
                if self.back_button.get_rect().collidepoint(clickpoint):
                    if self.show_instructions:
                        self.show_instructions = False
                    elif self.show_options:
                        self.show_options = False
Exemplo n.º 14
0
    def charSpecificUpdate(self):
        
        if (time.time() - self.timer > 10) and self.has_star :
            self.stopStar()

        evman = eventmanager.get()

        if (evman.SPECPRESSED and self.sattack_ammo > 0) or self.sattack_timer != 0:
            #Special attack takes precedence and stops normal attack
            self.attack_timer = 0

            if self.sattack_timer == 0:
                self.decAmmo()

            self._play_special()
            try: self.special_attack()
            except AttributeError: pass

        elif evman.NORMPRESSED or self.attack_timer != 0: #normal attack pressed

            try: self.normal_attack()
            except AttributeError:
    
                if self.isJumping:
                    self._load_image( self.jump_attack )
                else:
                    self._load_image( self.norm_attack )
    
                #mid attack
                if self.attack_timer > 1:
                    self.attacking = True
                    self.attack_timer -= 1
                    self.velX = self.primary_attack_speed if self.facingRight else -1*self.primary_attack_speed
    
                #start recovery phase
                elif self.attack_timer == 1:
                    self.attacking = False
                    self.attack_timer = -1*self.primary_attack_recovery
                    if not self.isJumping: self.stallX()
    
                #start attack
                elif self.attack_timer == 0:
                    self.attacking = True
                    self.attack_timer = self.primary_attack_length
                    #now plays a random sound which may or may not be captain falcon
                    self._play_attack()
    
                #mid recovery
                else:
                    self.attacking = False
                    self.attack_timer += 1
                    if not self.isJumping: self.stallX()


        elif evman.LEFTPRESSED: #left key pressed
            self.velX = -self.runVel
            self.facingRight = False
            self._load_image( self.walk )

        elif evman.RIGHTPRESSED: #right key pressed
            self.velX = self.runVel
            self.facingRight = True
            self._load_image( self.walk )

        else:
            self.velX = 0
            if not self.isJumping:
                self._load_image( self.stand )

        #Attack animation overrides others
        if not self.attacking:
            if self.isJumping:
                self._load_image( self.jump )

            #jumping upwards
            elif evman.SPACEPRESSED:
                self.isJumping = True
                self.velY -= self.jumpVel
                self._load_image( self.jump )
                self._play_jump()
Exemplo n.º 15
0
    def update(self):
        #Game loop
        wasplaying = True #Hack to figure out when we need to change sounds
        self.timer = 0
        self.frameCount = 0 #Timer logic: after 30 frames, increment hud timer

        self.didTeleport = False
        while True:

            #Start timer and handle events
            milliStart = pygame.time.get_ticks()
            events = pygame.event.get()
            logEvents = eventmanager.get().handleEvents(events)
            #if event = r or pause --> don't log
            if logEvents :
                logger.get().add(logger.LogNode(events))
                if (time.clock() - self.timer > 2) and self.invincible :
                    self.stopInvincibility()
            elif eventmanager.get().REPLAYPRESSED == True :
                #save game before hand
                self.saveState()
                logger.get().replay()
                self.saveCharSelection() # for some reason, replay resets the save file's char to 0
                self.loadLevel(0)
                #give temporary invincibility -> for 2 seconds
                self.tempInvincibility()

            #player is playing the game
            if self.startMenu.isPlaying():

                if not wasplaying: sound.play_bgm(self.currLevel.bgm)

                #player died
                if not self.currLevel.player_alive:
                    self.player_lives -= 1
                    #reset logger
                    logger.get().setStart(self.currLevel.player.rect.x, self.currLevel.player.rect.y)
                    logger.get().clear()
                    #reload level
                    self.loadLevel()
                    #check if died due to teleportation
                    if self.didTeleport:
                        sound.play_bgm(self.currLevel.bgm)
                        self.didTeleport = False

                    #game over
                    if self.player_lives < 1:
                        self.currLevel.charSelected = False
                        self.currLevel.charsel.char = 0
                        self.screen.fill(0)
                        gameover = StaticImage( "images/gameover.jpg", 0, 0 )
                        gameover.rect.topleft = self.camera.window.centerx - gameover.rect.width/2,\
                                                self.camera.window.centery - gameover.rect.width/2
                        gameover.draw(self.camera)
                        pygame.display.flip()
                        time.sleep(3)
                        self.player_lives = constants.PLAYER_LIVES
                        logger.get().setStart(0, 500)

                #select bg color depending on level
                #hopefully to cut down on image size
                if self.currLevel.levelNumber == -1:
                    self.screen.fill(constants.LEVELNEG1_BGCOLOR)
                elif self.currLevel.levelNumber == 0:
                    self.screen.fill(constants.LEVEL0_BGCOLOR)
                elif self.currLevel.levelNumber == 1:
                    self.screen.fill(constants.LEVEL1_BGCOLOR)
                elif self.currLevel.levelNumber == 3:
                    self.screen.fill(constants.LEVEL3_BGCOLOR)
                else:
                    self.screen.fill(constants.DEFAULT_BGCOLOR)
                self.currLevel.draw(self.camera)

                if self.currLevel.charSelected and self.currLevel.plotOver:
                    #Hud timer logic
                    self.frameCount = self.frameCount + 1
                    if self.frameCount > 30:
                        self.hud.incTime()
                        self.frameCount = 0
                    self.hud.draw(self.camera, self)

                #Update player and enemies positions/current actions
                if not eventmanager.get().isPaused():
                    self.currLevel.update()
                    if self.currLevel.charSelected:
                        self.hud.update()
                    #check for telportation
                    if constants.TELEPORT == True:
                        wasplaying = False
                        self.handleTeleport()
                        constants.TELEPORT = False
                    #check for level completion
                    if self.currLevel.levelCompleted:
                        wasplaying = False
                        self.levelNumber += 1
                        self.hud.resetTime()
                        self.currLevel = self.getCurrentLevel()
                        logger.get().clear()
                    else:
                        wasplaying = True

                else:
                #show pause menu
                    self.pauseMenu.draw(self.camera)
                    self.pauseMenu.update()
                    #'quit to main' clicked
                    if self.pauseMenu.showMainMenu:
                        self.startMenu.playing = False
                        self.startMenu.show_level = False
                        self.currLevel = self.getCurrentLevel()
                        self.pauseMenu.showMainMenu = False
                        eventmanager.get().PAUSED = False
                    elif self.pauseMenu.restartLevel:
                    #'restart level' clicked 
                        self.hud.resetTime()
                        self.currLevel = self.getCurrentLevel()
                        self.pauseMenu.restartLevel = False
                        eventmanager.get().PAUSED = False


                #Update camera position using player's
                player_rect = self.currLevel.get_player_rect()
                self.camera.updatePosition(player_rect)

            else:

                #update inputs from startMenu
                if wasplaying: sound.play_bgm(self.startMenu.bgm)
                self.startMenu.update()
                self.camera.zeroPosition()
                self.startMenu.draw(self.camera)
                wasplaying = False

                if self.startMenu.isPlaying():
                    self.levelNumber = self.startMenu.getLevel()
                    self.hud.resetTime()
                    self.currLevel = self.getCurrentLevel()
                    logger.get().clear()

                #'Load Game' clicked
                if self.startMenu.loadLevel:
                    self.loadLevel()
            
            #Fill the screen, draw level, flip the buffer
            pygame.display.flip()

            #Stop timer and sleep for remainder of time
            milliEnd = pygame.time.get_ticks()
            leftover = constants.mSPF - (milliEnd - milliStart)
            #sys.stdout.write('Time left in frame: %s\n' % leftover)
            if leftover > 0: pygame.time.wait(int(leftover))
Exemplo n.º 16
0
    def charSpecificUpdate(self):

        if (time.time() - self.timer > 10) and self.has_star:
            self.stopStar()

        evman = eventmanager.get()

        if (evman.SPECPRESSED
                and self.sattack_ammo > 0) or self.sattack_timer != 0:
            #Special attack takes precedence and stops normal attack
            self.attack_timer = 0

            if self.sattack_timer == 0:
                self.decAmmo()

            self._play_special()
            try:
                self.special_attack()
            except AttributeError:
                pass

        elif evman.NORMPRESSED or self.attack_timer != 0:  #normal attack pressed

            try:
                self.normal_attack()
            except AttributeError:

                if self.isJumping:
                    self._load_image(self.jump_attack)
                else:
                    self._load_image(self.norm_attack)

                #mid attack
                if self.attack_timer > 1:
                    self.attacking = True
                    self.attack_timer -= 1
                    self.velX = self.primary_attack_speed if self.facingRight else -1 * self.primary_attack_speed

                #start recovery phase
                elif self.attack_timer == 1:
                    self.attacking = False
                    self.attack_timer = -1 * self.primary_attack_recovery
                    if not self.isJumping: self.stallX()

                #start attack
                elif self.attack_timer == 0:
                    self.attacking = True
                    self.attack_timer = self.primary_attack_length
                    #now plays a random sound which may or may not be captain falcon
                    self._play_attack()

                #mid recovery
                else:
                    self.attacking = False
                    self.attack_timer += 1
                    if not self.isJumping: self.stallX()

        elif evman.LEFTPRESSED:  #left key pressed
            self.velX = -self.runVel
            self.facingRight = False
            self._load_image(self.walk)

        elif evman.RIGHTPRESSED:  #right key pressed
            self.velX = self.runVel
            self.facingRight = True
            self._load_image(self.walk)

        else:
            self.velX = 0
            if not self.isJumping:
                self._load_image(self.stand)

        #Attack animation overrides others
        if not self.attacking:
            if self.isJumping:
                self._load_image(self.jump)

            #jumping upwards
            elif evman.SPACEPRESSED:
                self.isJumping = True
                self.velY -= self.jumpVel
                self._load_image(self.jump)
                self._play_jump()
Exemplo n.º 17
0
    def update(self):

        evman = eventmanager.get()

        if evman.MOUSE1CLICK != False:
            event = evman.MOUSE1CLICK
            clickpoint = event.pos

            #StartMenu
            if not self.show_instructions and not self.show_options and not self.show_level:
                #new game
                if self.newgame_button.get_rect().collidepoint(clickpoint):
                    #self.currentLevel = 0
                    self.show_level = True
                #load game
                elif self.loadgame_button.get_rect().collidepoint(clickpoint):
                    if os.path.isfile('save'):
                        self.loadLevel = True

                #options
                elif self.options_button.get_rect().collidepoint(clickpoint):
                    self.show_instructions = False
                    self.show_options = True
                #exit
                elif self.quit_button.get_rect().collidepoint(clickpoint):
                    print("Exiting....")
                    sys.exit(0)

                #isntructions
                elif self.instructions_button.get_rect().collidepoint(
                        clickpoint):
                    self.show_options = False
                    self.show_instructions = True

            #Options Menu
            elif self.show_options:
                if self.volup_button.get_rect().collidepoint(clickpoint):
                    #clicked bgm vol up
                    sound.set_bgm_vol(sound.get_bgm_vol() + 10)
                    sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol()))
                elif self.voldown_button.get_rect().collidepoint(clickpoint):
                    #clicked bgm vol down
                    sound.set_bgm_vol(sound.get_bgm_vol() - 10)
                    sys.stdout.write('BGM vol: %s\n' % (sound.get_bgm_vol()))
                elif self.volupFX_button.get_rect().collidepoint(clickpoint):
                    #clicked sfx vol up
                    sound.set_sfx_vol(sound.get_sfx_vol() + 10)
                    sound.play_sfx('sounds/sfx/punch.wav')
                    sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol()))
                elif self.voldownFX_button.get_rect().collidepoint(clickpoint):
                    #clicked sfx vol down
                    sound.set_sfx_vol(sound.get_sfx_vol() - 10)
                    sound.play_sfx('sounds/sfx/punch.wav')
                    sys.stdout.write('SFX vol: %s\n' % (sound.get_sfx_vol()))
                elif self.gammaUp_button.get_rect().collidepoint(clickpoint):
                    #clicked gamma up
                    if self.gamma < 2.5:
                        self.gamma = self.gamma + .1
                    pygame.display.set_gamma(self.gamma)
                    sys.stdout.write('Gamma: %s\n' % (self.gamma))
                elif self.gammaDown_button.get_rect().collidepoint(clickpoint):
                    #clicked gamma down
                    if self.gamma > 0.2:
                        self.gamma = self.gamma - .1
                    pygame.display.set_gamma(self.gamma)
                    sys.stdout.write('Gamma: %s\n' % (self.gamma))
                elif self.options_back_button.get_rect().collidepoint(
                        clickpoint):
                    #clicked back
                    self.show_options = False
            #Options Menu
            elif self.show_level:
                if self.lvltut.get_rect().collidepoint(clickpoint):
                    self.setLevel(0)
                elif self.lvl1.get_rect().collidepoint(clickpoint):
                    self.setLevel(1)
                elif self.lvl2.get_rect().collidepoint(clickpoint):
                    self.setLevel(2)
                elif self.lvl3.get_rect().collidepoint(clickpoint):
                    self.setLevel(3)
                elif self.lvl4.get_rect().collidepoint(clickpoint):
                    self.setLevel(4)
                elif self.lvl5.get_rect().collidepoint(clickpoint):
                    self.setLevel(5)

            #if on instructions go back to StartMenu
            else:
                if self.back_button.get_rect().collidepoint(clickpoint):
                    if self.show_instructions:
                        self.show_instructions = False
                    elif self.show_options:
                        self.show_options = False