Android Open Source - BulletsForever Draw Object H U D






From Project

Back to project page BulletsForever.

License

The source code is released under:

GNU General Public License

If you think the Android project BulletsForever 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.bulletsforever.bullets;
/*from w  w w  .jav a  2 s .com*/
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Paint.Align;

/**
 * This is DrawWorld's HUD
 * This should be instantiated by DrawWorld's onCreate()
 * Only a single instance should exist per DrawWorld instance
 */
public class DrawObjectHUD extends DrawObject {
  
  // Stuff
  private ToolsFPSCounter fpsCounter;
  private Paint textPaint;
  
  // FPS
  private float fpsX, fpsY;
  
  // Info
  private float infoX1, infoY1;
  private float infoX2, infoY2;
  private float infoX3, infoY3;
  
  // Box
  private Paint boxPaint;
  private Rect boxRect;
  
  public DrawObjectHUD(DrawWorld dw) {
    super(dw, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f); // dummy
    
    // Text
    textPaint = new Paint();
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(20f);
    textPaint.setTextAlign(Align.LEFT);
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC));
    
    // Info
    infoX1 = 10f;
    infoY1 = textPaint.getFontSpacing();
    infoX2 = 10f;
    infoY2 = infoY1 + textPaint.getFontSpacing();
    infoX3 = 10f;
    infoY3 = infoY2 + textPaint.getFontSpacing();
    
    
    
    
    
    // FPS counter
    fpsCounter = new ToolsFPSCounter(Settings.getInt(R.string.fpsUpdateFrequency));
    fpsX = 10f;
    fpsY = infoY2 + textPaint.getFontSpacing();
    
    // Box
    boxPaint = new Paint();
    boxPaint.setARGB(255/2, 32, 128, 32); // Dark green
    boxRect = new Rect();
    boxRect.set(0, 0, Settings.screenWidth, (int)(fpsY + textPaint.getFontSpacing() / 2));
    
  }
  
  @Override
  public void nextFrame() {
    // FPS counter
    fpsCounter.nextFrame();
  }
  
  @Override
  public void draw(Canvas canvas) {
    // Box
    canvas.drawRect(boxRect, boxPaint);
    
    // Info
    canvas.drawText(
        String.format(
            "Boss Level: %d, Boss HP: %d",
            dw.boss.level, dw.boss.health             
            ),
        infoX1, infoY1, textPaint);
    canvas.drawText(
        String.format(
            "Lives: %d",
            dw.lives
            ),
        infoX2, infoY2, textPaint);
    canvas.drawText(
        String.format(
            "%s",
            fpsCounter.getDisplayedFPS()            
            ),
        infoX3, infoY3, textPaint);
    
    // FPS counter
  //  canvas.drawText(fpsCounter.getDisplayedFPS(), fpsX, fpsY, textPaint);
  
  }
  
  @Override
  public void onCollision(DrawObject object) {
    // Do nothing    
  }
}




Java Source Code List

com.bulletsforever.bullets.AudioMusicPlayer.java
com.bulletsforever.bullets.AudioSoundPool.java
com.bulletsforever.bullets.DrawBitmapLoader.java
com.bulletsforever.bullets.DrawKeyHandler.java
com.bulletsforever.bullets.DrawObjectBackground.java
com.bulletsforever.bullets.DrawObjectBoss.java
com.bulletsforever.bullets.DrawObjectBullet.java
com.bulletsforever.bullets.DrawObjectDynamicArm.java
com.bulletsforever.bullets.DrawObjectDynamicBoss.java
com.bulletsforever.bullets.DrawObjectHUD.java
com.bulletsforever.bullets.DrawObjectPlayer.java
com.bulletsforever.bullets.DrawObject.java
com.bulletsforever.bullets.DrawRefreshHandler.java
com.bulletsforever.bullets.DrawTouchHandler.java
com.bulletsforever.bullets.DrawWorld.java
com.bulletsforever.bullets.GameMain.java
com.bulletsforever.bullets.GameScore.java
com.bulletsforever.bullets.MenuHome.java
com.bulletsforever.bullets.MenuSettings.java
com.bulletsforever.bullets.Settings.java
com.bulletsforever.bullets.ToolsFPSCounter.java
com.bulletsforever.bullets.ToolsRandomizer.java
com.bulletsforever.bullets.ToolsScoreboard.java
com.bulletsforever.bullets.ToolsTracker.java
com.bulletsforever.bullets.ToolsVibrator.java