changeset 516:d70fc46c8aa5

Added some placeholder graphics for the warrior. The player can now walk around the map.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 25 May 2010 21:41:59 +0000
parents 520bd1621644
children c3a026cdd91b
files demos/rpg/maps/town.xml demos/rpg/objects/actors/player/warrior/object.xml demos/rpg/objects/actors/player/warrior/walk/045.png demos/rpg/objects/actors/player/warrior/walk/animation.xml demos/rpg/objects/ground/grass/01/135.png demos/rpg/objects/ground/grass/01/225.png demos/rpg/objects/ground/grass/01/315.png demos/rpg/objects/ground/grass/01/45.png demos/rpg/objects/ground/grass/01/object.xml demos/rpg/scripts/actors/baseactor.py demos/rpg/scripts/actors/player.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/scene.py demos/rpg/settings-dist.xml
diffstat 14 files changed, 108 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/demos/rpg/maps/town.xml	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/maps/town.xml	Tue May 25 21:41:59 2010 +0000
@@ -1,10 +1,6 @@
 <?xml version="1.0" encoding="ascii"?>
 <map id="maintown" format="1.0">
 	<import file="../objects/ground/grass/01/object.xml"></import>
-	<layer y_scale="1.0" y_offset="0.0" pathing="cell_edges_only" grid_type="square" id="actor_layer" rotation="0.0" x_scale="1.0" x_offset="0.0" transparency="0">
-		<instances>
-		</instances>
-	</layer>
 	<layer y_scale="1.0" y_offset="0.0" pathing="cell_edges_only" grid_type="square" id="ground_layer" rotation="0.0" x_scale="1.0" x_offset="0.0" transparency="0">
 		<instances>
 			<i o="grass:01" ns="http://www.fifengine.de/xml/rpg" x="-2.0" r="0" y="0.0" z="0.0"></i>
@@ -153,6 +149,10 @@
 			<i r="0" x="4.0" o="grass:01" z="0.0" y="8.0"></i>
 		</instances>
 	</layer>
+	<layer y_scale="1.0" y_offset="0.0" pathing="cell_edges_only" grid_type="square" id="actor_layer" rotation="0.0" x_scale="1.0" x_offset="0.0" transparency="0">
+		<instances>
+		</instances>
+	</layer>
 	<camera ref_cell_height="64" zoom="1.0" rotation="45.0" ref_layer_id="ground_layer" ref_cell_width="64" id="camera1" tilt="-60.0">
 	</camera>
 </map>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/objects/actors/player/warrior/object.xml	Tue May 25 21:41:59 2010 +0000
@@ -0,0 +1,6 @@
+<?fife type="object"?>
+<object id="warrior" namespace="http://www.fifengine.de/xml/rpg" blocking="1" static="1">
+	<action id="walk">
+		<animation source="walk/animation.xml" direction="45" />
+	</action>
+</object>
Binary file demos/rpg/objects/actors/player/warrior/walk/045.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/objects/actors/player/warrior/walk/animation.xml	Tue May 25 21:41:59 2010 +0000
@@ -0,0 +1,4 @@
+<animation delay="2000" namespace="http://www.fifengine.de/xml/rpg" id="warrior:walk" x_offset="0" y_offset="0">
+	<frame source="045.png" />
+</animation>
+
Binary file demos/rpg/objects/ground/grass/01/135.png has changed
Binary file demos/rpg/objects/ground/grass/01/225.png has changed
Binary file demos/rpg/objects/ground/grass/01/315.png has changed
Binary file demos/rpg/objects/ground/grass/01/45.png has changed
--- a/demos/rpg/objects/ground/grass/01/object.xml	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/objects/ground/grass/01/object.xml	Tue May 25 21:41:59 2010 +0000
@@ -1,4 +1,7 @@
 <?fife type="object"?>
 <object id="grass:01" namespace="http://www.fifengine.de/xml/rpg" blocking="0" static="1">
 	<image source="45.png" direction="45" />
+	<image source="135.png" direction="135" />
+	<image source="225.png" direction="225" />
+	<image source="315.png" direction="315" />
 </object>
