# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1274934969 0 # Node ID 14f777be6b948c19615aa12d1af1e707694e8426 # Parent e4cd18a179af720e6dd84ffaa43b5e8a638af1a5 Added a rudimentary Action class. diff -r e4cd18a179af -r 14f777be6b94 demos/rpg/scripts/actors/baseactor.py --- 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) diff -r e4cd18a179af -r 14f777be6b94 demos/rpg/scripts/actors/player.py --- 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() diff -r e4cd18a179af -r 14f777be6b94 demos/rpg/scripts/gamecontroller.py --- 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) diff -r e4cd18a179af -r 14f777be6b94 demos/rpg/scripts/scene.py --- 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)