comparison src/parpg/gamemap.py @ 182:59c9ce2b8351

PARPG now works with, and needs Fife 0.3.3.
author KarstenBock@gmx.net
date Tue, 11 Oct 2011 14:47:37 +0200
parents ad75fa042b99
children
comparison
equal deleted inserted replaced
181:54c4277ed905 182:59c9ce2b8351
12 12
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. 14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
15 15
16 from fife import fife 16 from fife import fife
17 from fife.extensions import pychan
17 from fife.extensions.loaders import loadMapFile 18 from fife.extensions.loaders import loadMapFile
18 19
19 class GameMap(fife.MapChangeListener): 20 class GameMap(fife.MapChangeListener):
20 """Map class used to flag changes in the map""" 21 """Map class used to flag changes in the map"""
21 def __init__(self, engine, model): 22 def __init__(self, engine, model):
99 self.cameras[self.my_cam_id] = cam 100 self.cameras[self.my_cam_id] = cam
100 cam.resetRenderers() 101 cam.resetRenderers()
101 102
102 self.target_rotation = self.cameras[self.my_cam_id].getRotation() 103 self.target_rotation = self.cameras[self.my_cam_id].getRotation()
103 104
104 self.outline_renderer = fife.InstanceRenderer.\ 105 self.outline_renderer = (
105 getInstance( 106 fife.InstanceRenderer.getInstance(self.cameras[self.my_cam_id])
106 self.cameras[ 107 )
107 self.my_cam_id
108 ])
109 108
110 # set the render text 109 # set the render text
111 rend = fife.FloatingTextRenderer.getInstance(self.cameras[ 110 rend = fife.FloatingTextRenderer.getInstance(
112 self.my_cam_id 111 self.cameras[self.my_cam_id]
113 ]) 112 )
114 text = self.engine.getGuiManager().createFont('fonts/rpgfont.png', 113 font = pychan.manager.hook.guimanager.createFont(
115 0, 114 'fonts/rpgfont.png',
116 self.settings.fife.FontGlyphs) 115 0,
116 self.settings.fife.FontGlyphs
117 )
117 118
118 rend.changeDefaultFont(text) 119 rend.setFont(font)
119 rend.activateAllLayers(self.map) 120 rend.activateAllLayers(self.map)
120 rend.setEnabled(True) 121 rend.setEnabled(True)
121 122
122 # Activate the grid renderer on all layers 123 # Activate the grid renderer on all layers
123 rend = self.cameras['map_camera'].getRenderer('GridRenderer') 124 rend = self.cameras['map_camera'].getRenderer('GridRenderer')
124 rend.activateAllLayers(self.map) 125 rend.activateAllLayers(self.map)
125 126
126 # Activate the grid renderer on all layers 127 # Activate the grid renderer on all layers
127 rend = fife.CoordinateRenderer.getInstance(self.cameras[ 128 rend = fife.CoordinateRenderer.getInstance(
128 self.my_cam_id 129 self.cameras[self.my_cam_id]
129 ]) 130 )
130 rend.setColor(0, 0, 0) 131 rend.setColor(0, 0, 0)
131 rend.addActiveLayer(self.map.getLayer("GroundLayer")) 132 rend.addActiveLayer(self.map.getLayer("GroundLayer"))
132 133
133 # Make World aware that this is now the active map. 134 # Make World aware that this is now the active map.
134 self.model.active_map = self 135 self.model.active_map = self
135 136
136 def addPC(self): 137 def addPC(self):
137 """Add the player character to the map 138 """Add the player character to the map
138 @return: None""" 139 @return: None"""
139 # Update gamestate.player_character 140 # Update gamestate.player_character
140 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.onNewMap(self.agent_layer) 141 player = self.model.game_state.getObjectById("PlayerCharacter")
142 player.fifeagent.behaviour.onNewMap(self.agent_layer)
141 self.centerCameraOnPlayer() 143 self.centerCameraOnPlayer()
142 144
143 def toggleRenderer(self, r_name): 145 def toggleRenderer(self, r_name):
144 """Enable or disable a renderer. 146 """Enable or disable a renderer.
145 @return: None""" 147 @return: None"""
165 self.pause(not self.isPaused()) 167 self.pause(not self.isPaused())
166 168
167 def centerCameraOnPlayer(self): 169 def centerCameraOnPlayer(self):
168 """Center the camera on the player""" 170 """Center the camera on the player"""
169 camera = self.cameras[self.my_cam_id] 171 camera = self.cameras[self.my_cam_id]
170 player_agent = self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.agent 172 player = self.model.game_state.getObjectById("PlayerCharacter")
171 camera.setLocation(player_agent.getLocation()) 173 camera.setLocation(player.fifeagent.behaviour.getLocation())