Added automatic actions. Not tested yet.

This commit is contained in:
2014-06-23 16:07:06 -04:30
parent 6e30e6b56b
commit 4d006a3461
19 changed files with 692 additions and 254 deletions

View File

@@ -5,7 +5,7 @@ import java.io.Serializable;
public class MotorEvent implements Serializable{ public class MotorEvent implements Serializable{
private static final long serialVersionUID = 9989L; 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 motor_t motor;
private byte power; private byte power;

View File

@@ -15,6 +15,7 @@
*/ */
package ve.ucv.ciens.ccg.nxtar; 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.ActionResolver;
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener; import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor; 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.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread; import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread; 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.BaseState;
import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState; import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
import ve.ucv.ciens.ccg.nxtar.states.InGameState; import ve.ucv.ciens.ccg.nxtar.states.InGameState;
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase; import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState; import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState; 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.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import aurelienribon.tweenengine.Tween; import aurelienribon.tweenengine.Tween;
@@ -74,7 +75,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Valid game states. * Valid game states.
*/ */
public enum game_states_t { 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; private int value;
@@ -87,7 +88,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
} }
public static int getNumStates(){ public static int getNumStates(){
return 3; return 4;
} }
}; };
@@ -230,7 +231,28 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* sets the application states.</p> * sets the application states.</p>
*/ */
public void create(){ 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. // Create the state objects.
states = new BaseState[game_states_t.getNumStates()]; states = new BaseState[game_states_t.getNumStates()];
@@ -242,27 +264,26 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
try{ try{
states[game_states_t.IN_GAME.getValue()] = new InGameState(this); states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
}catch(IllegalStateException e){ }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(); Gdx.app.exit();
return; return;
} }
states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this); 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. // Register controller listeners.
for(BaseState state : states){ for(BaseState state : states){
Controllers.addListener(state); 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. // Set up the overlay font.
overlayX = -(Utils.getScreenWidth() / 2) + 10; overlayX = -(Utils.getScreenWidth() / 2) + 10;
overlayY = (Utils.getScreenHeight() / 2) - 10; overlayY = (Utils.getScreenHeight() / 2) - 10;
@@ -336,8 +357,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
super.render(); super.render();
// Load the assets. // Load the assets.
if(!GameSettings.getEntityCreator().areEntitiesCreated()) if(!GameGlobals.getEntityCreator().areEntitiesCreated())
GameSettings.getEntityCreator().updateAssetManager(); GameGlobals.getEntityCreator().updateAssetManager();
// If the current state set a value for nextState then switch to that state. // If the current state set a value for nextState then switch to that state.
if(nextState != null){ if(nextState != null){
@@ -452,7 +473,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
batch.dispose(); batch.dispose();
font.dispose(); font.dispose();
GameSettings.clearGameSettings(); GameGlobals.clearGameSettings();
} }
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@@ -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() { }
}

View File

@@ -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();
}

View File

@@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase; import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem; 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.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase; 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.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
public abstract class GameSettings{ public abstract class GameGlobals{
private static EntityCreatorBase entityCreator = null; private static EntityCreatorBase entityCreator = null;
private static GameLogicSystemBase gameLogicSystem = null; private static GameLogicSystemBase gameLogicSystem = null;
private static World gameWorld = null; private static World gameWorld = null;
private static ModelBatch modelBatch = 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) if(core == null)
throw new IllegalArgumentException("Core is null."); throw new IllegalArgumentException("Core is null.");
@@ -56,13 +55,42 @@ public abstract class GameSettings{
} }
if(getEntityCreator() == null){ 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.setWorld(gameWorld);
entityCreator.setCore(core); entityCreator.setCore(core);
} }
if(getGameLogicSystem() == null) if(getGameLogicSystem() == null){
gameLogicSystem = new BombGameLogicSystem(); 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 MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya); gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
@@ -70,6 +98,7 @@ public abstract class GameSettings{
gameWorld.setSystem(new AnimationSystem()); gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem()); gameWorld.setSystem(new CollisionDetectionSystem());
gameWorld.setSystem(gameLogicSystem); gameWorld.setSystem(gameLogicSystem);
// TODO: Add player processing system.
gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true); gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true);
gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true); gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true);
gameWorld.setSystem(new FadeEffectRenderingSystem(), true); gameWorld.setSystem(new FadeEffectRenderingSystem(), true);
@@ -113,4 +142,11 @@ public abstract class GameSettings{
public static World getGameWorld() { public static World getGameWorld() {
return gameWorld; return gameWorld;
} }
/**
* @return the automaticActionPerformer
*/
public static AutomaticActionPerformerBase getAutomaticActionPerformer() {
return automaticActionPerformer;
}
} }

