Android Open Source - RollOverSphere---a-simple-libgdx-game Box Manager






From Project

Back to project page RollOverSphere---a-simple-libgdx-game.

License

The source code is released under:

MIT License

If you think the Android project RollOverSphere---a-simple-libgdx-game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.igorcrevar.rolloverchuck.objects.boxes;
/*ww  w. j a  v  a2 s. co m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.igorcrevar.rolloverchuck.GameManager;
import com.igorcrevar.rolloverchuck.objects.BoxObject;

public class BoxManager {
  private static final int MAX_COUNT = 50;
  private BoxObject[] boxes = new BoxObject[MAX_COUNT];
  private Matrix4 tmp1 = new Matrix4();
  private Matrix4 tmp2 = new Matrix4();
  private int numberActive;
  
  public BoxManager(GameManager gameManager) {
    numberActive = 0;
    for (int i = 0; i < MAX_COUNT; ++i) {
      boxes[i] = new BoxObject(gameManager);
    }
  }
  
  public void init() {
    for (int i = 0; i < numberActive; ++i) {
      BoxObject box = boxes[i];
      box.destroy();
    }
    
    numberActive = 0;
  }
  
  public void update(float deltaTime) {
    int start = numberActive - 1;
    for (int i = start; i >= 0; --i) {
      BoxObject box = boxes[i];
      if (!box.update(deltaTime)) {
        remove(i);  
      }
    }
  }
  
  public void draw(Matrix4 projViewMatrix, Matrix4 viewMatrix, Vector3 lightPos) {
    for (int i = numberActive - 1; i >= 0; --i) {
      tmp1.set(projViewMatrix);
      tmp2.set(viewMatrix);
      boxes[i].draw(tmp1, tmp2, lightPos);
    }
  }
  
  public void drawShadow(ShaderProgram sp, Matrix4 projViewMatrix) {
    for (int i = numberActive - 1; i >= 0; --i) {
      tmp1.set(projViewMatrix);
      boxes[i].drawShadow(sp, tmp1);
    }
  }
  
  public void remove(int i) {
    // free resources / etc for box on position i
    boxes[i].destroy();
    // decrement number of active
    --numberActive;
    // put last active on i-th position
    BoxObject tmp = boxes[i];
    boxes[i] = boxes[numberActive];
    boxes[numberActive] = tmp;
  }
  
  public Vector3 add(IBoxRegion boxRegion, float timeToLive, IBoxType boxType) {
    if (!boxRegion.isFree()) {
      // throw new IllegalArgumentException("Box region passed to add BoxManager is not available! This should not happen");
      Gdx.app.log("chuck", "BoxManager region is not free"); 
      return null;
    }
    
    // no space for another
    if (numberActive == MAX_COUNT) {
      Gdx.app.log("chuck", "BoxManager couldn't find a element in poll");
      return null;
    }

    BoxObject newPP = boxes[numberActive++];
    newPP.init(boxRegion, timeToLive, boxType);
    return newPP.GetPosition();
  }
  
  public BoxObject getBoxObject(int i) {
    return i >= 0 && i < MAX_COUNT ? boxes[i] : null;
  }
  
  public int getAvailableCount() {
    return numberActive;
  }
}




Java Source Code List

com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
com.igorcrevar.rolloverchuck.DesktopRunner.java
com.igorcrevar.rolloverchuck.GameConsts.java
com.igorcrevar.rolloverchuck.GameData.java
com.igorcrevar.rolloverchuck.GameListener.java
com.igorcrevar.rolloverchuck.GameManager.java
com.igorcrevar.rolloverchuck.GameType.java
com.igorcrevar.rolloverchuck.IActivityRequestHandler.java
com.igorcrevar.rolloverchuck.ISceneManager.java
com.igorcrevar.rolloverchuck.IScene.java
com.igorcrevar.rolloverchuck.mesh.CubeMeshWithNormals.java
com.igorcrevar.rolloverchuck.mesh.CubeMesh.java
com.igorcrevar.rolloverchuck.mesh.FieldMesh.java
com.igorcrevar.rolloverchuck.mesh.IMesh.java
com.igorcrevar.rolloverchuck.mesh.SphereMesh.java
com.igorcrevar.rolloverchuck.objects.BoxObject.java
com.igorcrevar.rolloverchuck.objects.ChuckObject.java
com.igorcrevar.rolloverchuck.objects.ChuckSpriteObject.java
com.igorcrevar.rolloverchuck.objects.EndGameButtonsObject.java
com.igorcrevar.rolloverchuck.objects.FieldObject.java
com.igorcrevar.rolloverchuck.objects.GameButton.java
com.igorcrevar.rolloverchuck.objects.IntroSceneButtonsObject.java
com.igorcrevar.rolloverchuck.objects.MainWallObject.java
com.igorcrevar.rolloverchuck.objects.StarsObject.java
com.igorcrevar.rolloverchuck.objects.TextButton.java
com.igorcrevar.rolloverchuck.objects.TrailObject.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxManager.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxRegionManager.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxRegion.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxTypeFactory.java
com.igorcrevar.rolloverchuck.objects.boxes.IBoxRegion.java
com.igorcrevar.rolloverchuck.objects.boxes.IBoxType.java
com.igorcrevar.rolloverchuck.physics.CollisionSolver.java
com.igorcrevar.rolloverchuck.physics.ICollisionIterationHandler.java
com.igorcrevar.rolloverchuck.physics.SphereMoving.java
com.igorcrevar.rolloverchuck.points.PlayerPoint.java
com.igorcrevar.rolloverchuck.points.PointsManager.java
com.igorcrevar.rolloverchuck.scenes.GameLoadingScene.java
com.igorcrevar.rolloverchuck.scenes.GameScene.java
com.igorcrevar.rolloverchuck.scenes.IntroScene.java
com.igorcrevar.rolloverchuck.scenes.GameMode.ArcadeGameMode.java
com.igorcrevar.rolloverchuck.scenes.GameMode.IGameMode.java
com.igorcrevar.rolloverchuck.scenes.GameMode.StressFreeGameMode.java
com.igorcrevar.rolloverchuck.utils.CollisionHelper.java
com.igorcrevar.rolloverchuck.utils.GameHelper.java
com.igorcrevar.rolloverchuck.utils.IMyFontDrawerFont.java
com.igorcrevar.rolloverchuck.utils.Mathf.java
com.igorcrevar.rolloverchuck.utils.MyFontDrawerBatch.java
com.igorcrevar.rolloverchuck.utils.MyFontDrawerDefaultFont.java
com.igorcrevar.rolloverchuck.utils.MyFontDrawer.java
com.igorcrevar.rolloverchuck.utils.ShaderAssetLoader.java
com.wayilookatgames.rolloverball.MainActivity.java