Android Open Source - BobEngine Start Room






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  . jav a 2 s .c om
import bobby.engine.bobengine.BobView;
import bobby.engine.bobengine.GameObject;
import bobby.engine.bobengine.Room;

/**
 * Created by Ben on 1/6/2015.
 */
public class StartRoom extends Room {

    // Objects
    private GameObject title;           // The title graphic
    private GameObject playButton;      // The Play button
    private Background bg1;             // Background panel 1
    private Background bg2;             // Background panel 2

    public StartRoom(BobView container) {
        super(container);

        // Initialize objects
        /**
         * Game object initialization requires a unique ID number and the room
         * that the object is placed in. The easiest way to ensure unique ID numbers is
         * by using the nextInstance() function.
         *
         * If you don't use nextInstance(),
         * you must use setNumObjects(number) to be greater than the max number of
         * objects in this room and equal to or greater than the highest object
         * ID number.
         */
        title = new GameObject(nextInstance(), this);
        playButton = new GameObject(nextInstance(), this);
        bg1 = new Background(nextInstance(), this);
        bg2 = new Background(nextInstance(), this);

        /**
         * Add the objects to room. This is necessary so that the room knows that these objects need
         * to be updated and drawn.
         */
        addObject(title);
        addObject(playButton);
        addObject(bg1);
        addObject(bg2);
    }

    /**
     * Set method. I like to define one of these for each room and game object. The purpose of
     * this method is the setup and reset the room. This makes it easy to set up the initial
     * state of the game and to reset whatever rooms need to be reset when the player hits the
     * play or play again button.
     */
    public void set() {
        /*
         * Setting up the title graphic. Since we used a generic GameObject for the title graphic,
         * we'll just do all the setup for it here. The title graphic doesn't do much, so I don't
         * feel the need to define it's own class.
         */
        title.x = getWidth() / 2;            // getWidth() returns the width of this view. This line centers the graphic horizontally.
        title.y = getHeight() * 3 / 4;       // and this positions it 3/4 of the way up the screen.
        title.width = getWidth() * 3 / 4;    // The width of the title will be 3/4 the width of the screen.
        title.height = title.width / 2;      // Our graphic is twice as wide as it is tall.
        title.setGraphic(GameView.title, 1); // We assign the graphic that we added in our GameView to our title object. This graphic has 1 frame.

        /*
         * Setting up the play button will be very similar.
         */
        playButton.x = getWidth() / 2;
        playButton.y = getHeight() / 4;
        playButton.width = getWidth() / 4;
        playButton.height = playButton.width / 2;
        playButton.setGraphic(GameView.play, 2);  // Play button has 2 frames: one for pressed and one for not pressed.

        bg1.set(getWidth() / 2, 4);               // Visible, will move off screen
        bg2.set((int) bg1.x + getWidth(), 4);     // Off screen, will move on screen.
    }

    /**
     * Step event happens every frame.
     *
     * @param dt
     */
    @Override
    public void step(double dt) {
        if (getTouch().objectTouched(playButton)) {  // Is the play button being touched?
            playButton.frame = 1;                    // Pressed frame.
        } else {
            playButton.frame = 0;                    // Not pressed frame.
        }
    }

    public void released(int index){
        /**
         * getTouch() provides many useful functions for getting
         * touchscreen input. See the touchInput example for more
         * information.
         */
        if (getTouch().objectTouched(playButton)) {  // Play button touched
            GameView.game.set();                     // Set up the game room.
            getView().goToRoom(GameView.game);       // Go to the game room.
        }
    }
}




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