Android Open Source - BulletsForever Draw Touch Handler






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;
/*  w w w. j  ava  2  s.c om*/
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

/**
 * This is for handling the game's touch input
 * This should be instantiated by DrawWorld's initializer
 * Only a single instance should exist per GameMain instance
 */
public class DrawTouchHandler implements OnTouchListener {

  private DrawWorld dw;
  
  public DrawTouchHandler(DrawWorld dw) {
    this.dw = dw;
  }
  
  // Do not add multi-touch support for simplicity (no need for it in my opinion)
  public boolean onTouch(View v, MotionEvent event) {
    switch(event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        if (dw.mode.equals(DrawWorld.DemoMode.MOVE)) {
          // Change player's target location
          dw.player.tx = event.getX();
          dw.player.ty = event.getY();
        }
        return true;
      case MotionEvent.ACTION_DOWN:
        if (dw.mode.equals(DrawWorld.DemoMode.MOVE)) {
          // Change player's target location
          dw.player.tx = event.getX();
          dw.player.ty = event.getY();
          
          dw.player.shooting = true;
        // For demo purposes
        } else if (dw.mode.equals(DrawWorld.DemoMode.RANDOM)) {
          // Add 100 bullets in random locations at random speeds and angles
          for (int i = 0; i < 100; i++) { 
            DrawObjectBullet bullet = new DrawObjectBullet(
                dw, true, false,
                (float)Math.random() * Settings.screenWidth,
                (float)Math.random() * Settings.screenHeight,
                (float)Math.random() * 10f, 0f,
                0f, 0f,
                (float)Math.random() * 360f, 0f
                );
            dw.addBullet(bullet);
          }
        } else if (dw.mode.equals(DrawWorld.DemoMode.EXPLOSION)) {
          // Add 360 bullets fanning out from the point of contact
          for (int i = 0; i < 360; i++) {
            DrawObjectBullet bullet = new DrawObjectBullet(
                dw, true, false,
                event.getX(), event.getY(),
                (float)Math.random() * 10f, 0f,
                0f, 0f,
                i, 0f
                );
            dw.addBullet(bullet);
          }
        } else if (dw.mode.equals(DrawWorld.DemoMode.FIREWORKS)) {
          // Add 360 bullets spouting out from the point of contact
          for (int i = 0; i < 360; i++) {
            DrawObjectBullet bullet = new DrawObjectBullet(
                dw, true, false,
                event.getX(), event.getY(),
                (float)Math.random() * 10f, 0f,
                0f, 0.5f,
                i, 0f
                );
            dw.addBullet(bullet);
          }
        } else if (dw.mode.equals(DrawWorld.DemoMode.SPIRALS)) {
          // Add 180 bullets spiraling out from the point of contact
          for (int i = 0; i < 360; i += 2) {
            DrawObjectBullet bullet = new DrawObjectBullet(
                dw, true, false,
                event.getX(), event.getY(),
                (float)Math.random() * 10f, 0.1f,
                0f, 0f,
                i, 10f
                );
            dw.addBullet(bullet);
          }
        } else if (dw.mode.equals(DrawWorld.DemoMode.RINGS)) {
          // Add 36 bullets ringing out from the point of contact
          for (int i = 0; i < 360; i += 10) {
            DrawObjectBullet bullet = new DrawObjectBullet(
                dw, true, false,
                event.getX(), event.getY(),
                5f, 0f,
                0f, 0f,
                i, 10f
                );
            dw.addBullet(bullet);
          }
        } else if (dw.mode.equals(DrawWorld.DemoMode.ZOOM)) {
          // Add 36 bullets zooming out from the point of contact
          for (int i = 0; i < 360; i += 10) {
            DrawObjectBullet bullet = new DrawObjectBullet(
                dw, true, false,
                event.getX(), event.getY(),
                0f, 0.5f,
                0f, 0f,
                i, -15f
                );
            dw.addBullet(bullet);
          }
        }
        return true;
      case MotionEvent.ACTION_UP:
        dw.player.shooting = false;
        return true;
      default:
        return false;
    }
  }

}




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