Android Open Source - BulletsForever Draw Object Background






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 .java 2 s .  co  m*/
import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;

/**
 * This is DrawWorld's background grid
 * This should be instantiated by DrawWorld's onCreate()
 * Only a single instance should exist per DrawWorld instance
 */
public class DrawObjectBackground extends DrawObject {

  private Paint colourPaint;
  private RectF[] ovals;
  private int driftMode;
  private final int DRIFT_FRAMES = 150; // ~3s
  private final int NUM_OVALS = 10;
  
  public DrawObjectBackground(DrawWorld dw) {
    super(dw, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f); // dummy
    
    driftMode = 0;
    
    colourPaint = new Paint();
    colourPaint.setColor(Color.GREEN);
    colourPaint.setAlpha(64);
    colourPaint.setStyle(Style.STROKE);
    colourPaint.setStrokeWidth(2);
    ovals = new RectF[NUM_OVALS];
    int dimension = (Settings.screenHeight < Settings.screenWidth) ? Settings.screenHeight : Settings.screenWidth; 
    for (int i = 0; i < NUM_OVALS / 2; i++) {
      float width = i * dimension / (NUM_OVALS / 2);
      float height = dimension;
      ovals[i] = new RectF(
          Settings.screenWidth / 2 - width,
          Settings.screenHeight / 2 - height,
          Settings.screenWidth / 2 + width,
          Settings.screenHeight / 2 + height
          );
    }
    for (int i = 0; i < NUM_OVALS / 2; i++) {
      float width = dimension;
      float height = i * dimension / (NUM_OVALS / 2);
      ovals[i + NUM_OVALS / 2] = new RectF(
          Settings.screenWidth / 2 - width,
          Settings.screenHeight / 2 - height,
          Settings.screenWidth / 2 + width,
          Settings.screenHeight / 2 + height
          );
    }
    
  }
  
  @Override
  public void nextFrame() {
    frame++;
    if (frame % DRIFT_FRAMES == 0) {
      if (driftMode == 7) {
        driftMode = 0;
      } else {
        driftMode++;
      }
    }
    switch (driftMode) {
    /*   __
     *  |__|__
     *     |__| 
     */
      default:
      case 0: for (RectF oval : ovals) oval.offset(0, 0.3f); break;
      case 1: for (RectF oval : ovals) oval.offset(0.3f, 0); break;
      case 2: for (RectF oval : ovals) oval.offset(0, -0.3f); break;
      case 3: for (RectF oval : ovals) oval.offset(-0.3f, 0); break;
      case 4: for (RectF oval : ovals) oval.offset(-0.3f, 0); break;
      case 5: for (RectF oval : ovals) oval.offset(0, -0.3f); break;
      case 6: for (RectF oval : ovals) oval.offset(0.3f, 0); break;
      case 7: for (RectF oval : ovals) oval.offset(0, 0.3f); break;
      
    }
  }
  
  @Override
  public void draw(Canvas canvas) {
    for (RectF oval : ovals) {
      canvas.drawOval(oval, colourPaint);
    }
  }
  
  @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