--- a/demos/rpg/scripts/actors/baseactor.py	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py	Tue May 25 21:41:59 2010 +0000
@@ -29,6 +29,10 @@
 from fife import fife
 from fife.extensions.loaders import loadMapFile
 
+ActorStates = {'IDLE':0,
+			   'WALK':1,
+			   'ATTACK':2}
+
 class Actor(object):
 	def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
 		"""
@@ -52,10 +56,13 @@
 		self._instance = None
 		
 		if createInstance:
-			self._createFIFEInstance(self._name)
+			self._createFIFEInstance()
 		else:
-			self._instance = self._gamecontroller.scene.layer.getInstance(self._id)
-			self._instance.thisown = 0			
+			self._instance = self._gamecontroller.scene.actorlayer.getInstance(self._id)
+			self._instance.thisown = 0
+			
+		self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
+		self._state = ActorStates["IDLE"]
 		
 	def destroy(self):
 		"""
@@ -64,6 +71,10 @@
 		if self._instance :
 			self._gamecontroller.scene.actorlayer.deleteInstance(self._instance)
 			self._instance = None
+			
+	def walk(self, location):
+		self._state = ActorStates["WALK"]
+		self._instance.move('walk', location, self._walkspeed)
 	
 	def _createFIFEInstance(self):
 		"""
--- a/demos/rpg/scripts/actors/player.py	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/scripts/actors/player.py	Tue May 25 21:41:59 2010 +0000
@@ -27,7 +27,7 @@
 import sys, os, re, math, random, shutil
 
 from fife import fife
-from scripts.actors.baseactor import Actor
+from scripts.actors.baseactor import Actor, ActorStates
 
 class Player(Actor):
 	def __init__(self, gamecontroller, playermodelname):
--- a/demos/rpg/scripts/gamecontroller.py	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Tue May 25 21:41:59 2010 +0000
@@ -30,6 +30,7 @@
 
 from scripts.scene import Scene
 from scripts.guicontroller import GUIController
+from fife.extensions.loaders import loadImportFile
 
 class KeyState(object):
 	def __init__(self):
@@ -55,15 +56,13 @@
 		self._eventmanager = self._engine.getEventManager()
 		
 		fife.IMouseListener.__init__(self)
-		self._eventmanager.addMouseListener(self)
-	
 		fife.IKeyListener.__init__(self)
-		self._eventmanager.addKeyListener(self)
 		
 		self._attached = False
 		
 	def attach(self):
 		if not self._attached:
+			self._gamecontroller.keystate.reset()
 			self._eventmanager.addMouseListenerFront(self)
 			self._eventmanager.addKeyListenerFront(self)
 			self._attached = True
@@ -75,9 +74,37 @@
 			self._attached = False
 		
 	def mousePressed(self, event):
-		pass
+		#mouse press was consumed by some pychan widget
+		if event.isConsumedByWidgets():
+			return
+
+		clickpoint = fife.ScreenPoint(event.getX(), event.getY())
+		if (event.getButton() == fife.MouseEvent.LEFT):
+			self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) )
+			#self.hero.run( self.getLocationAt(clickpoint) )
+
+		if (event.getButton() == fife.MouseEvent.RIGHT):
+			instances = self._gamecontroller.scene.getInstancesAt(clickpoint)
+			print "selected instances on actor layer: ", [i.getObject().getId() for i in instances]
+			if instances:
+				#do something
+				pass
+				
 	def mouseReleased(self, event):
-		pass	
+		pass
+
+	def mouseMoved(self, event):
+		renderer = self._gamecontroller.instancerenderer
+		if renderer:
+			renderer.removeAllOutlines()
+		else:
+			return
+
+		pt = fife.ScreenPoint(event.getX(), event.getY())
+		instances = self.getInstancesAt(pt);
+		for i in instances:
+			renderer.addOutlined(i, 173, 255, 47, 2)
+
 	def mouseEntered(self, event):
 		pass
 	def mouseExited(self, event):
@@ -108,7 +135,6 @@
 		
 		self._gamecontroller.keystate.updateKey(keyval, False)
 		
-		
 class GameController(object):
 	def __init__(self, application, engine, settings):
 		self._application = application
@@ -124,6 +150,7 @@
 		self._guicontroller.showMainMenu()
 		
 		self._scene = None
+		self._instancerenderer = None
 	
 	def onConsoleCommand(self, command):
 		"""
