Android Open Source - BobEngine Flower






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;
// w  w w .j a v  a2  s .c o  m
import bobby.engine.bobengine.GameObject;
import bobby.engine.bobengine.Room;
import bobby.engine.bobengine.SoundPlayer;

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

    // Constants
    private final int SPEED = 8;   // Speed at which the flower moves

    // Variables
    private boolean passed;        // Indicates when the bug has passed the flower

    // Sounds
    private SoundPlayer player;    // Plays sound effects
    private int ding;              // Score sound

    /**
     * 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 Flower(int id, Room containingRoom) {
        super(id, containingRoom);

        player = new SoundPlayer(getActivity().getApplicationContext()); // Initialize the sound player
        ding = player.newSound(R.raw.ding);                              // Add new sound.

        setGraphic(GameView.flower, 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.
         *
         * Note: collision boxes do not rotate with the object.
         */
        giveCollisionBox(0, 0, 1, 1);     // Top, the flower pedals
    }

    public void set(boolean isTop) {
        height = getRoom().getHeight() / 2;
        width = height / 4;
        x = -width;

        passed = true;

        if (isTop) {
            y = getRoom().getHeight();
            angle = 180;
        } else {
            y = 0;
            angle = 0;
        }
    }

    @Override
    public void step(double dt) {
        x -= SPEED;

        // Passed the bug, increment score.
        if (x < getRoom().getWidth() / 2 && !passed && angle == 0) {
            ((GameRoom) getRoom()).incrementScore();
            passed = true;

            player.play(ding); // Play the sound effect.
        }

        // Back on the right, can be passed again.
        if (x > getRoom().getWidth()) {
            passed = false;
        }
    }
}




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