Mercurial > fife-parpg
comparison demos/shooter/scripts/world.py @ 460:5e1d6e40d19d
Fixed bounding boxes.
Added bounding box renderer.
The player is now better confined to the screen.
Added more enemies to the map.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 09 Apr 2010 21:42:28 +0000 |
parents | 597b066d5ccb |
children | c4f745a566d6 |
comparison
equal
deleted
inserted
replaced
459:302a69c5141d | 460:5e1d6e40d19d |
---|---|
20 # Free Software Foundation, Inc., | 20 # Free Software Foundation, Inc., |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 # #################################################################### | 22 # #################################################################### |
23 | 23 |
24 from fife import fife | 24 from fife import fife |
25 import copy | |
25 import math, random | 26 import math, random |
26 from fife.extensions import pychan | 27 from fife.extensions import pychan |
27 from fife.extensions.pychan import widgets | 28 from fife.extensions.pychan import widgets |
28 | 29 |
29 from scripts.common.eventlistenerbase import EventListenerBase | 30 from scripts.common.eventlistenerbase import EventListenerBase |
69 | 70 |
70 self._hudwindow = HeadsUpDisplay(self) | 71 self._hudwindow = HeadsUpDisplay(self) |
71 self._hudwindow.hide() | 72 self._hudwindow.hide() |
72 | 73 |
73 self._gameover = GameOverDisplay() | 74 self._gameover = GameOverDisplay() |
74 self._gameover.hide() | 75 self._gameover.hide() |
75 | 76 |
77 self._genericrenderer = None | |
78 | |
76 def showMainMenu(self): | 79 def showMainMenu(self): |
77 if self.scene: | 80 if self.scene: |
78 self._paused = True | 81 self._paused = True |
79 cont = True | 82 cont = True |
80 else: | 83 else: |
116 | 119 |
117 self._hudwindow.show() | 120 self._hudwindow.show() |
118 self._gameover.hide() | 121 self._gameover.hide() |
119 | 122 |
120 self._starttime = self.timemanager.getTime() | 123 self._starttime = self.timemanager.getTime() |
124 | |
125 self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main']) | |
126 self._genericrenderer.clearActiveLayers() | |
127 self._genericrenderer.addActiveLayer(self.map.getLayer('objects')) | |
128 self._genericrenderer.setEnabled(True) | |
129 | |
130 | |
131 def renderBoundingBox(self, obj): | |
132 bbox = copy.copy(obj.boundingbox) | |
133 | |
134 #apply the object layer scale | |
135 bbox.x /= 0.25 | |
136 bbox.y /= 0.25 | |
137 bbox.w /= 0.25 | |
138 bbox.h /= 0.25 | |
139 | |
140 obj_topleft = fife.ExactModelCoordinate(bbox.x, bbox.y) | |
141 obj_topright = fife.ExactModelCoordinate(bbox.x + bbox.w, bbox.y) | |
142 obj_bottomright = fife.ExactModelCoordinate(bbox.x + bbox.w, bbox.y + bbox.h) | |
143 obj_bottomleft = fife.ExactModelCoordinate(bbox.x, bbox.y + bbox.h) | |
144 | |
145 loc_topleft = fife.Location() | |
146 loc_topleft.setLayer(self.map.getLayer('boundingbox')) | |
147 loc_topleft.setExactLayerCoordinates(obj_topleft) | |
148 | |
149 loc_topright = fife.Location() | |
150 loc_topright.setLayer(self.map.getLayer('boundingbox')) | |
151 loc_topright.setExactLayerCoordinates(obj_topright) | |
152 | |
153 loc_bottomright = fife.Location() | |
154 loc_bottomright.setLayer(self.map.getLayer('boundingbox')) | |
155 loc_bottomright.setExactLayerCoordinates(obj_bottomright) | |
156 | |
157 loc_bottomleft = fife.Location() | |
158 loc_bottomleft.setLayer(self.map.getLayer('boundingbox')) | |
159 loc_bottomleft.setExactLayerCoordinates(obj_bottomleft) | |
160 | |
161 node_topleft = fife.GenericRendererNode(loc_topleft) | |
162 node_topright = fife.GenericRendererNode(loc_topright) | |
163 node_bottomright = fife.GenericRendererNode(loc_bottomright) | |
164 node_bottomleft = fife.GenericRendererNode(loc_bottomleft) | |
165 | |
166 | |
167 self._genericrenderer.addLine("quads", node_topleft, node_topright, 255, 255, 255) | |
168 self._genericrenderer.addLine("quads", node_topright, node_bottomright, 255, 255, 255) | |
169 self._genericrenderer.addLine("quads", node_bottomright, node_bottomleft, 255, 255, 255) | |
170 self._genericrenderer.addLine("quads", node_bottomleft, node_topleft, 255, 255, 255) | |
171 | |
172 #had to do this or it would segfault | |
173 obj_topleft.thisown = 0 | |
174 obj_topright.thisown = 0 | |
175 obj_bottomright.thisown = 0 | |
176 obj_bottomleft.thisown = 0 | |
177 loc_topleft.thisown = 0 | |
178 loc_topright.thisown = 0 | |
179 loc_bottomright.thisown = 0 | |
180 loc_bottomleft.thisown = 0 | |
181 node_topleft.thisown = 0 | |
182 node_topright.thisown = 0 | |
183 node_bottomright.thisown = 0 | |
184 node_bottomleft.thisown = 0 | |
121 | 185 |
122 def gameOver(self): | 186 def gameOver(self): |
123 self._gameover.show() | 187 self._gameover.show() |
124 | 188 |
125 def newGame(self): | 189 def newGame(self): |
197 | 261 |
198 def pump(self): | 262 def pump(self): |
199 """ | 263 """ |
200 Called every frame. | 264 Called every frame. |
201 """ | 265 """ |
266 | |
267 if self._genericrenderer: | |
268 self._genericrenderer.removeAll("quads") | |
269 | |
202 | 270 |
203 if not self.scene: | 271 if not self.scene: |
204 return | 272 return |
205 | 273 |
206 #update the scene | 274 #update the scene |