changeset 519:14f777be6b94

Added a rudimentary Action class.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 27 May 2010 04:36:09 +0000
parents e4cd18a179af
children b6bd314df28a
files demos/rpg/scripts/actors/baseactor.py demos/rpg/scripts/actors/player.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/scene.py
diffstat 4 files changed, 43 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/demos/rpg/scripts/actors/baseactor.py	Wed May 26 21:29:46 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py	Thu May 27 04:36:09 2010 +0000
@@ -31,6 +31,27 @@
 
 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject
 
+Actions = {'NONE':0,
+		   'PICKUP':1,
+		   'TALK':2,
+		   'HIT':3}
+
+class BaseAction(object):
+	def __init__(self):
+		self._actiontype = Actions['NONE']
+		
+	def execute(self):
+		pass
+		
+class TalkAction(BaseAction):
+	def __init__(self, sourceobj, destobj):
+		self._actiontype = Actions['TALK']
+		self._source = sourceobj
+		self._dest = destobj
+		
+	def execute(self):
+		print "talking"
+
 ActorStates = {'STAND':0,
 			   'WALK':1,
 			   'ATTACK':2}
@@ -42,6 +63,7 @@
 	def onInstanceActionFinished(self, instance, action):
 		if action.getId() == 'walk':
 			self._object.stand()
+			self._object.performNextAction()
 
 class Actor(BaseGameObject):
 	def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
@@ -51,6 +73,8 @@
 		
 		self._actionlistener = ActorActionListener(self._gamecontroller, self)
 		
+		self._nextaction = None
+		
 		self.stand()
 
 	def stand(self):
@@ -61,10 +85,22 @@
 		self._state = ActorStates["WALK"]
 		self._instance.move('walk', location, self._walkspeed)
 		
+	def performNextAction(self):
+		if self._nextaction:
+			self._nextaction.execute()
+			self._nextaction = None
+		
 	def _getState(self):
 		return self._state
 		
 	def _setState(self, state):
 		self._state = state
+		
+	def _getNextAction(self):
+		return self._nextaction
+		
+	def _setNextAction(self, action):
+		self._nextaction = action
 	
 	state = property(_getState, _setState)
+	nextaction = property(_getNextAction, _setNextAction)
--- a/demos/rpg/scripts/actors/player.py	Wed May 26 21:29:46 2010 +0000
+++ b/demos/rpg/scripts/actors/player.py	Thu May 27 04:36:09 2010 +0000
@@ -35,6 +35,7 @@
 		super(PlayerActionListener, self).__init__(gamecontroller, obj)
 
 	def onInstanceActionFinished(self, instance, action):
+		super(PlayerActionListener, self).onInstanceActionFinished(instance, action)
 		if action.getId() == 'walk':
 			print "player done walking"
 			#self._object.completeAction()
--- a/demos/rpg/scripts/gamecontroller.py	Wed May 26 21:29:46 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Thu May 27 04:36:09 2010 +0000
@@ -33,6 +33,7 @@
 
 from scripts.scene import Scene
 from scripts.guicontroller import GUIController
+from scripts.actors.baseactor import TalkAction
 
 
 class KeyState(object):
@@ -85,7 +86,9 @@
 		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) )
+			instances = self._gamecontroller.scene.getInstancesAt(clickpoint)
+			if instances:
+				self._gamecontroller.scene.player.nextaction = TalkAction(self, self)
 
 		if (event.getButton() == fife.MouseEvent.RIGHT):
 			instances = self._gamecontroller.scene.getInstancesAt(clickpoint)
--- a/demos/rpg/scripts/scene.py	Wed May 26 21:29:46 2010 +0000
+++ b/demos/rpg/scripts/scene.py	Thu May 27 04:36:09 2010 +0000
@@ -87,13 +87,13 @@
 		
 	def getInstancesAt(self, clickpoint):
 		"""
-		Query the main camera for instances on our actor layer.
+		Query the main camera for instances on the 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)
+		Query the main camera for the Map location (on the actor layer)
 		that a screen point refers to.
 		"""
 		target_mapcoord = self._cameras[self._maincameraname].toMapCoordinates(clickpoint, False)