Exemple #1
0
    def loop(self):
        gameVariables = self.main.gameVariables
        levelName = ""
        currentLevel = None
        running = True

        while running:

            while currentLevel == None:
                levelName = "gamelevel" + str(
                    self.data['chapter']) + "_" + str(self.data['level'])
                if base.NEED_MORE_BIBLES == False:
                    levelName = "gamelevel" + str(6) + "_" + str(1)
                #else:
                #	levelName = "gamelevel" + str(self.data['chapter']) + "_" + str(self.data['level'])

                try:
                    if self.data['difficulty'] != 3:
                        if self.data['chapter'] == 3:
                            if self.data['level'] == 3:
                                levelName = "gamelevel" + str(3) + "_" + str(4)

                    ## Load the new level from the dynamically loaded module
                    currentLevel = initLevel(levelName)
                    # save all the variables level and other scripts might have created in gameVariables
                    for key, value in gameVariables.iteritems():
                        self.data[key] = value
                    saveGame(self.data)

                except ImportError, err:
                    # if we weren't looking for the first level of current major
                    # number (x_0), then check for next major
                    if self.data['level'] > 1:
                        self.data['chapter'] += 1
                        self.data['level'] = 1
                    else:
                        raise base.ResourceException("Error loading level " +
                                                     levelName + "!")

                if base.SOUND == True:
                    if self.data["chapter"] == 5:
                        if self.playing != "MountainMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("MountainMusic")
                            self.playing = "MountainMusic"

                    if self.data["chapter"] == 4:
                        if self.playing != "TempleMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("TempleMusic")
                            self.playing = "TempleMusic"

                    if self.data["chapter"] == 2:
                        if self.playing != "CaveMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("CaveMusic")
                            self.playing = "CaveMusic"

                    if (((self.data["chapter"] == 1)
                         or (self.data["chapter"] == 3)
                         or (self.data["chapter"] == 6))):
                        if self.playing != "JungleMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("JungleMusic")
                            self.playing = "JungleMusic"

            chapter = int(self.data['chapter'])
            print "Loaded level", levelName

            if len(base.testLevelname) > 0:
                currentLevel.levelFileName = base.testLevelname

            # give the level access to the gameVariables
            currentLevel.pvars = gameVariables
            # run until user quits
            endState = currentLevel.run()

            if (endState == base.NEXTLEVEL):
                self.data['bibles'] = base.num_bibles
                self.data['bananas'] = base.numBananas

                self.data['level'] += 1
                currentLevel = None
                base.testLevelname = ""
                if base.num_bibles >= base.NEEDED_BIBLES:
                    base.NEED_MORE_BIBLES = False
                    for key, value in gameVariables.iteritems():
                        self.data[key] = value
                        saveGame(self.data)

                if base.NEED_MORE_BIBLES == True:
                    base.DATA["chapter"] = randrange(1, 5)
                    base.DATA["level"] = randrange(1, 2)

                self.data['bibles'] = base.num_bibles
                self.data['bananas'] = base.numBananas

                #self.data['level'] += 1
                #currentLevel = None
                base.testLevelname = ""
            elif endState == base.GAMEOVER:
                base.num_bibles = int(self.data['bibles'])
                base.numBananas = int(self.data['bananas'])

                if base.testLevelname == "":
                    currentLevel = initLevel(levelName)
                else:  # special case for restarting the testlevel which uses custom level class
                    currentLevel = initCustomLevel("testlevel")

            elif (endState == base.RESTARTLEVEL):
                if base.testLevelname == "":
                    currentLevel = initLevel(levelName)
                else:  # special case for restarting the testlevel which uses custom level class
                    currentLevel = initCustomLevel("testlevel")
            elif endState == base.QUITGAME:  # todo, game over screen?
                running = False
            elif endState == base.GOTOLEVEL:
                levelName = currentLevel.gotoLevelName
                currentLevel = initLevel(levelName)
                # need to keep track on these
                self.data['chapter'] = currentLevel.level_maj
                self.data['level'] = currentLevel.level_min
                base.testLevelname = ""
            elif endState == base.GOTOTESTLEVEL:
                if base.testLevelname == "":
                    Exception("testLevelname not set")
                    # user the testlevel.py level script
                    levelName = "testlevel"

                    currentLevel = initCustomLevel(base.testLevelname)

                    # need to keep track on these
                    self.data['chapter'] = currentLevel.level_maj
                    self.data['level'] = currentLevel.level_min
                else:
                    raise Exception("Unknown level end state", endState)
            elif endState == base.SHOWGAMEOVER:
                return GameOver(self.main)
