Ejemplo n.º 1
0
 def testAddCollision(self):
   self.ship.addCollision( point3ToTuple( Point3(1, 2, 0) ) )
   self.failIfEqual( self.ship.getCollisions(), [] )
Ejemplo n.º 2
0
    def tick(self, task):
        if not self.pause:
            ships = self.getShips()

            # Check if the ships' positions need to be warped
            xDistance = abs(ships[0].getPos()[0] - ships[1].getPos()[0])
            if xDistance >= Game.SHIPS_MAX_X_DISTANCE:
                #and self.gameFrames - self.lastWarp > 10:
                self.warpShips('x')
                #self.lastWarp = self.gameFrames
            yDistance = abs(ships[0].getPos()[1] - ships[1].getPos()[1])
            if yDistance >= Game.SHIPS_MAX_Y_DISTANCE:
                self.warpShips('y')

            # Check if the planet's position needs to be warped
            planetXDistance = abs(self.getCameraPos()[0] -
                                  self.planet.getPos()[0])
            if planetXDistance >= Game.PLANET_CAMERA_DISTANCE_MAX:
                self.warpPlanet('x')
            planetYDistance = abs(self.getCameraPos()[1] -
                                  self.planet.getPos()[1])
            if planetYDistance >= Game.PLANET_CAMERA_DISTANCE_MAX:
                self.warpPlanet('y')

            # Check collisions
            col = OdeUtil.collide(ships[0].collisionSphere,
                                  ships[1].collisionSphere, 1)
            if not col.isEmpty():
                ships[0].addCollision(point3ToTuple(col.getContactPoint(0)))
                ships[1].addCollision(point3ToTuple(col.getContactPoint(0)))
            colPlanet1 = OdeUtil.collide(ships[0].collisionSphere,
                                         self.planetCollGeom, 1)
            colPlanet2 = OdeUtil.collide(ships[1].collisionSphere,
                                         self.planetCollGeom, 1)
            if not colPlanet1.isEmpty():
                ships[0].addCollision(
                    point3ToTuple(colPlanet1.getContactPoint(0)))
                ships[0].planetHit()
            if not colPlanet2.isEmpty():
                ships[1].addCollision(
                    point3ToTuple(colPlanet2.getContactPoint(0)))
                ships[1].planetHit()

            # Bullet collisions ship one
            for bullet in ships[0].bullets:
                colBulletShip1 = OdeUtil.collide(bullet['physical'],
                                                 ships[1].collisionSphere, 1)
                if not colBulletShip1.isEmpty():
                    ships[0].destroyBullet(bullet)
                    ships[1].bulletHit()
                colBulletPlanet = OdeUtil.collide(bullet['physical'],
                                                  self.planetCollGeom, 1)
                if not colBulletPlanet.isEmpty():
                    ships[0].destroyBullet(bullet)
            # Bullet collisions ship two
            for bullet in ships[1].bullets:
                colBulletShip2 = OdeUtil.collide(bullet['physical'],
                                                 ships[0].collisionSphere, 1)
                if not colBulletShip2.isEmpty():
                    ships[1].destroyBullet(bullet)
                    ships[0].bulletHit()
                colBulletPlanet = OdeUtil.collide(bullet['physical'],
                                                  self.planetCollGeom, 1)
                if not colBulletPlanet.isEmpty():
                    ships[1].destroyBullet(bullet)
            for ship in ships:
                self.applyGravity(ship, self.getDeltaTime())
                ship.update(self.getDeltaTime())

            if not ships[0].isAlive:
                self.showWinnerText(self.players[1])
                self.players[1].score += 1
                self.restartGame()
            if not ships[1].isAlive:
                self.showWinnerText(self.players[0])
                self.players[0].score += 1
                self.restartGame()
            if self.cameraMode == Game.CAMERA_MODE_GAME:
                self.updateCamera()
            if self.gameFrames >= 125:
                self.winnerText.hide()
            self.gameFrames += 1

            # Update health points in the HUD
            # TODO: These should be optimized so that they get updated only when they
            # change.
            self.healthPlayerOne.setText("Health: " +
                                         str(self.ships[0].health))
            self.healthPlayerTwo.setText("Health: " +
                                         str(self.ships[1].health))

        return task.cont
