Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
539:4c7b5eee211c | 540:2e739ae9a8bc |
---|---|
69 self._actor = actor | 69 self._actor = actor |
70 self._item = item | 70 self._item = item |
71 | 71 |
72 def execute(self): | 72 def execute(self): |
73 self._actor.pickUpItem(self._item) | 73 self._actor.pickUpItem(self._item) |
74 | |
75 class EnterPortalAction(BaseAction): | |
76 def __init__(self, actor, portal): | |
77 self._actiontype = Actions["ENTER"] | |
78 self._actor = actor | |
79 self._portal = portal | |
80 | |
81 def execute(self): | |
82 self._actor.enterPortal(self._portal) | |
74 | 83 |
75 ActorStates = {'STAND':0, | 84 ActorStates = {'STAND':0, |
76 'WALK':1, | 85 'WALK':1, |
77 'ATTACK':2} | 86 'ATTACK':2} |
78 | 87 |
84 if action.getId() == 'walk': | 93 if action.getId() == 'walk': |
85 self._object.stand() | 94 self._object.stand() |
86 self._object.performNextAction() | 95 self._object.performNextAction() |
87 | 96 |
88 class Actor(BaseGameObject): | 97 class Actor(BaseGameObject): |
89 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): | 98 def __init__(self, gamecontroller, actortype, instancename, instanceid=None, createInstance=False): |
90 | 99 super(Actor, self).__init__(gamecontroller, actortype, instancename, instanceid, createInstance) |
91 if not hasattr(self, "_type"): | |
92 self._type = GameObjectTypes["NPC"] | |
93 | |
94 super(Actor, self).__init__(gamecontroller, instancename, instanceid, createInstance) | |
95 | 100 |
96 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) | 101 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) |
97 | |
98 self._actionlistener = ActorActionListener(self._gamecontroller, self) | |
99 | 102 |
100 self._nextaction = None | 103 self._nextaction = None |
101 self._inventory = [] | 104 self._inventory = [] |
102 self._maxinventoryitems = 20 | 105 self._maxinventoryitems = 20 |
103 | 106 |
104 self._gold = 0 | 107 self._gold = 0 |
105 | 108 |
106 self.stand() | 109 self.stand() |
107 | 110 |
108 def stand(self): | 111 def stand(self): |
109 self._state = ActorStates["STAND"] | 112 self._state = ActorStates["STAND"] |
110 self._instance.act('stand', self._instance.getFacingLocation()) | 113 self._instance.act('stand', self._instance.getFacingLocation()) |
111 | 114 |
112 def walk(self, location): | 115 def walk(self, location): |
128 if item.modelname == "goldstack": | 131 if item.modelname == "goldstack": |
129 self._gold += item.value | 132 self._gold += item.value |
130 else: | 133 else: |
131 self._inventory.append(item) | 134 self._inventory.append(item) |
132 | 135 |
133 item.onPickUp() | 136 item.onLeftClick() |
134 | 137 |
138 def enterPortal(self, portal): | |
139 if self._id == "player": | |
140 self._gamecontroller.switchMap(portal.dest) | |
141 else: | |
142 self._gamecontroller.scene.removeObjectFromScene(self._id) | |
143 | |
135 def removeItemFromInventory(self, itemid): | 144 def removeItemFromInventory(self, itemid): |
136 itemtoremove = None | 145 itemtoremove = None |
137 for item in self._inventory: | 146 for item in self._inventory: |
138 if item.id == itemid: | 147 if item.id == itemid: |
139 itemtoremove = item | 148 itemtoremove = item |