Android Open Source - crash-landing Fuel Meter






From Project

Back to project page crash-landing.

License

The source code is released under:

MIT License

If you think the Android project crash-landing 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.balitechy.crashlanding.models;
/*from   ww w .  j  a  va 2s .c o  m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector2;

public class FuelMeter extends BaseObject {
  private Texture textureBar, textureSafe, textureCritical;
  private float level; //percentage of fuel level

  public FuelMeter(Vector2 position, float width, float height) {
    super(position, width, height);
    
    textureBar = new Texture(Gdx.files.internal("data/white.png"));
    textureBar.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    
    textureSafe = new Texture(Gdx.files.internal("data/green.png"));
    textureSafe.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    
    textureCritical = new Texture(Gdx.files.internal("data/red.png"));
    textureCritical.setFilter(TextureFilter.Linear, TextureFilter.Linear);
  }
  
  public void setLevel(float level) {
    this.level = level;
  }

  @Override
  public void draw(Batch batch, float parentAlpha) {
    batch.draw(textureBar, position.x, position.y, width, height);
    if(level > 0.5f)
      batch.draw(textureSafe, position.x, position.y, width*level, height);
    else
      batch.draw(textureCritical, position.x, position.y, width*level, height);
  }

  
  @Override
  public void dispose() {
    textureBar.dispose();
    textureSafe.dispose();
    textureCritical.dispose();
  }

}




Java Source Code List

com.balitechy.crashlanding.CrashLanding.java
com.balitechy.crashlanding.GameAudio.java
com.balitechy.crashlanding.GameUtils.java
com.balitechy.crashlanding.MainActivity.java
com.balitechy.crashlanding.Main.java
com.balitechy.crashlanding.models.Accelerator.java
com.balitechy.crashlanding.models.BaseObject.java
com.balitechy.crashlanding.models.FuelMeter.java
com.balitechy.crashlanding.models.LandingPad.java
com.balitechy.crashlanding.models.MovableObject.java
com.balitechy.crashlanding.models.SpaceShip.java
com.balitechy.crashlanding.screens.GameResult.java
com.balitechy.crashlanding.screens.GameScreen.java
com.balitechy.crashlanding.screens.HomeScreen.java