Ejemplo n.º 1
0
  private void placePlanets() {
    int width = getWidth();

    float planetStart = 150 * getPixelScale();
    float distanceBetweenPlanets = width - planetStart;
    distanceBetweenPlanets /= mPlanetInfos.length;

    for (int i = 0; i < mPlanetInfos.length; i++) {
      PlanetInfo planetInfo = mPlanetInfos[i];

      float distanceFromSun =
          planetStart + (distanceBetweenPlanets * i) + (distanceBetweenPlanets / 2.0f);
      float x = 0;
      float y = -1 * distanceFromSun;

      float angle = (0.5f / (mPlanetInfos.length + 1));
      angle = (float) ((angle * i * Math.PI) + angle * Math.PI);

      Vector2 centre = new Vector2(x, y);
      centre.rotate(angle);
      centre.y *= -1;

      planetInfo.centre = centre;
      planetInfo.distanceFromSun = distanceFromSun;

      List<BaseColony> colonies = mStar.getColonies();
      if (colonies != null && !colonies.isEmpty()) {
        for (BaseColony colony : colonies) {
          if (colony.getPlanetIndex() == mPlanetInfos[i].planet.getIndex()) {
            planetInfo.colony = (Colony) colony;
            planetInfo.buildings = new ArrayList<Building>();

            for (BaseBuilding building : colony.getBuildings()) {
              BuildingDesign design =
                  (BuildingDesign)
                      DesignManager.i.getDesign(DesignKind.BUILDING, building.getDesignID());
              if (design.showInSolarSystem()) {
                planetInfo.buildings.add((Building) building);
              }
            }

            if (!planetInfo.buildings.isEmpty()) {
              Collections.sort(planetInfo.buildings, mBuildingDesignComparator);
            }
          }
        }
      }

      mPlanetInfos[i] = planetInfo;
    }

    updateSelection();
  }
Ejemplo n.º 2
0
  private void drawPlanets(Canvas canvas) {
    for (int i = 0; i < mPlanetInfos.length; i++) {
      canvas.drawCircle(0, 0, mPlanetInfos[i].distanceFromSun, mPlanetPaint);
    }

    PlanetImageManager pim = PlanetImageManager.getInstance();

    for (int i = 0; i < mPlanetInfos.length; i++) {
      final PlanetInfo planetInfo = mPlanetInfos[i];

      Sprite sprite = pim.getSprite(planetInfo.planet);
      mMatrix.reset();
      mMatrix.postTranslate(-(sprite.getWidth() / 2.0f), -(sprite.getHeight() / 2.0f));
      mMatrix.postScale(
          100.0f * getPixelScale() / sprite.getWidth(),
          100.0f * getPixelScale() / sprite.getHeight());
      mMatrix.postTranslate((float) planetInfo.centre.x, (float) planetInfo.centre.y);
      canvas.save();
      canvas.concat(mMatrix);
      sprite.draw(canvas);
      canvas.restore();

      if (planetInfo.buildings != null) {
        int j = 0;
        float angleOffset = (float) (Math.PI / 4.0) * (planetInfo.buildings.size() - 1) / 2.0f;
        for (Building building : planetInfo.buildings) {
          BuildingDesign design = building.getDesign();
          Sprite buildingSprite = SpriteManager.i.getSprite(design.getSpriteName());

          Vector2 pt = Vector2.pool.borrow().reset(0, -30.0f);
          pt.rotate(angleOffset - (float) (Math.PI / 4.0) * j);

          mMatrix.reset();
          mMatrix.postTranslate(
              -(buildingSprite.getWidth() / 2.0f), -(buildingSprite.getHeight() / 2.0f));
          mMatrix.postScale(
              20.0f * getPixelScale() / buildingSprite.getWidth(),
              20.0f * getPixelScale() / buildingSprite.getHeight());
          mMatrix.postTranslate(
              (float) (planetInfo.centre.x + (pt.x * getPixelScale())),
              (float) (planetInfo.centre.y + (pt.y * getPixelScale())));

          canvas.save();
          canvas.concat(mMatrix);
          buildingSprite.draw(canvas);
          canvas.restore();

          j++;
        }
      }

      if (planetInfo.colony != null) {
        Empire empire = EmpireManager.i.getEmpire(planetInfo.colony.getEmpireID());
        if (empire != null) {
          Bitmap shield = EmpireShieldManager.i.getShield(mContext, empire);
          if (shield != null) {
            mMatrix.reset();
            mMatrix.postTranslate(-shield.getWidth() / 2.0f, -shield.getHeight() / 2.0f);
            mMatrix.postScale(
                20.0f * getPixelScale() / shield.getWidth(),
                20.0f * getPixelScale() / shield.getHeight());
            mMatrix.postTranslate(
                (float) planetInfo.centre.x,
                (float) planetInfo.centre.y + (30.0f * getPixelScale()));
            canvas.drawBitmap(shield, mMatrix, mPlanetPaint);
          }
        }
      }
    }
  }