changeset 471:7a79dc2a0592

Adding the credits window (still needs to be written) Hopefully fixed some memory leaks. Moved the flashing code to the appropriate spot (in ShipBase).
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 15 Apr 2010 15:53:06 +0000
parents 3b04e921c93d
children 3164715a0621
files demos/shooter/gui/credits.txt demos/shooter/gui/credits.xml demos/shooter/scripts/gui/guis.py demos/shooter/scripts/scene.py demos/shooter/scripts/ships/enemies.py demos/shooter/scripts/ships/player.py demos/shooter/scripts/ships/shipbase.py demos/shooter/scripts/weapons.py demos/shooter/scripts/world.py
diffstat 9 files changed, 85 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/shooter/gui/credits.txt	Thu Apr 15 15:53:06 2010 +0000
@@ -0,0 +1,8 @@
+This is the credits file.
+
+Information regarding who worked on this demo along
+with FIFE will go into this file.
+
+Thanks,
+
+The FIFE team!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/shooter/gui/credits.xml	Thu Apr 15 15:53:06 2010 +0000
@@ -0,0 +1,17 @@
+<Container base_color="0,0,0" border_size="0" opaque="0" position="0,0" name="Credits" size="1024,768">
+	<VBox name="credits" position="312,200" opaque="1" base_color="188,0,0">
+		<HBox>
+			<Spacer />
+			<Label name="credits" border_size="0" text="Credits" />
+			<Spacer />
+		</HBox>
+		<HBox>
+			<ScrollArea min_size="400,400" max_size="400,400" size="400,400" vertical_scrollbar="1">
+				<TextBox name="creditText" filename="gui/credits.txt"/>
+			</ScrollArea>
+		</HBox>
+		<HBox>
+			<Button name="close" text="Close"/>
+		</HBox>
+	</VBox>
+</Container>
\ No newline at end of file
--- a/demos/shooter/scripts/gui/guis.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/gui/guis.py	Thu Apr 15 15:53:06 2010 +0000
@@ -359,4 +359,21 @@
 		self._widget.hide()
 
 	def isVisible(self):
-		return self._widget.isVisible()
\ No newline at end of file
+		return self._widget.isVisible()
+		
+class CreditsDisplay(object):
+	def __init__(self, world):
+		self._world = world
+		self._widget = pychan.loadXML('gui/credits.xml')
+
+		eventMap = {
+			'close': self.hide,
+		}
+
+		self._widget.mapEvents(eventMap)
+		
+	def show(self):
+		self._widget.show()
+		
+	def hide(self):
+		self._widget.hide()
\ No newline at end of file
--- a/demos/shooter/scripts/scene.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/scene.py	Thu Apr 15 15:53:06 2010 +0000
@@ -200,9 +200,9 @@
 		#TODO: search to ensure the object isn't already part of the scene
 		loc = obj.instance.getLocation().getExactLayerCoordinates()
 		nodeindex = int(loc.x * self._xscale)
-		
+
+		obj.scenenodeid = nodeindex		
 		self._nodes[nodeindex].spaceobjects.append(obj)
-		obj.scenenodeid = nodeindex		
 
 	def addProjectileToScene(self, projectile):
 		self._projectiles.append(projectile)
@@ -212,10 +212,12 @@
 		nodeindex = int(loc.x * self._xscale)
 		
 		if nodeindex != obj.scenenodeid:
-			self._nodes[obj.scenenodeid].spaceobjects.remove(obj)
+			if obj in self._nodes[obj.scenenodeid].spaceobjects:
+				self._nodes[obj.scenenodeid].spaceobjects.remove(obj)
+
+			obj.scenenodeid = nodeindex
 			self._nodes[nodeindex].spaceobjects.append(obj)
-			obj.scenenodeid = nodeindex
-	
+
 	def removeObjectFromScene(self, obj):
 		for node in self._nodes:
 			if obj in node.spaceobjects:
@@ -317,6 +319,7 @@
 		#remove any expired projectiles 
 		for p in projtodelete:
 			if p in self._projectiles:
+				p.destroy()
 				self._projectiles.remove(p)
 
 				
--- a/demos/shooter/scripts/ships/enemies.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/ships/enemies.py	Thu Apr 15 15:53:06 2010 +0000
@@ -34,6 +34,8 @@
 	def onInstanceActionFinished(self, instance, action):
 		if action.getId() == 'explode':
 			self._ship.removeFromScene()
+			
+		super(EnemyActionListener, self).onInstanceActionFinished(instance, action)
 
 class BossActionListener(ShipActionListener):
 	def __init__(self, ship):
@@ -43,12 +45,9 @@
 		if action.getId() == 'explode':
 			self._ship.removeFromScene()
 			self._ship.endLevel()
