comparison entities/action.py @ 158:04854cf6e1ac

The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
author KarstenBock@gmx.net
date Sat, 12 Nov 2011 20:54:25 +0100
parents 79d6b17b80a3
children ee2d6835d87a
comparison
equal deleted inserted replaced
157:79d6b17b80a3 158:04854cf6e1ac
322 def execute(self): 322 def execute(self):
323 """Talk with the NPC when close enough, otherwise move closer. 323 """Talk with the NPC when close enough, otherwise move closer.
324 @return: None""" 324 @return: None"""
325 player_char = self.model.game_state.\ 325 player_char = self.model.game_state.\
326 getObjectById("PlayerCharacter").fifeagent 326 getObjectById("PlayerCharacter").fifeagent
327 npc_coordinates = self.npc.fifeagent.behaviour.getLocation().\ 327 player_char.behaviour.animate(
328 getLayerCoordinates() 328 'stand',
329 pc_coordinates = player_char.behaviour.agent.\ 329 self.npc.fifeagent.behaviour.getLocation()
330 getLocation().getLayerCoordinates() 330 )
331 331
332 distance_squared = (npc_coordinates.x - pc_coordinates.x) *\ 332 if self.npc.dialogue.dialogue is not None:
333 (npc_coordinates.x - pc_coordinates.x) +\ 333 dialogue_controller = DialogueController(
334 (npc_coordinates.y - pc_coordinates.y) *\ 334 self.controller.engine,
335 (npc_coordinates.y - pc_coordinates.y) 335 self.view,
336 336 self.model,
337 # If we are too far away, we approach the NPC again 337 self.controller.application
338 if distance_squared > 2: 338 )
339 player_char.behaviour.approach( 339 self.controller.application.manager.push_mode(
340 [npc_coordinates.x, npc_coordinates.y], 340 dialogue_controller
341 TalkAction(self.controller, 341 )
342 self.npc, 342 dialogue_controller.startTalk(self.npc)
343 self.commands
344 )
345 )
346 else: 343 else:
347 player_char.behaviour.agent.act( 344 self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000)
348 'stand', 345
349 self.npc.fifeagent.behaviour.getLocation() 346 self.model.game_state.getObjectById("PlayerCharacter").\
350 ) 347 fifeagent.behaviour.idle()
351 348 self.model.game_state.getObjectById("PlayerCharacter").\
352 if self.npc.dialogue.dialogue is not None: 349 fifeagent.behaviour.nextAction = None
353 dialogue_controller = DialogueController( 350 super(TalkAction, self).execute()
354 self.controller.engine,
355 self.view,
356 self.model,
357 self.controller.application
358 )
359 self.controller.application.manager.push_mode(
360 dialogue_controller
361 )
362 dialogue_controller.startTalk(self.npc)
363 else:
364 self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000)
365
366 self.model.game_state.getObjectById("PlayerCharacter").\
367 fifeagent.behaviour.idle()
368 self.model.game_state.getObjectById("PlayerCharacter").\
369 fifeagent.behaviour.nextAction = None
370 super(TalkAction, self).execute()
371 351
372 class UseAction(Action): 352 class UseAction(Action):
373 """Action for carryable items. It executes special commands that can be only 353 """Action for carryable items. It executes special commands that can be only
374 used on carryable utens""" 354 used on carryable utens"""
375 355