Exemple #2
0
    def event(self, e):
        data = base.DATA
        ##		gameVariables = self.main.gameVariables

        if e.type is KEYDOWN and e.key == K_UP:
            self.cur = (self.cur - 1 + len(self.menu)) % len(self.menu)
            self.repaint()
        if e.type is KEYDOWN and e.key == K_DOWN:
            self.cur = (self.cur + 1 + len(self.menu)) % len(self.menu)
            self.repaint()

        if e.type is MOUSEMOTION:
            for n, rect in self.zones:
                if rect.collidepoint(e.pos):
                    if self.cur != n:
                        self.cur = n
                        self.repaint()


##		ToDo: Finish Joystick movement settings
##		if e.type is JOYAXISMOTION: and e.key == K_UP:
##			self.cur = (self.cur-1+len(self.menu))%len(self.menu)
##			self.repaint()
##		if e.type is JOYAXISMOTION: and e.key == K_DOWN:
##			self.cur = (self.cur+1+len(self.menu))%len(self.menu)
##			self.repaint()

        if (e.type is KEYDOWN and e.key in (K_RETURN, K_ESCAPE)) or (
                e.type is MOUSEBUTTONDOWN) or (e.type is JOYBUTTONDOWN):
            val = self.menu[self.cur]
            if e.type is KEYDOWN and e.key == K_ESCAPE:
                return Menu(self.main)

            if val == "back":
                return Menu(self.main)
            if val == "hard":
                data['chapter'] = 1
                data['level'] = 1
                data['bibles'] = 0
                data['bananas'] = 0
                data['difficulty'] = base.DIFFICULTY_HARDEST
                base.saveGame(data)
                ##				return Loading(self.main)
                import game
                return game.Game(self.main)

            if val == "easy":
                data['chapter'] = 1
                data['level'] = 1
                data['bibles'] = 0
                data['bananas'] = 0
                data['difficulty'] = base.DIFFICULTY_EASIEST
                base.saveGame(data)
                ##				return Loading(self.main)
                import game
                return game.Game(self.main)

            if val == "medium":
                data['chapter'] = 1
                data['level'] = 1
                data['bibles'] = 0
                data['bananas'] = 0
                data['difficulty'] = base.DIFFICULTY_MEDIUM
                base.saveGame(data)
                ##				return Loading(self.main)
                import game
                return game.Game(self.main)
