Exemplo n.º 1
0
    def draw(self,camera,avengers_obj):

        self.drawVol(camera)

        for i in range(0,avengers_obj.player_lives):
            self.heart.rect.topleft = ( camera.window.left + i*( self.heart.rect.width + 10) + 10,
                                        camera.window.top + 10 )
            self.heart.draw(camera)

        self.sattackbar.rect.topleft = camera.window.left + 10, camera.window.top + 55
        self.sattackbar.draw(camera)

        for i in range(0, avengers_obj.currLevel.player.sattack_ammo):
            self.sattackblock.rect.topleft = ( camera.window.left + 13 + i*self.sattackblock.rect.width,
                                               camera.window.top + 58 )
            self.sattackblock.draw(camera)
        
        self.time_title.rect.topleft = camera.window.right - 160, camera.window.top + 55
        self.time_title.draw(camera)
        for i in range(0, len(self.timeString)):
            self.digit = StaticImage( "images/hudsprites/%s.png" % self.timeString[i], 
                                          camera.window.right - 100 + i*(self.digit.rect.width-6), 
                                          camera.window.top + 64 )
            self.digit.draw(camera)
            #sys.stdout.write('String element: %s\n' % timer)
        
        self.score_title.rect.topleft = camera.window.right - 580, camera.window.top + 55
        self.score_title.draw(camera)    
        self.scoreString = score.get().getScore()
        
        for i in range(0, len(self.scoreString)):
            self.digit = StaticImage( "images/hudsprites/%s.png" % self.scoreString[i], 
                                          camera.window.right - 500 + i*(self.digit.rect.width-6), 
                                          camera.window.top + 63 )
            self.digit.draw(camera)
Exemplo n.º 2
0
    def draw(self,camera):
        if self.camera == None:
            self.camera = camera

        #to center: x:camera window + window width/2 - img width
        self.bgIm = StaticImage("images/menusprites/pauseScreen.png",camera.window.left+500-149,camera.window.top+300-218)
        self.resumeIm = StaticImage("images/menusprites/resume.png",camera.window.left+500-52,camera.window.top+300-70)
        self.restartIm = StaticImage("images/menusprites/restart.png",camera.window.left+500-57,camera.window.top+300-10)
        self.quitIm = StaticImage("images/menusprites/quittomain.png",camera.window.left+500-85,camera.window.top+300+50)

        self.bgIm.draw(camera)
        self.resumeIm.draw(camera)
        self.restartIm.draw(camera)
        self.quitIm.draw(camera)
Exemplo n.º 3
0
    def draw(self, camera, avengers_obj):

        self.drawVol(camera)

        for i in range(0, avengers_obj.player_lives):
            self.heart.rect.topleft = (camera.window.left + i *
                                       (self.heart.rect.width + 10) + 10,
                                       camera.window.top + 10)
            self.heart.draw(camera)

        self.sattackbar.rect.topleft = camera.window.left + 10, camera.window.top + 55
        self.sattackbar.draw(camera)

        for i in range(0, avengers_obj.currLevel.player.sattack_ammo):
            self.sattackblock.rect.topleft = (camera.window.left + 13 +
                                              i * self.sattackblock.rect.width,
                                              camera.window.top + 58)
            self.sattackblock.draw(camera)

        self.time_title.rect.topleft = camera.window.right - 160, camera.window.top + 55
        self.time_title.draw(camera)
        for i in range(0, len(self.timeString)):
            self.digit = StaticImage(
                "images/hudsprites/%s.png" % self.timeString[i],
                camera.window.right - 100 + i * (self.digit.rect.width - 6),
                camera.window.top + 64)
            self.digit.draw(camera)
            #sys.stdout.write('String element: %s\n' % timer)

        self.score_title.rect.topleft = camera.window.right - 580, camera.window.top + 55
        self.score_title.draw(camera)
        self.scoreString = score.get().getScore()

        for i in range(0, len(self.scoreString)):
            self.digit = StaticImage(
                "images/hudsprites/%s.png" % self.scoreString[i],
                camera.window.right - 500 + i * (self.digit.rect.width - 6),
                camera.window.top + 63)
            self.digit.draw(camera)
Exemplo n.º 4
0
    def draw(self,camera):
#        if self.camera == None:
#            self.camera = camera