View File

@@ -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(){}
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package ve.ucv.ciens.ccg.nxtar.components; package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import com.artemis.Component; import com.artemis.Component;

View File

@@ -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<Integer> detectedMarkers;
private float then;
public BombGameAutomaticActionPerformer(){
nextAction = automatic_action_t.NO_ACTION;
state = action_state_t.START;
detectedMarkers = new LinkedList<Integer>();
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;
}
}
}

View File

@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.LinkedList;
import java.util.List; import java.util.List;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent; import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent; 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.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent; 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.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent; 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.graphics.shaders.DirectionalLightPerPixelShader;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem; import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;

View File

@@ -13,17 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.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.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent; import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent; import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase; import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent; 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.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package ve.ucv.ciens.ccg.nxtar.components; package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import com.artemis.Component; import com.artemis.Component;

View File

@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 class BombGamePlayerComponent extends PlayerComponentBase {
public static final int MIN_LIVES = 1; public static final int MIN_LIVES = 1;

View File

@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent; import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.artemis.ComponentMapper; import com.artemis.ComponentMapper;

View File

@@ -15,20 +15,20 @@
*/ */
package ve.ucv.ciens.ccg.nxtar.states; 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;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t; 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.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData; 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.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.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem; 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.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; 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.Input;
import com.badlogic.gdx.controllers.Controller; import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.mappings.Ouya; import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap; 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;
import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap; 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.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion; 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.g3d.ModelBatch;
import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3; 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{ 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 CLASS_NAME = AutomaticActionState.class.getSimpleName();
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg"; private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
private static final float NEAR = 0.01f; private static final float NEAR = 0.01f;
@@ -73,9 +82,9 @@ public class AutomaticActionState extends BaseState{
// Game related fields. // Game related fields.
private World gameWorld; private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem; private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem; private boolean ignoreBackKey;
private RobotArmPositioningSystem robotArmPositioningSystem; private boolean automaticActionEnabled;
private FadeEffectRenderingSystem fadeEffectRenderingSystem; private AutomaticActionPerformerBase automaticActionPerformer;
// Cameras. // Cameras.
private OrthographicCamera unitaryOrthographicCamera; private OrthographicCamera unitaryOrthographicCamera;
@@ -87,6 +96,22 @@ public class AutomaticActionState extends BaseState{
private Sprite renderableVideoFrame; private Sprite renderableVideoFrame;
private Pixmap videoFrame; 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. // Button touch helper fields.
private boolean[] buttonsTouched; private boolean[] buttonsTouched;
private int[] buttonPointers; private int[] buttonPointers;
@@ -94,17 +119,23 @@ public class AutomaticActionState extends BaseState{
// Monitors. // Monitors.
private VideoFrameMonitor frameMonitor; private VideoFrameMonitor frameMonitor;
// private MotorEventQueue queue; private MotorEventQueue queue;
// private SensorReportThread sensorThread; private SensorReportThread sensorThread;
public AutomaticActionState(final NxtARCore core){ public AutomaticActionState(final NxtARCore core) throws IllegalStateException, IllegalArgumentException{
this.core = core; if(core == null)
frameMonitor = VideoFrameMonitor.getInstance(); throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
// queue = MotorEventQueue.getInstance();
// sensorThread = SensorReportThread.getInstance();
// Set up rendering fields; this.core = core;
videoFrame = null; 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. // Set up the cameras.
pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
@@ -149,25 +180,15 @@ public class AutomaticActionState extends BaseState{
perspectiveCamera = null; perspectiveCamera = null;
frameBufferSprite = null; frameBufferSprite = null;
// Create the gui.
setUpButton();
// Set up the game world. // Set up the game world.
gameWorld = GameSettings.getGameWorld(); gameWorld = GameGlobals.getGameWorld();
markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
robotArmPositioningSystem = new RobotArmPositioningSystem(); if(markerRenderingSystem == null)
markerRenderingSystem = new MarkerRenderingSystem(modelBatch); throw new IllegalStateException(CLASS_NAME + ": Essential marker rendering system is null.");
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();
} }
/*;;;;;;;;;;;;;;;;;;;;;; /*;;;;;;;;;;;;;;;;;;;;;;
@@ -220,6 +241,9 @@ public class AutomaticActionState extends BaseState{
// If a valid frame was fetched. // If a valid frame was fetched.
if(data != null && data.outFrame != null){ if(data != null && data.outFrame != null){
if(automaticActionEnabled)
performAutomaticAction(data);
// Set the camera to the correct projection. // Set the camera to the correct projection.
focalPointX = core.cvProc.getFocalPointX(); focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY(); focalPointY = core.cvProc.getFocalPointY();
@@ -308,11 +332,35 @@ public class AutomaticActionState extends BaseState{
videoFrameTexture.dispose(); 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; data = null;
} }
@Override @Override
public void dispose(){ 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) if(modelBatch != null)
modelBatch.dispose(); modelBatch.dispose();
@@ -327,14 +375,8 @@ public class AutomaticActionState extends BaseState{
if(frameBuffer != null) if(frameBuffer != null)
frameBuffer.dispose(); frameBuffer.dispose();
fadeEffectRenderingSystem.dispose();
} }
/*;;;;;;;;;;;;;;;;;;
; HELPER METHODS ;
;;;;;;;;;;;;;;;;;;*/
@Override @Override
public void onStateSet(){ public void onStateSet(){
stateActive = true; stateActive = true;
@@ -351,6 +393,188 @@ public class AutomaticActionState extends BaseState{
Gdx.input.setCatchMenuKey(false); 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 ; ; INPUT PROCESSOR METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ ;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@@ -361,6 +585,11 @@ public class AutomaticActionState extends BaseState{
win2world.set(screenX, screenY, 0.0f); win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world); unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight()); touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
startButtonPressed = true;
}
} }
return false; return false;
@@ -372,6 +601,13 @@ public class AutomaticActionState extends BaseState{
win2world.set(screenX, screenY, 0.0f); win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world); unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight()); 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; return false;
@@ -383,6 +619,11 @@ public class AutomaticActionState extends BaseState{
win2world.set(screenX, screenY, 0.0f); win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world); unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight()); touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
if(!startButton.isDisabled() && startButtonPressed && !startButtonBBox.contains(touchPointWorldCoords)){
startButtonPressed = false;
}
} }
return false; return false;
@@ -390,7 +631,7 @@ public class AutomaticActionState extends BaseState{
@Override @Override
public boolean keyDown(int keycode){ public boolean keyDown(int keycode){
if(keycode == Input.Keys.BACK){ if(keycode == Input.Keys.BACK && !ignoreBackKey){
core.nextState = game_states_t.MAIN_MENU; core.nextState = game_states_t.MAIN_MENU;
return true; return true;
} }
@@ -405,10 +646,11 @@ public class AutomaticActionState extends BaseState{
@Override @Override
public boolean buttonDown(Controller controller, int buttonCode){ public boolean buttonDown(Controller controller, int buttonCode){
if(stateActive){ if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); if(buttonCode == Ouya.BUTTON_O && !startButton.isDisabled()){
oButtonPressed = true;
if(buttonCode == Ouya.BUTTON_O){ startButton.setChecked(true);
}else if(buttonCode == Ouya.BUTTON_A && !ignoreBackKey){
aButtonPressed = true;
} }
return true; return true;
@@ -420,9 +662,17 @@ public class AutomaticActionState extends BaseState{
@Override @Override
public boolean buttonUp(Controller controller, int buttonCode){ public boolean buttonUp(Controller controller, int buttonCode){
if(stateActive){ if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); if(buttonCode == Ouya.BUTTON_O && oButtonPressed){
if(oButtonPressed){
if(buttonCode == Ouya.BUTTON_O){ } 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; return true;
}else{ }else{

View File

@@ -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.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t; 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.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput; import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput; 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.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem; 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.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -149,7 +149,10 @@ public class InGameState extends BaseState{
private VideoFrameMonitor frameMonitor; private VideoFrameMonitor frameMonitor;
private MotorEventQueue queue; 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; this.core = core;
frameMonitor = VideoFrameMonitor.getInstance(); frameMonitor = VideoFrameMonitor.getInstance();
queue = MotorEventQueue.getInstance(); queue = MotorEventQueue.getInstance();
@@ -226,7 +229,7 @@ public class InGameState extends BaseState{
setUpButtons(); setUpButtons();
// Set up the game world. // Set up the game world.
gameWorld = GameSettings.getGameWorld(); gameWorld = GameGlobals.getGameWorld();
robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class); robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class);
markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class); markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
@@ -1162,7 +1165,7 @@ public class InGameState extends BaseState{
if(!gamepadButtonPressed[3]){ if(!gamepadButtonPressed[3]){
event = new MotorEvent(); event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B); event.setMotor(motor_t.MOTOR_B);
event.setPower((byte)-40); event.setPower((byte)-25);
queue.addEvent(event); queue.addEvent(event);
} }
@@ -1172,7 +1175,7 @@ public class InGameState extends BaseState{
if(!gamepadButtonPressed[2]){ if(!gamepadButtonPressed[2]){
event = new MotorEvent(); event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B); event.setMotor(motor_t.MOTOR_B);
event.setPower((byte)40); event.setPower((byte)25);
queue.addEvent(event); queue.addEvent(event);
} }

View File

@@ -45,7 +45,7 @@ public abstract class MainMenuStateBase extends BaseState{
private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName(); private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName();
private static final String SHADER_PATH = "shaders/movingBckg/movingBckg"; 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. // Helper fields.
protected boolean clientConnected; protected boolean clientConnected;
@@ -59,6 +59,8 @@ public abstract class MainMenuStateBase extends BaseState{
protected Rectangle startButtonBBox; protected Rectangle startButtonBBox;
protected TextButton calibrationButton; protected TextButton calibrationButton;
protected Rectangle calibrationButtonBBox; protected Rectangle calibrationButtonBBox;
protected TextButton autoButton;
protected Rectangle autoButtonBBox;
protected Sprite cameraCalibratedLedOn; protected Sprite cameraCalibratedLedOn;
protected Sprite cameraCalibratedLedOff; protected Sprite cameraCalibratedLedOff;
protected Sprite assetsLoadedLedOn; protected Sprite assetsLoadedLedOn;
@@ -86,6 +88,8 @@ public abstract class MainMenuStateBase extends BaseState{
protected int startButtonTouchPointer; protected int startButtonTouchPointer;
protected boolean calibrationButtonTouched; protected boolean calibrationButtonTouched;
protected int calibrationButtonTouchPointer; protected int calibrationButtonTouchPointer;
protected boolean autoButtonTouched;
protected int autoButtonTouchPointer;
public MainMenuStateBase(){ public MainMenuStateBase(){
TextureRegion region; TextureRegion region;
@@ -120,10 +124,12 @@ public abstract class MainMenuStateBase extends BaseState{
textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p); textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p);
textButtonStyle.checked = new NinePatchDrawable(menuButtonPressed9p); textButtonStyle.checked = new NinePatchDrawable(menuButtonPressed9p);
textButtonStyle.disabled = new NinePatchDrawable(menuButtonDisabled9p); 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 = new TextButton("Manual control", textButtonStyle);
startButton.setText("Start game"); startButton.setText("Manual control");
startButton.setDisabled(true); startButton.setDisabled(true);
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight()); startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
@@ -133,6 +139,11 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButton.setDisabled(true); calibrationButton.setDisabled(true);
calibrationButtonBBox = new Rectangle(0, 0, calibrationButton.getWidth(), calibrationButton.getHeight()); 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. // Create the connection leds.
ledOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png"); ledOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
ledOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png"); ledOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
@@ -177,6 +188,8 @@ public abstract class MainMenuStateBase extends BaseState{
startButtonTouchPointer = -1; startButtonTouchPointer = -1;
calibrationButtonTouched = false; calibrationButtonTouched = false;
calibrationButtonTouchPointer = -1; calibrationButtonTouchPointer = -1;
autoButtonTouched = false;
autoButtonTouchPointer = -1;
clientConnected = false; clientConnected = false;
cameraCalibrated = false; cameraCalibrated = false;
@@ -233,16 +246,17 @@ public abstract class MainMenuStateBase extends BaseState{
public void onCameraCalibrated(){ public void onCameraCalibrated(){
cameraCalibrated = true; cameraCalibrated = true;
startGame(); enableGameButtons();
} }
public void onAssetsLoaded(){ public void onAssetsLoaded(){
assetsLoaded = true; assetsLoaded = true;
startGame(); enableGameButtons();
} }
private void startGame(){ private void enableGameButtons(){
startButton.setDisabled(!(cameraCalibrated && assetsLoaded)); 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(%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)); 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); startButton.setChecked(true);
startButtonTouched = true; startButtonTouched = true;
startButtonTouchPointer = pointer; startButtonTouchPointer = pointer;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed."); 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); calibrationButton.setChecked(true);
calibrationButtonTouched = true; calibrationButtonTouched = true;
calibrationButtonTouchPointer = pointer; calibrationButtonTouchPointer = pointer;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button pressed."); 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; return true;
@@ -290,6 +309,12 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButtonTouchPointer = -1; calibrationButtonTouchPointer = -1;
core.nextState = game_states_t.CALIBRATION; core.nextState = game_states_t.CALIBRATION;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button released."); 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; return true;
@@ -309,6 +334,11 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButtonTouched = false; calibrationButtonTouched = false;
calibrationButton.setChecked(false); calibrationButton.setChecked(false);
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released."); 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; return true;

View File

@@ -46,9 +46,11 @@ public class OuyaMainMenuState extends MainMenuStateBase{
startButtonBBox.setPosition(startButton.getX(), startButton.getY()); startButtonBBox.setPosition(startButton.getX(), startButton.getY());
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10); calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY()); calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
autoButton.setPosition(-(autoButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10);
autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY());
//Set leds. //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.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f);
cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos); cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f); cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
@@ -88,12 +90,15 @@ public class OuyaMainMenuState extends MainMenuStateBase{
// Render buttons. // Render buttons.
startButton.draw(core.batch, 1.0f); startButton.draw(core.batch, 1.0f);
calibrationButton.draw(core.batch, 1.0f); calibrationButton.draw(core.batch, 1.0f);
autoButton.draw(core.batch, 1.0f);
// Render O button. // Render O button.
if(oButtonSelection == 0){ if(oButtonSelection == 0){
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2)); ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
}else if(oButtonSelection == 1){ }else if(oButtonSelection == 1){
ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2)); 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); ouyaOButton.draw(core.batch);
@@ -132,6 +137,13 @@ public class OuyaMainMenuState extends MainMenuStateBase{
oButtonPressed = true; oButtonPressed = true;
calibrationButton.setChecked(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){ }else if(buttonCode == Ouya.BUTTON_DPAD_UP){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed."); Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
@@ -162,6 +174,9 @@ public class OuyaMainMenuState extends MainMenuStateBase{
}else if(oButtonSelection == 1){ }else if(oButtonSelection == 1){
calibrationButton.setChecked(false); calibrationButton.setChecked(false);
core.nextState = game_states_t.CALIBRATION; core.nextState = game_states_t.CALIBRATION;
}else if(oButtonSelection == 2){
autoButton.setChecked(false);
core.nextState = game_states_t.AUTOMATIC_ACTION;
} }
} }
} }

View File

@@ -34,9 +34,11 @@ public class TabletMainMenuState extends MainMenuStateBase{
startButtonBBox.setPosition(startButton.getX(), startButton.getY()); startButtonBBox.setPosition(startButton.getX(), startButton.getY());
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10); calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY()); calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
autoButton.setPosition(-(autoButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10);
autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY());
// Set leds. // 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.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f);
cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos); cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f); cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
@@ -69,6 +71,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
// Render buttons. // Render buttons.
startButton.draw(core.batch, 1.0f); startButton.draw(core.batch, 1.0f);
calibrationButton.draw(core.batch, 1.0f); calibrationButton.draw(core.batch, 1.0f);
autoButton.draw(core.batch, 1.0f);
}core.batch.end(); }core.batch.end();
} }

View File

@@ -17,7 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase; 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.Aspect;
import com.artemis.Entity; import com.artemis.Entity;
@@ -42,7 +42,7 @@ public abstract class PlayerSystemBase extends EntityProcessingSystem {
protected final void finishGame(boolean victory){ protected final void finishGame(boolean victory){
// TODO: Switch to game over state. // TODO: Switch to game over state.
// TODO: Set game over state parameters. // TODO: Set game over state parameters.
GameSettings.getEntityCreator().resetAllEntities(); GameGlobals.getEntityCreator().resetAllEntities();
core.nextState = NxtARCore.game_states_t.MAIN_MENU; core.nextState = NxtARCore.game_states_t.MAIN_MENU;
} }