Exemple #3
0
	def loop(self):
		gameVariables = self.main.gameVariables
		levelName = ""
		currentLevel = None
		running = True
		
		while running:
				
			while currentLevel == None:
				levelName = "gamelevel" + str(self.data['chapter']) + "_" + str(self.data['level'])
		
				try:
					if base.num_bibles >= base.NEEDED_BIBLES:
						if base.NEED_MORE_BIBLES == True:
							base.NEED_MORE_BIBLES = False
							levelName = "gamelevel" + str(6) + "_" + str(1)
							
					
					## Load the new level from the dynamically loaded module
					currentLevel = initLevel(levelName)
					# save all the variables level and other scripts might have created in gameVariables
					for key,value in gameVariables.iteritems():
						self.data[key] = value
					saveGame(self.data)
														
				except ImportError, err:
					# if we weren't looking for the first level of current major 
					# number (x_0), then check for next major
					if self.data['level'] > 1:
						self.data['chapter'] += 1
						self.data['level'] = 1
					else:
						raise base.ResourceException("Error loading level " + levelName + "!")
				
				if base.SOUND == True:
					if self.data["chapter"] == 5:
						if self.playing != "MountainMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("MountainMusic")
							self.playing = "MountainMusic"
					
					if self.data["chapter"] == 4:
						if self.playing != "TempleMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("TempleMusic")
							self.playing = "TempleMusic"
							
					if self.data["chapter"] == 2:
						if self.playing != "CaveMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("CaveMusic")
							self.playing = "CaveMusic"
	
					if (((self.data["chapter"] == 1) or (self.data["chapter"] == 3) or (self.data["chapter"] == 6))):
						if self.playing != "JungleMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("JungleMusic")
							self.playing = "JungleMusic"
			
			chapter = int(self.data['chapter'])
			print "Loaded level", levelName
						
			if len(base.testLevelname) > 0:
				currentLevel.levelFileName = base.testLevelname
														
			# give the level access to the gameVariables
			currentLevel.pvars = gameVariables
			# run until user quits
			endState = currentLevel.run()
		
			if (endState == base.NEXTLEVEL):
				self.data['bibles'] = base.num_bibles
				self.data['bananas'] = base.numBananas
				
				self.data['level'] += 1
				currentLevel = None
				base.testLevelname = ""
			elif endState == base.GAMEOVER:
				base.num_bibles = int(self.data['bibles'])
				base.numBananas = int(self.data['bananas'])
				
				if base.testLevelname == "":
					currentLevel = initLevel(levelName)
				else: # special case for restarting the testlevel which uses custom level class 
					currentLevel = initCustomLevel("testlevel")
				
			elif (endState == base.RESTARTLEVEL):
				if base.testLevelname == "":
					currentLevel = initLevel(levelName)
				else: # special case for restarting the testlevel which uses custom level class 
					currentLevel = initCustomLevel("testlevel")
			elif endState == base.QUITGAME: # todo, game over screen?
				running = False
			elif endState == base.GOTOLEVEL:
				levelName = currentLevel.gotoLevelName
				currentLevel = initLevel(levelName)
				# need to keep track on these
				self.data['chapter'] = currentLevel.level_maj
				self.data['level'] = currentLevel.level_min
				base.testLevelname = ""
			elif endState == base.GOTOTESTLEVEL:
				if base.testLevelname == "": 
					Exception("testLevelname not set")
					# user the testlevel.py level script
					levelName = "testlevel"												 
								
					currentLevel = initCustomLevel(base.testLevelname)
								
					# need to keep track on these
					self.data['chapter'] = currentLevel.level_maj
					self.data['level'] = currentLevel.level_min
				else:
					raise Exception("Unknown level end state",endState)
			elif endState == base.SHOWGAMEOVER:
				return GameOver(self.main)
Exemple #4
0
	def event(self,e):
		data = base.DATA
##		gameVariables = self.main.gameVariables
		
		if e.type is KEYDOWN and e.key == K_UP:
			self.cur = (self.cur-1+len(self.menu))%len(self.menu)
			self.repaint()
		if e.type is KEYDOWN and e.key == K_DOWN:
			self.cur = (self.cur+1+len(self.menu))%len(self.menu)
			self.repaint()
			
		if e.type is MOUSEMOTION:
			for n,rect in self.zones:
				if rect.collidepoint(e.pos):
					if self.cur != n:
						self.cur = n
						self.repaint()
						
##		ToDo: Finish Joystick movement settings
##		if e.type is JOYAXISMOTION: and e.key == K_UP:
##			self.cur = (self.cur-1+len(self.menu))%len(self.menu)
##			self.repaint()
##		if e.type is JOYAXISMOTION: and e.key == K_DOWN:
##			self.cur = (self.cur+1+len(self.menu))%len(self.menu)
##			self.repaint()
			
		if (e.type is KEYDOWN and e.key in (K_RETURN,K_ESCAPE)) or (e.type is MOUSEBUTTONDOWN) or (e.type is  JOYBUTTONDOWN):
			val = self.menu[self.cur]
			if e.type is KEYDOWN and e.key == K_ESCAPE:
				return Menu(self.main)

			if val == "back":
				return Menu(self.main)
			if val == "hard":
				data['chapter'] = 1
				data['level'] = 1
				data['bibles'] = 0
				data['bananas'] = 0
				data['difficulty'] = base.DIFFICULTY_HARDEST
				base.saveGame(data)
##				return Loading(self.main)
				import game
				return game.Game(self.main)
				
			if val == "easy":
				data['chapter'] = 1
				data['level'] = 1
				data['bibles'] = 0
				data['bananas'] = 0
				data['difficulty'] = base.DIFFICULTY_EASIEST
				base.saveGame(data)
##				return Loading(self.main)
				import game
				return game.Game(self.main)
				
			if val == "medium":
				data['chapter'] = 1
				data['level'] = 1
				data['bibles'] = 0
				data['bananas'] = 0
				data['difficulty'] = base.DIFFICULTY_MEDIUM
				base.saveGame(data)
##				return Loading(self.main)
				import game
				return game.Game(self.main)