#        self.volume_button = StaticImage("images/menusprites/volume.png",camera.window.right-30,camera.window.top+10)
#        self.mute_button   = StaticImage("images/menusprites/mute.png",camera.window.right-30,camera.window.top+10)

        self.plot_bg = StaticImage( "images/plot/%s/%s.jpg" % (self.plotfolder, self.currentPlot),0,0)
        self.plot_bg.draw(camera)
        self.plot_skip_button.draw(camera)
        self.plot_back_button.draw(camera)
        self.plot_next_button.draw(camera)
        
        #Mute button
        if self.vol:
            #self.volume_button.rect.topleft = ( camera.window.right - 30, camera.window.top )
            self.volume_button.draw(camera)
        else:
            #self.mute_button.rect.topleft = ( camera.window.right - 30, camera.window.top )
            self.mute_button.draw(camera)
Exemplo n.º 5
0
    def __init__(self):
        self.vol = True
        
        #Remember where the volume was after un-muting
        self.bgm_vol = sound.get_bgm_vol()
        self.sfx_vol = sound.get_sfx_vol()
        
        self.time = 0
        self.timeString = "000"
        
        self.scoreString = "0"

        self.volume_button = StaticImage( "images/menusprites/volume.png", 0, 0 )
        self.mute_button = StaticImage( "images/menusprites/mute.png", 0, 0 )

        self.heart = StaticImage( "images/heart.png", 0, 0 )
        self.sattackbar = StaticImage( "images/sattackbar.png", 0, 0 )
        self.sattackblock = StaticImage( "images/sattackblock.png", 0, 0 )
        
        self.score_title = StaticImage( "images/hudsprites/score.png", 0, 0 )
        self.time_title = StaticImage( "images/hudsprites/time.png", 0, 0 )
        self.digit = StaticImage( "images/hudsprites/0.png", 0, 0 )
Exemplo n.º 6
0
    def __init__(self,currLevel):
        self.currentLevel = 0
        self.plotfolder = "tut"
        self.maxPlot = 1
        
        #only set the level during init, doesn't have to update every time
        if currLevel == 1:    #Super Mario World
            self.plotfolder = "smw"
            self.maxPlot = 15
        elif currLevel == 2:  #Sonic World
            self.plotfolder = "sonic"
            self.maxPlot = 1
        elif currLevel == 3:  #Megaman World
            self.plotfolder = "megaman"
            self.maxPlot = 2
        elif currLevel == 4:  #Metroid World
            self.plotfolder = "metroid"
            self.maxPlot = 2
        elif currLevel == 5:  #Castlevania World
            self.plotfolder = "castlevania"
            self.maxPlot = 2    
        
        self.currentPlot = 1

        self.plotOver = False
        #self.camera = None

        #plot page
        self.plot_back_button    = StaticImage( "images/menusprites/back.png",904, 490 )
        self.plot_next_button    = StaticImage( "images/menusprites/next.png",900, 530 )
        self.plot_skip_button    = StaticImage( "images/menusprites/skip.png",900, 450 )
        self.plot_bg             = StaticImage( "images/plot/smw/1.jpg",0,0)

        #self.bgm = 'sounds/SureShot.wav'
        
        #Mute button
        self.vol = True
        #Remember where the volume was after un-muting
        self.bgm_vol = sound.get_bgm_vol()
        self.sfx_vol = sound.get_sfx_vol()
        
        self.volume_button = StaticImage("images/menusprites/volume.png",960,10)
        self.mute_button   = StaticImage("images/menusprites/mute.png",960,10)
Exemplo n.º 7
0
	def draw(self,camera):
		if self.camera == None:
			self.camera = camera

		self.splash_bg     = StaticImage("images/menusprites/charsel.png",camera.window.left, camera.window.top)
		self.hulk          = StaticImage("images/hulk/hulkselect.png",camera.window.left+220,300+camera.window.top)
		self.america       = StaticImage("images/america/america_select.png",camera.window.left+550,300+camera.window.top)
		self.hawkeye       = StaticImage("images/hawkeye/hawkeye_select.png",camera.window.left+30,300+camera.window.top)
		self.ironman       = StaticImage("images/ironman/ironman_select.png",camera.window.left+350,300+camera.window.top)
		self.thor          = StaticImage("images/thor/norm_attack_left.gif",camera.window.left+700,300+camera.window.top)
		self.blackwidow    = StaticImage("images/blackwidow/blackwidow_select.png",camera.window.left+900,310+camera.window.top)
		self.volume_button = StaticImage("images/menusprites/volume.png",camera.window.right-30,camera.window.top+10)
		self.mute_button   = StaticImage("images/menusprites/mute.png",camera.window.right-30,camera.window.top+10)

		self.splash_bg.draw(camera)
		self.hulk.draw(camera)
		self.america.draw(camera)
		self.hawkeye.draw(camera)
		self.ironman.draw(camera)
		self.thor.draw(camera)
		self.blackwidow.draw(camera)
