Fixes for OUYA. Added labels. Started modelling player.

This commit is contained in:
2014-06-19 18:29:06 -04:30
parent 83199df36d
commit 6a392856ee
20 changed files with 501 additions and 166 deletions

View File

@@ -30,6 +30,7 @@ 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.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 aurelienribon.tweenengine.Tween; import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenEquations; import aurelienribon.tweenengine.TweenEquations;
import aurelienribon.tweenengine.primitives.MutableFloat; import aurelienribon.tweenengine.primitives.MutableFloat;
@@ -51,7 +52,7 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram;
/** /**
* <p>Core of the application.</p> * <p>Core of the application.</p>
* *
* <p>This class has three basic resposibilities:</p> * <p>This class has three basic responsibilities:</p>
* <ul> * <ul>
* <li> Handling the main game loop.</li> * <li> Handling the main game loop.</li>
* <li> Starting and destroying the networking threads.</li> * <li> Starting and destroying the networking threads.</li>
@@ -255,8 +256,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
ShaderProgram.pedantic = false; ShaderProgram.pedantic = false;
// Set up the overlay font. // Set up the overlay font.
overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10; overlayX = -(Utils.getScreenWidth() / 2) + 10;
overlayY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10; overlayY = (Utils.getScreenHeight() / 2) - 10;
font = new BitmapFont(); font = new BitmapFont();
font.setColor(1.0f, 1.0f, 0.0f, 1.0f); font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
@@ -392,6 +393,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), overlayX, overlayY - (2 * font.getCapHeight()) - 10); font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), overlayX, overlayY - (2 * font.getCapHeight()) - 10);
font.draw(batch, String.format("Light sensor data: %d", sensorThread.getLightSensorReading()), overlayX, overlayY - (3 * font.getCapHeight()) - 15); font.draw(batch, String.format("Light sensor data: %d", sensorThread.getLightSensorReading()), overlayX, overlayY - (3 * font.getCapHeight()) - 15);
font.draw(batch, String.format("Device roll: %f", Gdx.input.getRoll()), overlayX, overlayY - (4 * font.getCapHeight()) - 20); font.draw(batch, String.format("Device roll: %f", Gdx.input.getRoll()), overlayX, overlayY - (4 * font.getCapHeight()) - 20);
font.draw(batch, String.format("Device pitch: %f", Gdx.input.getPitch()), overlayX, overlayY - (5 * font.getCapHeight()) - 25);
font.draw(batch, String.format("Device azimuth: %f", Gdx.input.getAzimuth()), overlayX, overlayY - (6 * font.getCapHeight()) - 30);
}batch.end(); }batch.end();
} }

View File

@@ -0,0 +1,47 @@
/*
* 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.components;
public class BombGamePlayerComponent extends PlayerComponentBase {
public static final int MIN_LIVES = 1;
public static final int MAX_LIVES = 5;
private int startingLives;
public int lives;
public int disabledBombs;
public BombGamePlayerComponent(int lives) throws IllegalArgumentException{
super();
if(lives < MIN_LIVES || lives > MAX_LIVES)
throw new IllegalArgumentException("Lives number out of range: " + Integer.toString(lives));
startingLives = lives;
reset();
}
public BombGamePlayerComponent(){
this(3);
}
@Override
public void reset(){
super.reset();
this.lives = startingLives;
this.disabledBombs = 0;
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.components;
import com.artemis.Component;
/**
* Tag class.
*/
public abstract class PlayerComponentBase extends Component {
public static final String PLAYER_GROUP = "PLAYER";
public boolean gameFinished;
public boolean victory;
public PlayerComponentBase(){
this.gameFinished = false;
this.victory = false;
}
public void reset(){
this.gameFinished = false;
this.victory = false;
}
}

View File

