def produce(self, unitName, position: Vector2):
   unit = EntityFactory.getSingleton().produce(self, unitName, True)
   pC = unit.getComponent(PositionComponent)
   if pC != None:
     pC.p = position
   else:
     print("[ERROR] Producing \"" + unitName + "\" but cannot find way to set position.")
     return None
   self.throwEntityCreatedEvent(unit)
   
   unit._em.registerListener(Event.ENTITY_DIED, self.entityDeath)
   unit._em.registerListener(Event.ENTITY_DIED, self.propagateEvent)
   unit._em.registerListener(Event.RESEARCH_DEPLETED, self.researchDepleted)
   unit._em.registerListener(Event.RESEARCH_DEPLETED, self.propagateEvent)
   
   return unit
Exemple #2
0
from nEngine.Entities import EntityFactory
from nEngine.Entities import World


w = World()
f = EntityFactory.getSingleton()
f.readFile("planet5521/data/entities.xml")
f.produce(w, "XCC Grunt")
for key in f._map:
  f.produce(w, key)
Exemple #3
0
 def initialise(self):
   
   # Register event types
   Event.registerEventType("ENTITY_ADDED")
   Event.registerEventType("ENTITY_REMOVED")
   Event.registerEventType("ENTITY_MOVING")
   Event.registerEventType("ENTITY_STOPPED")
   Event.registerEventType("ENTITY_MOVED")
   Event.registerEventType("ENTITY_FACING_UPDATED")
   Event.registerEventType("ENTITY_ATTACKING")
   Event.registerEventType("ENTITY_DIED")
   Event.registerEventType("RESEARCH_DEPLETED")
   Event.registerEventType("ENTITY_HARVEST_START")
   Event.registerEventType("ENTITY_HARVEST_STOP")
   Event.registerEventType("ENTITY_RESEARCH_DUMPED")
   
   
   
   # Load stuff
   ResourceManager.loadAnimations("planet5521/data/animations.xml")
   EntityFactory.getSingleton().readFile("planet5521/data/entities.xml")
   EntityViewFactory.readFile("planet5521/data/views.xml")
   
   self._world = Planet5521World(200, 80)
   
   self._gameView = Planet5521GameView(0, 0, 1280, 720, self._world)
   self._gameView.name = "Game View"
   
  
   
   
   self._world._em.registerListener(Event.ENTITY_ADDED, self._gameView.entityCreated)
   # Entity destruction is handled at the entity EventManager level
   
   
   # Make environment
   self._world.produce("Sky", (0, 0))
   self._world.produce("Ground", (0, self._world.height - 10))
   self._world.produce("Ground Surface", (0, self._world.height - 10))
   
   for _ in range(0):
     e = self._world.produce("Cloud", Vector2(Rand.r.random()*self._world.width, Rand.r.random()*(self._world.height - 20)))
     e.getComponent(VelocityComponent).v.x = Rand.r.random()
     
   # Make some units
   insectFaction = self._world.factions["Insects"]
   for _ in range(15):
   #for _ in range(0):
     insectFaction.produce("Insect Warrior", Vector2(10 + Rand.r.random()*20, self._world.height - 10-1.4))
   for _ in range(15):
   #for _ in range(0):
     insectFaction.produce("Insect Warrior", Vector2(170 + Rand.r.random()*20, self._world.height - 10-1.4))
   
   terrans = self._world.factions["Terrans"]
   for _ in range(15):
   #for _ in range(0):
     entity = terrans.produce("Terran Grunt", Vector2(80 + (Rand.r.random())*10, self._world.height - 10-1))
     entity.getComponent(FacingComponent).facingLeft = Rand.r.random() < 0.5
   for _ in range(15):
   #for _ in range(0):
     entity = terrans.produce("Terran Grunt", Vector2(110 + (Rand.r.random())*10, self._world.height - 10-1))
     entity.getComponent(FacingComponent).facingLeft = Rand.r.random() < 0.5
   for _ in range(15):
   #for _ in range(0):
     entity = terrans.produce("Terran Engineer", Vector2(90 + (Rand.r.random())*20, self._world.height - 10-1))
     entity.getComponent(FacingComponent).facingLeft = Rand.r.random() < 0.5
     
   #insectFaction.produce("Insect Warrior", Vector2(100, self._world.height - 10-1.4))
   terrans.produce("Terran Barracks", Vector2(100,self._world.height - 10))
   
   # Controllers
   self._gameView.addListener(TestGroundTroopController(self._world, self._gameView))
   selectionController = SelectedUnitsController(self._world, self._gameView)
   self._gameView.addListener(selectionController)
   self._gameView.addListener(SelectionController(self._world, self._gameView, terrans, selectionController))
   self._gameView.addListener(CameraController(self._world, self._gameView))
   
   # Close by interactions
   #terrans.produce("Terran Grunt", Vector2(80, self._world.height - 10-1))
   #terrans.produce("Terran Grunt", Vector2(80.5, self._world.height - 10-1))
   #entity = terrans.produce("Terran Engineer", Vector2(81, self._world.height - 10-1))
   #insectFaction.produce("Insect Warrior", Vector2(65, self._world.height - 10-1.4))
   
   # Dropship is going to have something different.
   #dp = self._world.produce("Dropship", Vector2(10, 10))
   #self._gameView.addListener(DropshipController(dp))
   
   self._humanView.getPane().addChild(self._gameView)
   
   # Make humanview visible
   self._pm.processList.append(ViewUpdateProcess(self._gameView))
   self._pm.processList.append(WorldUpdateProcess(self._world))
   self._pm.processList.append(EntityFadeAndRemovalProcess(self._world, self._gameView))
   self._pm.processList.append(HumanViewProcess(self._humanView))
   #self._pm.processList.append(CinematicCamProcess(self._gameView.camera))
   
   # TODO: This should perhaps be in Planet5521GameView?
   # TODO: And instead of changing the position, it should change view's dy 
   self.bdP = BuildingDestructionProcess(self._world, self._gameView)
   self._pm.processList.append(self.bdP)
   self._world._em.registerListener(Event.ENTITY_DIED, self.entityDied)
   
   
   # For checking window resize events
   Input.addListener(self)