Android Open Source - BobEngine Bug






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 com.bobbyloujo.jumpybug;
//ww w . java  2 s .  c om
import bobby.engine.bobengine.GameObject;
import bobby.engine.bobengine.Room;

/**
 * Created by Ben on 1/6/2015.
 */
public class Bug extends GameObject {

    // Constants
    private final double ACC = .8;   // The acceleration of gravity. Determines how fast the bug falls.
    private final int JUMP_V = 20;   // Velocity to give the bug to make it jump.

    // Variables
    private double vy;               // The bug's velocity on the y axis.

    /**
     * Initialization. Requires a unique Id number and the room containing this
     * GameObject.
     *
     * @param id             - ID number
     * @param containingRoom - Room that this object is in.
     */
    public Bug(int id, Room containingRoom) {
        super(id, containingRoom);

        /**
         * Assign the bug graphic we created in GameView to this object.
         * This graphic has only 1 frame. Graphics with many frames must
         * have those frames arranged vertically and all frames must be the
         * same size.
         */
        setGraphic(GameView.bug, 1);

        /**
         * Collision detection.
         *
         * You can give any object up to 10 collision boxes. Boxes are defined with 2 points.
         * (0,0) is the top left corner of the object, and (1,1) is the bottom right.
         *
         * Detection is done with a function call in the room containing the two objects
         * that are being compared. In the step event in GameRoom you'll find a loop
         * that checks the collision between the bug and each flower.
         */
        giveCollisionBox(.25,.25,.75,.75);
    }

    /**
     * Set up and reset the bug.
     */
    public void set() {
        x = getRoom().getWidth() / 2;
        y = getRoom().getHeight() * 3 / 4;
        width = getRoom().getWidth() / 8;
        height = width;
        vy = 0;
    }

    /**
     * Step event happens each frame.
     */
    @Override
    public void step(double dt) {
        vy -= ACC;                 // Acceleration of gravity
        y += vy;                   // y velocity

        angle = vy / 2;            // Change the bug's angle based on the bug's y velocity

        if (y < height / 2) {      // Hit the ground, game over!
            GameView.gameOver.set();
            getView().goToRoom(GameView.gameOver);
        }
    }

    /**
     * The screen has been touched.
     *
     * @param index
     */
    @Override
    public void newpress(int index) {
        // Make the bug jump
        if (y + JUMP_V < getRoom().getHeight()) vy = JUMP_V;
    }
}




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