Ejemplo n.º 1
0
	def initGame(self, gamefilename=None):
		if gamefilename is None:
			gamefilename = self.gamefilename
		self.gameState = GameState()
		self.gameState.load(gamefilename)
		self.playerState = self.gameState.playerState
		
		self.loadGameMap(self.gameState.playerState.map)
		
		# editor camera handler
		self.editorCam = EditorCamHandler()
		
		
		
		self.playerData = {}
		self.playerData["name"] = "Galya"
		self.playerData["sex"] = "female"
		
		#print "Game manager : creating map manager"
		self.mapManager = MapManager(self)
		self.mapManager.playerData = self.playerData
		
		# game camera handler
		self.gameCam = GameCamHandler(self.mapManager.player.model)
		self.setMode("playing")
		
		#print "Game manager : creating map editor"
		self.editor = MapEditor(self)
		
		
		
		# light
		if CONFIG_LIGHT:
			self.light = LightManager(self.mapManager.player.model)
			self.light.lightCenter.setPos(0,0,3)
			self.light.lightCenter.reparentTo(self.mapManager.player.model)
		
		self.accept(OPEN_EDITOR, self.toggle)
Ejemplo n.º 2
0
class Game(FSM, DirectObject):
	def __init__(self, gamefilename=None):
		FSM.__init__(self, 'Game')
		self.gameState = GameState()
		if gamefilename is None:
			gamefilename = "save/default.txt"
		
		self.gameState.load(gamefilename)
		self.playerState = self.gameState.playerState
		self.gamefilename = gamefilename
		self.map = None
		self.mapManager = None
		self.editor = None
		self.prevMode = None # previous mode
		
		self.cursor = MouseCursor()
		
		self.mainMenu = MainMenu()
		self.mainMenu.buttons[0].bind(DGG.B1PRESS, self.request, ["Game"])
		self.mainMenu.buttons[3].bind(DGG.B1PRESS, self.quit)
		self.mainMenu.hide()
		
		self.mainMenuImg = makeImg(0,0,"img/bg/title1.jpg", (RATIO, 0,1))
		self.mainMenuImg.setBin("fixed", -150)
		self.request("MainMenu")
		
	def initGame(self, gamefilename=None):
		if gamefilename is None:
			gamefilename = self.gamefilename
		self.gameState = GameState()
		self.gameState.load(gamefilename)
		self.playerState = self.gameState.playerState
		
		self.loadGameMap(self.gameState.playerState.map)
		
		# editor camera handler
		self.editorCam = EditorCamHandler()
		
		
		
		self.playerData = {}
		self.playerData["name"] = "Galya"
		self.playerData["sex"] = "female"
		
		#print "Game manager : creating map manager"
		self.mapManager = MapManager(self)
		self.mapManager.playerData = self.playerData
		
		# game camera handler
		self.gameCam = GameCamHandler(self.mapManager.player.model)
		self.setMode("playing")
		
		#print "Game manager : creating map editor"
		self.editor = MapEditor(self)
		
		
		
		# light
		if CONFIG_LIGHT:
			self.light = LightManager(self.mapManager.player.model)
			self.light.lightCenter.setPos(0,0,3)
			self.light.lightCenter.reparentTo(self.mapManager.player.model)
		
		self.accept(OPEN_EDITOR, self.toggle)
		
	def quit(self, sentArgs=[]):
		sys.exit()
			
	def loadGameMap(self, filename):
		print "Game : load game map %s" % (filename)
		if self.map:
			self.mapManager.removeAllNPC()
			self.map.destroy()
			#del self.map
			
		self.map = Map(filename)
		if self.map.collisionGrid:
			#print "Game : loaded new game map %s, it has a collisionGrid %s" % (str(self.map), str(self.map.collisionGrid))
			print "Game : loaded new game map from file %s " % (filename)
		else:
			print "Game : loaded new game map %s, but WARNING : collisionGrid not found" % (filename)
			
		if self.mapManager:
			#print "Game : assigning new map %s to mapManager" % (filename)
			self.mapManager.setMap(self.map)
		if self.editor:
			#print "Game : assigning new map %s to editor" % (filename)
			self.editor.setMap(self.map)
		
	def load(self, filename):
		self.prevState = self.state
		self.request("LoadMode")
		self.loadGameMap(filename)
		self.request(self.prevState)
		
	def setMode(self, mode):
		self.mode = mode
		if mode == "game":
			self.gameCam.start()
		else:
			self.editorCam.start()
		
	def toggle(self):
		if self.state == "Game":
			self.request("Editor")
		elif self.state == "Editor":
			self.request("Game")
	
	def enterMainMenu(self, sentArgs=[]):
		self.mainMenu.show()
		self.mainMenuImg.show()
		self.accept("escape", self.request, ["Game"])
		
	def exitMainMenu(self):
		self.mainMenu.hide()
		self.mainMenuImg.hide()
		
	def enterLoadMode(self, sentArgs=[]):
		print "Game : Entering load mode"
		
		
	def exitLoadMode(self):
		print "Game : Exiting load mode"
		
	
	def enterGame(self, sentArgs=[]):
		if not self.map:
			self.initGame()
			
		self.setMode("game")
		self.accept("escape", self.request, ["MainMenu"])
		self.mapManager.start()
		
	def exitGame(self):
		self.mapManager.stop()
		
	def enterEditor(self, sentArgs=[]):
		self.setMode("edit")
		self.editor.start()
		
	def exitEditor(self):
		self.editor.stop()