Exemplo n.º 8
0
class CharSel(object):

	def __init__(self):

		self.char = 0
		self.camera = None

		#self.bgm = 'sounds/SureShot.wav'

	def draw(self,camera):
		if self.camera == None:
			self.camera = camera

		self.splash_bg     = StaticImage("images/menusprites/charsel.png",camera.window.left, camera.window.top)
		self.hulk          = StaticImage("images/hulk/hulkselect.png",camera.window.left+220,300+camera.window.top)
		self.america       = StaticImage("images/america/america_select.png",camera.window.left+550,300+camera.window.top)
		self.hawkeye       = StaticImage("images/hawkeye/hawkeye_select.png",camera.window.left+30,300+camera.window.top)
		self.ironman       = StaticImage("images/ironman/ironman_select.png",camera.window.left+350,300+camera.window.top)
		self.thor          = StaticImage("images/thor/norm_attack_left.gif",camera.window.left+700,300+camera.window.top)
		self.blackwidow    = StaticImage("images/blackwidow/blackwidow_select.png",camera.window.left+900,310+camera.window.top)
		self.volume_button = StaticImage("images/menusprites/volume.png",camera.window.right-30,camera.window.top+10)
		self.mute_button   = StaticImage("images/menusprites/mute.png",camera.window.right-30,camera.window.top+10)

		self.splash_bg.draw(camera)
		self.hulk.draw(camera)
		self.america.draw(camera)
		self.hawkeye.draw(camera)
		self.ironman.draw(camera)
		self.thor.draw(camera)
		self.blackwidow.draw(camera)

	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)

	def setChar(self, thechar):
		self.char = thechar
		logger.get().setChar(thechar)

	def getChar(self):
		return self.char
Exemplo n.º 9
0
class StartMenu(object):

    def __init__(self):
        self.level = 0
        
        self.gamma = 1.0

        self.splash_bg           = StaticImage( "images/menusprites/splash.png",0,0 )
        #StartMenu buttons
        self.newgame_button      = StaticImage( "images/menusprites/newgame.png",460, 304 )
        self.loadgame_button     = StaticImage( "images/menusprites/loadgame.png", 460, 340)
        self.instructions_button = StaticImage( "images/menusprites/instructions.png", 445, 375 )
        self.options_button      = StaticImage( "images/menusprites/options.png",465, 410 )
        self.quit_button         = StaticImage( "images/menusprites/quit.png",480, 445 )
        #instructions page 
        self.instructions_bg     = StaticImage( "images/menusprites/instrScreen.png",0,0 )
        self.back_button         = StaticImage( "images/menusprites/back.png",414, 500 )
        #level select page
        self.lvl_bg        = StaticImage("images/menusprites/levelsel.png",0,0)
        self.lvl1          = StaticImage("images/menusprites/lvl1.png",415,177)
        self.lvl2          = StaticImage("images/menusprites/lvl2.png",415,262)
        self.lvl3          = StaticImage("images/menusprites/lvl3.png",415,347)
        self.lvl4          = StaticImage("images/menusprites/lvl4.png",415,430)
        self.lvl5          = StaticImage("images/menusprites/lvl5.png",415,515)
        self.lvltut        = StaticImage("images/menusprites/tutorial.png",400,93)
        #options page
        self.options_bg          = StaticImage( "images/menusprites/optionsScreen.png",0,0)
        self.volup_button        = StaticImage( "images/menusprites/volumeUp.png",445, 262 )
        self.voldown_button      = StaticImage( "images/menusprites/volumeDown.png",5, 262 )
        self.volupFX_button      = StaticImage( "images/menusprites/volumeUp.png",445, 392 )
        self.voldownFX_button    = StaticImage( "images/menusprites/volumeDown.png",5, 392 )
        self.gammaUp_button      = StaticImage( "images/menusprites/plus.png", 245, 510 )
        self.gammaDown_button    = StaticImage( "images/menusprites/minus.png", 205, 510 )
        self.menublock           = StaticImage( "images/menusprites/menublock.png", 0, 0 )
        self.options_back_button = StaticImage( "images/menusprites/back.png",444, 530 )

        self.bgm = 'sounds/bgm/SureShot.wav'

        self.playing = False
        self.loadLevel = False
        self.show_instructions = False
        self.show_options = False
        self.show_level = False

    def draw(self,camera):

        if not self.show_instructions and not self.show_options and not self.show_level:
            self.splash_bg.draw(camera)
            self.newgame_button.draw(camera)
            self.loadgame_button.draw(camera)
            self.instructions_button.draw(camera)
            self.options_button.draw(camera)
            self.quit_button.draw(camera)

        elif self.show_instructions:
            self.instructions_bg.draw(camera)
            self.back_button.draw(camera)

        elif self.show_options:
            #Options Screen
            self.options_bg.draw(camera)
            self.volup_button.draw(camera)
            self.voldown_button.draw(camera)
            self.volupFX_button.draw(camera)
            self.voldownFX_button.draw(camera)
            self.gammaUp_button.draw(camera)
            self.gammaDown_button.draw(camera)
            self.options_back_button.draw(camera)
            #bgm volume bar
            for i in range(0, sound.get_bgm_vol()):
                self.menublock.rect.topleft = ( 133 + i*self.menublock.rect.width,265 )
                self.menublock.draw(camera)
            #sfx volume bar
            for i in range(0, sound.get_sfx_vol()):
                self.menublock.rect.topleft = ( 133 + i*self.menublock.rect.width,395 )
                self.menublock.draw(camera)
                
        elif self.show_level:
            #Level Select Screen
            self.lvl_bg.draw(camera)
            self.lvltut.draw(camera)
            self.lvl1.draw(camera)
            self.lvl2.draw(camera)
            self.lvl3.draw(camera)
            self.lvl4.draw(camera)
            self.lvl5.draw(camera)

    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
                        
    def isPlaying(self):
        return self.playing

    def setLevel(self, thelevel):
        self.level = thelevel
        self.playing = True
        #logger.get().setChar(thechar)

    def getLevel(self):
        return self.level
