Android Open Source - RollOverSphere---a-simple-libgdx-game Stars Object






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;
//from  w  ww .j av a 2  s . co  m
import java.util.Random;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class StarsObject {
  private class Star {
    public float speed;
    public Sprite sprite;
    public Star() {
      sprite = new Sprite();
    }
    
    public void setTexture(TextureRegion tr) {
      sprite.setRegion(tr);
    }
    
    public void init(float x, float y, float scale, float speed, float colorFactor) {
      sprite.setBounds(x, y, 32 * scale, 32 * scale);
      sprite.setColor(Color.WHITE.toFloatBits() * colorFactor);
      this.speed = speed;
    }
    
    public boolean update(float deltaTime) {
      sprite.setY(sprite.getY() - speed * deltaTime);
      return sprite.getY() >= 0;
    }
  }
  private static final int MAX_COUNT = 50;
  private Star[] points = new Star[MAX_COUNT];
  private Random rnd = new Random();
  
  public StarsObject() {
    for (int i = 0; i < MAX_COUNT; ++i) {
      points[i] = new Star();
    }
  }
  
  public void init(TextureRegion tr) {
    for (int i = 0; i < MAX_COUNT; ++i) {
      points[i].setTexture(tr);
      initStar(i, 1080);
    }
  }
  
  public void update(float deltaTime) {
    for (int i = MAX_COUNT - 1; i >= 0; --i) {
      Star p = points[i];          
      if (!p.update(deltaTime)) {
        initStar(i, 0); // create new on ith place
      }
    }
  }
  
  public void draw(SpriteBatch spriteBatch) {
    for (int i = MAX_COUNT - 1; i >= 0; --i) {
      Star p = points[i];
      p.sprite.draw(spriteBatch);
    }
  }
  
  private void initStar(int i, int randomY) {
    float yPos = 1080;
    if (randomY > 0) {
      yPos -= rnd.nextInt(randomY);
    }
    points[i].init(rnd.nextInt(1920), yPos, -rnd.nextFloat() + 1.0f, 75 + rnd.nextInt(150), rnd.nextFloat() * 0.3f + 0.7f);
  }  
}




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