-		elif action.getId() == 'flash':
-			if self._ship._flashnumber > 0:
-				self._ship.instance.act('flash', self._ship.instance.getFacingLocation())
-				self._ship._flashnumber -= 1	
-			else:	
-				self._ship._flashing = False
+		
+		super(BossActionListener, self).onInstanceActionFinished(instance, action)
+
 				
 class Saucer1(Ship):
 	def __init__(self, scene, name, instance, findInstance=True):
@@ -107,7 +106,10 @@
 		self.hitpoints = 2
 		self.scorevalue = 100
 
-				
+	def applyHit(self, hp):
+		self.flash(1)
+		super(Saucer2, self).applyHit(hp)
+		
 	def update(self):	
 		if self._dir == 1:
 			self.applyThrust(fife.DoublePoint(0,-0.25))
@@ -171,6 +173,10 @@
 		
 		self.hitpoints = 2
 		self.scorevalue = 150
+
+	def applyHit(self, hp):
+		self.flash(1)
+		super(Streaker, self).applyHit(hp)
 		
 	def update(self):	
 		self.applyThrust(fife.DoublePoint(-0.40,0))
--- a/demos/shooter/scripts/ships/player.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/ships/player.py	Thu Apr 15 15:53:06 2010 +0000
@@ -34,12 +34,8 @@
 	def onInstanceActionFinished(self, instance, action):
 		if action.getId() == 'explode':
 			self._ship.respawn()
-		if action.getId() == 'flash':
-			if self._ship._flashnumber > 0:
-				self._ship.instance.act('flash', self._ship.instance.getFacingLocation())
-				self._ship._flashnumber -= 1	
-			else:	
-				self._ship._flashing = False
+		
+		super(PlayerActionListener, self).onInstanceActionFinished(instance, action)
 		
 		
 class Player(Ship):
@@ -100,6 +96,9 @@
 			self._invulnerable = True
 			self._lives -= 1		
 
+	def fire(self, direction):
+		return self._weapon.fire(direction)
+
 	def update(self):
 	
 		key = False
--- a/demos/shooter/scripts/ships/shipbase.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/ships/shipbase.py	Thu Apr 15 15:53:06 2010 +0000
@@ -36,7 +36,13 @@
 		self._ship.instance.addActionListener(self)
 
 	def onInstanceActionFinished(self, instance, action):
-		pass
+		if action.getId() == 'flash':
+			if self._ship._flashing and self._ship._flashnumber > 0:
+				self._ship.instance.act('flash', self._ship.instance.getFacingLocation())
+				self._ship._flashnumber -= 1	
+			else:	
+				self._ship._flashing = False
+				self._ship._flashnumber = 0
 
 class Ship(SpaceObject):
 	def __init__(self, scene, name, findInstance=True):
@@ -64,7 +70,7 @@
 		self._flashing = True	
 	
 	def fire(self, direction):
-		if self._weapon:
+		if self._weapon and self._hitpoints > 0:
 			return self._weapon.fire(direction)
 		
 		return None
--- a/demos/shooter/scripts/weapons.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/weapons.py	Thu Apr 15 15:53:06 2010 +0000
@@ -58,9 +58,11 @@
 			self._starttime = self._scene.time
 		
 	def destroy(self):
-		if self._running and self._instance:
+		if self._instance:
 			self._layer.deleteInstance(self._instance)
-			self._running = False
+			self._instance = None
+		
+		self._running = False
 		
 	def _getTTL(self):
 		return self._ttl
@@ -110,7 +112,6 @@
 	def __init__(self, scene, ship, firerate):
 		super(Cannon, self).__init__(scene, ship, firerate)
 		
-		#cannon's projectile velocity
 		self._projectileVelocity = 0.75
 
 		
@@ -129,7 +130,6 @@
 	def __init__(self, scene, ship, firerate):
 		super(FireBall, self).__init__(scene, ship, firerate)
 		
-		#cannon's projectile velocity
 		self._projectileVelocity = 0.50
 
 		
--- a/demos/shooter/scripts/world.py	Wed Apr 14 19:15:27 2010 +0000
+++ b/demos/shooter/scripts/world.py	Thu Apr 15 15:53:06 2010 +0000
@@ -80,6 +80,9 @@
 		self._winner = WinnerDisplay()
 		self._winner.hide()
 		
+		self._credits = CreditsDisplay(self)
+		self._credits.hide()
+		
 		self._genericrenderer = None
 		
 		self._gamecomplete = False
@@ -94,7 +97,7 @@
 		self._mainmenu.show(cont)
 		
 	def showCredits(self):
-		pass
+		self._credits.show()
 		
 	def showHighScores(self):
 		self._highscores.show()