comparison demos/rpg/scripts/gamecontroller.py @ 524:6037f79b0dcf

Multiple quests now work. Added the item layer. Made movement more like diablo by allowing you to hold and drag the left mouse button. All objects are now loaded from a separate "allobjects" file. Specific item attributes are loaded from the map objects file (like position). This allows for the possibility of multiple instances using the same FIFE model.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 27 May 2010 21:11:37 +0000
parents d01eb65b2726
children 796d49ab9380
comparison
equal deleted inserted replaced
523:d01eb65b2726 524:6037f79b0dcf
64 fife.IMouseListener.__init__(self) 64 fife.IMouseListener.__init__(self)
65 fife.IKeyListener.__init__(self) 65 fife.IKeyListener.__init__(self)
66 66
67 self._attached = False 67 self._attached = False
68 68
69 self._lastmousepos = (0.0,0.0)
70
69 def attach(self): 71 def attach(self):
70 if not self._attached: 72 if not self._attached:
71 self._gamecontroller.keystate.reset() 73 self._gamecontroller.keystate.reset()
72 self._eventmanager.addMouseListenerFront(self) 74 self._eventmanager.addMouseListenerFront(self)
73 self._eventmanager.addKeyListenerFront(self) 75 self._eventmanager.addKeyListenerFront(self)
83 #mouse press was consumed by some pychan widget 85 #mouse press was consumed by some pychan widget
84 if event.isConsumedByWidgets(): 86 if event.isConsumedByWidgets():
85 return 87 return
86 88
87 clickpoint = fife.ScreenPoint(event.getX(), event.getY()) 89 clickpoint = fife.ScreenPoint(event.getX(), event.getY())
90
88 if (event.getButton() == fife.MouseEvent.LEFT): 91 if (event.getButton() == fife.MouseEvent.LEFT):
92 self._lastmousepos = (clickpoint.x, clickpoint.y)
89 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) ) 93 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) )
90 instances = self._gamecontroller.scene.getInstancesAt(clickpoint) 94 instances = self._gamecontroller.scene.getInstancesAt(clickpoint)
91 if instances: 95 if instances:
92 obj = self._gamecontroller.scene.objectlist[instances[0].getId()] 96 obj = self._gamecontroller.scene.objectlist[instances[0].getId()]
93 if obj.type == GameObjectTypes["QUESTGIVER"]: 97 if obj.type == GameObjectTypes["QUESTGIVER"]:
131 135
132 def mouseWheelMovedDown(self, event): 136 def mouseWheelMovedDown(self, event):
133 pass 137 pass
134 138
135 def mouseDragged(self, event): 139 def mouseDragged(self, event):
136 pass 140 if event.isConsumedByWidgets():
141 return
142
143 clickpoint = fife.ScreenPoint(event.getX(), event.getY())
144 if (event.getButton() == fife.MouseEvent.LEFT):
145 if clickpoint.x > self._lastmousepos[0] + 5 or clickpoint.x < self._lastmousepos[0] - 5 or clickpoint.y > self._lastmousepos[1] + 5 or clickpoint.y < self._lastmousepos[1] - 5:
146 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) )
147
148 self._lastmousepos = (clickpoint.x, clickpoint.y)
137 149
138 def keyPressed(self, event): 150 def keyPressed(self, event):
139 keyval = event.getKey().getValue() 151 keyval = event.getKey().getValue()
140 keystr = event.getKey().getAsString().lower() 152 keystr = event.getKey().getAsString().lower()
141 if keyval == fife.Key.ESCAPE: 153 if keyval == fife.Key.ESCAPE:
185 if self._scene: 197 if self._scene:
186 self._scene.destroyScene() 198 self._scene.destroyScene()
187 self._scene = None 199 self._scene = None
188 200
189 loadImportFile("objects/actors/player/warrior/object.xml", self._engine) 201 loadImportFile("objects/actors/player/warrior/object.xml", self._engine)
202 loadImportFile("objects/items/goldstack/object.xml", self._engine)
190 203
191 self._scene = Scene(self) 204 self._scene = Scene(self)
192 self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml")) 205 self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml"))
193 206
194 self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")]) 207 self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")])