diff demos/rpg/scripts/actors/baseactor.py @ 540:2e739ae9a8bc

Some misc code cleanup. Added the EnterPortalAction action. You can now move between town and level1.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 01 Jun 2010 19:17:30 +0000
parents 1afe46247ab1
children cb7ec12214a9
line wrap: on
line diff
--- a/demos/rpg/scripts/actors/baseactor.py	Tue Jun 01 18:28:25 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py	Tue Jun 01 19:17:30 2010 +0000
@@ -71,6 +71,15 @@
 		
 	def execute(self):
 		self._actor.pickUpItem(self._item)
+		
+class EnterPortalAction(BaseAction):
+	def __init__(self, actor, portal):
+		self._actiontype = Actions["ENTER"]
+		self._actor = actor
+		self._portal = portal
+		
+	def execute(self):
+		self._actor.enterPortal(self._portal)
 
 ActorStates = {'STAND':0,
 			   'WALK':1,
@@ -86,17 +95,11 @@
 			self._object.performNextAction()
 
 class Actor(BaseGameObject):
-	def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
-
-		if not hasattr(self, "_type"):
-			self._type = GameObjectTypes["NPC"]
-			
-		super(Actor, self).__init__(gamecontroller, instancename, instanceid, createInstance)
+	def __init__(self, gamecontroller, actortype, instancename, instanceid=None, createInstance=False):
+		super(Actor, self).__init__(gamecontroller, actortype, instancename, instanceid, createInstance)
 
 		self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
 		
-		self._actionlistener = ActorActionListener(self._gamecontroller, self)
-		
 		self._nextaction = None
 		self._inventory = []
 		self._maxinventoryitems = 20
@@ -104,7 +107,7 @@
 		self._gold = 0
 		
 		self.stand()
-
+		
 	def stand(self):
 		self._state = ActorStates["STAND"]
 		self._instance.act('stand', self._instance.getFacingLocation())
@@ -130,8 +133,14 @@
 			else:
 				self._inventory.append(item)
 		
-			item.onPickUp()
+			item.onLeftClick()
 			
+	def enterPortal(self, portal):
+		if self._id == "player":
+			self._gamecontroller.switchMap(portal.dest)
+		else:
+			self._gamecontroller.scene.removeObjectFromScene(self._id)
+		
 	def removeItemFromInventory(self, itemid):
 		itemtoremove = None
 		for item in self._inventory: