Back to project page Roll-Ball-Roll.
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.
/** * 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 } }