@@ -15,11 +15,15 @@
*/ */
package ve.ucv.ciens.ccg.nxtar.entities; package ve.ucv.ciens.ccg.nxtar.entities;
import java.util.LinkedList;
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;
import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t; 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.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;
@@ -57,6 +61,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
public static final Vector3 ROBOT_ARM_START_POINT = new Vector3(0.0f, 0.0f, -1.0f); public static final Vector3 ROBOT_ARM_START_POINT = new Vector3(0.0f, 0.0f, -1.0f);
public static final int DOOR_OPEN_ANIMATION = 1; public static final int DOOR_OPEN_ANIMATION = 1;
public static final int DOOR_CLOSE_ANIMATION = 0; public static final int DOOR_CLOSE_ANIMATION = 0;
public static int NUM_BOMBS = 0;
private class EntityParameters{ private class EntityParameters{
public Environment environment; public Environment environment;
@@ -77,6 +82,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Shader shader; private Shader shader;
private int currentBombId; private int currentBombId;
private GroupManager groupManager; private GroupManager groupManager;
private List<Entity> entities;
private Entity player;
// Render models. // Render models.
private Model robotArmModel = null; private Model robotArmModel = null;
@@ -114,6 +121,17 @@ public class BombGameEntityCreator extends EntityCreatorBase{
public BombGameEntityCreator(){ public BombGameEntityCreator(){
currentBombId = 0; currentBombId = 0;
manager = new AssetManager(); manager = new AssetManager();
entities = new LinkedList<Entity>();
player = null;
// Load the shader.
shader = new DirectionalLightPerPixelShader();
try{
shader.init();
}catch(GdxRuntimeException gdx){
Gdx.app.error(TAG, CLASS_NAME + ".BombGameEntityCreator(): Shader failed to load: " + gdx.getMessage());
shader = null;
}
// Load the render models. // Load the render models.
manager.load("models/render_models/bomb_game/robot_arm.g3db", Model.class); manager.load("models/render_models/bomb_game/robot_arm.g3db", Model.class);
@@ -166,15 +184,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters = new EntityParameters(); parameters = new EntityParameters();
parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f)); parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(0, 0, -1))); parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(0, 0, -1)));
// Load the shader.
shader = new DirectionalLightPerPixelShader();
try{
shader.init();
}catch(GdxRuntimeException gdx){
Gdx.app.error(TAG, CLASS_NAME + ".BombGameEntityCreator(): Shader failed to load: " + gdx.getMessage());
shader = null;
}
parameters.shader = shader; parameters.shader = shader;
addRobotArm(parameters); addRobotArm(parameters);
@@ -207,6 +216,16 @@ public class BombGameEntityCreator extends EntityCreatorBase{
monkey.addComponent(new ShaderComponent(shader)); monkey.addComponent(new ShaderComponent(shader));
monkey.addComponent(new EnvironmentComponent(parameters.environment)); monkey.addComponent(new EnvironmentComponent(parameters.environment));
monkey.addToWorld(); monkey.addToWorld();
entities.add(monkey);
// Create the player.
if(player == null){
player = world.createEntity();
player.addComponent(new BombGamePlayerComponent(3));
player.addToWorld();
}else{
player.getComponent(BombGamePlayerComponent.class).reset();
}
entitiesCreated = true; entitiesCreated = true;
} }
@@ -245,6 +264,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
robotArm.addComponent(new CollisionDetectionComponent()); robotArm.addComponent(new CollisionDetectionComponent());
robotArm.addComponent(new AutomaticMovementComponent()); robotArm.addComponent(new AutomaticMovementComponent());
robotArm.addToWorld(); robotArm.addToWorld();
entities.add(robotArm);
} }
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{ private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
@@ -288,7 +308,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Add the bomb and increase the id for the next one. // Add the bomb and increase the id for the next one.
//groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT); //groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT);
bomb.addToWorld(); bomb.addToWorld();
entities.add(bomb);
currentBombId++; currentBombId++;
NUM_BOMBS++;
} }
private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){ private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){
@@ -353,6 +375,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS) if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(collisionModel, parameters, false); addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
entities.add(thing);
return thing; return thing;
} }
@@ -391,6 +415,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
groupManager.add(door, DOORS_GROUP); groupManager.add(door, DOORS_GROUP);
door.addToWorld(); door.addToWorld();
entities.add(frame);
entities.add(door);
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){ if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
addDebugCollisionModelRenderingEntity(doorFrameCollisionModel, parameters, false); addDebugCollisionModelRenderingEntity(doorFrameCollisionModel, parameters, false);
addDebugCollisionModelRenderingEntity(doorCollisionModel, parameters, true); addDebugCollisionModelRenderingEntity(doorCollisionModel, parameters, true);
@@ -413,6 +440,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new AnimationComponent(instance, parameters.nextAnimation, parameters.loopAnimation)); thing.addComponent(new AnimationComponent(instance, parameters.nextAnimation, parameters.loopAnimation));
} }
thing.addToWorld(); thing.addToWorld();
entities.add(thing);
} }
private void getModels(){ private void getModels(){
@@ -455,4 +483,19 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombCollisionModelWire2 = manager.get("models/collision_models/bomb_game/cable_2_col.g3db", Model.class); wiresBombCollisionModelWire2 = manager.get("models/collision_models/bomb_game/cable_2_col.g3db", Model.class);
wiresBombCollisionModelWire3 = manager.get("models/collision_models/bomb_game/cable_3_col.g3db", Model.class); wiresBombCollisionModelWire3 = manager.get("models/collision_models/bomb_game/cable_3_col.g3db", Model.class);
} }
@Override
public void resetAllEntities() {
for(Entity entity : entities){
try{
if(entity.isActive())
entity.deleteFromWorld();
}catch(NullPointerException n){
Gdx.app.error(TAG, CLASS_NAME + ".resetAllEntities(): Null pointer exception while deleting entity.");
}
}
entities.clear();
NUM_BOMBS = 0;
createAllEntities();
}
} }

View File

@@ -78,4 +78,9 @@ public abstract class EntityCreatorBase implements Disposable{
* <p>Creates all entities for a game scenario.</p> * <p>Creates all entities for a game scenario.</p>
*/ */
protected abstract void createAllEntities(); protected abstract void createAllEntities();
/**
* <p>Recreates all entities in the game.</p>
*/
public abstract void resetAllEntities();
} }

View File

@@ -134,4 +134,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
return true; return true;
} }
@Override
public void resetAllEntities() { }
} }

View File

@@ -20,11 +20,13 @@ public class GamepadUserInput extends UserInput {
public float axisLeftY; public float axisLeftY;
public float axisRightX; public float axisRightX;
public float axisRightY; public float axisRightY;
public boolean oButton;
public GamepadUserInput(){ public GamepadUserInput(){
this.axisLeftX = 0.0f; this.axisLeftX = 0.0f;
this.axisLeftY = 0.0f; this.axisLeftY = 0.0f;
this.axisRightX = 0.0f; this.axisRightX = 0.0f;
this.axisRightY = 0.0f; this.axisRightY = 0.0f;
this.oButton = false;
} }
} }

View File

@@ -20,15 +20,13 @@ public class KeyboardUserInput extends UserInput {
public boolean keyRight; public boolean keyRight;
public boolean keyUp; public boolean keyUp;
public boolean keyDown; public boolean keyDown;
public boolean keyA; public boolean keySpace;
public boolean keyZ;
public KeyboardUserInput(){ public KeyboardUserInput(){
this.keyLeft = false; this.keyLeft = false;
this.keyRight = false; this.keyRight = false;
this.keyUp = false; this.keyUp = false;
this.keyDown = false; this.keyDown = false;
this.keyA = false; this.keySpace = false;
this.keyZ = false;
} }
} }

View File

