comparison gamescenecontroller.py @ 88:0411a4bcceee

Fixed moving between maps.
author KarstenBock@gmx.net
date Mon, 26 Sep 2011 15:44:42 +0200
parents a9cc5559ec2a
children 485d866a847f
comparison
equal deleted inserted replaced
87:aed2e094e0c7 88:0411a4bcceee
30 from parpg.gui import drag_drop_data as data_drag 30 from parpg.gui import drag_drop_data as data_drag
31 from objects.action import ChangeMapAction, ExamineAction, OpenBoxAction, \ 31 from objects.action import ChangeMapAction, ExamineAction, OpenBoxAction, \
32 UnlockBoxAction, LockBoxAction, TalkAction, \ 32 UnlockBoxAction, LockBoxAction, TalkAction, \
33 PickUpAction, DropItemAction 33 PickUpAction, DropItemAction
34 34
35 from parpg.world import World
36
35 #For debugging/code analysis 37 #For debugging/code analysis
36 if False: 38 if False:
37 from gamesceneview import GameSceneView 39 from gamesceneview import GameSceneView
38 from gamemodel import GameModel 40 from gamemodel import GameModel
39 from parpg import PARPGApplication 41 from parpg import PARPGApplication
40 42
41 43
42 logger = logging.getLogger('gamescenecontroller') 44 logger = logging.getLogger('gamescenecontroller')
43 45
44 class GameSceneController(ControllerBase): 46 class GameSceneController(World, ControllerBase):
45 ''' 47 '''
46 This controller handles inputs when the game is in "scene" state. 48 This controller handles inputs when the game is in "scene" state.
47 "Scene" state is when the player can move around and interact 49 "Scene" state is when the player can move around and interact
48 with objects. Like, talking to a npc or examining the contents of a box. 50 with objects. Like, talking to a npc or examining the contents of a box.
49 ''' 51 '''
66 ControllerBase.__init__(self, 68 ControllerBase.__init__(self,
67 engine, 69 engine,
68 view, 70 view,
69 model, 71 model,
70 application) 72 application)
73 World.__init__(self)
71 #this can be helpful for IDEs code analysis 74 #this can be helpful for IDEs code analysis
72 if False: 75 if False:
73 assert(isinstance(self.engine, fife.Engine)) 76 assert(isinstance(self.engine, fife.Engine))
74 assert(isinstance(self.view, GameSceneView)) 77 assert(isinstance(self.view, GameSceneView))
75 assert(isinstance(self.view, GameModel)) 78 assert(isinstance(self.view, GameModel))
325 """Check if a command is to be executed 328 """Check if a command is to be executed
326 """ 329 """
327 if self.model.map_change: 330 if self.model.map_change:
328 self.pause(True) 331 self.pause(True)
329 if self.model.active_map: 332 if self.model.active_map:
330 player_char = self.model.game_state.getObjectById("PlayerCharacter").fifeagent 333 self.model.updateObjectDB(self)
331 self.model.game_state.getObjectById("PlayerCharacter").fifeagent = None 334 player_char = self.model.game_state.\
332 pc_agent = self.model.agents[self.model.ALL_AGENTS_KEY]\ 335 getObjectById("PlayerCharacter").fifeagent
333 ["PlayerCharacter"] 336 pc_agent = self.model.agents\
334 pc_agent.update(player_char.getStateForSaving()) 337 [self.model.ALL_AGENTS_KEY]["PlayerCharacter"]
335 pc_agent["Map"] = self.model.target_map_name 338 pc_agent["Map"] = self.model.target_map_name
336 pc_agent["Position"] = self.model.target_position 339 pc_agent["Position"] = self.model.target_position
337 pc_agent["Inventory"] = \
338 player_char.inventory.serializeInventory()
339 player_agent = self.model.active_map.\ 340 player_agent = self.model.active_map.\
340 agent_layer.getInstance("PlayerCharacter") 341 agent_layer.getInstance("PlayerCharacter")
341 self.model.active_map.agent_layer.deleteInstance(player_agent) 342 self.model.game_state.deleteObject("PlayerCharacter")
343 self.model.game_state.deleteObjectsFromMap(
344 self.model.game_state.current_map_name
345 )
342 346
343 self.model.loadMap(self.model.target_map_name) 347 self.model.loadMap(self.model.target_map_name)
344 348
345 self.model.setActiveMap(self.model.target_map_name) 349 self.model.setActiveMap(self.model.target_map_name)
346 self.model.readAgentsOfMap(self.model.target_map_name) 350 self.model.readAgentsOfMap(self.model.target_map_name)