Exemplo n.º 10
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.º 11
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.º 12
0
    def __init__(self):
        self.level = 0
        
        self.gamma = 1.0

        self.splash_bg           = StaticImage( "images/menusprites/splash.png",0,0 )
        #StartMenu buttons
        self.newgame_button      = StaticImage( "images/menusprites/newgame.png",460, 304 )
        self.loadgame_button     = StaticImage( "images/menusprites/loadgame.png", 460, 340)
        self.instructions_button = StaticImage( "images/menusprites/instructions.png", 445, 375 )
        self.options_button      = StaticImage( "images/menusprites/options.png",465, 410 )
        self.quit_button         = StaticImage( "images/menusprites/quit.png",480, 445 )
        #instructions page 
        self.instructions_bg     = StaticImage( "images/menusprites/instrScreen.png",0,0 )
        self.back_button         = StaticImage( "images/menusprites/back.png",414, 500 )
        #level select page
        self.lvl_bg        = StaticImage("images/menusprites/levelsel.png",0,0)
        self.lvl1          = StaticImage("images/menusprites/lvl1.png",415,177)
        self.lvl2          = StaticImage("images/menusprites/lvl2.png",415,262)
        self.lvl3          = StaticImage("images/menusprites/lvl3.png",415,347)
        self.lvl4          = StaticImage("images/menusprites/lvl4.png",415,430)
        self.lvl5          = StaticImage("images/menusprites/lvl5.png",415,515)
        self.lvltut        = StaticImage("images/menusprites/tutorial.png",400,93)
        #options page
        self.options_bg          = StaticImage( "images/menusprites/optionsScreen.png",0,0)
        self.volup_button        = StaticImage( "images/menusprites/volumeUp.png",445, 262 )
        self.voldown_button      = StaticImage( "images/menusprites/volumeDown.png",5, 262 )
        self.volupFX_button      = StaticImage( "images/menusprites/volumeUp.png",445, 392 )
        self.voldownFX_button    = StaticImage( "images/menusprites/volumeDown.png",5, 392 )
        self.gammaUp_button      = StaticImage( "images/menusprites/plus.png", 245, 510 )
        self.gammaDown_button    = StaticImage( "images/menusprites/minus.png", 205, 510 )
        self.menublock           = StaticImage( "images/menusprites/menublock.png", 0, 0 )
        self.options_back_button = StaticImage( "images/menusprites/back.png",444, 530 )

        self.bgm = 'sounds/bgm/SureShot.wav'

        self.playing = False
        self.loadLevel = False
        self.show_instructions = False
        self.show_options = False
        self.show_level = False
