From 4d006a34617f4b6248798bf52f3966e598d1f230 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 23 Jun 2014 16:07:06 -0430 Subject: [PATCH] Added automatic actions. Not tested yet. --- .../ucv/ciens/ccg/networkdata/MotorEvent.java | 2 +- src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 55 ++- .../entities/MarkerTestEntityCreator.java | 140 ------- .../game/AutomaticActionPerformerBase.java | 39 ++ .../GameGlobals.java} | 60 ++- .../nxtar/game/ScenarioImplementation.java | 29 ++ .../bombgame}/BombComponent.java | 2 +- .../BombGameAutomaticActionPerformer.java | 154 ++++++++ .../bombgame}/BombGameEntityCreator.java | 8 +- .../bombgame}/BombGameLogicSystem.java | 7 +- .../BombGameObjectTypeComponent.java | 2 +- .../bombgame}/BombGamePlayerComponent.java | 4 +- .../bombgame}/BombGamePlayerSystem.java | 5 +- .../nxtar/states/AutomaticActionState.java | 352 +++++++++++++++--- .../ciens/ccg/nxtar/states/InGameState.java | 13 +- .../ccg/nxtar/states/MainMenuStateBase.java | 48 ++- .../ccg/nxtar/states/OuyaMainMenuState.java | 17 +- .../ccg/nxtar/states/TabletMainMenuState.java | 5 +- .../ccg/nxtar/systems/PlayerSystemBase.java | 4 +- 19 files changed, 692 insertions(+), 254 deletions(-) delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java rename src/ve/ucv/ciens/ccg/nxtar/{utils/GameSettings.java => game/GameGlobals.java} (62%) create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java rename src/ve/ucv/ciens/ccg/nxtar/{components => game/bombgame}/BombComponent.java (96%) create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java rename src/ve/ucv/ciens/ccg/nxtar/{entities => game/bombgame}/BombGameEntityCreator.java (98%) rename src/ve/ucv/ciens/ccg/nxtar/{systems => game/bombgame}/BombGameLogicSystem.java (98%) rename src/ve/ucv/ciens/ccg/nxtar/{components => game/bombgame}/BombGameObjectTypeComponent.java (96%) rename src/ve/ucv/ciens/ccg/nxtar/{components => game/bombgame}/BombGamePlayerComponent.java (92%) rename src/ve/ucv/ciens/ccg/nxtar/{systems => game/bombgame}/BombGamePlayerSystem.java (93%) diff --git a/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java b/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java index 50f1c60..40761b6 100644 --- a/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java +++ b/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java @@ -5,7 +5,7 @@ import java.io.Serializable; public class MotorEvent implements Serializable{ private static final long serialVersionUID = 9989L; - public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC, RECENTER}; + public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC, RECENTER, ROTATE_90}; private motor_t motor; private byte power; diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java index da7bbfc..db77ca5 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java +++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java @@ -15,6 +15,7 @@ */ package ve.ucv.ciens.ccg.nxtar; +import ve.ucv.ciens.ccg.nxtar.game.GameGlobals; import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver; import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener; import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor; @@ -22,13 +23,13 @@ import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread; import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread; import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread; import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread; +import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionState; import ve.ucv.ciens.ccg.nxtar.states.BaseState; import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState; import ve.ucv.ciens.ccg.nxtar.states.InGameState; import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase; import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState; import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState; -import ve.ucv.ciens.ccg.nxtar.utils.GameSettings; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import ve.ucv.ciens.ccg.nxtar.utils.Utils; import aurelienribon.tweenengine.Tween; @@ -74,7 +75,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ * Valid game states. */ public enum game_states_t { - MAIN_MENU(0), IN_GAME(1), CALIBRATION(2); + MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3); private int value; @@ -87,7 +88,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ } public static int getNumStates(){ - return 3; + return 4; } }; @@ -230,7 +231,28 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ * sets the application states.

