Fixes for OUYA. Added labels. Started modelling player.
This commit is contained in:
@@ -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.utils.GameSettings;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
|
||||
import aurelienribon.tweenengine.Tween;
|
||||
import aurelienribon.tweenengine.TweenEquations;
|
||||
import aurelienribon.tweenengine.primitives.MutableFloat;
|
||||
@@ -51,7 +52,7 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
/**
|
||||
* <p>Core of the application.</p>
|
||||
*
|
||||
* <p>This class has three basic resposibilities:</p>
|
||||
* <p>This class has three basic responsibilities:</p>
|
||||
* <ul>
|
||||
* <li> Handling the main game loop.</li>
|
||||
* <li> Starting and destroying the networking threads.</li>
|
||||
@@ -255,8 +256,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
ShaderProgram.pedantic = false;
|
||||
|
||||
// Set up the overlay font.
|
||||
overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
||||
overlayY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
||||
overlayX = -(Utils.getScreenWidth() / 2) + 10;
|
||||
overlayY = (Utils.getScreenHeight() / 2) - 10;
|
||||
|
||||
font = new BitmapFont();
|
||||
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("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 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,15 @@
|
||||
*/
|
||||
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.AutomaticMovementComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.BombComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
||||
@@ -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 int DOOR_OPEN_ANIMATION = 1;
|
||||
public static final int DOOR_CLOSE_ANIMATION = 0;
|
||||
public static int NUM_BOMBS = 0;
|
||||
|
||||
private class EntityParameters{
|
||||
public Environment environment;
|
||||
@@ -77,6 +82,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
private Shader shader;
|
||||
private int currentBombId;
|
||||
private GroupManager groupManager;
|
||||
private List<Entity> entities;
|
||||
private Entity player;
|
||||
|
||||
// Render models.
|
||||
private Model robotArmModel = null;
|
||||
@@ -114,6 +121,17 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
public BombGameEntityCreator(){
|
||||
currentBombId = 0;
|
||||
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.
|
||||
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.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)));
|
||||
|
||||
// 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;
|
||||
|
||||
addRobotArm(parameters);
|
||||
@@ -207,6 +216,16 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
monkey.addComponent(new ShaderComponent(shader));
|
||||
monkey.addComponent(new EnvironmentComponent(parameters.environment));
|
||||
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;
|
||||
}
|
||||
@@ -245,6 +264,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
robotArm.addComponent(new CollisionDetectionComponent());
|
||||
robotArm.addComponent(new AutomaticMovementComponent());
|
||||
robotArm.addToWorld();
|
||||
entities.add(robotArm);
|
||||
}
|
||||
|
||||
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.
|
||||
//groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT);
|
||||
bomb.addToWorld();
|
||||
entities.add(bomb);
|
||||
currentBombId++;
|
||||
NUM_BOMBS++;
|
||||
}
|
||||
|
||||
private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){
|
||||
@@ -353,6 +375,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
|
||||
addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
|
||||
|
||||
entities.add(thing);
|
||||
|
||||
return thing;
|
||||
}
|
||||
|
||||
@@ -391,6 +415,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
groupManager.add(door, DOORS_GROUP);
|
||||
door.addToWorld();
|
||||
|
||||
entities.add(frame);
|
||||
entities.add(door);
|
||||
|
||||
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
|
||||
addDebugCollisionModelRenderingEntity(doorFrameCollisionModel, parameters, false);
|
||||
addDebugCollisionModelRenderingEntity(doorCollisionModel, parameters, true);
|
||||
@@ -413,6 +440,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
thing.addComponent(new AnimationComponent(instance, parameters.nextAnimation, parameters.loopAnimation));
|
||||
}
|
||||
thing.addToWorld();
|
||||
entities.add(thing);
|
||||
}
|
||||
|
||||
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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +78,9 @@ public abstract class EntityCreatorBase implements Disposable{
|
||||
* <p>Creates all entities for a game scenario.</p>
|
||||
*/
|
||||
protected abstract void createAllEntities();
|
||||
|
||||
/**
|
||||
* <p>Recreates all entities in the game.</p>
|
||||
*/
|
||||
public abstract void resetAllEntities();
|
||||
}
|
||||
|
||||
@@ -134,4 +134,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetAllEntities() { }
|
||||
}
|
||||
|
||||
@@ -20,11 +20,13 @@ public class GamepadUserInput extends UserInput {
|
||||
public float axisLeftY;
|
||||
public float axisRightX;
|
||||
public float axisRightY;
|
||||
public boolean oButton;
|
||||
|
||||
public GamepadUserInput(){
|
||||
this.axisLeftX = 0.0f;
|
||||
this.axisLeftY = 0.0f;
|
||||
this.axisRightX = 0.0f;
|
||||
this.axisRightY = 0.0f;
|
||||
this.oButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,13 @@ public class KeyboardUserInput extends UserInput {
|
||||
public boolean keyRight;
|
||||
public boolean keyUp;
|
||||
public boolean keyDown;
|
||||
public boolean keyA;
|
||||
public boolean keyZ;
|
||||
|
||||
public boolean keySpace;
|
||||
|
||||
public KeyboardUserInput(){
|
||||
this.keyLeft = false;
|
||||
this.keyRight = false;
|
||||
this.keyUp = false;
|
||||
this.keyDown = false;
|
||||
this.keyA = false;
|
||||
this.keyZ = false;
|
||||
this.keySpace = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package ve.ucv.ciens.ccg.nxtar.input;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
public class TouchUserInput extends UserInput {
|
||||
public Vector3 userTouchEndPoint;
|
||||
public Vector3 userTouchEndPoint;
|
||||
|
||||
public TouchUserInput(){
|
||||
this.userTouchEndPoint = new Vector3();
|
||||
|
||||
@@ -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.UserInput;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
|
||||
@@ -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.utils.GameSettings;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
|
||||
|
||||
import com.artemis.World;
|
||||
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 CLASS_NAME = InGameState.class.getSimpleName();
|
||||
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 FAR = 100.0f;
|
||||
|
||||
@@ -94,9 +94,9 @@ public class InGameState extends BaseState{
|
||||
private ModelBatch modelBatch;
|
||||
private FrameBuffer frameBuffer;
|
||||
private Sprite frameBufferSprite;
|
||||
private FrameBuffer robotArmFrameBuffer;
|
||||
private Sprite robotArmFrameBufferSprite;
|
||||
private ShaderProgram alphaShader;
|
||||
// private FrameBuffer robotArmFrameBuffer;
|
||||
// private Sprite robotArmFrameBufferSprite;
|
||||
// private ShaderProgram alphaShader;
|
||||
|
||||
// Game related fields.
|
||||
private World gameWorld;
|
||||
@@ -116,18 +116,27 @@ public class InGameState extends BaseState{
|
||||
private Sprite renderableVideoFrame;
|
||||
private Pixmap videoFrame;
|
||||
|
||||
// Interface buttons.
|
||||
private Texture mainControlButtonTexture;
|
||||
// Gui textures.
|
||||
private Texture upControlButtonTexture;
|
||||
private Texture downControlButtonTexture;
|
||||
private Texture leftControlButtonTexture;
|
||||
private Texture rightControlButtonTexture;
|
||||
private Texture headControlButtonTexture;
|
||||
private Texture wheelControlButtonTexture;
|
||||
private Texture armControlButtonTexture;
|
||||
private Texture correctAngleLedOnTexture;
|
||||
private Texture correctAngleLedOffTexture;
|
||||
private Texture crossSectionFloorTexture;
|
||||
|
||||
// Gui renderable sprites.
|
||||
private Sprite motorAButton;
|
||||
private Sprite motorBButton;
|
||||
private Sprite motorCButton;
|
||||
private Sprite motorDButton;
|
||||
private Sprite armAButton;
|
||||
private Sprite armBButton;
|
||||
private Sprite armCButton;
|
||||
private Sprite armDButton;
|
||||
private Sprite headAButton;
|
||||
private Sprite headBButton;
|
||||
private Sprite headCButton;
|
||||
@@ -147,14 +156,14 @@ public class InGameState extends BaseState{
|
||||
// Monitors.
|
||||
private VideoFrameMonitor frameMonitor;
|
||||
private MotorEventQueue queue;
|
||||
private SensorReportThread sensorThread;
|
||||
// private SensorReportThread sensorThread;
|
||||
|
||||
public InGameState(final NxtARCore core){
|
||||
this.core = core;
|
||||
frameMonitor = VideoFrameMonitor.getInstance();
|
||||
queue = MotorEventQueue.getInstance();
|
||||
controlMode = robot_control_mode_t.WHEEL_CONTROL;
|
||||
sensorThread = SensorReportThread.getInstance();
|
||||
// sensorThread = SensorReportThread.getInstance();
|
||||
|
||||
// Set up rendering fields;
|
||||
videoFrame = null;
|
||||
@@ -217,20 +226,20 @@ public class InGameState extends BaseState{
|
||||
uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||
|
||||
// Set up the alpha shader.
|
||||
alphaShader = new ShaderProgram(Gdx.files.internal(ALPHA_SHADER_PREFIX + "_vert.glsl"), Gdx.files.internal(ALPHA_SHADER_PREFIX + "_frag.glsl"));
|
||||
if(!alphaShader.isCompiled()){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".InGameState() :: Failed to compile the alpha shader.");
|
||||
Gdx.app.error(TAG, CLASS_NAME + alphaShader.getLog());
|
||||
alphaShader = null;
|
||||
}
|
||||
// alphaShader = new ShaderProgram(Gdx.files.internal(ALPHA_SHADER_PREFIX + "_vert.glsl"), Gdx.files.internal(ALPHA_SHADER_PREFIX + "_frag.glsl"));
|
||||
// if(!alphaShader.isCompiled()){
|
||||
// Gdx.app.error(TAG, CLASS_NAME + ".InGameState() :: Failed to compile the alpha shader.");
|
||||
// Gdx.app.error(TAG, CLASS_NAME + alphaShader.getLog());
|
||||
// alphaShader = null;
|
||||
// }
|
||||
|
||||
// Set up the 3D rendering.
|
||||
modelBatch = new ModelBatch();
|
||||
frameBuffer = null;
|
||||
perspectiveCamera = null;
|
||||
frameBufferSprite = null;
|
||||
robotArmFrameBuffer = null;
|
||||
robotArmFrameBufferSprite = null;
|
||||
// robotArmFrameBuffer = null;
|
||||
// robotArmFrameBufferSprite = null;
|
||||
|
||||
// Set up floor leds and possibly the buttons.
|
||||
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);
|
||||
itemNearbyFloorLed.setSize(itemNearbyFloorLed.getWidth() * 0.25f, itemNearbyFloorLed.getHeight() * 0.25f);
|
||||
|
||||
crossSectionFloorLed.setPosition(-(crossSectionFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - crossSectionFloorLed.getHeight() - 5);
|
||||
normalFloorLed.setPosition(-(normalFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - normalFloorLed.getHeight() - 5);
|
||||
itemNearbyFloorLed.setPosition(-(itemNearbyFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - itemNearbyFloorLed.getHeight() - 5);
|
||||
crossSectionFloorLed.setPosition(-(crossSectionFloorLed.getWidth() / 2), (Utils.getScreenHeight() / 2) - crossSectionFloorLed.getHeight() - 5);
|
||||
normalFloorLed.setPosition(-(normalFloorLed.getWidth() / 2), (Utils.getScreenHeight() / 2) - normalFloorLed.getHeight() - 5);
|
||||
itemNearbyFloorLed.setPosition(-(itemNearbyFloorLed.getWidth() / 2), (Utils.getScreenHeight() / 2) - itemNearbyFloorLed.getHeight() - 5);
|
||||
|
||||
if(!Ouya.runningOnOuya)
|
||||
setUpButtons();
|
||||
@@ -310,8 +319,8 @@ public class InGameState extends BaseState{
|
||||
frameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
|
||||
frameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||
|
||||
robotArmFrameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
|
||||
robotArmFrameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||
// robotArmFrameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
|
||||
// robotArmFrameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||
|
||||
perspectiveCamera = new CustomPerspectiveCamera(67, w, h);
|
||||
perspectiveCamera.translate(0.0f, 0.0f, 0.0f);
|
||||
@@ -365,19 +374,25 @@ public class InGameState extends BaseState{
|
||||
markerRenderingSystem.begin(perspectiveCamera);
|
||||
markerRenderingSystem.process();
|
||||
markerRenderingSystem.end();
|
||||
|
||||
if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
|
||||
objectRenderingSystem.begin(perspectiveCamera);
|
||||
objectRenderingSystem.process();
|
||||
objectRenderingSystem.end();
|
||||
}
|
||||
}frameBuffer.end();
|
||||
|
||||
robotArmFrameBuffer.begin();{
|
||||
// Set OpenGL state.
|
||||
Gdx.gl.glClearColor(0, 0, 0, 0);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
||||
Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
|
||||
|
||||
// Call rendering systems.
|
||||
objectRenderingSystem.begin(perspectiveCamera);
|
||||
objectRenderingSystem.process();
|
||||
objectRenderingSystem.end();
|
||||
}robotArmFrameBuffer.end();
|
||||
// robotArmFrameBuffer.begin();{
|
||||
// // Set OpenGL state.
|
||||
// Gdx.gl.glClearColor(0, 0, 0, 0);
|
||||
// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
||||
// Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
|
||||
//
|
||||
// // Call rendering systems.
|
||||
// objectRenderingSystem.begin(perspectiveCamera);
|
||||
// objectRenderingSystem.process();
|
||||
// objectRenderingSystem.end();
|
||||
// }robotArmFrameBuffer.end();
|
||||
|
||||
// Set the frame buffer object texture to a renderable sprite.
|
||||
region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
|
||||
@@ -390,14 +405,14 @@ public class InGameState extends BaseState{
|
||||
frameBufferSprite.setPosition(0, 0);
|
||||
|
||||
// Set the other frame buffer object texture to a renderable sprite.
|
||||
region = new TextureRegion(robotArmFrameBuffer.getColorBufferTexture(), 0, 0, robotArmFrameBuffer.getWidth(), robotArmFrameBuffer.getHeight());
|
||||
region.flip(false, true);
|
||||
if(robotArmFrameBufferSprite == null)
|
||||
robotArmFrameBufferSprite = new Sprite(region);
|
||||
else
|
||||
robotArmFrameBufferSprite.setRegion(region);
|
||||
robotArmFrameBufferSprite.setOrigin(robotArmFrameBuffer.getWidth() / 2, robotArmFrameBuffer.getHeight() / 2);
|
||||
robotArmFrameBufferSprite.setPosition(0, 0);
|
||||
// region = new TextureRegion(robotArmFrameBuffer.getColorBufferTexture(), 0, 0, robotArmFrameBuffer.getWidth(), robotArmFrameBuffer.getHeight());
|
||||
// region.flip(false, true);
|
||||
// if(robotArmFrameBufferSprite == null)
|
||||
// robotArmFrameBufferSprite = new Sprite(region);
|
||||
// else
|
||||
// robotArmFrameBufferSprite.setRegion(region);
|
||||
// robotArmFrameBufferSprite.setOrigin(robotArmFrameBuffer.getWidth() / 2, robotArmFrameBuffer.getHeight() / 2);
|
||||
// robotArmFrameBufferSprite.setPosition(0, 0);
|
||||
|
||||
// Set the position and orientation of the renderable video frame and the frame buffer.
|
||||
if(!Ouya.runningOnOuya){
|
||||
@@ -409,22 +424,22 @@ public class InGameState extends BaseState{
|
||||
frameBufferSprite.rotate90(true);
|
||||
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
|
||||
|
||||
robotArmFrameBufferSprite.setSize(1.0f, robotArmFrameBufferSprite.getHeight() / robotArmFrameBufferSprite.getWidth() );
|
||||
robotArmFrameBufferSprite.rotate90(true);
|
||||
robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, 0.5f - robotArmFrameBufferSprite.getHeight());
|
||||
// robotArmFrameBufferSprite.setSize(1.0f, robotArmFrameBufferSprite.getHeight() / robotArmFrameBufferSprite.getWidth() );
|
||||
// robotArmFrameBufferSprite.rotate90(true);
|
||||
// robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, 0.5f - robotArmFrameBufferSprite.getHeight());
|
||||
}else{
|
||||
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.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.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
|
||||
|
||||
robotArmFrameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
|
||||
robotArmFrameBufferSprite.rotate90(true);
|
||||
robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, -robotArmFrameBufferSprite.getHeight() / 2);
|
||||
// robotArmFrameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
|
||||
// robotArmFrameBufferSprite.rotate90(true);
|
||||
// robotArmFrameBufferSprite.translate(-robotArmFrameBufferSprite.getWidth() / 2, -robotArmFrameBufferSprite.getHeight() / 2);
|
||||
}
|
||||
|
||||
// Set the correct camera for the device.
|
||||
@@ -439,11 +454,14 @@ public class InGameState extends BaseState{
|
||||
renderableVideoFrame.draw(core.batch);
|
||||
frameBufferSprite.draw(core.batch);
|
||||
|
||||
if(alphaShader != null){
|
||||
core.batch.setShader(alphaShader);
|
||||
}
|
||||
robotArmFrameBufferSprite.draw(core.batch);
|
||||
if(alphaShader != null) core.batch.setShader(null);
|
||||
// Render the robot arm only when in the corresponding control mode. Always render it on the OUYA.
|
||||
// if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
|
||||
// if(alphaShader != null){
|
||||
// core.batch.setShader(alphaShader);
|
||||
// }
|
||||
// robotArmFrameBufferSprite.draw(core.batch);
|
||||
// if(alphaShader != null) core.batch.setShader(null);
|
||||
// }
|
||||
|
||||
}core.batch.end();
|
||||
|
||||
@@ -455,41 +473,40 @@ public class InGameState extends BaseState{
|
||||
if(!Ouya.runningOnOuya){
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
|
||||
core.batch.begin();{
|
||||
motorAButton.draw(core.batch);
|
||||
motorBButton.draw(core.batch);
|
||||
motorCButton.draw(core.batch);
|
||||
motorDButton.draw(core.batch);
|
||||
headAButton.draw(core.batch);
|
||||
headBButton.draw(core.batch);
|
||||
headCButton.draw(core.batch);
|
||||
|
||||
// Draw control mode button.
|
||||
if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
|
||||
armControlButton.draw(core.batch);
|
||||
}else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
|
||||
// Draw motor control buttons.
|
||||
motorAButton.draw(core.batch);
|
||||
motorBButton.draw(core.batch);
|
||||
motorCButton.draw(core.batch);
|
||||
motorDButton.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{
|
||||
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);
|
||||
}else{
|
||||
correctAngleLedOffSprite.draw(core.batch);
|
||||
}
|
||||
|
||||
// TODO: Draw rotation slider.
|
||||
}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();
|
||||
|
||||
data = null;
|
||||
@@ -497,17 +514,23 @@ public class InGameState extends BaseState{
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
SensorReportThread.freeInstance();
|
||||
sensorThread = null;
|
||||
|
||||
if(modelBatch != null)
|
||||
modelBatch.dispose();
|
||||
|
||||
if(videoFrameTexture != null)
|
||||
videoFrameTexture.dispose();
|
||||
|
||||
if(mainControlButtonTexture != null)
|
||||
mainControlButtonTexture.dispose();
|
||||
if(upControlButtonTexture != null)
|
||||
upControlButtonTexture.dispose();
|
||||
|
||||
if(downControlButtonTexture != null)
|
||||
downControlButtonTexture.dispose();
|
||||
|
||||
if(leftControlButtonTexture != null)
|
||||
leftControlButtonTexture.dispose();
|
||||
|
||||
if(rightControlButtonTexture != null)
|
||||
rightControlButtonTexture.dispose();
|
||||
|
||||
if(headControlButtonTexture != null)
|
||||
headControlButtonTexture.dispose();
|
||||
@@ -527,14 +550,11 @@ public class InGameState extends BaseState{
|
||||
if(backgroundShader != null)
|
||||
backgroundShader.dispose();
|
||||
|
||||
if(alphaShader != null)
|
||||
alphaShader.dispose();
|
||||
|
||||
if(frameBuffer != null)
|
||||
frameBuffer.dispose();
|
||||
|
||||
if(robotArmFrameBuffer != null)
|
||||
robotArmFrameBuffer.dispose();
|
||||
// if(robotArmFrameBuffer != null)
|
||||
// robotArmFrameBuffer.dispose();
|
||||
|
||||
if(correctAngleLedOffTexture != null)
|
||||
correctAngleLedOffTexture.dispose();
|
||||
@@ -567,21 +587,22 @@ public class InGameState extends BaseState{
|
||||
|
||||
private void setUpButtons(){
|
||||
// Set the main control buttons.
|
||||
mainControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/PBCrichton_Flat_Button.png"));
|
||||
mainControlButtonTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||
upControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/up_button.png"));
|
||||
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());
|
||||
|
||||
motorAButton = new Sprite(region);
|
||||
// Set the motor control buttons.
|
||||
motorAButton = new Sprite(upControlButtonTexture);
|
||||
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);
|
||||
|
||||
motorCButton = new Sprite(region);
|
||||
motorCButton = new Sprite(downControlButtonTexture);
|
||||
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);
|
||||
|
||||
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);
|
||||
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.
|
||||
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);
|
||||
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);
|
||||
correctAngleLedOffSprite.setPosition(Gdx.graphics.getWidth() / 2 - correctAngleLedOffSprite.getWidth() - 5, Gdx.graphics.getHeight() / 2 - correctAngleLedOffSprite.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);
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@@ -1099,13 +1138,9 @@ public class InGameState extends BaseState{
|
||||
input = new KeyboardUserInput();
|
||||
input.keyDown = true;
|
||||
break;
|
||||
case Input.Keys.A:
|
||||
case Input.Keys.SPACE:
|
||||
input = new KeyboardUserInput();
|
||||
input.keyA = true;
|
||||
break;
|
||||
case Input.Keys.Z:
|
||||
input = new KeyboardUserInput();
|
||||
input.keyZ = true;
|
||||
input.keySpace = true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@@ -1145,13 +1180,9 @@ public class InGameState extends BaseState{
|
||||
input = new KeyboardUserInput();
|
||||
input.keyDown = false;
|
||||
break;
|
||||
case Input.Keys.A:
|
||||
case Input.Keys.SPACE:
|
||||
input = new KeyboardUserInput();
|
||||
input.keyA = false;
|
||||
break;
|
||||
case Input.Keys.Z:
|
||||
input = new KeyboardUserInput();
|
||||
input.keyZ = false;
|
||||
input.keySpace = false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@@ -1171,7 +1202,8 @@ public class InGameState extends BaseState{
|
||||
|
||||
@Override
|
||||
public boolean buttonDown(Controller controller, int buttonCode){
|
||||
MotorEvent event;
|
||||
MotorEvent event;
|
||||
GamepadUserInput userInput;
|
||||
|
||||
if(stateActive){
|
||||
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);
|
||||
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){
|
||||
core.nextState = game_states_t.MAIN_MENU;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
|
||||
public abstract class MainMenuStateBase extends BaseState{
|
||||
protected static final String TAG = "MAIN_MENU";
|
||||
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;
|
||||
|
||||
@@ -52,6 +52,7 @@ public abstract class MainMenuStateBase extends BaseState{
|
||||
protected boolean cameraCalibrated;
|
||||
protected boolean assetsLoaded;
|
||||
private float u_scaling[];
|
||||
private float u_displacement;
|
||||
|
||||
// Buttons and other gui components.
|
||||
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[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||
|
||||
u_displacement = 1.0f;
|
||||
|
||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
touchPointWorldCoords = new Vector2();
|
||||
startButtonTouched = false;
|
||||
@@ -200,9 +203,11 @@ public abstract class MainMenuStateBase extends BaseState{
|
||||
if(backgroundShader != null){
|
||||
batch.setShader(backgroundShader);
|
||||
backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2);
|
||||
backgroundShader.setUniformf("u_displacement", u_displacement);
|
||||
}
|
||||
background.draw(batch);
|
||||
if(backgroundShader != null) batch.setShader(null);
|
||||
u_displacement = u_displacement < 0.0f ? 1.0f : u_displacement - 0.0005f;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.game_states_t;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.controllers.Controller;
|
||||
@@ -47,7 +48,7 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
||||
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
|
||||
|
||||
//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.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
|
||||
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
|
||||
@@ -118,6 +119,8 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
||||
if(oButtonSelection == 0){
|
||||
if(!clientConnected){
|
||||
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{
|
||||
oButtonPressed = true;
|
||||
startButton.setChecked(true);
|
||||
@@ -158,7 +161,7 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
||||
core.nextState = game_states_t.IN_GAME;
|
||||
}else if(oButtonSelection == 1){
|
||||
calibrationButton.setChecked(false);
|
||||
core.nextState = game_states_t.IN_GAME;
|
||||
core.nextState = game_states_t.CALIBRATION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package ve.ucv.ciens.ccg.nxtar.states;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
@@ -35,7 +36,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
||||
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
|
||||
|
||||
// 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.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
|
||||
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
|
||||
|
||||
@@ -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.entities.BombGameEntityCreator;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
|
||||
|
||||
import com.artemis.Aspect;
|
||||
import com.artemis.ComponentMapper;
|
||||
@@ -32,7 +33,6 @@ import com.artemis.annotations.Mapper;
|
||||
import com.artemis.managers.GroupManager;
|
||||
import com.artemis.utils.ImmutableBag;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Peripheral;
|
||||
|
||||
public class BombGameLogicSystem extends GameLogicSystemBase {
|
||||
private static final String TAG = "BOMB_GAME_LOGIC";
|
||||
@@ -208,7 +208,6 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
|
||||
// Get the components of the big button.
|
||||
CollisionDetectionComponent collision = collisionMapper.getSafe(b);
|
||||
MarkerCodeComponent marker = markerMapper.getSafe(b);
|
||||
float angle;
|
||||
|
||||
// If any of the components is missing, skip this entity.
|
||||
if(marker == null || collision == null ){
|
||||
@@ -225,10 +224,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
|
||||
manager.remove(b, Integer.toString(marker.code));
|
||||
b.deleteFromWorld();
|
||||
|
||||
angle = Gdx.input.getRoll();
|
||||
Gdx.app.log("ROTATION", "Roll: " + Float.toString(angle));
|
||||
|
||||
if(Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Math.abs(angle) > ProjectConstants.MAX_ABS_ROLL){
|
||||
if(Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
|
||||
createFadeOutEffect();
|
||||
}
|
||||
|
||||
48
src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
Normal file
48
src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,10 @@ import com.artemis.ComponentMapper;
|
||||
import com.artemis.Entity;
|
||||
import com.artemis.annotations.Mapper;
|
||||
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 {
|
||||
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||
@@ -33,12 +37,18 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
|
||||
@Mapper ComponentMapper<VisibilityComponent> visibilityMapper;
|
||||
|
||||
private MarkerData markers;
|
||||
private Quaternion qAux;
|
||||
private Matrix4 correctedRotation;
|
||||
private Matrix3 mAux;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MarkerPositioningSystem(){
|
||||
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, VisibilityComponent.class));
|
||||
|
||||
markers = null;
|
||||
qAux = new Quaternion();
|
||||
mAux = new Matrix3();
|
||||
correctedRotation = new Matrix4();
|
||||
}
|
||||
|
||||
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++){
|
||||
if(markers.markerCodes[i] != 1){
|
||||
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.rotation.set(markers.rotationMatrices[i]);
|
||||
geometry.rotation.set(mAux);
|
||||
visibility.visible = true;
|
||||
break;
|
||||
}else{
|
||||
|
||||
52
src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
Normal file
52
src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
Normal 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);
|
||||
|
||||
}
|
||||
@@ -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.GeometryComponent;
|
||||
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.KeyboardUserInput;
|
||||
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 STEP_SIZE = 0.05f;
|
||||
private static final float MAX_Z = -4.5f;
|
||||
private static final float MIN_Z = -1.0f;
|
||||
|
||||
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||
@Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;
|
||||
@@ -73,7 +73,7 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
||||
if(input instanceof TouchUserInput){
|
||||
if(!auto.moving){
|
||||
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.endPoint.set(endPoint);
|
||||
auto.moving = true;
|
||||
@@ -85,33 +85,36 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
||||
}else if(input instanceof GamepadUserInput){
|
||||
tempGP = (GamepadUserInput) input;
|
||||
|
||||
if(!collision.colliding){
|
||||
geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
|
||||
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
|
||||
geometry.position.z += tempGP.axisRightY * STEP_SIZE;
|
||||
}else{
|
||||
auto.moving = true;
|
||||
auto.forward = false;
|
||||
auto.startPoint.set(geometry.position);
|
||||
auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
|
||||
}
|
||||
if(!auto.moving){
|
||||
if(!tempGP.oButton){
|
||||
geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
|
||||
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
|
||||
}else{
|
||||
endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
|
||||
auto.startPoint.set(geometry.position);
|
||||
auto.endPoint.set(endPoint);
|
||||
auto.moving = true;
|
||||
auto.forward = true;
|
||||
}
|
||||
}else autoMove(geometry, auto, collision);
|
||||
|
||||
}else if(input instanceof KeyboardUserInput){
|
||||
tempKey = (KeyboardUserInput) input;
|
||||
|
||||
if(!collision.colliding){
|
||||
geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f;
|
||||
geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
|
||||
geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
|
||||
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
|
||||
geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f;
|
||||
geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f;
|
||||
}else{
|
||||
auto.moving = true;
|
||||
auto.forward = false;
|
||||
auto.startPoint.set(geometry.position);
|
||||
auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
|
||||
}
|
||||
if(!auto.moving){
|
||||
if(!tempKey.keySpace){
|
||||
geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f;
|
||||
geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
|
||||
geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
|
||||
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
|
||||
}else{
|
||||
endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
|
||||
auto.startPoint.set(geometry.position);
|
||||
auto.endPoint.set(endPoint);
|
||||
auto.moving = true;
|
||||
auto.forward = true;
|
||||
}
|
||||
}else autoMove(geometry, auto, collision);
|
||||
|
||||
}else
|
||||
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));
|
||||
|
||||
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.moving = false;
|
||||
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
|
||||
|
||||
}else if(auto.distance >= 1.0f || collision.colliding){
|
||||
auto.forward = false;
|
||||
auto.startPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class ProjectConstants{
|
||||
public static final int EXIT_SUCCESS = 0;
|
||||
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 float MAX_ABS_ROLL = 60.0f;
|
||||
|
||||
@@ -15,10 +15,28 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar.utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Peripheral;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
public abstract class Utils{
|
||||
public static String vector2String(Vector3 v){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user