Exemplo n.º 13
0
class StartMenu(object):
    def __init__(self):
        self.level = 0

        self.gamma = 1.0

        self.splash_bg = StaticImage("images/menusprites/splash.png", 0, 0)
        #StartMenu buttons
        self.newgame_button = StaticImage("images/menusprites/newgame.png",
                                          460, 304)
        self.loadgame_button = StaticImage("images/menusprites/loadgame.png",
                                           460, 340)
        self.instructions_button = StaticImage(
            "images/menusprites/instructions.png", 445, 375)
        self.options_button = StaticImage("images/menusprites/options.png",
                                          465, 410)
        self.quit_button = StaticImage("images/menusprites/quit.png", 480, 445)
        #instructions page
        self.instructions_bg = StaticImage(
            "images/menusprites/instrScreen.png", 0, 0)
        self.back_button = StaticImage("images/menusprites/back.png", 414, 500)
        #level select page
        self.lvl_bg = StaticImage("images/menusprites/levelsel.png", 0, 0)
        self.lvl1 = StaticImage("images/menusprites/lvl1.png", 415, 177)
        self.lvl2 = StaticImage("images/menusprites/lvl2.png", 415, 262)
        self.lvl3 = StaticImage("images/menusprites/lvl3.png", 415, 347)
        self.lvl4 = StaticImage("images/menusprites/lvl4.png", 415, 430)
        self.lvl5 = StaticImage("images/menusprites/lvl5.png", 415, 515)
        self.lvltut = StaticImage("images/menusprites/tutorial.png", 400, 93)
        #options page
        self.options_bg = StaticImage("images/menusprites/optionsScreen.png",
                                      0, 0)
        self.volup_button = StaticImage("images/menusprites/volumeUp.png", 445,
                                        262)
        self.voldown_button = StaticImage("images/menusprites/volumeDown.png",
                                          5, 262)
        self.volupFX_button = StaticImage("images/menusprites/volumeUp.png",
                                          445, 392)
        self.voldownFX_button = StaticImage(
            "images/menusprites/volumeDown.png", 5, 392)
        self.gammaUp_button = StaticImage("images/menusprites/plus.png", 245,
                                          510)
        self.gammaDown_button = StaticImage("images/menusprites/minus.png",
                                            205, 510)
        self.menublock = StaticImage("images/menusprites/menublock.png", 0, 0)
        self.options_back_button = StaticImage("images/menusprites/back.png",
                                               444, 530)

        self.bgm = 'sounds/bgm/SureShot.wav'

        self.playing = False
        self.loadLevel = False
        self.show_instructions = False
        self.show_options = False
        self.show_level = False

    def draw(self, camera):

        if not self.show_instructions and not self.show_options and not self.show_level:
            self.splash_bg.draw(camera)
            self.newgame_button.draw(camera)
            self.loadgame_button.draw(camera)
            self.instructions_button.draw(camera)
            self.options_button.draw(camera)
            self.quit_button.draw(camera)

        elif self.show_instructions:
            self.instructions_bg.draw(camera)
            self.back_button.draw(camera)

        elif self.show_options:
            #Options Screen
            self.options_bg.draw(camera)
            self.volup_button.draw(camera)
            self.voldown_button.draw(camera)
            self.volupFX_button.draw(camera)
            self.voldownFX_button.draw(camera)
            self.gammaUp_button.draw(camera)
            self.gammaDown_button.draw(camera)
            self.options_back_button.draw(camera)
            #bgm volume bar
            for i in range(0, sound.get_bgm_vol()):
                self.menublock.rect.topleft = (133 +
                                               i * self.menublock.rect.width,
                                               265)
                self.menublock.draw(camera)
            #sfx volume bar
            for i in range(0, sound.get_sfx_vol()):
                self.menublock.rect.topleft = (133 +
                                               i * self.menublock.rect.width,
                                               395)
                self.menublock.draw(camera)

        elif self.show_level:
            #Level Select Screen
            self.lvl_bg.draw(camera)
            self.lvltut.draw(camera)
            self.lvl1.draw(camera)
            self.lvl2.draw(camera)
            self.lvl3.draw(camera)
            self.lvl4.draw(camera)
            self.lvl5.draw(camera)

    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

    def isPlaying(self):
        return self.playing

    def setLevel(self, thelevel):
        self.level = thelevel
        self.playing = True
        #logger.get().setChar(thechar)

    def getLevel(self):
        return self.level