Ejemplo n.º 3
0
 def testPoint3ToTuple(self):
     self.failUnlessEqual(point3ToTuple(Point3(2, 4, 0)), (2, 4))
Ejemplo n.º 4
0
 def testPoint3ToTuple(self):
   self.failUnlessEqual( point3ToTuple( Point3(2, 4, 0) ), (2, 4) )
Ejemplo n.º 5
0
  def tick(self, task):
    if not self.pause:
      ships = self.getShips()

      # Check if the ships' positions need to be warped
      xDistance = abs(ships[0].getPos()[0] - ships[1].getPos()[0] )
      if xDistance >= Game.SHIPS_MAX_X_DISTANCE:
        #and self.gameFrames - self.lastWarp > 10:
        self.warpShips('x')
        #self.lastWarp = self.gameFrames
      yDistance = abs(ships[0].getPos()[1] - ships[1].getPos()[1] )
      if yDistance >= Game.SHIPS_MAX_Y_DISTANCE:
        self.warpShips('y')

      # Check if the planet's position needs to be warped
      planetXDistance = abs( self.getCameraPos()[0] - self.planet.getPos()[0] )
      if planetXDistance >= Game.PLANET_CAMERA_DISTANCE_MAX:
        self.warpPlanet('x')
      planetYDistance = abs( self.getCameraPos()[1] - self.planet.getPos()[1] )
      if planetYDistance >= Game.PLANET_CAMERA_DISTANCE_MAX:
        self.warpPlanet('y')

      # Check collisions
      col = OdeUtil.collide(ships[0].collisionSphere, ships[1].collisionSphere, 1)
      if not col.isEmpty():
        ships[0].addCollision( point3ToTuple( col.getContactPoint(0) ) )
        ships[1].addCollision( point3ToTuple( col.getContactPoint(0) ) )
      colPlanet1 = OdeUtil.collide(ships[0].collisionSphere, self.planetCollGeom, 1)
      colPlanet2 = OdeUtil.collide(ships[1].collisionSphere, self.planetCollGeom, 1)
      if not colPlanet1.isEmpty():
        ships[0].addCollision( point3ToTuple( colPlanet1.getContactPoint(0) ) )
        ships[0].planetHit()
      if not colPlanet2.isEmpty():
        ships[1].addCollision( point3ToTuple( colPlanet2.getContactPoint(0) ) )
        ships[1].planetHit()

      # Bullet collisions ship one
      for bullet in ships[0].bullets:
        colBulletShip1 = OdeUtil.collide( bullet['physical'], ships[1].collisionSphere, 1 )
        if not colBulletShip1.isEmpty():
          ships[0].destroyBullet(bullet)
          ships[1].bulletHit()
        colBulletPlanet = OdeUtil.collide( bullet['physical'], self.planetCollGeom, 1 )
        if not colBulletPlanet.isEmpty():
          ships[0].destroyBullet(bullet)
      # Bullet collisions ship two
      for bullet in ships[1].bullets:
        colBulletShip2 = OdeUtil.collide( bullet['physical'], ships[0].collisionSphere, 1 )
        if not colBulletShip2.isEmpty():
          ships[1].destroyBullet(bullet)
          ships[0].bulletHit()
        colBulletPlanet = OdeUtil.collide( bullet['physical'], self.planetCollGeom, 1 )
        if not colBulletPlanet.isEmpty():
          ships[1].destroyBullet(bullet)
      for ship in ships:
        self.applyGravity( ship, self.getDeltaTime() )
        ship.update( self.getDeltaTime() )

      if not ships[0].isAlive:
        self.showWinnerText(self.players[1])
        self.players[1].score += 1
        self.restartGame()
      if not ships[1].isAlive:
        self.showWinnerText(self.players[0])
        self.players[0].score += 1
        self.restartGame()
      if self.cameraMode == Game.CAMERA_MODE_GAME:
        self.updateCamera()
      if self.gameFrames >= 125:
        self.winnerText.hide()
      self.gameFrames += 1

      # Update health points in the HUD
      # TODO: These should be optimized so that they get updated only when they
      # change.
      self.healthPlayerOne.setText( "Health: " + str(self.ships[0].health) )
      self.healthPlayerTwo.setText( "Health: " + str(self.ships[1].health) )

    return task.cont