예제 #1
0
 private StarsSector getSector(int x, int y) {
   for (StarsSector tmp : this.starSectors) {
     if (tmp.getPos().x == x && tmp.getPos().y == y) {
       return tmp;
     }
   }
   return null;
 }
예제 #2
0
  @Override
  protected void onManagedUpdate(float pSecondsElapsed) {
    int sectorX =
        (int) Math.floor(this.getSectorX(this.camera.getXMin() + this.camera.getWidth() / 2));
    int sectorY =
        (int) Math.floor(this.getSectorY(this.camera.getYMin() + this.camera.getHeight() / 2));

    if (sectorX != this.lastChangedSectorX || sectorY != this.lastChangedSectorY)
      for (int i = -1; i < 2; i++) {
        for (int j = -1; j < 2; j++) {
          StarsSector tmp = this.getSector(sectorX + i, sectorY + j);
          if (tmp == null) {
            StarsSector tmp2 = this.getOutsideSector(sectorX, sectorY);
            if (tmp2 != null) {
              tmp2.setPosX(sectorX + i);
              tmp2.setPosY(sectorY + j);
            }
          }
        }
      }
    this.lastChangedSectorX = sectorX;
    this.lastChangedSectorY = sectorY;

    for (StarsSector sector : this.starSectors) {
      sector.getEntity().setX(sector.getPos().x * sectorW + this.camera.getXMin() * scrollFactor);
      sector.getEntity().setY(sector.getPos().y * sectorH + this.camera.getYMin() * scrollFactor);
    }

    this.camera.onUpdate(pSecondsElapsed);
  }
예제 #3
0
 private StarsSector getOutsideSector(int x, int y) {
   for (StarsSector tmp : this.starSectors) {
     float distX = Maths.dist(tmp.getPos().x, x);
     float distY = Maths.dist(tmp.getPos().y, y);
     if (distX > 1 || distY > 1) {
       return tmp;
     }
   }
   return null;
 }