Exemplo n.º 14
0
class Plot(object):

    def __init__(self,currLevel):
        self.currentLevel = 0
        self.plotfolder = "tut"
        self.maxPlot = 1
        
        #only set the level during init, doesn't have to update every time
        if currLevel == 1:    #Super Mario World
            self.plotfolder = "smw"
            self.maxPlot = 15
        elif currLevel == 2:  #Sonic World
            self.plotfolder = "sonic"
            self.maxPlot = 1
        elif currLevel == 3:  #Megaman World
            self.plotfolder = "megaman"
            self.maxPlot = 2
        elif currLevel == 4:  #Metroid World
            self.plotfolder = "metroid"
            self.maxPlot = 2
        elif currLevel == 5:  #Castlevania World
            self.plotfolder = "castlevania"
            self.maxPlot = 2    
        
        self.currentPlot = 1

        self.plotOver = False
        #self.camera = None

        #plot page
        self.plot_back_button    = StaticImage( "images/menusprites/back.png",904, 490 )
        self.plot_next_button    = StaticImage( "images/menusprites/next.png",900, 530 )
        self.plot_skip_button    = StaticImage( "images/menusprites/skip.png",900, 450 )
        self.plot_bg             = StaticImage( "images/plot/smw/1.jpg",0,0)

        #self.bgm = 'sounds/SureShot.wav'
        
        #Mute button
        self.vol = True
        #Remember where the volume was after un-muting
        self.bgm_vol = sound.get_bgm_vol()
        self.sfx_vol = sound.get_sfx_vol()
        
        self.volume_button = StaticImage("images/menusprites/volume.png",960,10)
        self.mute_button   = StaticImage("images/menusprites/mute.png",960,10)

    def draw(self,camera):
#        if self.camera == None:
#            self.camera = camera

#        self.volume_button = StaticImage("images/menusprites/volume.png",camera.window.right-30,camera.window.top+10)
#        self.mute_button   = StaticImage("images/menusprites/mute.png",camera.window.right-30,camera.window.top+10)

        self.plot_bg = StaticImage( "images/plot/%s/%s.jpg" % (self.plotfolder, self.currentPlot),0,0)
        self.plot_bg.draw(camera)
        self.plot_skip_button.draw(camera)
        self.plot_back_button.draw(camera)
        self.plot_next_button.draw(camera)
        
        #Mute button
        if self.vol:
            #self.volume_button.rect.topleft = ( camera.window.right - 30, camera.window.top )
            self.volume_button.draw(camera)
        else:
            #self.mute_button.rect.topleft = ( camera.window.right - 30, camera.window.top )
            self.mute_button.draw(camera)

    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
                
    def getPlot(self):
        return self.plotOver
Exemplo n.º 15
0
class HUD(object):
    def __init__(self):
        self.vol = True

        #Remember where the volume was after un-muting
        self.bgm_vol = sound.get_bgm_vol()
        self.sfx_vol = sound.get_sfx_vol()

        self.time = 0
        self.timeString = "000"

        self.scoreString = "0"

        self.volume_button = StaticImage("images/menusprites/volume.png", 0, 0)
        self.mute_button = StaticImage("images/menusprites/mute.png", 0, 0)

        self.heart = StaticImage("images/heart.png", 0, 0)
        self.sattackbar = StaticImage("images/sattackbar.png", 0, 0)
        self.sattackblock = StaticImage("images/sattackblock.png", 0, 0)

        self.score_title = StaticImage("images/hudsprites/score.png", 0, 0)
        self.time_title = StaticImage("images/hudsprites/time.png", 0, 0)
        self.digit = StaticImage("images/hudsprites/0.png", 0, 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)

    def drawVol(self, camera):
        if self.vol:
            self.volume_button.rect.topleft = (camera.window.right - 30,
                                               camera.window.top)
            self.volume_button.draw(camera)
        else:
            self.mute_button.rect.topleft = (camera.window.right - 30,
                                             camera.window.top)
            self.mute_button.draw(camera)

    def draw(self, camera, avengers_obj):

        self.drawVol(camera)

        for i in range(0, avengers_obj.player_lives):
            self.heart.rect.topleft = (camera.window.left + i *
                                       (self.heart.rect.width + 10) + 10,
                                       camera.window.top + 10)
            self.heart.draw(camera)

        self.sattackbar.rect.topleft = camera.window.left + 10, camera.window.top + 55
        self.sattackbar.draw(camera)

        for i in range(0, avengers_obj.currLevel.player.sattack_ammo):
            self.sattackblock.rect.topleft = (camera.window.left + 13 +
                                              i * self.sattackblock.rect.width,
                                              camera.window.top + 58)
            self.sattackblock.draw(camera)

        self.time_title.rect.topleft = camera.window.right - 160, camera.window.top + 55
        self.time_title.draw(camera)
        for i in range(0, len(self.timeString)):
            self.digit = StaticImage(
                "images/hudsprites/%s.png" % self.timeString[i],
                camera.window.right - 100 + i * (self.digit.rect.width - 6),
                camera.window.top + 64)
            self.digit.draw(camera)
            #sys.stdout.write('String element: %s\n' % timer)

        self.score_title.rect.topleft = camera.window.right - 580, camera.window.top + 55
        self.score_title.draw(camera)
        self.scoreString = score.get().getScore()

        for i in range(0, len(self.scoreString)):
            self.digit = StaticImage(
                "images/hudsprites/%s.png" % self.scoreString[i],
                camera.window.right - 500 + i * (self.digit.rect.width - 6),
                camera.window.top + 63)
            self.digit.draw(camera)

    def getVol(self):
        return self.vol

    def incTime(self):
        self.time = self.time + 1
        self.timeString = "%03d" % self.time

    def resetTime(self):
        self.time = 0
        self.timeString = "000"
