Beispiel #1
0
  def loadFromXML(self, XMLRoot):
    self.name = XMLRoot.find("name").text
    self.animation = ResourceManager.getAnimation(self.name).produce()
    self.layer = int(XMLRoot.find("layer").text)
    self.dp = Vector2(float(0), float(0))
    if XMLRoot.find("dx") != None and XMLRoot.find("dy") != None:
      self.dp = Vector2(float(XMLRoot.find("dx").text),
                      float(XMLRoot.find("dy").text))
    self.origin = XMLRoot.find("origin")
    if self.origin != None:
      self.origin = Util.parseVector2(self.origin)
    if XMLRoot.find("width") != None and XMLRoot.find("height") != None:
      self.size = Vector2(float(XMLRoot.find("width").text),
                          float(XMLRoot.find("height").text))
    else:
      self.size = Vector2(-1, -1)
    
    if XMLRoot.find("tileWidth") == None or XMLRoot.find("tileHeight") == None:
      self.tileSize = None
    else:
      self.tileSize = Vector2(float(XMLRoot.find("tileWidth").text),
                              float(XMLRoot.find("tileHeight").text))
    
    self._sprite = Sprite(self.animation._anim.getTexture(), self.animation.getRect())
    if type(self.origin) == Vector2:
      self._sprite.origin = self.origin

    # Default value for when there is no FacingComponent
    self._facingLeft = False
    
    # This needs to be the ordering. Facing interferes with entitySizeUpdate.
    self.reset()
    self.entitySizeUpdate()
Beispiel #2
0
 def initialise(self):
   
   # Background
   self._background = NGUIImage(0, 0, Sprite(ResourceManager.getTexture("planet5521/data/screen.png")))
   self._background.name = "background"
   self._humanView.getPane().addChild(self._background)
   
   # Buttons
   self._startButton = NGUIBasicButton(500, 350, 200, 75, "Start")
   self._exitButton = NGUIBasicButton(500, 450, 200, 75, "Exit")
   
   self._startButton.style = self._exitButton.style =  "default_title"
   self._startButton.styleFocus = self._exitButton.styleFocus = "default_title_focus"
   self._startButton.stylePrimed = self._exitButton.stylePrimed = "default_title_primed"
   self._startButton.backgroundColour = self._exitButton.backgroundColour = Color(80, 25, 25, 100)
   self._startButton.backgroundColourFocus = self._exitButton.backgroundColourFocus = Color(80, 25, 25, 200)
   self._startButton.backgroundColourPrimed = self._exitButton.backgroundColourPrimed = Color(80, 25, 25, 255)
   
   self._humanView.getPane().addChild(self._startButton)
   self._humanView.getPane().addChild(self._exitButton)
   
   self._startButton.addListener(self)
   self._exitButton.addListener(self)
   # Make humanview visible
   self._pm.processList.append(HumanViewProcess(self._humanView)) 
 def newParticle(self):
   
   sprite = Sprite(ResourceManager.getTexture("planet5521/data/sprites.png"))
   sprite.texture_rectangle = Rectangle(Vector2(161, 234), Vector2(25, 20))
   sprite.origin = Vector2(12, 10)
   sprite.ratio = Vector2(0.08,0.08)
   
   r = self.gameView.entityToView[self.building].getDrawBounds()
   x = r.left + Rand.r.random()*r.width
   y = self.building._world.groundLevel
   sprite.position = Vector2(x, y + sprite.global_bounds.height/2-0.01)
   
   p = SimpleParticle(sprite)
   p.v = Vector2(Rand.r.random()*0.3, -Rand.r.random()*4)
   p.a = Vector2(0, 5)
   p.rV = Rand.r.random()*100
   
   self.particles.append(p)
Beispiel #4
0
 def createSprite(self):
   sprite = Sprite(ResourceManager.getTexture("planet5521/data/sprites.png"))
   sprite.texture_rectangle = self._textureRect
   sprite.origin = Vector2(2.5, 3)
   sprite.ratio = Vector2(0.1, 0.1)
   return sprite
Beispiel #5
0
 def playSound(soundName):
   buffer = ResourceManager.loadSound(soundName)
   sound = sfml.audio.Sound(buffer)
   sound.play()
   Audio._sounds.append(sound)
Beispiel #6
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)