@@ -18,7 +18,7 @@ package ve.ucv.ciens.ccg.nxtar.input;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
public class TouchUserInput extends UserInput { public class TouchUserInput extends UserInput {
public Vector3 userTouchEndPoint; public Vector3 userTouchEndPoint;
public TouchUserInput(){ public TouchUserInput(){
this.userTouchEndPoint = new Vector3(); this.userTouchEndPoint = new Vector3();

View File

@@ -25,7 +25,6 @@ import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput; import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
import ve.ucv.ciens.ccg.nxtar.input.UserInput; import ve.ucv.ciens.ccg.nxtar.input.UserInput;
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.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.AnimationSystem;
@@ -38,6 +37,7 @@ 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.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 com.artemis.World; import com.artemis.World;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
@@ -63,7 +63,7 @@ public class InGameState extends BaseState{
private static final String TAG = "IN_GAME_STATE"; private static final String TAG = "IN_GAME_STATE";
private static final String CLASS_NAME = InGameState.class.getSimpleName(); private static final String CLASS_NAME = InGameState.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 String ALPHA_SHADER_PREFIX = "shaders/alphaSprite/alpha"; // private static final String ALPHA_SHADER_PREFIX = "shaders/alphaSprite/alpha";
private static final float NEAR = 0.01f; private static final float NEAR = 0.01f;
private static final float FAR = 100.0f; private static final float FAR = 100.0f;
@@ -94,9 +94,9 @@ public class InGameState extends BaseState{
private ModelBatch modelBatch; private ModelBatch modelBatch;
private FrameBuffer frameBuffer; private FrameBuffer frameBuffer;
private Sprite frameBufferSprite; private Sprite frameBufferSprite;
private FrameBuffer robotArmFrameBuffer; // private FrameBuffer robotArmFrameBuffer;
private Sprite robotArmFrameBufferSprite; // private Sprite robotArmFrameBufferSprite;
private ShaderProgram alphaShader; // private ShaderProgram alphaShader;
// Game related fields. // Game related fields.
private World gameWorld; private World gameWorld;
@@ -116,18 +116,27 @@ public class InGameState extends BaseState{
private Sprite renderableVideoFrame; private Sprite renderableVideoFrame;
private Pixmap videoFrame; private Pixmap videoFrame;
// Interface buttons. // Gui textures.
private Texture mainControlButtonTexture; private Texture upControlButtonTexture;
private Texture downControlButtonTexture;
private Texture leftControlButtonTexture;
private Texture rightControlButtonTexture;
private Texture headControlButtonTexture; private Texture headControlButtonTexture;
private Texture wheelControlButtonTexture; private Texture wheelControlButtonTexture;
private Texture armControlButtonTexture; private Texture armControlButtonTexture;
private Texture correctAngleLedOnTexture; private Texture correctAngleLedOnTexture;
private Texture correctAngleLedOffTexture; private Texture correctAngleLedOffTexture;
private Texture crossSectionFloorTexture; private Texture crossSectionFloorTexture;
// Gui renderable sprites.
private Sprite motorAButton; private Sprite motorAButton;
private Sprite motorBButton; private Sprite motorBButton;
private Sprite motorCButton; private Sprite motorCButton;
private Sprite motorDButton; private Sprite motorDButton;
private Sprite armAButton;
private Sprite armBButton;
private Sprite armCButton;
private Sprite armDButton;
private Sprite headAButton; private Sprite headAButton;
private Sprite headBButton; private Sprite headBButton;
private Sprite headCButton; private Sprite headCButton;
@@ -147,14 +156,14 @@ public class InGameState extends BaseState{
// Monitors. // Monitors.
private VideoFrameMonitor frameMonitor; private VideoFrameMonitor frameMonitor;
private MotorEventQueue queue; private MotorEventQueue queue;
private SensorReportThread sensorThread; // private SensorReportThread sensorThread;
public InGameState(final NxtARCore core){ public InGameState(final NxtARCore core){
this.core = core; this.core = core;
frameMonitor = VideoFrameMonitor.getInstance(); frameMonitor = VideoFrameMonitor.getInstance();
queue = MotorEventQueue.getInstance(); queue = MotorEventQueue.getInstance();
controlMode = robot_control_mode_t.WHEEL_CONTROL; controlMode = robot_control_mode_t.WHEEL_CONTROL;
sensorThread = SensorReportThread.getInstance(); // sensorThread = SensorReportThread.getInstance();
// Set up rendering fields; // Set up rendering fields;
videoFrame = null; videoFrame = null;
@@ -217,20 +226,20 @@ public class InGameState extends BaseState{
uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f; uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
// Set up the alpha shader. // Set up the alpha shader.
alphaShader = new ShaderProgram(Gdx.files.internal(ALPHA_SHADER_PREFIX + "_vert.glsl"), Gdx.files.internal(ALPHA_SHADER_PREFIX + "_frag.glsl")); // alphaShader = new ShaderProgram(Gdx.files.internal(ALPHA_SHADER_PREFIX + "_vert.glsl"), Gdx.files.internal(ALPHA_SHADER_PREFIX + "_frag.glsl"));
if(!alphaShader.isCompiled()){ // if(!alphaShader.isCompiled()){
Gdx.app.error(TAG, CLASS_NAME + ".InGameState() :: Failed to compile the alpha shader."); // Gdx.app.error(TAG, CLASS_NAME + ".InGameState() :: Failed to compile the alpha shader.");
Gdx.app.error(TAG, CLASS_NAME + alphaShader.getLog()); // Gdx.app.error(TAG, CLASS_NAME + alphaShader.getLog());
alphaShader = null; // alphaShader = null;
} // }
// Set up the 3D rendering. // Set up the 3D rendering.
modelBatch = new ModelBatch(); modelBatch = new ModelBatch();
frameBuffer = null; frameBuffer = null;
perspectiveCamera = null; perspectiveCamera = null;
frameBufferSprite = null; frameBufferSprite = null;
robotArmFrameBuffer = null; // robotArmFrameBuffer = null;
robotArmFrameBufferSprite = null; // robotArmFrameBufferSprite = null;
// Set up floor leds and possibly the buttons. // Set up floor leds and possibly the buttons.
correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png")); correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png"));
@@ -245,9 +254,9 @@ public class InGameState extends BaseState{
normalFloorLed.setSize(normalFloorLed.getWidth() * 0.25f, normalFloorLed.getHeight() * 0.25f); normalFloorLed.setSize(normalFloorLed.getWidth() * 0.25f, normalFloorLed.getHeight() * 0.25f);
itemNearbyFloorLed.setSize(itemNearbyFloorLed.getWidth() * 0.25f, itemNearbyFloorLed.getHeight() * 0.25f); itemNearbyFloorLed.setSize(itemNearbyFloorLed.getWidth() * 0.25f, itemNearbyFloorLed.getHeight() * 0.25f);
crossSectionFloorLed.setPosition(-(crossSectionFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - crossSectionFloorLed.getHeight() - 5); crossSectionFloorLed.setPosition(-(crossSectionFloorLed.getWidth() / 2), (Utils.getScreenHeight() / 2) - crossSectionFloorLed.getHeight() - 5);
normalFloorLed.setPosition(-(normalFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - normalFloorLed.getHeight() - 5); normalFloorLed.setPosition(-(normalFloorLed.getWidth() / 2), (Utils.getScreenHeight() / 2) - normalFloorLed.getHeight() - 5);
itemNearbyFloorLed.setPosition(-(itemNearbyFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - itemNearbyFloorLed.getHeight() - 5); itemNearbyFloorLed.setPosition(-(itemNearbyFloorLed.getWidth() / 2), (Utils.getScreenHeight() / 2) - itemNearbyFloorLed.getHeight() - 5);
if(!Ouya.runningOnOuya) if(!Ouya.runningOnOuya)
setUpButtons(); setUpButtons();
@@ -310,8 +319,8 @@ public class InGameState extends BaseState{
frameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true); frameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
frameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); frameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
robotArmFrameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true); // robotArmFrameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
robotArmFrameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); // robotArmFrameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
perspectiveCamera = new CustomPerspectiveCamera(67, w, h); perspectiveCamera = new CustomPerspectiveCamera(67, w, h);
perspectiveCamera.translate(0.0f, 0.0f, 0.0f); perspectiveCamera.translate(0.0f, 0.0f, 0.0f);
@@ -365,19 +374,25 @@ public class InGameState extends BaseState{
markerRenderingSystem.begin(perspectiveCamera); markerRenderingSystem.begin(perspectiveCamera);
markerRenderingSystem.process(); markerRenderingSystem.process();
markerRenderingSystem.end(); markerRenderingSystem.end();
if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process();
objectRenderingSystem.end();
}
}frameBuffer.end(); }frameBuffer.end();
robotArmFrameBuffer.begin();{ // robotArmFrameBuffer.begin();{
// Set OpenGL state. // // Set OpenGL state.
Gdx.gl.glClearColor(0, 0, 0, 0); // Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDisable(GL20.GL_TEXTURE_2D); // Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
//
// Call rendering systems. // // Call rendering systems.
objectRenderingSystem.begin(perspectiveCamera); // objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process(); // objectRenderingSystem.process();
objectRenderingSystem.end(); // objectRenderingSystem.end();
}robotArmFrameBuffer.end(); // }robotArmFrameBuffer.end();
// Set the frame buffer object texture to a renderable sprite. // Set the frame buffer object texture to a renderable sprite.
region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight()); region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
@@ -390,14 +405,14 @@ public class InGameState extends BaseState{
frameBufferSprite.setPosition(0, 0); frameBufferSprite.setPosition(0, 0);
// Set the other frame buffer object texture to a renderable sprite. // Set the other frame buffer object texture to a renderable sprite.
region = new TextureRegion(robotArmFrameBuffer.getColorBufferTexture(), 0, 0, robotArmFrameBuffer.getWidth(), robotArmFrameBuffer.getHeight()); // region = new TextureRegion(robotArmFrameBuffer.getColorBufferTexture(), 0, 0, robotArmFrameBuffer.getWidth(), robotArmFrameBuffer.getHeight());
region.flip(false, true); // region.flip(false, true);
if(robotArmFrameBufferSprite == null) // if(robotArmFrameBufferSprite == null)
robotArmFrameBufferSprite = new Sprite(region); // robotArmFrameBufferSprite = new Sprite(region);
else // else
robotArmFrameBufferSprite.setRegion(region); // robotArmFrameBufferSprite.setRegion(region);
robotArmFrameBufferSprite.setOrigin(robotArmFrameBuffer.getWidth() / 2, robotArmFrameBuffer.getHeight() / 2); // robotArmFrameBufferSprite.setOrigin(robotArmFrameBuffer.getWidth() / 2, robotArmFrameBuffer.getHeight() / 2);
robotArmFrameBufferSprite.setPosition(0, 0); // robotArmFrameBufferSprite.setPosition(0, 0);
// Set the position and orientation of the renderable video frame and the frame buffer. // Set the position and orientation of the renderable video frame and the frame buffer.
if(!Ouya.runningOnOuya){ if(!Ouya.runningOnOuya){
@@ -409,22 +424,22 @@ public class InGameState extends BaseState{
frameBufferSprite.rotate90(true); frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight()); frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
robotArmFrameBufferSprite.setSize(1.0f, robotArmFrameBufferSprite.getHeight() / robotArmFrameBufferSprite.getWidth() ); // robotArmFrameBufferSprite.setSize(1.0f, robotArmFrameBufferSprite.getHeight() / robotArmFrameBufferSprite.getWidth() );
robotArmFrameBufferSprite.rotate90(true); // robotArmFrameBufferSprite.rotate90(true);
robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, 0.5f - robotArmFrameBufferSprite.getHeight()); // robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, 0.5f - robotArmFrameBufferSprite.getHeight());
}else{ }else{
float xSize = Gdx.graphics.getHeight() * (w / h); float xSize = Gdx.graphics.getHeight() * (w / h);
renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN); renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
renderableVideoFrame.rotate90(true); renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2); renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN); frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
frameBufferSprite.rotate90(true); frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2); frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
robotArmFrameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN); // robotArmFrameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
robotArmFrameBufferSprite.rotate90(true); // robotArmFrameBufferSprite.rotate90(true);
robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, -robotArmFrameBufferSprite.getHeight() / 2); // robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, -robotArmFrameBufferSprite.getHeight() / 2);
} }
// Set the correct camera for the device. // Set the correct camera for the device.
@@ -439,11 +454,14 @@ public class InGameState extends BaseState{
renderableVideoFrame.draw(core.batch); renderableVideoFrame.draw(core.batch);
frameBufferSprite.draw(core.batch); frameBufferSprite.draw(core.batch);
if(alphaShader != null){ // Render the robot arm only when in the corresponding control mode. Always render it on the OUYA.
core.batch.setShader(alphaShader); // if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
} // if(alphaShader != null){
robotArmFrameBufferSprite.draw(core.batch); // core.batch.setShader(alphaShader);
if(alphaShader != null) core.batch.setShader(null); // }
// robotArmFrameBufferSprite.draw(core.batch);
// if(alphaShader != null) core.batch.setShader(null);
// }
}core.batch.end(); }core.batch.end();
@@ -455,41 +473,40 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya){ if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined); core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{ core.batch.begin();{
motorAButton.draw(core.batch); // Draw control mode button.
motorBButton.draw(core.batch);
motorCButton.draw(core.batch);
motorDButton.draw(core.batch);
headAButton.draw(core.batch);
headBButton.draw(core.batch);
headCButton.draw(core.batch);
if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
armControlButton.draw(core.batch); // Draw motor control buttons.
}else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){ motorAButton.draw(core.batch);
motorBButton.draw(core.batch);
motorCButton.draw(core.batch);
motorDButton.draw(core.batch);
wheelControlButton.draw(core.batch); wheelControlButton.draw(core.batch);
}else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
// Draw arm control buttons.
armAButton.draw(core.batch);
armBButton.draw(core.batch);
armCButton.draw(core.batch);
armDButton.draw(core.batch);
armControlButton.draw(core.batch);
}else{ }else{
throw new IllegalStateException("Unrecognized control mode: " + Integer.toString(controlMode.getValue())); throw new IllegalStateException("Unrecognized control mode: " + Integer.toString(controlMode.getValue()));
} }
if(Math.abs(Gdx.input.getRoll()) < ProjectConstants.MAX_ABS_ROLL){ headAButton.draw(core.batch);
headBButton.draw(core.batch);
headCButton.draw(core.batch);
// Draw device rotation led.
if(Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) < ProjectConstants.MAX_ABS_ROLL){
correctAngleLedOnSprite.draw(core.batch); correctAngleLedOnSprite.draw(core.batch);
}else{ }else{
correctAngleLedOffSprite.draw(core.batch); correctAngleLedOffSprite.draw(core.batch);
} }
// TODO: Draw rotation slider.
}core.batch.end(); }core.batch.end();
} }
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{
if(sensorThread.getLightSensorReading() < 40){
normalFloorLed.draw(core.batch);
}else if(sensorThread.getLightSensorReading() >= 40 && sensorThread.getLightSensorReading() <= 80){
itemNearbyFloorLed.draw(core.batch);
}else{
crossSectionFloorLed.draw(core.batch);
}
}core.batch.end();
fadeEffectRenderingSystem.process(); fadeEffectRenderingSystem.process();
data = null; data = null;
@@ -497,17 +514,23 @@ public class InGameState extends BaseState{
@Override @Override
public void dispose(){ public void dispose(){
SensorReportThread.freeInstance();
sensorThread = null;
if(modelBatch != null) if(modelBatch != null)
modelBatch.dispose(); modelBatch.dispose();
if(videoFrameTexture != null) if(videoFrameTexture != null)
videoFrameTexture.dispose(); videoFrameTexture.dispose();
if(mainControlButtonTexture != null) if(upControlButtonTexture != null)
mainControlButtonTexture.dispose(); upControlButtonTexture.dispose();
if(downControlButtonTexture != null)
downControlButtonTexture.dispose();
if(leftControlButtonTexture != null)
leftControlButtonTexture.dispose();
if(rightControlButtonTexture != null)
rightControlButtonTexture.dispose();
if(headControlButtonTexture != null) if(headControlButtonTexture != null)
headControlButtonTexture.dispose(); headControlButtonTexture.dispose();
@@ -527,14 +550,11 @@ public class InGameState extends BaseState{
if(backgroundShader != null) if(backgroundShader != null)
backgroundShader.dispose(); backgroundShader.dispose();
if(alphaShader != null)
alphaShader.dispose();
if(frameBuffer != null) if(frameBuffer != null)
frameBuffer.dispose(); frameBuffer.dispose();
if(robotArmFrameBuffer != null) // if(robotArmFrameBuffer != null)
robotArmFrameBuffer.dispose(); // robotArmFrameBuffer.dispose();
if(correctAngleLedOffTexture != null) if(correctAngleLedOffTexture != null)
correctAngleLedOffTexture.dispose(); correctAngleLedOffTexture.dispose();
@@ -567,21 +587,22 @@ public class InGameState extends BaseState{
private void setUpButtons(){ private void setUpButtons(){
// Set the main control buttons. // Set the main control buttons.
mainControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/PBCrichton_Flat_Button.png")); upControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/up_button.png"));
mainControlButtonTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); downControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/down_button.png"));
leftControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/left_button.png"));
rightControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/right_button.png"));
TextureRegion region = new TextureRegion(mainControlButtonTexture, 0, 0, mainControlButtonTexture.getWidth(), mainControlButtonTexture.getHeight()); // Set the motor control buttons.
motorAButton = new Sprite(upControlButtonTexture);
motorAButton = new Sprite(region);
motorAButton.setSize(motorAButton.getWidth() * 0.7f, motorAButton.getHeight() * 0.7f); motorAButton.setSize(motorAButton.getWidth() * 0.7f, motorAButton.getHeight() * 0.7f);
motorBButton = new Sprite(region); motorBButton = new Sprite(downControlButtonTexture);
motorBButton.setSize(motorBButton.getWidth() * 0.7f, motorBButton.getHeight() * 0.7f); motorBButton.setSize(motorBButton.getWidth() * 0.7f, motorBButton.getHeight() * 0.7f);
motorCButton = new Sprite(region); motorCButton = new Sprite(downControlButtonTexture);
motorCButton.setSize(motorCButton.getWidth() * 0.7f, motorCButton.getHeight() * 0.7f); motorCButton.setSize(motorCButton.getWidth() * 0.7f, motorCButton.getHeight() * 0.7f);
motorDButton = new Sprite(region); motorDButton = new Sprite(upControlButtonTexture);
motorDButton.setSize(motorDButton.getWidth() * 0.7f, motorDButton.getHeight() * 0.7f); motorDButton.setSize(motorDButton.getWidth() * 0.7f, motorDButton.getHeight() * 0.7f);
motorAButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 10, -(Gdx.graphics.getHeight() / 2) + motorBButton.getHeight() + 20); motorAButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 10, -(Gdx.graphics.getHeight() / 2) + motorBButton.getHeight() + 20);
@@ -589,6 +610,24 @@ public class InGameState extends BaseState{
motorCButton.setPosition((Gdx.graphics.getWidth() / 2) - (1.5f * (motorDButton.getWidth())) - 20, -(Gdx.graphics.getHeight() / 2) + 10); motorCButton.setPosition((Gdx.graphics.getWidth() / 2) - (1.5f * (motorDButton.getWidth())) - 20, -(Gdx.graphics.getHeight() / 2) + 10);
motorDButton.setPosition((Gdx.graphics.getWidth() / 2) - motorDButton.getWidth() - 10, -(Gdx.graphics.getHeight() / 2) + 20 + motorCButton.getHeight()); motorDButton.setPosition((Gdx.graphics.getWidth() / 2) - motorDButton.getWidth() - 10, -(Gdx.graphics.getHeight() / 2) + 20 + motorCButton.getHeight());
// Set up robot arm control buttons.
armAButton = new Sprite(upControlButtonTexture);
armAButton.setSize(armAButton.getWidth() * 0.7f, armAButton.getHeight() * 0.7f);
armBButton = new Sprite(leftControlButtonTexture);
armBButton.setSize(armBButton.getWidth() * 0.7f, armBButton.getHeight() * 0.7f);
armCButton = new Sprite(rightControlButtonTexture);
armCButton.setSize(armCButton.getWidth() * 0.7f, armCButton.getHeight() * 0.7f);
armDButton = new Sprite(downControlButtonTexture);
armDButton.setSize(armDButton.getWidth() * 0.7f, armDButton.getHeight() * 0.7f);
armAButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 10, -(Gdx.graphics.getHeight() / 2) + armBButton.getHeight() + 20);
armBButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 20 + (armAButton.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10);
armCButton.setPosition((Gdx.graphics.getWidth() / 2) - (1.5f * (armDButton.getWidth())) - 20, -(Gdx.graphics.getHeight() / 2) + 10);
armDButton.setPosition((Gdx.graphics.getWidth() / 2) - armDButton.getWidth() - 10, -(Gdx.graphics.getHeight() / 2) + 20 + armCButton.getHeight());
// Set the head control buttons. // Set the head control buttons.
headControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/orange_glowy_button.png")); headControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/orange_glowy_button.png"));
@@ -624,8 +663,8 @@ public class InGameState extends BaseState{
correctAngleLedOnSprite.setSize(correctAngleLedOnSprite.getWidth() * 0.25f, correctAngleLedOnSprite.getHeight() * 0.25f); correctAngleLedOnSprite.setSize(correctAngleLedOnSprite.getWidth() * 0.25f, correctAngleLedOnSprite.getHeight() * 0.25f);
correctAngleLedOffSprite.setSize(correctAngleLedOffSprite.getWidth() * 0.25f, correctAngleLedOffSprite.getHeight() * 0.25f); correctAngleLedOffSprite.setSize(correctAngleLedOffSprite.getWidth() * 0.25f, correctAngleLedOffSprite.getHeight() * 0.25f);
correctAngleLedOnSprite.setPosition(Gdx.graphics.getWidth() / 2 - correctAngleLedOnSprite.getWidth() - 5, Gdx.graphics.getHeight() / 2 - correctAngleLedOnSprite.getHeight() - 5); correctAngleLedOnSprite.setPosition((Gdx.graphics.getWidth() / 2) - correctAngleLedOnSprite.getWidth() - 5, (Gdx.graphics.getHeight() / 2) - correctAngleLedOnSprite.getHeight() - 5);
correctAngleLedOffSprite.setPosition(Gdx.graphics.getWidth() / 2 - correctAngleLedOffSprite.getWidth() - 5, Gdx.graphics.getHeight() / 2 - correctAngleLedOffSprite.getHeight() - 5); correctAngleLedOffSprite.setPosition((Gdx.graphics.getWidth() / 2) - correctAngleLedOffSprite.getWidth() - 5, (Gdx.graphics.getHeight() / 2) - correctAngleLedOffSprite.getHeight() - 5);
} }
/*;;;;;;;;;;;;;;;;;;;;;;;;;;; /*;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1099,13 +1138,9 @@ public class InGameState extends BaseState{
input = new KeyboardUserInput(); input = new KeyboardUserInput();
input.keyDown = true; input.keyDown = true;
break; break;
case Input.Keys.A: case Input.Keys.SPACE:
input = new KeyboardUserInput(); input = new KeyboardUserInput();
input.keyA = true; input.keySpace = true;
break;
case Input.Keys.Z:
input = new KeyboardUserInput();
input.keyZ = true;
break; break;
default: default:
return false; return false;
@@ -1145,13 +1180,9 @@ public class InGameState extends BaseState{
input = new KeyboardUserInput(); input = new KeyboardUserInput();
input.keyDown = false; input.keyDown = false;
break; break;
case Input.Keys.A: case Input.Keys.SPACE:
input = new KeyboardUserInput(); input = new KeyboardUserInput();
input.keyA = false; input.keySpace = false;
break;
case Input.Keys.Z:
input = new KeyboardUserInput();
input.keyZ = false;
break; break;
default: default:
return false; return false;
@@ -1171,7 +1202,8 @@ public class InGameState extends BaseState{
@Override @Override
public boolean buttonDown(Controller controller, int buttonCode){ public boolean buttonDown(Controller controller, int buttonCode){
MotorEvent event; MotorEvent event;
GamepadUserInput userInput;
if(stateActive){ if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
@@ -1244,6 +1276,12 @@ public class InGameState extends BaseState{
event.setPower((byte)0x00); event.setPower((byte)0x00);
queue.addEvent(event); queue.addEvent(event);
}else if(buttonCode == Ouya.BUTTON_O){
userInput = new GamepadUserInput();
userInput.oButton = true;
robotArmPositioningSystem.setUserInput(userInput);
robotArmPositioningSystem.process();
}else if(buttonCode == Ouya.BUTTON_A){ }else if(buttonCode == Ouya.BUTTON_A){
core.nextState = game_states_t.MAIN_MENU; core.nextState = game_states_t.MAIN_MENU;
} }

View File

@@ -43,7 +43,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
public abstract class MainMenuStateBase extends BaseState{ public abstract class MainMenuStateBase extends BaseState{
protected static final String TAG = "MAIN_MENU"; protected static final String TAG = "MAIN_MENU";
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/bckg/bckg"; private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
protected final int NUM_MENU_BUTTONS = 2; protected final int NUM_MENU_BUTTONS = 2;
@@ -52,6 +52,7 @@ public abstract class MainMenuStateBase extends BaseState{
protected boolean cameraCalibrated; protected boolean cameraCalibrated;
protected boolean assetsLoaded; protected boolean assetsLoaded;
private float u_scaling[]; private float u_scaling[];
private float u_displacement;
// Buttons and other gui components. // Buttons and other gui components.
protected TextButton startButton; protected TextButton startButton;
@@ -168,6 +169,8 @@ public abstract class MainMenuStateBase extends BaseState{
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f; u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f; u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
u_displacement = 1.0f;
win2world = new Vector3(0.0f, 0.0f, 0.0f); win2world = new Vector3(0.0f, 0.0f, 0.0f);
touchPointWorldCoords = new Vector2(); touchPointWorldCoords = new Vector2();
startButtonTouched = false; startButtonTouched = false;
@@ -200,9 +203,11 @@ public abstract class MainMenuStateBase extends BaseState{
if(backgroundShader != null){ if(backgroundShader != null){
batch.setShader(backgroundShader); batch.setShader(backgroundShader);
backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2); backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2);
backgroundShader.setUniformf("u_displacement", u_displacement);
} }
background.draw(batch); background.draw(batch);
if(backgroundShader != null) batch.setShader(null); if(backgroundShader != null) batch.setShader(null);
u_displacement = u_displacement < 0.0f ? 1.0f : u_displacement - 0.0005f;
} }
@Override @Override

View File

@@ -17,6 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.states;
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.utils.Utils;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controller; import com.badlogic.gdx.controllers.Controller;
@@ -47,7 +48,7 @@ public class OuyaMainMenuState extends MainMenuStateBase{
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY()); calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
//Set leds. //Set leds.
ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f); ledYPos = (-(Utils.getScreenHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
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);
@@ -118,6 +119,8 @@ public class OuyaMainMenuState extends MainMenuStateBase{
if(oButtonSelection == 0){ if(oButtonSelection == 0){
if(!clientConnected){ if(!clientConnected){
core.toast("Can't start the game. No client is connected.", true); core.toast("Can't start the game. No client is connected.", true);
}else if(!core.cvProc.isCameraCalibrated()){
core.toast("Can't start the game. Camera is not calibrated.", true);
}else{ }else{
oButtonPressed = true; oButtonPressed = true;
startButton.setChecked(true); startButton.setChecked(true);
@@ -158,7 +161,7 @@ public class OuyaMainMenuState extends MainMenuStateBase{
core.nextState = game_states_t.IN_GAME; core.nextState = game_states_t.IN_GAME;
}else if(oButtonSelection == 1){ }else if(oButtonSelection == 1){
calibrationButton.setChecked(false); calibrationButton.setChecked(false);
core.nextState = game_states_t.IN_GAME; core.nextState = game_states_t.CALIBRATION;
} }
} }
} }

View File

@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.states; package ve.ucv.ciens.ccg.nxtar.states;
import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
@@ -35,7 +36,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY()); calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
// Set leds. // Set leds.
ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f); ledYPos = (-(Utils.getScreenHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
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);

View File

@@ -23,6 +23,7 @@ import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
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.entities.BombGameEntityCreator;
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 com.artemis.Aspect; import com.artemis.Aspect;
import com.artemis.ComponentMapper; import com.artemis.ComponentMapper;
@@ -32,7 +33,6 @@ import com.artemis.annotations.Mapper;
import com.artemis.managers.GroupManager; import com.artemis.managers.GroupManager;
import com.artemis.utils.ImmutableBag; import com.artemis.utils.ImmutableBag;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Peripheral;
public class BombGameLogicSystem extends GameLogicSystemBase { public class BombGameLogicSystem extends GameLogicSystemBase {
private static final String TAG = "BOMB_GAME_LOGIC"; private static final String TAG = "BOMB_GAME_LOGIC";
@@ -208,7 +208,6 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
// Get the components of the big button. // Get the components of the big button.
CollisionDetectionComponent collision = collisionMapper.getSafe(b); CollisionDetectionComponent collision = collisionMapper.getSafe(b);
MarkerCodeComponent marker = markerMapper.getSafe(b); MarkerCodeComponent marker = markerMapper.getSafe(b);
float angle;
// If any of the components is missing, skip this entity. // If any of the components is missing, skip this entity.
if(marker == null || collision == null ){ if(marker == null || collision == null ){
@@ -225,10 +224,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
manager.remove(b, Integer.toString(marker.code)); manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld(); b.deleteFromWorld();
angle = Gdx.input.getRoll(); if(Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL){
Gdx.app.log("ROTATION", "Roll: " + Float.toString(angle));
if(Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Math.abs(angle) > ProjectConstants.MAX_ABS_ROLL){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded."); Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
createFadeOutEffect(); createFadeOutEffect();
} }

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2013 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.systems;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
public class BombGamePlayerSystem extends PlayerSystemBase{
@Mapper ComponentMapper<BombGamePlayerComponent> playerMapper;
public BombGamePlayerSystem(NxtARCore core){
super(BombGamePlayerComponent.class, core);
}
@Override
protected void process(Entity e) {
BombGamePlayerComponent player = playerMapper.get(e);
if(player.lives == 0){
player.gameFinished = true;
player.victory = false;
}else if(player.disabledBombs == BombGameEntityCreator.NUM_BOMBS){
player.gameFinished = true;
player.victory = true;
}
if(player.gameFinished)
finishGame(player.victory);
}
}

View File

@@ -26,6 +26,10 @@ import com.artemis.ComponentMapper;
import com.artemis.Entity; import com.artemis.Entity;
import com.artemis.annotations.Mapper; import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem; import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Matrix3;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
public class MarkerPositioningSystem extends EntityProcessingSystem { public class MarkerPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper; @Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
@@ -33,12 +37,18 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper<VisibilityComponent> visibilityMapper; @Mapper ComponentMapper<VisibilityComponent> visibilityMapper;
private MarkerData markers; private MarkerData markers;
private Quaternion qAux;
private Matrix4 correctedRotation;
private Matrix3 mAux;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public MarkerPositioningSystem(){ public MarkerPositioningSystem(){
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, VisibilityComponent.class)); super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, VisibilityComponent.class));
markers = null; markers = null;
qAux = new Quaternion();
mAux = new Matrix3();
correctedRotation = new Matrix4();
} }
public void setMarkerData(MarkerData markers){ public void setMarkerData(MarkerData markers){
@@ -61,8 +71,25 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){ for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
if(markers.markerCodes[i] != 1){ if(markers.markerCodes[i] != 1){
if(markers.markerCodes[i] == marker.code){ if(markers.markerCodes[i] == marker.code){
qAux.setFromMatrix(markers.rotationMatrices[i]).nor();
if(Math.abs(qAux.getRoll()) > 10.0f){
// qAux.setEulerAngles(qAux.getYaw(), qAux.getPitch(), 0.0f);
// qAux.toMatrix(correctedRotation.val);
// mAux.set(correctedRotation);
mAux.set(markers.rotationMatrices[i]);
Gdx.app.log("ROTATION", "YAW : " + Float.toString(qAux.getYaw()));
Gdx.app.log("ROTATION", "PITCH: " + Float.toString(qAux.getPitch()));
Gdx.app.log("ROTATION", "ROLL : " + Float.toString(qAux.getRoll()));
Gdx.app.log("ROTATION", "------------------------------------------");
}else{
mAux.set(markers.rotationMatrices[i]);
}
geometry.position.set(markers.translationVectors[i]); geometry.position.set(markers.translationVectors[i]);
geometry.rotation.set(markers.rotationMatrices[i]); geometry.rotation.set(mAux);
visibility.visible = true; visibility.visible = true;
break; break;
}else{ }else{

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2013 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.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 com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.systems.EntityProcessingSystem;
public abstract class PlayerSystemBase extends EntityProcessingSystem {
protected NxtARCore core;
@SuppressWarnings("unchecked")
public PlayerSystemBase(Class<? extends PlayerComponentBase> component, NxtARCore core){
super(Aspect.getAspectForAll(component));
if(component == null)
throw new IllegalArgumentException("Component is null.");
if(core == null)
throw new IllegalArgumentException("Core is null.");
this.core = core;
}
protected final void finishGame(boolean victory){
// TODO: Switch to game over state.
// TODO: Set game over state parameters.
GameSettings.getEntityCreator().resetAllEntities();
core.nextState = NxtARCore.game_states_t.MAIN_MENU;
}
@Override
protected abstract void process(Entity e);
}

View File

@@ -19,7 +19,6 @@ import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent; import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent; import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
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;
import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput; import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
@@ -40,6 +39,7 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
private static final float INTERPOLATION_STEP = 0.05f; private static final float INTERPOLATION_STEP = 0.05f;
private static final float STEP_SIZE = 0.05f; private static final float STEP_SIZE = 0.05f;
private static final float MAX_Z = -4.5f; private static final float MAX_Z = -4.5f;
private static final float MIN_Z = -1.0f;
@Mapper ComponentMapper<GeometryComponent> geometryMapper; @Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<AutomaticMovementComponent> autoMapper; @Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;
@@ -73,7 +73,7 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
if(input instanceof TouchUserInput){ if(input instanceof TouchUserInput){
if(!auto.moving){ if(!auto.moving){
endPoint = ((TouchUserInput) input).userTouchEndPoint; endPoint = ((TouchUserInput) input).userTouchEndPoint;
endPoint.set(endPoint.x, endPoint.y, MAX_Z); endPoint.set(geometry.position.x, geometry.position.y, MAX_Z);
auto.startPoint.set(geometry.position); auto.startPoint.set(geometry.position);
auto.endPoint.set(endPoint); auto.endPoint.set(endPoint);
auto.moving = true; auto.moving = true;
@@ -85,33 +85,36 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
}else if(input instanceof GamepadUserInput){ }else if(input instanceof GamepadUserInput){
tempGP = (GamepadUserInput) input; tempGP = (GamepadUserInput) input;
if(!collision.colliding){ if(!auto.moving){
geometry.position.x += tempGP.axisLeftY * STEP_SIZE; if(!tempGP.oButton){
geometry.position.y += tempGP.axisLeftX * STEP_SIZE; geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
geometry.position.z += tempGP.axisRightY * STEP_SIZE; geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
}else{ }else{
auto.moving = true; endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
auto.forward = false; auto.startPoint.set(geometry.position);
auto.startPoint.set(geometry.position); auto.endPoint.set(endPoint);
auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT); auto.moving = true;
} auto.forward = true;
}
}else autoMove(geometry, auto, collision);
}else if(input instanceof KeyboardUserInput){ }else if(input instanceof KeyboardUserInput){
tempKey = (KeyboardUserInput) input; tempKey = (KeyboardUserInput) input;
if(!collision.colliding){ if(!auto.moving){
geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f; if(!tempKey.keySpace){
geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f; geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f;
geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f; geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f; geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f; geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f; }else{
}else{ endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
auto.moving = true; auto.startPoint.set(geometry.position);
auto.forward = false; auto.endPoint.set(endPoint);
auto.startPoint.set(geometry.position); auto.moving = true;
auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT); auto.forward = true;
} }
}else autoMove(geometry, auto, collision);
}else }else
throw new ClassCastException("Input is not a valid UserInput instance."); throw new ClassCastException("Input is not a valid UserInput instance.");
@@ -141,13 +144,18 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position)); Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
if(auto.distance <= 0.0f){ if(auto.distance <= 0.0f || geometry.position.z >= MIN_Z){
geometry.position.x = auto.startPoint.x;
geometry.position.y = auto.startPoint.y;
geometry.position.z = MIN_Z;
auto.forward = true; auto.forward = true;
auto.moving = false; auto.moving = false;
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now."); Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
}else if(auto.distance >= 1.0f || collision.colliding){ }else if(auto.distance >= 1.0f || collision.colliding){
auto.forward = false; auto.forward = false;
auto.startPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now."); Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
} }

View File

@@ -28,7 +28,7 @@ public abstract class ProjectConstants{
public static final int EXIT_SUCCESS = 0; public static final int EXIT_SUCCESS = 0;
public static final int EXIT_FAILURE = 1; public static final int EXIT_FAILURE = 1;
public static final boolean DEBUG = false; public static final boolean DEBUG = true;
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048}; public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
public static final float MAX_ABS_ROLL = 60.0f; public static final float MAX_ABS_ROLL = 60.0f;

View File

@@ -15,10 +15,28 @@
*/ */
package ve.ucv.ciens.ccg.nxtar.utils; package ve.ucv.ciens.ccg.nxtar.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Peripheral;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
public abstract class Utils{ public abstract class Utils{
public static String vector2String(Vector3 v){ public static String vector2String(Vector3 v){
return "(" + Float.toString(v.x) + ", " + Float.toString(v.y) + ", " + Float.toString(v.z) + ")"; return "(" + Float.toString(v.x) + ", " + Float.toString(v.y) + ", " + Float.toString(v.z) + ")";
} }
public static int getScreenWidth(){
return (int)(Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN);
}
public static int getScreenHeight(){
return (int)(Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
}
public static boolean isDeviceRollValid(){
boolean rollValid = Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Gdx.input.isPeripheralAvailable(Peripheral.Compass);
// TODO: Check device orientation for limits.
return rollValid;
}
} }