Exemplo n.º 16
0
    def __init__(self):
        self.vol = True

        #Remember where the volume was after un-muting
        self.bgm_vol = sound.get_bgm_vol()
        self.sfx_vol = sound.get_sfx_vol()

        self.time = 0
        self.timeString = "000"

        self.scoreString = "0"

        self.volume_button = StaticImage("images/menusprites/volume.png", 0, 0)
        self.mute_button = StaticImage("images/menusprites/mute.png", 0, 0)

        self.heart = StaticImage("images/heart.png", 0, 0)
        self.sattackbar = StaticImage("images/sattackbar.png", 0, 0)
        self.sattackblock = StaticImage("images/sattackblock.png", 0, 0)

        self.score_title = StaticImage("images/hudsprites/score.png", 0, 0)
        self.time_title = StaticImage("images/hudsprites/time.png", 0, 0)
        self.digit = StaticImage("images/hudsprites/0.png", 0, 0)
Exemplo n.º 17
0
class HUD(object):
    def __init__(self):
        self.vol = True
        
        #Remember where the volume was after un-muting
        self.bgm_vol = sound.get_bgm_vol()
        self.sfx_vol = sound.get_sfx_vol()
        
        self.time = 0
        self.timeString = "000"
        
        self.scoreString = "0"

        self.volume_button = StaticImage( "images/menusprites/volume.png", 0, 0 )
        self.mute_button = StaticImage( "images/menusprites/mute.png", 0, 0 )

        self.heart = StaticImage( "images/heart.png", 0, 0 )
        self.sattackbar = StaticImage( "images/sattackbar.png", 0, 0 )
        self.sattackblock = StaticImage( "images/sattackblock.png", 0, 0 )
        
        self.score_title = StaticImage( "images/hudsprites/score.png", 0, 0 )
        self.time_title = StaticImage( "images/hudsprites/time.png", 0, 0 )
        self.digit = StaticImage( "images/hudsprites/0.png", 0, 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)

    def drawVol(self,camera):
        if self.vol:
            self.volume_button.rect.topleft = ( camera.window.right - 30, camera.window.top )
            self.volume_button.draw(camera)
        else:
            self.mute_button.rect.topleft = ( camera.window.right - 30, camera.window.top )
            self.mute_button.draw(camera)

    def draw(self,camera,avengers_obj):

        self.drawVol(camera)

        for i in range(0,avengers_obj.player_lives):
            self.heart.rect.topleft = ( camera.window.left + i*( self.heart.rect.width + 10) + 10,
                                        camera.window.top + 10 )
            self.heart.draw(camera)

        self.sattackbar.rect.topleft = camera.window.left + 10, camera.window.top + 55
        self.sattackbar.draw(camera)

        for i in range(0, avengers_obj.currLevel.player.sattack_ammo):
            self.sattackblock.rect.topleft = ( camera.window.left + 13 + i*self.sattackblock.rect.width,
                                               camera.window.top + 58 )
            self.sattackblock.draw(camera)
        
        self.time_title.rect.topleft = camera.window.right - 160, camera.window.top + 55
        self.time_title.draw(camera)
        for i in range(0, len(self.timeString)):
            self.digit = StaticImage( "images/hudsprites/%s.png" % self.timeString[i], 
                                          camera.window.right - 100 + i*(self.digit.rect.width-6), 
                                          camera.window.top + 64 )
            self.digit.draw(camera)
            #sys.stdout.write('String element: %s\n' % timer)
        
        self.score_title.rect.topleft = camera.window.right - 580, camera.window.top + 55
        self.score_title.draw(camera)    
        self.scoreString = score.get().getScore()
        
        for i in range(0, len(self.scoreString)):
            self.digit = StaticImage( "images/hudsprites/%s.png" % self.scoreString[i], 
                                          camera.window.right - 500 + i*(self.digit.rect.width-6), 
                                          camera.window.top + 63 )
            self.digit.draw(camera)
        
    def getVol(self):
        return self.vol
    
    def incTime(self):
        self.time = self.time + 1
        self.timeString = "%03d" % self.time
        
    def resetTime(self):
        self.time = 0
        self.timeString = "000"