@@ -141,17 +168,22 @@
 		if self._scene:
 			self._scene.destroyScene()
 			self._scene = None
+			
+		loadImportFile("objects/actors/player/warrior/object.xml", self._engine)
 		
 		self._scene = Scene(self)
 		self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml"))
 
+		self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")])
+
 		#start listening to events
 		self._listener.attach()
 		
 	def endGame(self):
 		if self._scene:
 			self._scene.destroyScene()
-			self._scene = None		
+			self._scene = None
+			self._instancerenderer = None
 		
 	def quit(self):
 		self.endGame()
@@ -177,8 +209,12 @@
 	def _getKeyState(self):
 		return self._keystate
 	
+	def _getInstanceRenderer(self):
+		return self._instancerenderer
+	
 	guicontroller = property(_getGUIController) 
 	engine = property(_getEngine)
 	settings = property(_getSettings)
 	scene = property(_getScene)
 	keystate = property(_getKeyState)
+	instancerenderer = property(_getInstanceRenderer)
--- a/demos/rpg/scripts/scene.py	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/scripts/scene.py	Tue May 25 21:41:59 2010 +0000
@@ -36,6 +36,7 @@
 		self._gamecontroller = gamecontroller
 		
 		self._map = None
+		self._maincameraname = self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1")
 		self._cameras = {}
 		
 		self._actorlayer = None
@@ -51,10 +52,12 @@
 		for cam in self._map.getCameras():
 			self._cameras[cam.getId()] = cam
 		
-		self._cameras[self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1")].setZoom(1.0)
+		self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 2.0))
 		
 		self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer"))
 		
+		self._player = Player(self._gamecontroller, "warrior")
+		
 	def destroyScene(self):
 		self._cameras.clear()
 		
@@ -63,12 +66,37 @@
 		
 		self._map = None
 		self._actorlayer = None
+		
+	def getInstancesAt(self, clickpoint):
+		"""
+		Query the main camera for instances on our actor layer.
+		"""
+		return self.cameras[self._maincameraname].getMatchingInstances(clickpoint, self._actorlayer)
+
+	def getLocationAt(self, clickpoint):
+		"""
+		Query the main camera for the Map location (on the agent layer)
+		that a screen point refers to.
+		"""
+		target_mapcoord = self._cameras[self._maincameraname].toMapCoordinates(clickpoint, False)
+		target_mapcoord.z = 0
+		location = fife.Location(self._actorlayer)
+		location.setMapCoordinates(target_mapcoord)
+		return location
 				
 	def updateScene(self):
 		pass
 		
 	def _getActorLayer(self):
 		return self._actorlayer
-		
+	
+	def _getCameras(self):
+		return self._cameras
+	
+	def _getPlayer(self):
+		return self._player
+	
 	actorlayer = property(_getActorLayer)
+	cameras = property(_getCameras)
+	player = property(_getPlayer)
 		
--- a/demos/rpg/settings-dist.xml	Tue May 25 15:02:16 2010 +0000
+++ b/demos/rpg/settings-dist.xml	Tue May 25 21:41:59 2010 +0000
@@ -26,8 +26,11 @@
 		<Setting name="TownMapFile" type="str"> maps/town.xml </Setting>
 		<Setting name="Level1MapFile" type="str"> maps/level1.xml </Setting>
 		<Setting name="DefaultCameraName" type="str"> camera1 </Setting>
+		<Setting name="DefaultZoom" type="float"> 2.0 </Setting>
 		<Setting name="ObjectNamespace" type="str"> http://www.fifengine.de/xml/rpg </Setting>
 		<Setting name="ActorLayer" type="str"> actor_layer </Setting>
 		<Setting name="HelpText" type="str"> misc/help.txt </Setting>
+		
+		<Setting name="DefaultActorWalkSpeed" type="float"> 2.5 </Setting>
 	</Module>
 </Settings>