Mercurial > parpg-source
annotate gamemap.py @ 167:b3b82c2aebee
Using fife settings module again instead of our own.
author | Beliar <KarstenBock@gmx.net> |
---|---|
date | Mon, 20 Feb 2012 16:50:10 +0100 |
parents | 80672955ab70 |
children |
rev | line source |
---|---|
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
1 # This file is part of PARPG. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
2 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
3 # PARPG is free software: you can redistribute it and/or modify |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
5 # the Free Software Foundation, either version 3 of the License, or |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
6 # (at your option) any later version. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
7 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
8 # PARPG is distributed in the hope that it will be useful, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
11 # GNU General Public License for more details. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
12 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 from fife import fife |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
17 from fife.extensions import pychan |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 from fife.extensions.loaders import loadMapFile |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 class GameMap(fife.MapChangeListener): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
21 """Map class used to flag changes in the map""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
22 def __init__(self, engine, model): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
23 # init mapchange listener |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 fife.MapChangeListener.__init__(self) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 self.map = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 self.engine = engine |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 self.model = model |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
28 self.settings = self.model.settings |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 # init map attributes |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
31 self.my_cam_id = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 self.cameras = {} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 self.agent_layer = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 self.top_layer = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 self.fife_model = engine.getModel() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 self.transitions = [] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 self.cur_cam2_x = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 self.initial_cam2_x = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 self.cam2_scrolling_right = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 self.target_rotation = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 self.outline_renderer = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 def reset(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 """Reset the model to default settings. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 # We have to delete the map in Fife. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 if self.map: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 self.model.deleteObjects() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 self.model.deleteMap(self.map) |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
50 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 self.transitions = [] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
52 self.map = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
53 self.agent_layer = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 self.top_layer = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 # We have to clear the cameras in the view as well, or we can't reuse |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 # camera names like 'main' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 #self.view.clearCameras() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 self.initial_cam2_x = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 self.cam2_scrolling_right = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 #self.cameras = {} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 self.cur_cam2_x = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 self.target_rotation = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 self.outline_renderer = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 def makeActive(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 """Makes this map the active one. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 self.cameras[self.my_cam_id].setEnabled(True) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 def load(self, filename): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 """Load a map given the filename. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 @type filename: String |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 @param filename: Name of map to load |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 self.reset() |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
76 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 self.map = loadMapFile(filename, self.engine) |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
78 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 self.agent_layer = self.map.getLayer('ObjectLayer') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 self.top_layer = self.map.getLayer('TopLayer') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 # it's possible there's no transition layer |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 size = len('TransitionLayer') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 for layer in self.map.getLayers(): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 # could be many layers, but hopefully no more than 3 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 if(layer.getId()[:size] == 'TransitionLayer'): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 self.transitions.append(self.map.getLayer(layer.getId())) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
88 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 """ Initialize the camera. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
90 Note that if we have more than one camera in a map file |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
91 we will have to rework how self.my_cam_id works. To make sure |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
92 the proper camera is set as the 'main' camera. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
93 At this point we also set the viewport to the current resolution.""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
94 for cam in self.map.getCameras(): |
167
b3b82c2aebee
Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents:
150
diff
changeset
|
95 width = self.engine.getSettings().getScreenWidth() |
b3b82c2aebee
Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents:
150
diff
changeset
|
96 height = self.engine.getSettings().getScreenHeight() |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
97 viewport = fife.Rect(0, 0, width, height) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
98 cam.setViewPort(viewport) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
99 self.my_cam_id = cam.getId() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
100 self.cameras[self.my_cam_id] = cam |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
101 cam.resetRenderers() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
102 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
103 self.target_rotation = self.cameras[self.my_cam_id].getRotation() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
104 |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
105 self.outline_renderer = ( |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
106 fife.InstanceRenderer.getInstance(self.cameras[self.my_cam_id]) |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
107 ) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
108 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
109 # set the render text |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
110 rend = fife.FloatingTextRenderer.getInstance( |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
111 self.cameras[self.my_cam_id] |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
112 ) |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
113 font = pychan.manager.hook.guimanager.createFont( |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
114 'fonts/rpgfont.png', |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
115 0, |
167
b3b82c2aebee
Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents:
150
diff
changeset
|
116 self.settings.get("FIFE", "FontGlyphs") |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
117 ) |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
118 |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
119 rend.setFont(font) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
120 rend.activateAllLayers(self.map) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
121 rend.setEnabled(True) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
122 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
123 # Activate the grid renderer on all layers |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
124 rend = self.cameras['map_camera'].getRenderer('GridRenderer') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
125 rend.activateAllLayers(self.map) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
126 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
127 # Activate the grid renderer on all layers |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
128 rend = fife.CoordinateRenderer.getInstance( |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
129 self.cameras[self.my_cam_id] |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
130 ) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
131 rend.setColor(0, 0, 0) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
132 rend.addActiveLayer(self.map.getLayer("GroundLayer")) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
133 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 # Make World aware that this is now the active map. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
135 self.model.active_map = self |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
136 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
137 def addPC(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 """Add the player character to the map |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
139 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
140 # Update gamestate.player_character |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
141 player = self.model.game_state.getObjectById("PlayerCharacter") |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
142 player.fifeagent.behaviour.onNewMap(self.agent_layer) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
143 self.centerCameraOnPlayer() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
144 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
145 def toggleRenderer(self, r_name): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
146 """Enable or disable a renderer. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
147 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
148 renderer = self.cameras[self.my_cam_id].getRenderer(str(r_name)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
149 renderer.setEnabled(not renderer.isEnabled()) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
150 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
151 def isPaused(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
152 """Returns wheter the map is currentply paused or not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
153 # Time multiplier is a float, never do equals on floats |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
154 return not self.map.getTimeMultiplier() >= 1.0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
155 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
156 def pause(self, paused): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
157 """ Pause/Unpause the game. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
158 @return: nothing""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
159 if paused: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
160 self.map.setTimeMultiplier(0.0) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
161 if not paused and self.isPaused(): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
162 self.map.setTimeMultiplier(1.0) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
163 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
164 def togglePause(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
165 """ Toggle paused state. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
166 @return: nothing""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
167 self.pause(not self.isPaused()) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
168 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
169 def centerCameraOnPlayer(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
170 """Center the camera on the player""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
171 camera = self.cameras[self.my_cam_id] |
150
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
172 player = self.model.game_state.getObjectById("PlayerCharacter") |
80672955ab70
PARPG now works with, and needs Fife 0.3.3.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
173 camera.setLocation(player.fifeagent.behaviour.getLocation()) |