Android Open Source - Roll-Ball-Roll Floor Manager






From Project

Back to project page Roll-Ball-Roll.

License

The source code is released under:

GNU General Public License

If you think the Android project Roll-Ball-Roll 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

/**
 * Copyright (c) 2014 Lewis Chun/*from  ww w.  ja  v a 2s  . co  m*/
 * Android game in which the user controls a ball to get a high score.
 *
 * This file is part of Roll Ball Roll.
 *
 * Roll Ball Roll is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.zwac035.finalprogram.managers;

import com.jme3.bullet.PhysicsSpace;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.zwac035.finalprogram.FloorType;
import com.zwac035.finalprogram.Res;
import java.util.ArrayList;

/**
 * Class the spawns and deletes the floor pieces as needed.
 * @author Lewis Chun
 */
public class FloorManager extends LevelChangeManager implements Manager {
 
    private Node rootNode;
    private PhysicsSpace physics;
    private int floorHeight = 4;
    private ArrayList<Spatial> listOfPieces;
    private ColorRGBA floorColour, beginColour, finalColour;
    private FloorPool pool;
    private boolean tutorialStartFloor;
    
    public FloorManager(Node root, PhysicsSpace physics, boolean tutorial){
        rootNode = root;
        this.physics = physics;
        beginColour = ColorRGBA.randomColor();
        floorColour = beginColour;
        finalColour = ColorRGBA.randomColor();
        listOfPieces = new ArrayList<Spatial>();
        tutorialStartFloor = tutorial;
    }
    
    public void initialise(){
        // Create pool, and build the start floor
        pool = new FloorPool(10, 6);
        for(int i = -4; i < 5; i++){
            Spatial newPiece;
            if(!tutorialStartFloor && i != 0 && Res.rnd.nextFloat() < 0.3f){
                newPiece = pool.takePeice(0, i * floorHeight, floorColour.clone(), FloorType.random());
            } else {
                newPiece = pool.takePlainPeice(0, i * floorHeight, floorColour.clone());
            }
            changeFloorColour();
            listOfPieces.add(newPiece);
            rootNode.attachChild(newPiece);
            physics.add(newPiece);
        }
    }
     
    public void update(int distanceTravelled){
        Spatial newPiece;
        if(currentLevel != null){
            FloorType f = currentLevel.getFloorPiece(distanceTravelled);
            newPiece = pool.takePeice(0, distanceTravelled, floorColour.clone(), f);
        } else {
            float rndInc = ((float) distanceTravelled) / 500;
            rndInc = rndInc > 0.6f ? 0.6f : rndInc;
            // Pick a random piece
            if(Res.rnd.nextFloat() < 0.3f + rndInc){
                newPiece = pool.takePeice(0, distanceTravelled, floorColour.clone(), FloorType.random());
            } else {
                newPiece = pool.takePlainPeice(0, distanceTravelled, floorColour.clone());
            }
        }
        
        listOfPieces.add(newPiece);
        rootNode.attachChild(newPiece);
        physics.add(newPiece);
        
        changeFloorColour();

        // Delete the nodes going offscreen
        Spatial s = listOfPieces.remove(0);
        rootNode.detachChild(s);
        physics.remove(s);
        pool.addToPool(s);
    }
    
    private float percent = 0.1f;
    
    private void changeFloorColour(){
        floorColour.interpolate(beginColour, finalColour, percent);
        percent += 0.1f;
        if(percent >= 1){
            percent = 0;
            beginColour = finalColour;
            floorColour = beginColour;
            finalColour = ColorRGBA.randomColor();
        }
    }
    
    public void removeAll(){
        physics.removeAll(rootNode);
        rootNode.detachAllChildren();
        listOfPieces.clear();
    }

    public void quickUpdate() {
        // Nothing needs to be done every frame
    }
}




Java Source Code List

com.zwac035.finalprogram.Database.java
com.zwac035.finalprogram.EnterNameActivity.java
com.zwac035.finalprogram.FloorType.java
com.zwac035.finalprogram.ForceChangeListener.java
com.zwac035.finalprogram.GameCamera.java
com.zwac035.finalprogram.GamePauseState.java
com.zwac035.finalprogram.GameRunningState.java
com.zwac035.finalprogram.HighScoreScreenActivity.java
com.zwac035.finalprogram.InfoScreenActivity.java
com.zwac035.finalprogram.Level.java
com.zwac035.finalprogram.MainActivity.java
com.zwac035.finalprogram.Main.java
com.zwac035.finalprogram.Player.java
com.zwac035.finalprogram.Res.java
com.zwac035.finalprogram.ShopActivity.java
com.zwac035.finalprogram.StartScreenActivity.java
com.zwac035.finalprogram.TutorialState.java
com.zwac035.finalprogram.box.BoxControl.java
com.zwac035.finalprogram.box.BoxType.java
com.zwac035.finalprogram.box.ExplodingBox.java
com.zwac035.finalprogram.box.HeavyBox.java
com.zwac035.finalprogram.box.MagnetBox.java
com.zwac035.finalprogram.box.NormalBoxControl.java
com.zwac035.finalprogram.box.Triangle.java
com.zwac035.finalprogram.managers.BoxManager.java
com.zwac035.finalprogram.managers.BoxPool.java
com.zwac035.finalprogram.managers.FloorManager.java
com.zwac035.finalprogram.managers.FloorPool.java
com.zwac035.finalprogram.managers.LevelChangeManager.java
com.zwac035.finalprogram.managers.LevelChangeObservable.java
com.zwac035.finalprogram.managers.LevelChangeObserver.java
com.zwac035.finalprogram.managers.LevelManager.java
com.zwac035.finalprogram.managers.ManagerFacade.java
com.zwac035.finalprogram.managers.Manager.java
com.zwac035.finalprogram.managers.TriangleManager.java
com.zwac035.finalprogram.managers.TrianglePool.java