comparison gamemodel.py @ 44:98f26f7636d8

Changes to make PARPG "runable" with grease. (With the correct modified assets)
author KarstenBock@gmx.net
date Tue, 06 Sep 2011 15:22:51 +0200
parents ff3e395abf91
children bf506f739322
comparison
equal deleted inserted replaced
43:8f9e9f47c363 44:98f26f7636d8
235 for agent in self.agents["All"]: 235 for agent in self.agents["All"]:
236 map_name = self.agents["All"][agent]["Map"] 236 map_name = self.agents["All"][agent]["Map"]
237 agent_dict = self.agents["All"][agent] 237 agent_dict = self.agents["All"][agent]
238 agent_obj = None 238 agent_obj = None
239 if agent == "PlayerCharacter": 239 if agent == "PlayerCharacter":
240 agent_obj = self.game_state.player_character 240 agent_obj = self.game_state.getObjectById("PlayerCharacter").fifeagent
241 else: 241 else:
242 agent_obj = self.game_state.getObjectById(agent, map_name) 242 agent_obj = self.game_state.getObjectById(agent, map_name)
243 if agent_obj: 243 if agent_obj:
244 agent_inst = self.game_state.maps[map_name].\ 244 agent_inst = self.game_state.maps[map_name].\
245 agent_layer.getInstance(agent) 245 agent_layer.getInstance(agent)
519 inst_dict["target_map_name"] = agent["TargetMap"] 519 inst_dict["target_map_name"] = agent["TargetMap"]
520 if agent.has_key("TargetPosition"): 520 if agent.has_key("TargetPosition"):
521 inst_dict["target_x"] = agent["TargetPosition"][0] 521 inst_dict["target_x"] = agent["TargetPosition"][0]
522 inst_dict["target_y"] = agent["TargetPosition"][1] 522 inst_dict["target_y"] = agent["TargetPosition"][1]
523 if agent.has_key("Inventory"): 523 if agent.has_key("Inventory"):
524 inventory = Inventory() 524 #TODO: Fix setting of inventory
525 inventory_objs = agent["Inventory"] 525 #inventory = Inventory()
526 for inventory_obj in inventory_objs: 526 #inventory_objs = agent["Inventory"]
527 self.createInventoryObject(inventory, 527 #for inventory_obj in inventory_objs:
528 inventory_obj 528 # self.createInventoryObject(inventory,
529 ) 529 # inventory_obj
530 inst_dict["inventory"] = inventory 530 # )
531 #inst_dict["inventory"] = inventory
532 pass
531 533
532 if agent.has_key("Items"): 534 if agent.has_key("Items"):
533 container_objs = agent["Items"] 535 container_objs = agent["Items"]
534 items = self.createContainerItems(container_objs) 536 #TODO: Create inventory items
537 items = []#self.createContainerItems(container_objs)
535 inst_dict["items"] = items 538 inst_dict["items"] = items
536 539
537 if agent.has_key("ItemType"): 540 if agent.has_key("ItemType"):
538 if not agent.has_key("item"): 541 if not agent.has_key("item"):
539 item_data = {} 542 item_data = {}
540 item_data["type"] = agent["ItemType"] 543 item_data["type"] = agent["ItemType"]
541 item_data["ID"] = inst_id 544 item_data["ID"] = inst_id
542 item_data = self.createContainerObject(item_data) 545 #TODO item_data = self.createContainerObject(item_data)
543 else: 546 else:
544 item_data = agent["item"] 547 item_data = agent["item"]
545 inst_dict["item"] = item_data 548 inst_dict["item"] = item_data
546 inst_dict["item_type"] = agent["ItemType"] 549 inst_dict["item_type"] = agent["ItemType"]
547 if agent.has_key("Behaviour"): 550 if agent.has_key("Behaviour"):
563 continue 566 continue
564 if self.active_map.agent_layer.getInstances(agent): 567 if self.active_map.agent_layer.getInstances(agent):
565 continue 568 continue
566 self.createAgent(agents[agent], agent, world) 569 self.createAgent(agents[agent], agent, world)
567 570
568 def placePC(self): 571 def placePC(self, world):
569 """Places the PlayerCharacter on the map""" 572 """Places the PlayerCharacter on the map"""
570 agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"] 573 agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"]
571 inst_id = "PlayerCharacter" 574 inst_id = "PlayerCharacter"
572 self.createAgent(agent, inst_id) 575 self.createAgent(agent, inst_id, world)
573 576
574 # create the PlayerCharacter agent 577 # create the PlayerCharacter agent
575 self.active_map.addPC() 578 self.active_map.addPC()
576 self.game_state.player_character.start() 579 #self.game_state.getObjectById("PlayerCharacter").fifeagent.start()
577 if agent.has_key("PeopleKnown"): 580 if agent.has_key("PeopleKnown"):
578 self.game_state.player_character.people_i_know = agent["PeopleKnown"] 581 self.game_state.getObjectById("PlayerCharacter").fifeagent.people_i_know = agent["PeopleKnown"]
579 582
580 def changeMap(self, map_name, target_position = None): 583 def changeMap(self, map_name, target_position = None):
581 """Registers for a map change on the next pump(). 584 """Registers for a map change on the next pump().
582 @type map_name: String 585 @type map_name: String
583 @param map_name: Id of the map to teleport to 586 @param map_name: Id of the map to teleport to
628 extra = {} 631 extra = {}
629 if layer is not None: 632 if layer is not None:
630 extra['layer'] = layer 633 extra['layer'] = layer
631 attributes = self.checkAttributes(attributes) 634 attributes = self.checkAttributes(attributes)
632 635
636 obj_type = attributes["type"]
633 obj = createEntity(attributes, extra) 637 obj = createEntity(attributes, extra)
634 638 if obj:
635 if obj.trueAttr("PC"): 639 self.addObject(layer, obj, obj_type)
636 self.addPC(layer, obj)
637 else:
638 self.addObject(layer, obj)
639 640
640 def addPC(self, layer, player_char): 641 def addPC(self, layer, player_char):
641 """Add the PlayerCharacter to the map 642 """Add the PlayerCharacter to the map
642 @type layer: fife.Layer 643 @type layer: fife.Layer
643 @param layer: FIFE layer object exists in 644 @param layer: FIFE layer object exists in
647 @param instance: FIFE instance of PlayerCharacter 648 @param instance: FIFE instance of PlayerCharacter
648 @return: None""" 649 @return: None"""
649 # For now we copy the PlayerCharacter, 650 # For now we copy the PlayerCharacter,
650 # in the future we will need to copy 651 # in the future we will need to copy
651 # PlayerCharacter specifics between the different PlayerCharacter's 652 # PlayerCharacter specifics between the different PlayerCharacter's
652 self.game_state.player_character = player_char 653 self.game_state.getObjectById("PlayerCharacter").fifeagent = player_char
653 self.game_state.player_character.setup() 654 self.game_state.getObjectById("PlayerCharacter").fifeagent.setup()
654 self.game_state.player_character.behaviour.speed = self.settings.parpg.PCSpeed 655 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.speed = self.settings.parpg.PCSpeed
655 656
656 657
657 def addObject(self, layer, obj): 658 def addObject(self, layer, obj, obj_type):
658 """Adds an object to the map. 659 """Adds an object to the map.
659 @type layer: fife.Layer 660 @type layer: fife.Layer
660 @param layer: FIFE layer object exists in 661 @param layer: FIFE layer object exists in
661 @type obj: GameObject 662 @type obj: GameObject
662 @param obj: corresponding object class 663 @param obj: corresponding object class
663 @type instance: fife.Instance 664 @type instance: fife.Instance
664 @param instance: FIFE instance of object 665 @param instance: FIFE instance of object
665 @return: None""" 666 @return: None"""
666 ref = self.game_state.getObjectById(obj.ID, \ 667 ref = self.game_state.getObjectById(obj.fifeagent.identifier,
667 self.game_state.current_map_name) 668 self.game_state.current_map_name)
668 if ref is None: 669 if ref is None:
669 # no, add it to the game state 670 # no, add it to the game state
670 self.game_state.addObject(self.game_state.current_map_name, obj) 671 self.game_state.addObject(self.game_state.current_map_name, obj)
671 else: 672 else:
672 # yes, use the current game state data 673 # yes, use the current game state data
673 obj.X = ref.X 674 obj.fifeagent.pos.X = ref.X
674 obj.Y = ref.Y 675 obj.fifeagent.pos.Y = ref.Y
675 obj.gfx = ref.gfx 676 obj.fifeagent.gfx = ref.gfx
676 677
677 if obj.trueAttr("NPC"): 678 if obj_type == "Character":
679 obj.fifeagent.behaviour.parent = obj
678 # create the agent 680 # create the agent
679 obj.setup() 681 #obj.setup()
680 obj.behaviour.speed = self.settings.parpg.PCSpeed - 1 682 #obj.behaviour.speed = self.settings.parpg.PCSpeed
681 # create the PlayerCharacter agent 683 # create the PlayerCharacter agent
682 obj.start() 684 #obj.start()
683 if obj.trueAttr("AnimatedContainer"): 685 #if obj.trueAttr("AnimatedContainer"):
684 # create the agent 686 # create the agent
685 obj.setup() 687 #obj.setup()
686 688
687 def objectActive(self, ident): 689 def objectActive(self, ident):
688 """Given the objects ID, pass back the object if it is active, 690 """Given the objects ID, pass back the object if it is active,
689 False if it doesn't exist or not displayed 691 False if it doesn't exist or not displayed
690 @type ident: string 692 @type ident: string
691 @param ident: ID of object 693 @param ident: ID of object
692 @rtype: boolean 694 @rtype: boolean
693 @return: Status of result (True/False)""" 695 @return: Status of result (True/False)"""
694 for game_object in \ 696 for game_object in \
695 self.game_state.getObjectsFromMap(self.game_state.current_map_name): 697 self.game_state.getObjectsFromMap(self.game_state.current_map_name):
696 if (game_object.ID == ident): 698 if (game_object.fifeagent.identifier == ident):
697 # we found a match 699 # we found a match
698 return game_object 700 return game_object
699 # no match 701 # no match
700 return False 702 return False
701 703
703 """Code called when the player should move to another location 705 """Code called when the player should move to another location
704 @type position: fife.ScreenPoint 706 @type position: fife.ScreenPoint
705 @param position: Screen position to move to 707 @param position: Screen position to move to
706 @return: None""" 708 @return: None"""
707 if(self.pc_run == 1): 709 if(self.pc_run == 1):
708 self.game_state.player_character.run(position) 710 self.game_state.getObjectById("PlayerCharacter").fifeagent.run(position)
709 else: 711 else:
710 self.game_state.player_character.walk(position) 712 self.game_state.getObjectById("PlayerCharacter").fifeagent.walk(position)
711 713
712 def teleportAgent(self, agent, position): 714 def teleportAgent(self, agent, position):
713 """Code called when an agent should teleport to another location 715 """Code called when an agent should teleport to another location
714 @type position: fife.ScreenPoint 716 @type position: fife.ScreenPoint
715 @param position: Screen position to teleport to 717 @param position: Screen position to teleport to