Exemplo n.º 18
0
class PauseMenu(object):

    def __init__(self):

        self.camera = None
        self.showMainMenu = False
        self.restartLevel = False

        #self.bgm = 'sounds/SureShot.wav'

    def draw(self,camera):
        if self.camera == None:
            self.camera = camera

        #to center: x:camera window + window width/2 - img width
        self.bgIm = StaticImage("images/menusprites/pauseScreen.png",camera.window.left+500-149,camera.window.top+300-218)
        self.resumeIm = StaticImage("images/menusprites/resume.png",camera.window.left+500-52,camera.window.top+300-70)
        self.restartIm = StaticImage("images/menusprites/restart.png",camera.window.left+500-57,camera.window.top+300-10)
        self.quitIm = StaticImage("images/menusprites/quittomain.png",camera.window.left+500-85,camera.window.top+300+50)

        self.bgIm.draw(camera)
        self.resumeIm.draw(camera)
        self.restartIm.draw(camera)
        self.quitIm.draw(camera)


    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.º 19
0
    def __init__(self):
        self.level = 0

        self.gamma = 1.0

        self.splash_bg = StaticImage("images/menusprites/splash.png", 0, 0)
        #StartMenu buttons
        self.newgame_button = StaticImage("images/menusprites/newgame.png",
                                          460, 304)
        self.loadgame_button = StaticImage("images/menusprites/loadgame.png",
                                           460, 340)
        self.instructions_button = StaticImage(
            "images/menusprites/instructions.png", 445, 375)
        self.options_button = StaticImage("images/menusprites/options.png",
                                          465, 410)
        self.quit_button = StaticImage("images/menusprites/quit.png", 480, 445)
        #instructions page
        self.instructions_bg = StaticImage(
            "images/menusprites/instrScreen.png", 0, 0)
        self.back_button = StaticImage("images/menusprites/back.png", 414, 500)
        #level select page
        self.lvl_bg = StaticImage("images/menusprites/levelsel.png", 0, 0)
        self.lvl1 = StaticImage("images/menusprites/lvl1.png", 415, 177)
        self.lvl2 = StaticImage("images/menusprites/lvl2.png", 415, 262)
        self.lvl3 = StaticImage("images/menusprites/lvl3.png", 415, 347)
        self.lvl4 = StaticImage("images/menusprites/lvl4.png", 415, 430)
        self.lvl5 = StaticImage("images/menusprites/lvl5.png", 415, 515)
        self.lvltut = StaticImage("images/menusprites/tutorial.png", 400, 93)
        #options page
        self.options_bg = StaticImage("images/menusprites/optionsScreen.png",
                                      0, 0)
        self.volup_button = StaticImage("images/menusprites/volumeUp.png", 445,
                                        262)
        self.voldown_button = StaticImage("images/menusprites/volumeDown.png",
                                          5, 262)
        self.volupFX_button = StaticImage("images/menusprites/volumeUp.png",
                                          445, 392)
        self.voldownFX_button = StaticImage(
            "images/menusprites/volumeDown.png", 5, 392)
        self.gammaUp_button = StaticImage("images/menusprites/plus.png", 245,
                                          510)
        self.gammaDown_button = StaticImage("images/menusprites/minus.png",
                                            205, 510)
        self.menublock = StaticImage("images/menusprites/menublock.png", 0, 0)
        self.options_back_button = StaticImage("images/menusprites/back.png",
                                               444, 530)

        self.bgm = 'sounds/bgm/SureShot.wav'

        self.playing = False
        self.loadLevel = False
        self.show_instructions = False
        self.show_options = False
        self.show_level = False