Mercurial > fife-parpg
comparison demos/rpg/scripts/gamecontroller.py @ 528:796d49ab9380
Cleaned up the createScene function.
Items can now be picked up.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 28 May 2010 14:52:56 +0000 |
parents | 6037f79b0dcf |
children | ea26e7b6f56c |
comparison
equal
deleted
inserted
replaced
527:79d5741fada6 | 528:796d49ab9380 |
---|---|
31 from fife.extensions.soundmanager import SoundManager | 31 from fife.extensions.soundmanager import SoundManager |
32 from fife.extensions.loaders import loadImportFile | 32 from fife.extensions.loaders import loadImportFile |
33 | 33 |
34 from scripts.scene import Scene | 34 from scripts.scene import Scene |
35 from scripts.guicontroller import GUIController | 35 from scripts.guicontroller import GUIController |
36 from scripts.actors.baseactor import TalkAction | 36 from scripts.actors.baseactor import TalkAction, PickUpItemAction |
37 from scripts.objects.baseobject import GameObjectTypes | 37 from scripts.objects.baseobject import GameObjectTypes |
38 | 38 |
39 | 39 |
40 class KeyState(object): | 40 class KeyState(object): |
41 def __init__(self): | 41 def __init__(self): |
89 clickpoint = fife.ScreenPoint(event.getX(), event.getY()) | 89 clickpoint = fife.ScreenPoint(event.getX(), event.getY()) |
90 | 90 |
91 if (event.getButton() == fife.MouseEvent.LEFT): | 91 if (event.getButton() == fife.MouseEvent.LEFT): |
92 self._lastmousepos = (clickpoint.x, clickpoint.y) | 92 self._lastmousepos = (clickpoint.x, clickpoint.y) |
93 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) ) | 93 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) ) |
94 instances = self._gamecontroller.scene.getInstancesAt(clickpoint) | 94 actor_instances = self._gamecontroller.scene.getInstancesAt(clickpoint, self._gamecontroller.scene.actorlayer) |
95 if instances: | 95 item_instances = self._gamecontroller.scene.getInstancesAt(clickpoint, self._gamecontroller.scene.itemlayer) |
96 obj = self._gamecontroller.scene.objectlist[instances[0].getId()] | 96 if actor_instances: |
97 obj = self._gamecontroller.scene.objectlist[actor_instances[0].getId()] | |
97 if obj.type == GameObjectTypes["QUESTGIVER"]: | 98 if obj.type == GameObjectTypes["QUESTGIVER"]: |
98 action = TalkAction(self._gamecontroller.scene.player, obj) | 99 action = TalkAction(self._gamecontroller.scene.player, obj) |
99 self._gamecontroller.scene.player.nextaction = action | 100 self._gamecontroller.scene.player.nextaction = action |
101 | |
102 if item_instances: | |
103 obj = self._gamecontroller.scene.objectlist[item_instances[0].getId()] | |
104 if obj.type == GameObjectTypes["ITEM"]: | |
105 action = PickUpItemAction(self._gamecontroller.scene.player, obj) | |
106 self._gamecontroller.scene.player.nextaction = action | |
107 | |
100 | 108 |
101 if (event.getButton() == fife.MouseEvent.RIGHT): | 109 if (event.getButton() == fife.MouseEvent.RIGHT): |
102 instances = self._gamecontroller.scene.getInstancesAt(clickpoint) | 110 instances = self._gamecontroller.scene.getInstancesAt(clickpoint) |
103 print "selected instances on actor layer: ", [i.getId() for i in instances] | 111 print "selected instances on actor layer: ", [i.getId() for i in instances] |
104 if instances: | 112 if instances: |
114 renderer.removeAllOutlines() | 122 renderer.removeAllOutlines() |
115 else: | 123 else: |
116 return | 124 return |
117 | 125 |
118 pt = fife.ScreenPoint(event.getX(), event.getY()) | 126 pt = fife.ScreenPoint(event.getX(), event.getY()) |
119 instances = self._gamecontroller.scene.getInstancesAt(pt); | 127 actor_instances = self._gamecontroller.scene.getInstancesAt(pt, self._gamecontroller.scene.actorlayer) |
120 | 128 item_instances = self._gamecontroller.scene.getInstancesAt(pt, self._gamecontroller.scene.itemlayer) |
121 for i in instances: | 129 for i in actor_instances: |
122 renderer.addOutlined(i, 173, 255, 47, 2) | 130 renderer.addOutlined(i, 173, 255, 47, 2) |
131 | |
132 for j in item_instances: | |
133 renderer.addOutlined(j, 173, 255, 47, 2) | |
123 | 134 |
124 def mouseEntered(self, event): | 135 def mouseEntered(self, event): |
125 pass | 136 pass |
126 | 137 |
127 def mouseExited(self, event): | 138 def mouseExited(self, event): |
195 self._keystate.reset() | 206 self._keystate.reset() |
196 | 207 |
197 if self._scene: | 208 if self._scene: |
198 self._scene.destroyScene() | 209 self._scene.destroyScene() |
199 self._scene = None | 210 self._scene = None |
200 | |
201 loadImportFile("objects/actors/player/warrior/object.xml", self._engine) | |
202 loadImportFile("objects/items/goldstack/object.xml", self._engine) | |
203 | 211 |
204 self._scene = Scene(self) | 212 self._scene = Scene(self) |
205 self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml")) | 213 self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml")) |
206 | 214 |
207 self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")]) | 215 self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")]) |