*/ public void create(){ - GameSettings.initGameSettings(this); + try { + GameGlobals.initGameSettings(this); + } catch (IllegalArgumentException e) { + Gdx.app.log(TAG, CLASS_NAME + ".create(): Illegal argument initializing globals: ", e); + Gdx.app.exit(); + return; + } catch (InstantiationException e) { + Gdx.app.log(TAG, CLASS_NAME + ".create(): Instantiation exception initializing globals: ", e); + Gdx.app.exit(); + return; + } catch (IllegalAccessException e) { + Gdx.app.log(TAG, CLASS_NAME + ".create(): Illegal access exception initializing globals: ", e); + Gdx.app.exit(); + return; + } + + // Set up rendering fields and settings. + batch = new SpriteBatch(); + batch.enableBlending(); + batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + ShaderProgram.pedantic = false; // Create the state objects. states = new BaseState[game_states_t.getNumStates()]; @@ -242,27 +264,26 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ try{ states[game_states_t.IN_GAME.getValue()] = new InGameState(this); }catch(IllegalStateException e){ - Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state: " + e.getMessage()); + Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: " + e.getMessage()); Gdx.app.exit(); return; } states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this); + try{ + states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this); + }catch(IllegalStateException e){ + Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: " + e.getMessage()); + Gdx.app.exit(); + return; + } + // Register controller listeners. for(BaseState state : states){ Controllers.addListener(state); } - // Set up rendering fields and settings. - batch = new SpriteBatch(); - batch.enableBlending(); - batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); - - pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - - ShaderProgram.pedantic = false; - // Set up the overlay font. overlayX = -(Utils.getScreenWidth() / 2) + 10; overlayY = (Utils.getScreenHeight() / 2) - 10; @@ -336,8 +357,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ super.render(); // Load the assets. - if(!GameSettings.getEntityCreator().areEntitiesCreated()) - GameSettings.getEntityCreator().updateAssetManager(); + if(!GameGlobals.getEntityCreator().areEntitiesCreated()) + GameGlobals.getEntityCreator().updateAssetManager(); // If the current state set a value for nextState then switch to that state. if(nextState != null){ @@ -452,7 +473,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ batch.dispose(); font.dispose(); - GameSettings.clearGameSettings(); + GameGlobals.clearGameSettings(); } /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java deleted file mode 100644 index afd0f8b..0000000 --- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2014 Miguel Angel Astor Romero - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ve.ucv.ciens.ccg.nxtar.entities; - -import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent; -import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent; -import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent; -import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent; -import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent; -import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; -import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader; - -import com.artemis.Entity; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.VertexAttribute; -import com.badlogic.gdx.graphics.VertexAttributes; -import com.badlogic.gdx.graphics.VertexAttributes.Usage; -import com.badlogic.gdx.graphics.g3d.Environment; -import com.badlogic.gdx.graphics.g3d.Material; -import com.badlogic.gdx.graphics.g3d.Model; -import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; -import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute; -import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight; -import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader; -import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder; -import com.badlogic.gdx.math.Matrix3; -import com.badlogic.gdx.math.Vector3; -import com.badlogic.gdx.utils.JsonReader; - -public class MarkerTestEntityCreator extends EntityCreatorBase { - private static final String TAG = "MARKER_TEST_ENTITY_CREATOR"; - private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName(); - - private Model bombModel; - private Model animatedModel; - private Model boxModel; - private DirectionalLightPerPixelShader ppShader; - - @Override - protected void createAllEntities() { - ModelBuilder builder; - Entity bomb, box, anim; - G3dModelLoader loader; - Environment environment; - Material material; - - // Create mesh. - Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes."); - - loader = new G3dModelLoader(new JsonReader()); - - bombModel = loader.loadModel(Gdx.files.internal("models/Bomb_test_2.g3dj")); - animatedModel = loader.loadModel(Gdx.files.internal("models/cube.g3dj")); - - material = new Material(new FloatAttribute(FloatAttribute.Shininess, 50.0f), new ColorAttribute(ColorAttribute.Diffuse, 1.0f, 1.0f, 1.0f, 1.0f), new ColorAttribute(ColorAttribute.Specular, 1.0f, 1.0f, 1.0f, 1.0f)); - - builder = new ModelBuilder(); - boxModel = builder.createBox(0.5f, 0.5f, 6.0f, material, new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")).getMask()); - - // Load the shader. - ppShader = new DirectionalLightPerPixelShader(); - ppShader.init(); - - environment = new Environment(); - environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f)); - environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, -0.5f))); - - // Create the entities. - Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites."); - bomb = world.createEntity(); - bomb.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f))); - bomb.addComponent(new RenderModelComponent(bombModel)); - bomb.addComponent(new EnvironmentComponent(environment)); - bomb.addComponent(new ShaderComponent(ppShader)); - bomb.addComponent(new MarkerCodeComponent(1023)); - - anim = world.createEntity(); - anim.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(0.25f, 0.25f, -0.25f))); - anim.addComponent(new RenderModelComponent(animatedModel)); - anim.addComponent(new AnimationComponent(anim.getComponent(RenderModelComponent.class).instance, 0, true)); - anim.addComponent(new EnvironmentComponent(environment)); - anim.addComponent(new MarkerCodeComponent(89)); - anim.addComponent(new ShaderComponent(ppShader)); - - box = world.createEntity(); - box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f))); - box.addComponent(new RenderModelComponent(boxModel)); - box.addComponent(new ShaderComponent(ppShader)); - box.addComponent(new EnvironmentComponent(environment)); - - // Add the entities to the world. - Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world."); - //sphere.addToWorld(); - bomb.addToWorld(); - anim.addToWorld(); - box.addToWorld(); - - entitiesCreated = true; - } - - @Override - public void dispose() { - if(boxModel != null) - boxModel.dispose(); - - if(animatedModel != null) - animatedModel.dispose(); - - if(bombModel != null) - bombModel.dispose(); - - if(ppShader != null) - ppShader.dispose(); - } - - @Override - public boolean updateAssetManager(){ - createAllEntities(); - if(core != null) core.onAssetsLoaded(); - - return true; - } - - @Override - public void resetAllEntities() { } -} diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java new file mode 100644 index 0000000..13f12ed --- /dev/null +++ b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014 Miguel Angel Astor Romero + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ve.ucv.ciens.ccg.nxtar.game; + +import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData; + +public abstract class AutomaticActionPerformerBase { + public enum automatic_action_t{ + NO_ACTION, + GO_FORWARD, + GO_BACKWARDS, + STOP, + TURN_LEFT, + TURN_RIGHT, + BACKWARDS_LEFT, + BACKWARDS_RIGHT, + ROTATE_90, + RECENTER, + LOOK_RIGHT, + LOOK_LEFT, + STOP_LOOKING; + } + + public abstract boolean performAutomaticAction(int lightSensorReading, MarkerData markers); + public abstract automatic_action_t getNextAction(); +} diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java similarity index 62% rename from src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java rename to src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java index 94fe904..5f5c3ff 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.utils; +package ve.ucv.ciens.ccg.nxtar.game; import ve.ucv.ciens.ccg.nxtar.NxtARCore; -import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator; import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase; import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem; -import ve.ucv.ciens.ccg.nxtar.systems.BombGameLogicSystem; import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase; @@ -37,13 +35,14 @@ import com.badlogic.gdx.controllers.mappings.Ouya; import com.badlogic.gdx.graphics.g3d.ModelBatch; import com.badlogic.gdx.utils.Disposable; -public abstract class GameSettings{ - private static EntityCreatorBase entityCreator = null; - private static GameLogicSystemBase gameLogicSystem = null; - private static World gameWorld = null; - private static ModelBatch modelBatch = null; +public abstract class GameGlobals{ + private static EntityCreatorBase entityCreator = null; + private static GameLogicSystemBase gameLogicSystem = null; + private static World gameWorld = null; + private static ModelBatch modelBatch = null; + private static AutomaticActionPerformerBase automaticActionPerformer = null; - public static void initGameSettings(NxtARCore core) throws IllegalArgumentException{ + public static void initGameSettings(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{ if(core == null) throw new IllegalArgumentException("Core is null."); @@ -56,13 +55,42 @@ public abstract class GameSettings{ } if(getEntityCreator() == null){ - entityCreator = new BombGameEntityCreator(); + try { + entityCreator = (EntityCreatorBase) ScenarioImplementation.entityCreatorClass.newInstance(); + } catch (InstantiationException e) { + System.out.println("Error instantiating entity creator."); + throw e; + } catch (IllegalAccessException e) { + System.out.println("Error accessing entity creator."); + throw e; + } entityCreator.setWorld(gameWorld); entityCreator.setCore(core); } - if(getGameLogicSystem() == null) - gameLogicSystem = new BombGameLogicSystem(); + if(getGameLogicSystem() == null){ + try { + gameLogicSystem = (GameLogicSystemBase) ScenarioImplementation.gameLogicSystemClass.newInstance(); + } catch (InstantiationException e) { + System.out.println("Error instantiating game logic system."); + throw e; + } catch (IllegalAccessException e) { + System.out.println("Error accessing game logic system."); + throw e; + } + } + + if(automaticActionPerformer == null){ + try { + automaticActionPerformer = (AutomaticActionPerformerBase) ScenarioImplementation.automaticActionPerformerClass.newInstance(); + } catch (InstantiationException e) { + System.out.println("Error instantiating automatic action performer."); + throw e; + } catch (IllegalAccessException e) { + System.out.println("Error accessing automatic action performer."); + throw e; + } + } gameWorld.setSystem(new MarkerPositioningSystem()); gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya); @@ -70,6 +98,7 @@ public abstract class GameSettings{ gameWorld.setSystem(new AnimationSystem()); gameWorld.setSystem(new CollisionDetectionSystem()); gameWorld.setSystem(gameLogicSystem); + // TODO: Add player processing system. gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true); gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true); gameWorld.setSystem(new FadeEffectRenderingSystem(), true); @@ -113,4 +142,11 @@ public abstract class GameSettings{ public static World getGameWorld() { return gameWorld; } + + /** + * @return the automaticActionPerformer + */ + public static AutomaticActionPerformerBase getAutomaticActionPerformer() { + return automaticActionPerformer; + } } diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java new file mode 100644 index 0000000..303bd50 --- /dev/null +++ b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Miguel Angel Astor Romero + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ve.ucv.ciens.ccg.nxtar.game; + +import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionPerformer; +import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameEntityCreator; +import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameLogicSystem; + +@SuppressWarnings("rawtypes") +public final class ScenarioImplementation{ + public static Class gameLogicSystemClass = BombGameLogicSystem.class; + public static Class entityCreatorClass = BombGameEntityCreator.class; + public static Class automaticActionPerformerClass = BombGameAutomaticActionPerformer.class; + + private ScenarioImplementation(){} +} diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java similarity index 96% rename from src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java index e50513c..4ffd0a3 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.components; +package ve.ucv.ciens.ccg.nxtar.game.bombgame; import com.artemis.Component; diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java new file mode 100644 index 0000000..3e04729 --- /dev/null +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2014 Miguel Angel Astor Romero + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ve.ucv.ciens.ccg.nxtar.game.bombgame; + +import java.util.LinkedList; +import java.util.List; + +import com.badlogic.gdx.Gdx; + +import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase; +import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData; +import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; + +public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBase { + private static final int GOAL_FLOOR_MIN_LUMINANCE = 85; + private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 45; + + private enum action_state_t{ + START, WALK_FORWARD, DETECT_MARKER, FINISHING, END; + } + + private automatic_action_t nextAction; + private action_state_t state; + private List detectedMarkers; + private float then; + + public BombGameAutomaticActionPerformer(){ + nextAction = automatic_action_t.NO_ACTION; + state = action_state_t.START; + detectedMarkers = new LinkedList(); + then = 0.0f; + } + + @Override + public boolean performAutomaticAction(int lightSensorReading, MarkerData markers) throws IllegalStateException, IllegalArgumentException{ + boolean finish = false; + int detectedCode = -1; + float now, deltaT; + + if(markers == null) + throw new IllegalArgumentException("Markers is null"); + + switch(state){ + case START: + nextAction = automatic_action_t.ROTATE_90; + state = action_state_t.WALK_FORWARD; + finish = false; + break; + + case WALK_FORWARD: + if(lightSensorReading >= GOAL_FLOOR_MIN_LUMINANCE){ + nextAction = automatic_action_t.STOP; + state = action_state_t.END; + }else{ + if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE && lightSensorReading < GOAL_FLOOR_MIN_LUMINANCE){ + nextAction = automatic_action_t.STOP; + state = action_state_t.DETECT_MARKER; + then = Gdx.graphics.getDeltaTime(); + }else{ + nextAction = automatic_action_t.GO_FORWARD; + } + } + finish = false; + break; + + case DETECT_MARKER: + for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){ + // Check if this marker has not been detected already. + for(Integer code : detectedMarkers){ + if(markers.markerCodes[i] == code){ + i = ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; + break; + } + } + + // If the marker has not been detected before then examine it. + if(i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS){ + detectedCode = markers.markerCodes[i]; + // TODO: If marker is a bomb then add it to the summary. + } + } + + if(detectedCode == -1) + detectedMarkers.add(detectedCode); + + if(lightSensorReading < MARKER_NEARBY_FLOOR_MIN_LUMINANCE){ + state = action_state_t.WALK_FORWARD; + nextAction = automatic_action_t.STOP; + then = 0.0f; + }else{ + now = Gdx.graphics.getDeltaTime(); + deltaT = now - then; + if(deltaT >= 2.0f){ + nextAction = automatic_action_t.GO_FORWARD; + then = Gdx.graphics.getDeltaTime(); + } + } + + finish = false; + + break; + + case FINISHING: + detectedMarkers.clear(); + state = action_state_t.END; + nextAction = automatic_action_t.RECENTER; + finish = false; + break; + + case END: + state = action_state_t.START; + nextAction = automatic_action_t.NO_ACTION; + finish = true; + break; + + default: + throw new IllegalStateException("Unknown automatic action state."); + } + + return finish; + } + + @Override + public automatic_action_t getNextAction() { + switch(nextAction){ + default: + case NO_ACTION: + return automatic_action_t.NO_ACTION; + case GO_BACKWARDS: + return automatic_action_t.GO_BACKWARDS; + case GO_FORWARD: + return automatic_action_t.GO_FORWARD; + case STOP: + return automatic_action_t.STOP; + case ROTATE_90: + return automatic_action_t.ROTATE_90; + case RECENTER: + return automatic_action_t.RECENTER; + } + } +} diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java similarity index 98% rename from src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java index c5ac8af..8369159 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java @@ -13,17 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.entities; +package ve.ucv.ciens.ccg.nxtar.game.bombgame; import java.util.LinkedList; import java.util.List; import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent; import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent; -import ve.ucv.ciens.ccg.nxtar.components.BombComponent; -import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t; -import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent; -import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent; import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent; @@ -33,6 +29,8 @@ import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase; import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent; +import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase; +import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombComponent.bomb_type_t; import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader; import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem; import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java similarity index 98% rename from src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java index a77b4f4..aa82fb2 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.systems; +package ve.ucv.ciens.ccg.nxtar.game.bombgame; import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent; -import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent; -import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent; import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent; import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent; import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase; import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent; -import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator; +import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; +import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import ve.ucv.ciens.ccg.nxtar.utils.Utils; diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java similarity index 96% rename from src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java index 5fd7862..61861ae 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.components; +package ve.ucv.ciens.ccg.nxtar.game.bombgame; import com.artemis.Component; diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java similarity index 92% rename from src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java index 82144ed..3950389 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.components; +package ve.ucv.ciens.ccg.nxtar.game.bombgame; + +import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase; public class BombGamePlayerComponent extends PlayerComponentBase { public static final int MIN_LIVES = 1; diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java similarity index 93% rename from src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java index db2a7cc..d45a7d5 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package ve.ucv.ciens.ccg.nxtar.systems; +package ve.ucv.ciens.ccg.nxtar.game.bombgame; import ve.ucv.ciens.ccg.nxtar.NxtARCore; -import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent; -import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator; +import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase; import ve.ucv.ciens.ccg.nxtar.utils.Utils; import com.artemis.ComponentMapper; diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java index 73b9354..3ad1abb 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java @@ -15,20 +15,20 @@ */ package ve.ucv.ciens.ccg.nxtar.states; +import ve.ucv.ciens.ccg.networkdata.MotorEvent; +import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t; import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t; +import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase; +import ve.ucv.ciens.ccg.nxtar.game.GameGlobals; +import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.automatic_action_t; import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera; import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData; +import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread; +import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue; import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor; -import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem; -import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; -import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem; -import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem; -import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem; -import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem; -import ve.ucv.ciens.ccg.nxtar.utils.GameSettings; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import ve.ucv.ciens.ccg.nxtar.utils.Utils; @@ -37,6 +37,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.controllers.Controller; import com.badlogic.gdx.controllers.mappings.Ouya; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Pixmap; @@ -44,16 +45,24 @@ import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.Texture.TextureWrap; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.graphics.g3d.ModelBatch; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; +import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable; public class AutomaticActionState extends BaseState{ - private static final String TAG = "IN_GAME_STATE"; + private static final String TAG = "AUTOMATIC_STATE"; private static final String CLASS_NAME = AutomaticActionState.class.getSimpleName(); private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg"; private static final float NEAR = 0.01f; @@ -73,9 +82,9 @@ public class AutomaticActionState extends BaseState{ // Game related fields. private World gameWorld; private MarkerRenderingSystem markerRenderingSystem; - private ObjectRenderingSystem objectRenderingSystem; - private RobotArmPositioningSystem robotArmPositioningSystem; - private FadeEffectRenderingSystem fadeEffectRenderingSystem; + private boolean ignoreBackKey; + private boolean automaticActionEnabled; + private AutomaticActionPerformerBase automaticActionPerformer; // Cameras. private OrthographicCamera unitaryOrthographicCamera; @@ -87,6 +96,22 @@ public class AutomaticActionState extends BaseState{ private Sprite renderableVideoFrame; private Pixmap videoFrame; + // Gui elements. + private Texture startButtonEnabledTexture; + private Texture startButtonDisabledTexture; + private Texture startButtonPressedTexture; + private NinePatch startButtonEnabled9p; + private NinePatch startButtonDisabled9p; + private NinePatch startButtonPressed9p; + private BitmapFont font; + private TextButton startButton; + private Rectangle startButtonBBox; + private boolean startButtonPressed; + private Texture ouyaOButtonTexture; + private Sprite ouyaOButton; + private boolean oButtonPressed; + private boolean aButtonPressed; + // Button touch helper fields. private boolean[] buttonsTouched; private int[] buttonPointers; @@ -94,17 +119,23 @@ public class AutomaticActionState extends BaseState{ // Monitors. private VideoFrameMonitor frameMonitor; - // private MotorEventQueue queue; - // private SensorReportThread sensorThread; + private MotorEventQueue queue; + private SensorReportThread sensorThread; - public AutomaticActionState(final NxtARCore core){ - this.core = core; - frameMonitor = VideoFrameMonitor.getInstance(); - // queue = MotorEventQueue.getInstance(); - // sensorThread = SensorReportThread.getInstance(); + public AutomaticActionState(final NxtARCore core) throws IllegalStateException, IllegalArgumentException{ + if(core == null) + throw new IllegalArgumentException(CLASS_NAME + ": Core is null."); - // Set up rendering fields; - videoFrame = null; + this.core = core; + frameMonitor = VideoFrameMonitor.getInstance(); + queue = MotorEventQueue.getInstance(); + sensorThread = SensorReportThread.getInstance(); + ignoreBackKey = false; + videoFrame = null; + aButtonPressed = false; + automaticActionEnabled = false; + startButtonPressed = false; + automaticActionPerformer = GameGlobals.getAutomaticActionPerformer(); // Set up the cameras. pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); @@ -149,25 +180,15 @@ public class AutomaticActionState extends BaseState{ perspectiveCamera = null; frameBufferSprite = null; + // Create the gui. + setUpButton(); + // Set up the game world. - gameWorld = GameSettings.getGameWorld(); + gameWorld = GameGlobals.getGameWorld(); + markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class); - robotArmPositioningSystem = new RobotArmPositioningSystem(); - markerRenderingSystem = new MarkerRenderingSystem(modelBatch); - objectRenderingSystem = new ObjectRenderingSystem(modelBatch); - fadeEffectRenderingSystem = new FadeEffectRenderingSystem(); - - gameWorld.setSystem(new MarkerPositioningSystem()); - gameWorld.setSystem(robotArmPositioningSystem, Ouya.runningOnOuya); - gameWorld.setSystem(new GeometrySystem()); - gameWorld.setSystem(new AnimationSystem()); - gameWorld.setSystem(new CollisionDetectionSystem()); - gameWorld.setSystem(GameSettings.getGameLogicSystem()); - gameWorld.setSystem(markerRenderingSystem, true); - gameWorld.setSystem(objectRenderingSystem, true); - gameWorld.setSystem(fadeEffectRenderingSystem, true); - - gameWorld.initialize(); + if(markerRenderingSystem == null) + throw new IllegalStateException(CLASS_NAME + ": Essential marker rendering system is null."); } /*;;;;;;;;;;;;;;;;;;;;;; @@ -220,6 +241,9 @@ public class AutomaticActionState extends BaseState{ // If a valid frame was fetched. if(data != null && data.outFrame != null){ + if(automaticActionEnabled) + performAutomaticAction(data); + // Set the camera to the correct projection. focalPointX = core.cvProc.getFocalPointX(); focalPointY = core.cvProc.getFocalPointY(); @@ -308,11 +332,35 @@ public class AutomaticActionState extends BaseState{ videoFrameTexture.dispose(); } + core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined); + core.batch.begin();{ + startButton.draw(core.batch, 1.0f); + if(Ouya.runningOnOuya) + ouyaOButton.draw(core.batch); + }core.batch.end(); + data = null; } @Override public void dispose(){ + SensorReportThread.freeInstance(); + + if(font != null) + font.dispose(); + + if(ouyaOButtonTexture != null) + ouyaOButtonTexture.dispose(); + + if(startButtonEnabledTexture != null) + startButtonEnabledTexture.dispose(); + + if(startButtonDisabledTexture != null) + startButtonDisabledTexture.dispose(); + + if(startButtonPressedTexture != null) + startButtonPressedTexture.dispose(); + if(modelBatch != null) modelBatch.dispose(); @@ -327,14 +375,8 @@ public class AutomaticActionState extends BaseState{ if(frameBuffer != null) frameBuffer.dispose(); - - fadeEffectRenderingSystem.dispose(); } - /*;;;;;;;;;;;;;;;;;; - ; HELPER METHODS ; - ;;;;;;;;;;;;;;;;;;*/ - @Override public void onStateSet(){ stateActive = true; @@ -351,6 +393,188 @@ public class AutomaticActionState extends BaseState{ Gdx.input.setCatchMenuKey(false); } + /*;;;;;;;;;;;;;;;;;; + ; HELPER METHODS ; + ;;;;;;;;;;;;;;;;;;*/ + + private void setUpButton(){ + TextButtonStyle textButtonStyle; + FreeTypeFontGenerator fontGenerator; + FreeTypeFontParameter fontParameters; + + // Create the start button background. + startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png")); + startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45); + startButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png")); + startButtonDisabled9p = new NinePatch(new TextureRegion(startButtonDisabledTexture, 0, 0, startButtonDisabledTexture.getWidth(), startButtonDisabledTexture.getHeight()), 49, 49, 45, 45); + startButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png")); + startButtonPressed9p = new NinePatch(new TextureRegion(startButtonPressedTexture, 0, 0, startButtonPressedTexture.getWidth(), startButtonPressedTexture.getHeight()), 49, 49, 45, 45); + + // Create the start button font. + fontParameters = new FreeTypeFontParameter(); + fontParameters.characters = ProjectConstants.FONT_CHARS; + fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE; + fontParameters.flip = false; + fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf")); + font = fontGenerator.generateFont(fontParameters); + fontGenerator.dispose(); + + // Create the start button. + textButtonStyle = new TextButtonStyle(); + textButtonStyle.font = font; + textButtonStyle.up = new NinePatchDrawable(startButtonEnabled9p); + textButtonStyle.checked = new NinePatchDrawable(startButtonPressed9p); + textButtonStyle.disabled = new NinePatchDrawable(startButtonDisabled9p); + textButtonStyle.fontColor = new Color(Color.BLACK); + textButtonStyle.downFontColor = new Color(Color.WHITE); + textButtonStyle.disabledFontColor = new Color(Color.BLACK); + + startButton = new TextButton("Start automatic action", textButtonStyle); + startButton.setText("Start automatic action"); + startButton.setDisabled(false); + startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight()); + startButton.setPosition(-(startButton.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10); + startButtonBBox.setPosition(startButton.getX(), startButton.getY()); + + // Set OUYA's O button. + if(Ouya.runningOnOuya){ + ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png"); + ouyaOButton = new Sprite(ouyaOButtonTexture); + ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f); + oButtonPressed = false; + ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2)); + }else{ + ouyaOButtonTexture = null; + } + } + + private void performAutomaticAction(MarkerData data){ + MotorEvent event1 = null; + MotorEvent event2 = null; + automatic_action_t nextAction; + + try{ + if(!automaticActionPerformer.performAutomaticAction(sensorThread.getLightSensorReading(), data)){ + nextAction = automaticActionPerformer.getNextAction(); + + switch(nextAction){ + case GO_BACKWARDS: + event1 = new MotorEvent(); + event2 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_A); + event1.setPower((byte)-100); + event2.setMotor(motor_t.MOTOR_C); + event2.setPower((byte)-100); + break; + + case GO_FORWARD: + event1 = new MotorEvent(); + event2 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_A); + event1.setPower((byte)100); + event2.setMotor(motor_t.MOTOR_C); + event2.setPower((byte)100); + break; + + case STOP: + event1 = new MotorEvent(); + event2 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_A); + event1.setPower((byte)0); + event2.setMotor(motor_t.MOTOR_C); + event2.setPower((byte)0); + break; + + case ROTATE_90: + event1 = new MotorEvent(); + event1.setMotor(motor_t.ROTATE_90); + event1.setPower((byte)100); + break; + + case RECENTER: + event1 = new MotorEvent(); + event1.setMotor(motor_t.RECENTER); + event1.setPower((byte)100); + break; + + case TURN_LEFT: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_A); + event1.setPower((byte)100); + break; + + case TURN_RIGHT: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_C); + event1.setPower((byte)100); + break; + + case BACKWARDS_LEFT: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_C); + event1.setPower((byte)-100); + break; + + case BACKWARDS_RIGHT: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_A); + event1.setPower((byte)-100); + break; + + case LOOK_RIGHT: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_B); + event1.setPower((byte)25); + break; + + case LOOK_LEFT: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_B); + event1.setPower((byte)-25); + break; + + case STOP_LOOKING: + event1 = new MotorEvent(); + event1.setMotor(motor_t.MOTOR_B); + event1.setPower((byte)0); + break; + + case NO_ACTION: + default: + break; + } + + if(event1 != null) + queue.addEvent(event1); + if(event2 != null) + queue.addEvent(event2); + + }else{ + // TODO: Go to summary screen. + startButton.setDisabled(false); + ignoreBackKey = false; + automaticActionEnabled = false; + core.nextState = game_states_t.MAIN_MENU; + } + + }catch(IllegalArgumentException e){ + Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Received IllegalArgumentException: ", e); + + startButton.setDisabled(false); + ignoreBackKey = false; + automaticActionEnabled = false; + core.nextState = game_states_t.MAIN_MENU; + + }catch(IllegalStateException e){ + Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Received IllegalStateException: ", e); + + startButton.setDisabled(false); + ignoreBackKey = false; + automaticActionEnabled = false; + core.nextState = game_states_t.MAIN_MENU; + } + } + /*;;;;;;;;;;;;;;;;;;;;;;;;;;; ; INPUT PROCESSOR METHODS ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ @@ -361,6 +585,11 @@ public class AutomaticActionState extends BaseState{ win2world.set(screenX, screenY, 0.0f); unitaryOrthographicCamera.unproject(win2world); touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight()); + + if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){ + startButtonPressed = true; + } + } return false; @@ -372,6 +601,13 @@ public class AutomaticActionState extends BaseState{ win2world.set(screenX, screenY, 0.0f); unitaryOrthographicCamera.unproject(win2world); touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight()); + + if(!startButton.isDisabled() && startButtonPressed && startButtonBBox.contains(touchPointWorldCoords)){ + startButton.setDisabled(true); + ignoreBackKey = true; + automaticActionEnabled = true; + } + } return false; @@ -383,6 +619,11 @@ public class AutomaticActionState extends BaseState{ win2world.set(screenX, screenY, 0.0f); unitaryOrthographicCamera.unproject(win2world); touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight()); + + if(!startButton.isDisabled() && startButtonPressed && !startButtonBBox.contains(touchPointWorldCoords)){ + startButtonPressed = false; + } + } return false; @@ -390,7 +631,7 @@ public class AutomaticActionState extends BaseState{ @Override public boolean keyDown(int keycode){ - if(keycode == Input.Keys.BACK){ + if(keycode == Input.Keys.BACK && !ignoreBackKey){ core.nextState = game_states_t.MAIN_MENU; return true; } @@ -405,10 +646,11 @@ public class AutomaticActionState extends BaseState{ @Override public boolean buttonDown(Controller controller, int buttonCode){ if(stateActive){ - Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); - - if(buttonCode == Ouya.BUTTON_O){ - + if(buttonCode == Ouya.BUTTON_O && !startButton.isDisabled()){ + oButtonPressed = true; + startButton.setChecked(true); + }else if(buttonCode == Ouya.BUTTON_A && !ignoreBackKey){ + aButtonPressed = true; } return true; @@ -420,9 +662,17 @@ public class AutomaticActionState extends BaseState{ @Override public boolean buttonUp(Controller controller, int buttonCode){ if(stateActive){ - Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); - - if(buttonCode == Ouya.BUTTON_O){ } + if(buttonCode == Ouya.BUTTON_O && oButtonPressed){ + if(oButtonPressed){ + oButtonPressed = false; + startButton.setChecked(false); + startButton.setDisabled(true); + ignoreBackKey = true; + automaticActionEnabled = true; + } + }else if(buttonCode == Ouya.BUTTON_A && aButtonPressed){ + core.nextState = game_states_t.MAIN_MENU; + } return true; }else{ diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java index 157028f..e02542e 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java @@ -19,6 +19,7 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent; import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t; import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t; +import ve.ucv.ciens.ccg.nxtar.game.GameGlobals; import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera; import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput; import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput; @@ -32,7 +33,6 @@ import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem; -import ve.ucv.ciens.ccg.nxtar.utils.GameSettings; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import ve.ucv.ciens.ccg.nxtar.utils.Utils; @@ -149,7 +149,10 @@ public class InGameState extends BaseState{ private VideoFrameMonitor frameMonitor; private MotorEventQueue queue; - public InGameState(final NxtARCore core) throws IllegalStateException{ + public InGameState(final NxtARCore core) throws IllegalStateException, IllegalArgumentException{ + if(core == null) + throw new IllegalArgumentException(CLASS_NAME + ": Core is null."); + this.core = core; frameMonitor = VideoFrameMonitor.getInstance(); queue = MotorEventQueue.getInstance(); @@ -226,7 +229,7 @@ public class InGameState extends BaseState{ setUpButtons(); // Set up the game world. - gameWorld = GameSettings.getGameWorld(); + gameWorld = GameGlobals.getGameWorld(); robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class); markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class); @@ -1162,7 +1165,7 @@ public class InGameState extends BaseState{ if(!gamepadButtonPressed[3]){ event = new MotorEvent(); event.setMotor(motor_t.MOTOR_B); - event.setPower((byte)-40); + event.setPower((byte)-25); queue.addEvent(event); } @@ -1172,7 +1175,7 @@ public class InGameState extends BaseState{ if(!gamepadButtonPressed[2]){ event = new MotorEvent(); event.setMotor(motor_t.MOTOR_B); - event.setPower((byte)40); + event.setPower((byte)25); queue.addEvent(event); } diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java index 60b6b5c..7e65221 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java @@ -45,7 +45,7 @@ public abstract class MainMenuStateBase extends BaseState{ private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName(); private static final String SHADER_PATH = "shaders/movingBckg/movingBckg"; - protected final int NUM_MENU_BUTTONS = 2; + protected final int NUM_MENU_BUTTONS = 3; // Helper fields. protected boolean clientConnected; @@ -59,6 +59,8 @@ public abstract class MainMenuStateBase extends BaseState{ protected Rectangle startButtonBBox; protected TextButton calibrationButton; protected Rectangle calibrationButtonBBox; + protected TextButton autoButton; + protected Rectangle autoButtonBBox; protected Sprite cameraCalibratedLedOn; protected Sprite cameraCalibratedLedOff; protected Sprite assetsLoadedLedOn; @@ -86,6 +88,8 @@ public abstract class MainMenuStateBase extends BaseState{ protected int startButtonTouchPointer; protected boolean calibrationButtonTouched; protected int calibrationButtonTouchPointer; + protected boolean autoButtonTouched; + protected int autoButtonTouchPointer; public MainMenuStateBase(){ TextureRegion region; @@ -120,10 +124,12 @@ public abstract class MainMenuStateBase extends BaseState{ textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p); textButtonStyle.checked = new NinePatchDrawable(menuButtonPressed9p); textButtonStyle.disabled = new NinePatchDrawable(menuButtonDisabled9p); - textButtonStyle.disabledFontColor = new Color(0, 0, 0, 1); + textButtonStyle.fontColor = new Color(Color.BLACK); + textButtonStyle.downFontColor = new Color(Color.WHITE); + textButtonStyle.disabledFontColor = new Color(Color.BLACK); - startButton = new TextButton("Start server", textButtonStyle); - startButton.setText("Start game"); + startButton = new TextButton("Manual control", textButtonStyle); + startButton.setText("Manual control"); startButton.setDisabled(true); startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight()); @@ -133,6 +139,11 @@ public abstract class MainMenuStateBase extends BaseState{ calibrationButton.setDisabled(true); calibrationButtonBBox = new Rectangle(0, 0, calibrationButton.getWidth(), calibrationButton.getHeight()); + autoButton = new TextButton("Automatic action", textButtonStyle); + autoButton.setText("Automatic action"); + autoButton.setDisabled(true); + autoButtonBBox = new Rectangle(0, 0, autoButton.getWidth(), autoButton.getHeight()); + // Create the connection leds. ledOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png"); ledOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png"); @@ -177,6 +188,8 @@ public abstract class MainMenuStateBase extends BaseState{ startButtonTouchPointer = -1; calibrationButtonTouched = false; calibrationButtonTouchPointer = -1; + autoButtonTouched = false; + autoButtonTouchPointer = -1; clientConnected = false; cameraCalibrated = false; @@ -233,16 +246,17 @@ public abstract class MainMenuStateBase extends BaseState{ public void onCameraCalibrated(){ cameraCalibrated = true; - startGame(); + enableGameButtons(); } public void onAssetsLoaded(){ assetsLoaded = true; - startGame(); + enableGameButtons(); } - private void startGame(){ + private void enableGameButtons(){ startButton.setDisabled(!(cameraCalibrated && assetsLoaded)); + autoButton.setDisabled(!(cameraCalibrated && assetsLoaded)); } /*;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -256,16 +270,21 @@ public abstract class MainMenuStateBase extends BaseState{ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button)); Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y)); - if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && !calibrationButtonTouched){ + if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && (!calibrationButtonTouched && !autoButtonTouched)){ startButton.setChecked(true); startButtonTouched = true; startButtonTouchPointer = pointer; Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed."); - }else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && !startButtonTouched){ + }else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && (!startButtonTouched && !autoButtonTouched)){ calibrationButton.setChecked(true); calibrationButtonTouched = true; calibrationButtonTouchPointer = pointer; Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button pressed."); + }else if(!autoButton.isDisabled() && autoButtonBBox.contains(touchPointWorldCoords) && (!startButtonTouched && !calibrationButtonTouched)){ + autoButton.setChecked(true); + autoButtonTouched = true; + autoButtonTouchPointer = pointer; + Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Auto button pressed."); } return true; @@ -290,6 +309,12 @@ public abstract class MainMenuStateBase extends BaseState{ calibrationButtonTouchPointer = -1; core.nextState = game_states_t.CALIBRATION; Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button released."); + }else if(!autoButton.isDisabled() && autoButtonBBox.contains(touchPointWorldCoords) && autoButtonTouched){ + autoButton.setChecked(false); + autoButtonTouched = false; + autoButtonTouchPointer = -1; + core.nextState = game_states_t.AUTOMATIC_ACTION; + Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Auto button released."); } return true; @@ -309,6 +334,11 @@ public abstract class MainMenuStateBase extends BaseState{ calibrationButtonTouched = false; calibrationButton.setChecked(false); Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released."); + }else if(!autoButton.isDisabled() && autoButtonTouched && pointer == autoButtonTouchPointer && !autoButtonBBox.contains(touchPointWorldCoords)){ + autoButtonTouchPointer = -1; + autoButtonTouched = false; + autoButton.setChecked(false); + Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Auto button released."); } return true; diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java index 00e829c..5809214 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java @@ -46,9 +46,11 @@ public class OuyaMainMenuState extends MainMenuStateBase{ startButtonBBox.setPosition(startButton.getX(), startButton.getY()); calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10); calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY()); + autoButton.setPosition(-(autoButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10); + autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY()); //Set leds. - ledYPos = (-(Utils.getScreenHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f); + ledYPos = -(Utils.getScreenHeight() / 2) + 10; cameraCalibratedLedOn.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f); cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos); cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f); @@ -88,12 +90,15 @@ public class OuyaMainMenuState extends MainMenuStateBase{ // Render buttons. startButton.draw(core.batch, 1.0f); calibrationButton.draw(core.batch, 1.0f); + autoButton.draw(core.batch, 1.0f); // Render O button. if(oButtonSelection == 0){ ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2)); }else if(oButtonSelection == 1){ ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2)); + }else if(oButtonSelection == 2){ + ouyaOButton.setPosition(autoButton.getX() - ouyaOButton.getWidth() - 20, autoButton.getY() + (ouyaOButton.getHeight() / 2)); } ouyaOButton.draw(core.batch); @@ -132,6 +137,13 @@ public class OuyaMainMenuState extends MainMenuStateBase{ oButtonPressed = true; calibrationButton.setChecked(true); } + }else if(oButtonSelection == 2){ + if(!clientConnected){ + core.toast("Can't launch automatic action. No client is connected.", true); + }else{ + oButtonPressed = true; + autoButton.setChecked(true); + } } }else if(buttonCode == Ouya.BUTTON_DPAD_UP){ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed."); @@ -162,6 +174,9 @@ public class OuyaMainMenuState extends MainMenuStateBase{ }else if(oButtonSelection == 1){ calibrationButton.setChecked(false); core.nextState = game_states_t.CALIBRATION; + }else if(oButtonSelection == 2){ + autoButton.setChecked(false); + core.nextState = game_states_t.AUTOMATIC_ACTION; } } } diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java index 60e2f46..8fb8331 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java @@ -34,9 +34,11 @@ public class TabletMainMenuState extends MainMenuStateBase{ startButtonBBox.setPosition(startButton.getX(), startButton.getY()); calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10); calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY()); + autoButton.setPosition(-(autoButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10); + autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY()); // Set leds. - ledYPos = (-(Utils.getScreenHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f); + ledYPos = -(Utils.getScreenHeight() / 2) + 10; cameraCalibratedLedOn.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f); cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos); cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f); @@ -69,6 +71,7 @@ public class TabletMainMenuState extends MainMenuStateBase{ // Render buttons. startButton.draw(core.batch, 1.0f); calibrationButton.draw(core.batch, 1.0f); + autoButton.draw(core.batch, 1.0f); }core.batch.end(); } diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java index c273e6a..d1ecf82 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java @@ -17,7 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.systems; import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase; -import ve.ucv.ciens.ccg.nxtar.utils.GameSettings; +import ve.ucv.ciens.ccg.nxtar.game.GameGlobals; import com.artemis.Aspect; import com.artemis.Entity; @@ -42,7 +42,7 @@ public abstract class PlayerSystemBase extends EntityProcessingSystem { protected final void finishGame(boolean victory){ // TODO: Switch to game over state. // TODO: Set game over state parameters. - GameSettings.getEntityCreator().resetAllEntities(); + GameGlobals.getEntityCreator().resetAllEntities(); core.nextState = NxtARCore.game_states_t.MAIN_MENU; }