Mercurial > fife-parpg
changeset 563:f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
- Removed the getModuleByType() helper function.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 24 Jun 2010 21:27:11 +0000 |
parents | e34b44afd428 |
children | 7d88eddd2ec7 |
files | demos/rpg/maps/allobjects.xml demos/rpg/maps/level1_objects.xml demos/rpg/scripts/actors/baseactor.py demos/rpg/scripts/actors/player.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/objects/baseobject.py demos/rpg/scripts/objects/items.py demos/rpg/scripts/scene.py |
diffstat | 8 files changed, 28 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/rpg/maps/allobjects.xml Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/maps/allobjects.xml Thu Jun 24 21:27:11 2010 +0000 @@ -10,6 +10,7 @@ <Module name="objects"> <Setting name="goldstack" type="dict"> type : GOLD ; modelname : GoldStack ; value : 5000 </Setting> <Setting name="templeportal" type="dict"> type : PORTAL ; modelname : TempleEntrance ; dest : town </Setting> - <Setting name="quiller" type="dict"> type : QUESTGIVER ; modelname : Quiller ; stat1 : 20 ; stat2 : 343 </Setting> + <Setting name="quiller" type="dict"> type : QUESTGIVER ; modelname : Quiller </Setting> + <Setting name="signenemy1" type="dict"> type : ENEMY ; modelname : Quiller </Setting> </Module> </Settings>
--- a/demos/rpg/maps/level1_objects.xml Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/maps/level1_objects.xml Thu Jun 24 21:27:11 2010 +0000 @@ -1,8 +1,9 @@ <?xml version='1.0' encoding='UTF-8'?> <Settings> <Module name="objects"> - <Setting name="objectlist" type="list"> gstack2 ; townportal </Setting> + <Setting name="objectlist" type="list"> gstack2 ; townportal ; sign1 </Setting> <Setting name="gstack2" type="dict"> objectname : goldstack ; value : 5000 ; posx : -3.0 ; posy : -3.0 </Setting> <Setting name="townportal" type="dict"> objectname : templeportal ; dest : town ; posx : 3.0 ; posy : 2.0 </Setting> + <Setting name="sign1" type="dict"> objectname : signenemy1 ; posx : 1.0 ; posy : 1.0 </Setting> </Module> </Settings>
--- a/demos/rpg/scripts/actors/baseactor.py Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Thu Jun 24 21:27:11 2010 +0000 @@ -62,7 +62,17 @@ else: self._dest.showNoQuestDialog() else: - self._dest.instance.say("Hello there!") + self._dest.say("Hello there!") + +class AttackAction(BaseAction): + def __init__(self, attacker, defender): + self._actiontype = Actions['ATTACK'] + self._attacker = attacker + self._defender = defender + + def execute(self): + if self._defender.type == GameObjectTypes["ENEMY"]: + self._defender.say("Ouch") class PickUpItemAction(BaseAction): def __init__(self, actor, item): @@ -155,8 +165,6 @@ def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) - self._type = GameObjectTypes["DEFAULT"] - self._nextaction = None self._inventory = [] self._maxinventoryitems = 20
--- a/demos/rpg/scripts/actors/player.py Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/scripts/actors/player.py Thu Jun 24 21:27:11 2010 +0000 @@ -40,9 +40,8 @@ class Player(Actor): def __init__(self, gamecontroller, layer, playermodelname): - super(Player, self).__init__(gamecontroller, layer, "Player", "player", playermodelname, "player", True) - self._type = GameObjectTypes["PLAYER"] - + super(Player, self).__init__(gamecontroller, layer, "PLAYER", "player", playermodelname, "player", True) + self._actionlistener = PlayerActionListener(self._gamecontroller, self) self._actionlistener.attachActionListener()
--- a/demos/rpg/scripts/gamecontroller.py Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Thu Jun 24 21:27:11 2010 +0000 @@ -32,7 +32,7 @@ from scripts.scene import Scene from scripts.guicontroller import GUIController -from scripts.actors.baseactor import TalkAction, PickUpItemAction, EnterPortalAction +from scripts.actors.baseactor import TalkAction, AttackAction, PickUpItemAction, EnterPortalAction from scripts.objects.baseobject import GameObjectTypes from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError from scripts.quests.questmanager import QuestManager @@ -133,6 +133,12 @@ if obj.type == GameObjectTypes["QUESTGIVER"]: action = TalkAction(self._gamecontroller.scene.player, obj) self._gamecontroller.scene.player.nextaction = action + elif obj.type == GameObjectTypes["ENEMY"]: + action = AttackAction(self._gamecontroller.scene.player, obj) + self._gamecontroller.scene.player.nextaction = action + else: + action = TalkAction(self._gamecontroller.scene.player, obj) + self._gamecontroller.scene.player.nextaction = action if item_instances: obj = self._gamecontroller.scene.objectlist[item_instances[0].getId()]
--- a/demos/rpg/scripts/objects/baseobject.py Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/scripts/objects/baseobject.py Thu Jun 24 21:27:11 2010 +0000 @@ -42,16 +42,6 @@ "PORTAL":7 } -def getModuleByType(objtype): - if objtype == GameObjectTypes["ITEM"] or objtype == GameObjectTypes["GOLD"] or objtype == GameObjectTypes["PORTAL"]: - module = "items" - elif objtype == GameObjectTypes["QUESTGIVER"] or objtype == GameObjectTypes["ENEMY"]: - module = "npcs" - else: - module = "unknown" - - return module - class ObjectActionListener(fife.InstanceActionListener): def __init__(self, gamecontroller, obj): fife.InstanceActionListener.__init__(self) @@ -84,6 +74,7 @@ self._fifeobject = None self._typename = typename + self._type = GameObjectTypes[typename] self._baseobjectname = baseobjectname self._name = instancename @@ -97,8 +88,6 @@ self._actionlistener = None - self._type = GameObjectTypes["DEFAULT"] - self._layer = layer if createInstance:
--- a/demos/rpg/scripts/objects/items.py Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/scripts/objects/items.py Thu Jun 24 21:27:11 2010 +0000 @@ -27,7 +27,7 @@ from fife import fife -from scripts.objects.baseobject import BaseGameObject, GameObjectTypes, getModuleByType +from scripts.objects.baseobject import BaseGameObject, GameObjectTypes class BaseItem(BaseGameObject):
--- a/demos/rpg/scripts/scene.py Thu Jun 24 19:58:59 2010 +0000 +++ b/demos/rpg/scripts/scene.py Thu Jun 24 21:27:11 2010 +0000 @@ -34,7 +34,7 @@ from scripts.actors.questgiver import QuestGiver from scripts.quests.basequest import Quest, ReturnItemQuest, QuestTypes from scripts.actors.player import Player -from scripts.objects.baseobject import GameObjectTypes, getModuleByType +from scripts.objects.baseobject import GameObjectTypes from scripts.objects.items import BaseItem, GoldStack, Portal from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError from scripts.misc.serializer import Serializer @@ -75,7 +75,7 @@ newobject = Portal(self._gamecontroller, self.itemlayer, objdict["type"], objectname, modeldict["model"], identifier) elif objdict["type"] == "QUESTGIVER": newobject = QuestGiver(self._gamecontroller, self.actorlayer, objdict["type"], objectname, modeldict["model"], identifier, True) - elif objdict["type"] == "NPC": + elif objdict["type"] == "ENEMY": newobject = Actor(self._gamecontroller, self.actorlayer, objdict["type"], objectname, modeldict["model"], identifier, True) else: return None