Android Open Source - BobEngine An Object






From Project

Back to project page BobEngine.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project BobEngine 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 bobby.engine.touchinput;
/*from   www  .j  a v a  2  s  . c  o m*/
import bobby.engine.bobengine.GameObject;
import bobby.engine.bobengine.Room;

public class AnObject extends GameObject {

  public AnObject(int id, Room containingRoom) {
    super(id, containingRoom);
    // TODO Initialization
    
    /* Set graphic and number of frames to use for this icon */
    setGraphic(GameView.icon, 1);
  }

  /**
   * Set up or reset this object.
   */
  public void set() {
    x = getRoom().getWidth() / 2;
    y = getRoom().getHeight() / 2;
    
    width = height = getRoom().getWidth() / 5;
  }
  
  /**
   * Step event happens every frame.
   */
  @Override
  public void step(double deltaTime) {
    
    
    /**
     * Rather than having an event like newpress and released,
     * the "held" state of a touch is determined by a function
     * call.
     */
    if (getTouch().held()) {                        // ANY finger is held
      angle++;                                    // Make it spin!
    } 
    
    if (getTouch().held(1)) {                       // 2 fingers are held (index IDs 0 and 1)
      width = height = getRoom().getWidth() / 3;  // Make it bigger!
    } else {                                        // Reset size
      width = height = getRoom().getWidth() / 5;
    }
  }
  
  /**
   * NEWPRESS: Fires once when the screen is touched.
   * 
   * index is the ID of the finger that touched the screen.
   * 0 - is the first finger
   * 1 - is the second... so on
   */
  @Override
  public void newpress(int index) {
    x = getTouch().X[0];         // Use "getTouch()" to get lots of information about the input
    y = getTouch().Y[0];         // These are the coords of the first index (the "oldest" finger on the screen)
    
    if (index == 1) {            // A second finger!
      getView().setBackgroundColor(1, 0, 0, 1);  // Red background. (RGBA)
    }
  }
  
  /**
   * RELEASED: Fires once when a finger stops touching the screen.
   * 
   * Note that when this happens, the index ID numbers for all the
   * fingers about this one move down to fill in the gap left.
   * 
   * ex.
   * if there are 3 fingers, their IDs are 0, 1, and 2
   * when finger 1 is removed, 2 becomes one. So now the IDs are 0, and 1
   * but 1 is the finger that was previously 2.
   * 
   * Test this out:
   * The code in newpress() will turn the background red when a second finger is touched down.
   * 
   * While still holding down the first finger, release the second one. This code
   * shoule turn the background white.
   * 
   * Now, turn background red again. This time, release the FIRST finger while still holding
   * down the second. The bg is still red.
   * 
   * Release the other finger, the bg stays red.
   * 
   * When you released the first finger, "index" was 0. Then, the second finger tooks the
   * first finger's place as 0. So when it was released "index" was still 0.
   */
  @Override
  public void released(int index) {
    if (index == 1) {                             // Second finger was released
      getView().setBackgroundColor(1, 1, 1, 1); // White
    }
  }
}




Java Source Code List

bobby.engine.bobengine.BobActivity.java
bobby.engine.bobengine.BobActivity.java
bobby.engine.bobengine.BobRenderer.java
bobby.engine.bobengine.BobRenderer.java
bobby.engine.bobengine.BobView.java
bobby.engine.bobengine.BobView.java
bobby.engine.bobengine.BuildConfig.java
bobby.engine.bobengine.BuildConfig.java
bobby.engine.bobengine.GameObject.java
bobby.engine.bobengine.GameObject.java
bobby.engine.bobengine.Graphic.java
bobby.engine.bobengine.Graphic.java
bobby.engine.bobengine.GraphicsHelper.java
bobby.engine.bobengine.GraphicsHelper.java
bobby.engine.bobengine.NumberDisplay.java
bobby.engine.bobengine.NumberDisplay.java
bobby.engine.bobengine.Room.java
bobby.engine.bobengine.Room.java
bobby.engine.bobengine.SoundPlayer.java
bobby.engine.bobengine.SoundPlayer.java
bobby.engine.bobengine.SplashActivity.java
bobby.engine.bobengine.SplashActivity.java
bobby.engine.bobengine.Touch.java
bobby.engine.bobengine.Touch.java
bobby.engine.template.AnObject.java
bobby.engine.template.AnObject.java
bobby.engine.template.BuildConfig.java
bobby.engine.template.BuildConfig.java
bobby.engine.template.GameView.java
bobby.engine.template.GameView.java
bobby.engine.template.MainActivity.java
bobby.engine.template.MainActivity.java
bobby.engine.template.StartRoom.java
bobby.engine.template.StartRoom.java
bobby.engine.touchinput.AnObject.java
bobby.engine.touchinput.AnObject.java
bobby.engine.touchinput.GameView.java
bobby.engine.touchinput.GameView.java
bobby.engine.touchinput.MainActivity.java
bobby.engine.touchinput.MainActivity.java
bobby.engine.touchinput.StartRoom.java
bobby.engine.touchinput.StartRoom.java
bobby.example.bobengineexample.Android.java
bobby.example.bobengineexample.BuildConfig.java
bobby.example.bobengineexample.GameView.java
bobby.example.bobengineexample.MainActivity.java
bobby.example.bobengineexample.StartRoom.java
bobby.example.cameraexample.ApplicationTest.java
bobby.example.cameraexample.MainActivity.java
com.bobbyloujo.jumpybug.ApplicationTest.java
com.bobbyloujo.jumpybug.Background.java
com.bobbyloujo.jumpybug.Bug.java
com.bobbyloujo.jumpybug.Flower.java
com.bobbyloujo.jumpybug.GameOver.java
com.bobbyloujo.jumpybug.GameRoom.java
com.bobbyloujo.jumpybug.GameView.java
com.bobbyloujo.jumpybug.MainActivity.java
com.bobbyloujo.jumpybug.StartRoom.java