From eb8206668f877bbb5e5e3fcc9b256a081c5c462c Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 28 May 2014 14:22:46 -0430
Subject: [PATCH 01/34] Removed needless source files. Added game settings.
---
.../ccg/nxtar/components/ModelComponent.java | 7 +
.../nxtar/entities/BombGameEntityCreator.java | 183 +++++++++++++++++-
.../ccg/nxtar/entities/EntityCreatorBase.java | 3 +-
.../entities/MarkerTestEntityCreator.java | 8 +-
.../nxtar/entities/TestGameEntityCreator.java | 134 -------------
.../ciens/ccg/nxtar/graphics/LightSource.java | 162 ----------------
.../ccg/nxtar/graphics/RenderParameters.java | 75 -------
...va => DirectionalLightPerPixelShader.java} | 8 +-
.../shaders/SingleLightPhongShader.java | 58 ------
.../ciens/ccg/nxtar/states/InGameState.java | 27 +--
.../BombGameLogicSystem.java} | 20 +-
.../GameLogicSystemBase.java} | 21 +-
.../GameSettings.java} | 23 ++-
13 files changed, 236 insertions(+), 493 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/entities/TestGameEntityCreator.java
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/graphics/RenderParameters.java
rename src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/{SingleLightPerPixelShader.java => DirectionalLightPerPixelShader.java} (96%)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPhongShader.java
rename src/ve/ucv/ciens/ccg/nxtar/{components/MeshComponent.java => systems/BombGameLogicSystem.java} (66%)
rename src/ve/ucv/ciens/ccg/nxtar/{components/CustomShaderComponent.java => systems/GameLogicSystemBase.java} (59%)
rename src/ve/ucv/ciens/ccg/nxtar/{graphics/shaders/CustomShaderBase.java => utils/GameSettings.java} (53%)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
index e630fca..4a8cc6e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
@@ -28,4 +28,11 @@ public class ModelComponent extends Component {
this.instance = new ModelInstance(model);
}
+
+ public ModelComponent(ModelInstance instance) throws IllegalArgumentException{
+ if(instance == null)
+ throw new IllegalArgumentException("Instance is null.");
+
+ this.instance = instance;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index c89f294..99e65c1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -15,18 +15,191 @@
*/
package ve.ucv.ciens.ccg.nxtar.entities;
-public class BombGameEntityCreator extends EntityCreatorBase {
+import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
+import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
+import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
+import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
+import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
+
+import com.artemis.Entity;
+import com.artemis.World;
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.g3d.Environment;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.ModelInstance;
+import com.badlogic.gdx.graphics.g3d.Shader;
+import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
+import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
+import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
+import com.badlogic.gdx.math.Matrix3;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.utils.GdxRuntimeException;
+import com.badlogic.gdx.utils.JsonReader;
+
+public class BombGameEntityCreator extends EntityCreatorBase{
+ private static final String TAG = "BOMB_ENTITY_CREATOR";
+ private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName();
+
+ /*private enum bomb_type_t{
+ COMBINATION(0), INCLINATION(1), WIRES(2);
+
+ private int value;
+
+ private bomb_type_t(int value){
+ this.value = value;
+ }
+
+ public int getValue(){
+ return this.value;
+ }
+ };*/
+
+ private class EntityParameters{
+ public Environment environment;
+ public Shader shader;
+ public Model model1;
+ public Model model2;
+ public int markerCode;
+ public int nextAnimation;
+ public boolean loopAnimation;
+
+ public EntityParameters(){
+ environment = new Environment();
+ shader = null;
+ model1 = null;
+ model2 = null;
+ markerCode = -1;
+ nextAnimation = -1;
+ loopAnimation = false;
+ }
+ }
+
+ private EntityParameters parameters;
+ private Shader shader;
+ private Model doorModel;
+ private Model doorFrameModel;
+ private Model bombModelCombination;
+ private Model bombModelInclination;
+ private Model bombModelWires;
+ private Model easterEggModel;
+
public BombGameEntityCreator(){
- // TODO: Empty constructor.
+ G3dModelLoader loader = new G3dModelLoader(new JsonReader());
+
+ 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(1, 0, -0.5f)));
+
+ // 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;
+
+ // Create the models.
+ // TODO: Set the correct model paths.
+ doorModel = loader.loadModel(Gdx.files.internal(""));
+ doorFrameModel = loader.loadModel(Gdx.files.internal(""));
+ bombModelCombination = loader.loadModel(Gdx.files.internal(""));
+ bombModelInclination = loader.loadModel(Gdx.files.internal(""));
+ bombModelWires = loader.loadModel(Gdx.files.internal(""));
+ easterEggModel = loader.loadModel(Gdx.files.internal(""));
}
@Override
- public void createAllEntities() {
- // TODO Auto-generated method stub
+ public void createAllEntities(){
+ // TODO: Create the scene.
+
+ // TODO: Add the robot arms.
+
+ // Add bombs.
+ parameters.markerCode = 89;
+ parameters.model1 = bombModelCombination;
+ addBomb(world, parameters);
+
+ parameters.markerCode = 90;
+ parameters.model1 = bombModelInclination;
+ addBomb(world, parameters);
+
+ parameters.markerCode = 91;
+ parameters.model1 = bombModelWires;
+ addBomb(world, parameters);
+
+ // Add doors.
+ parameters.model1 = doorFrameModel;
+ parameters.model2 = doorModel;
+ parameters.nextAnimation = 0;
+ parameters.loopAnimation = false;
+
+ parameters.markerCode = 89;
+ addDoor(world, parameters);
+ parameters.markerCode = 90;
+ addDoor(world, parameters);
+ parameters.markerCode = 91;
+ addDoor(world, parameters);
}
@Override
public void dispose() {
- // TODO Auto-generated method stub
+ if(shader != null)
+ shader.dispose();
+
+ // Dispose of the models.
+ if(doorModel != null)
+ doorModel.dispose();
+ if(doorFrameModel != null)
+ doorFrameModel.dispose();
+ if(bombModelCombination != null)
+ bombModelCombination.dispose();
+ if(bombModelInclination != null)
+ bombModelInclination.dispose();
+ if(bombModelWires != null)
+ bombModelWires.dispose();
+ if(easterEggModel != null)
+ easterEggModel.dispose();
+ }
+
+ private void addBomb(World world, EntityParameters parameters){
+ Entity bomb;
+
+ bomb = world.createEntity();
+ bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ bomb.addComponent(new ModelComponent(parameters.model1));
+ bomb.addComponent(new EnvironmentComponent(parameters.environment));
+ bomb.addComponent(new ShaderComponent(parameters.shader));
+ bomb.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ bomb.addToWorld();
+ }
+
+ private void addDoor(World world, EntityParameters parameters){
+ ModelInstance frameModel, doorModel;
+ Entity frame, door;
+
+ frameModel = new ModelInstance(parameters.model1);
+ doorModel = new ModelInstance(parameters.model2);
+
+ frame = world.createEntity();
+ frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ frame.addComponent(new ModelComponent(frameModel));
+ frame.addComponent(new EnvironmentComponent(parameters.environment));
+ frame.addComponent(new ShaderComponent(parameters.shader));
+ frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ frame.addToWorld();
+
+ door = world.createEntity();
+ door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ door.addComponent(new ModelComponent(doorModel));
+ door.addComponent(new EnvironmentComponent(parameters.environment));
+ door.addComponent(new ShaderComponent(parameters.shader));
+ door.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ door.addComponent(new AnimationComponent(doorModel, parameters.nextAnimation, parameters.loopAnimation));
+ door.addToWorld();
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
index a5a8fa0..413a080 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
@@ -16,8 +16,9 @@
package ve.ucv.ciens.ccg.nxtar.entities;
import com.artemis.World;
+import com.badlogic.gdx.utils.Disposable;
-public abstract class EntityCreatorBase {
+public abstract class EntityCreatorBase implements Disposable{
protected World world;
public void setWorld(World world) throws IllegalArgumentException{
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
index d9ee15f..2f475f9 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
@@ -21,7 +21,7 @@ import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
-import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPerPixelShader;
+import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import com.artemis.Entity;
import com.badlogic.gdx.Gdx;
@@ -48,7 +48,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
private Model bombModel;
private Model animatedModel;
private Model boxModel;
- private SingleLightPerPixelShader ppShader;
+ private DirectionalLightPerPixelShader ppShader;
@Override
public void createAllEntities() {
@@ -72,12 +72,12 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
boxModel = builder.createBox(0.5f, 0.5f, 6.0f, material, new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")).getMask());
// Load the shader.
- ppShader = new SingleLightPerPixelShader();
+ ppShader = new DirectionalLightPerPixelShader();
ppShader.init();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
- environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, 0.5f)));
+ environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, -0.5f)));
// Create the entities.
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/TestGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/TestGameEntityCreator.java
deleted file mode 100644
index b3842fc..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/TestGameEntityCreator.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.entities;
-
-import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
-import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
-import ve.ucv.ciens.ccg.nxtar.components.CustomShaderComponent;
-import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
-import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
-import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPhongShader;
-
-import com.artemis.Entity;
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.VertexAttribute;
-import com.badlogic.gdx.graphics.VertexAttributes;
-import com.badlogic.gdx.graphics.VertexAttributes.Usage;
-import com.badlogic.gdx.graphics.g3d.utils.MeshBuilder;
-import com.badlogic.gdx.math.Matrix3;
-import com.badlogic.gdx.math.Vector3;
-
-public class TestGameEntityCreator extends EntityCreatorBase {
- private static final String TAG = "TEST_ENTITY_CREATOR";
- private static final String CLASS_NAME = TestGameEntityCreator.class.getSimpleName();
-
- private MeshBuilder builder;
- private Mesh sphereMesh;
- private Mesh cubeMesh;
- private Mesh capsuleMesh;
- private CustomShaderBase singleLightPhongShader;
-
- @Override
- public void createAllEntities() {
- Matrix3 identity = new Matrix3();
- Entity sphere;
- Entity cube;
- Entity capsule1;
- Entity capsule2;
-
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Started.");
-
- identity.idt();
-
- // Create the sphere.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
- builder = new MeshBuilder();
- builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
- builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
- builder.sphere(1.0f, 1.0f, 1.0f, 10, 10);
- }sphereMesh = builder.end();
-
- // Create the cube.
- builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
- builder.setColor(0.2f, 0.5f, 1.0f, 1.0f);
- builder.box(0.5f, 0.5f, 0.5f);
- }cubeMesh = builder.end();
-
- // Create the capsule.
- builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
- builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
- builder.capsule(0.25f, 0.5f, 10);
- }capsuleMesh = builder.end();
-
- // Load the phong shader.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
- try{
- singleLightPhongShader = new SingleLightPhongShader().loadShader();
- }catch(ShaderFailedToLoadException se){
- Gdx.app.error(TAG, CLASS_NAME + ".InGameState(): " + se.getMessage());
- Gdx.app.exit();
- }
-
- // Create the entities.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
- sphere = world.createEntity();
- sphere.addComponent(new GeometryComponent(new Vector3(0.5f, 0.5f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
- sphere.addComponent(new MeshComponent(sphereMesh));
- sphere.addComponent(new CustomShaderComponent(singleLightPhongShader));
-
- cube = world.createEntity();
- cube.addComponent(new GeometryComponent(new Vector3(-0.5f, -0.5f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
- cube.addComponent(new MeshComponent(cubeMesh));
- cube.addComponent(new CustomShaderComponent(singleLightPhongShader));
-
- capsule1 = world.createEntity();
- capsule1.addComponent(new GeometryComponent(new Vector3(-0.5f, 0.5f, 0.0f), identity, new Vector3(1.5f, 1.0f, 1.0f)));
- capsule1.addComponent(new MeshComponent(capsuleMesh));
- capsule1.addComponent(new CustomShaderComponent(singleLightPhongShader));
-
- capsule2 = world.createEntity();
- capsule2.addComponent(new GeometryComponent(new Vector3(0.5f, -0.5f, 0.0f), identity, new Vector3(1.0f, 1.5f, 1.0f)));
- capsule2.addComponent(new MeshComponent(capsuleMesh));
- capsule2.addComponent(new CustomShaderComponent(singleLightPhongShader));
-
- // Add the entities to the world.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
- sphere.addToWorld();
- cube.addToWorld();
- capsule1.addToWorld();
- capsule2.addToWorld();
-
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Finished.");
- }
-
- @Override
- public void dispose() {
- if(singleLightPhongShader != null && singleLightPhongShader.getShaderProgram() != null)
- singleLightPhongShader.getShaderProgram().dispose();
-
- if(sphereMesh != null)
- sphereMesh.dispose();
-
- if(cubeMesh != null)
- cubeMesh.dispose();
-
- if(capsuleMesh != null)
- capsuleMesh.dispose();
- }
-
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
deleted file mode 100644
index d7dab46..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.graphics;
-
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.math.Vector3;
-
-/**
- * A 3D light source.
- */
-public class LightSource{
- private Vector3 position;
- private Color ambientColor;
- private Color diffuseColor;
- private Color specularColor;
- private float shinyness;
-
- /**
- * Creates a default white light source positioned at (0,0,0).
- */
- public LightSource(){
- position = new Vector3(0.0f, 0.0f, 0.0f);
- ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
- diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- specularColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- shinyness = 10.0f;
- }
-
- /**
- * Creates a white light source at the specified position.
- *
- * @param position The location of the light source.
- */
- public LightSource(Vector3 position){
- this.position = new Vector3();
-
- this.position.set(position);
- ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
- diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- specularColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- shinyness = 10.0f;
- }
-
- /**
- * Creates a custom light source.
- *
- * @param position The location of the light source.
- * @param ambientColor
- * @param diffuseColor
- * @param specularColor
- * @param shinyness The shinyness component. Must be between (0.0, 128.0].
- * @throws IllegalArgumentException When shinyness is outside the valid range.
- */
- public LightSource(Vector3 position, Color ambientColor, Color diffuseColor, Color specularColor, float shinyness) throws IllegalArgumentException {
- if(shinyness <= 0.0 || shinyness > 128.0)
- throw new IllegalArgumentException("Shinyness must be between (0.0, 128.0].");
-
- this.position = new Vector3();
- this.ambientColor = new Color();
- this.diffuseColor = new Color();
- this.ambientColor = new Color();
- this.specularColor = new Color();
-
- this.position.set(position);
- this.ambientColor.set(ambientColor);
- this.diffuseColor.set(diffuseColor);
- this.specularColor.set(specularColor);
- this.shinyness = shinyness;
- }
-
- public LightSource(LightSource light){
- this.position = new Vector3();
- this.ambientColor = new Color();
- this.diffuseColor = new Color();
- this.ambientColor = new Color();
- this.specularColor = new Color();
-
- set(light);
- }
-
- public void set(LightSource light){
- this.position.set(light.getPosition());
- this.ambientColor.set(light.getAmbientColor());
- this.diffuseColor.set(light.getDiffuseColor());
- this.specularColor.set(light.getSpecularColor());
- this.shinyness = light.shinyness;
- }
-
- public void setPosition(float x, float y, float z){
- position.set(x, y, z);
- }
-
- public void setPosition(Vector3 position){
- this.position.set(position);
- }
-
- public void setAmbientColor(float r, float g, float b, float a){
- ambientColor.set(r, g, b, a);
- }
-
- public void setAmbientColor(Color ambientColor){
- this.ambientColor.set(ambientColor);
- }
-
- public void setDiffuseColor(float r, float g, float b, float a){
- diffuseColor.set(r, g, b, a);
- }
-
- public void setdiffuseColor(Color diffuseColor){
- this.diffuseColor.set(diffuseColor);
- }
-
- public void setSpecularColor(float r, float g, float b, float a){
- specularColor.set(r, g, b, a);
- }
-
- public void setSpecularColor(Color specularColor){
- this.specularColor.set(specularColor);
- }
-
- public void setShinyness(float shinyness) throws IllegalArgumentException {
- if(shinyness <= 0.0 || shinyness > 128.0)
- throw new IllegalArgumentException("Shinyness must be between (0.0, 128.0].");
-
- this.shinyness = shinyness;
- }
-
- public Vector3 getPosition(){
- return position;
- }
-
- public Color getAmbientColor(){
- return ambientColor;
- }
-
- public Color getDiffuseColor(){
- return diffuseColor;
- }
-
- public Color getSpecularColor(){
- return specularColor;
- }
-
- public float getShinyness(){
- return shinyness;
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/RenderParameters.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/RenderParameters.java
deleted file mode 100644
index 12fd477..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/RenderParameters.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.graphics;
-
-import com.badlogic.gdx.math.Matrix4;
-import com.badlogic.gdx.math.Vector3;
-
-public abstract class RenderParameters {
- private static Matrix4 modelViewProjection;
- private static Matrix4 geometricTransformation;
- private static Vector3 eyePosition;
- private static LightSource lightSource1;
- private static LightSource lightSource2;
-
- static{
- modelViewProjection = new Matrix4();
- geometricTransformation = new Matrix4();
- eyePosition = new Vector3(0.0f, 0.0f, 1.4142f);
- lightSource1 = new LightSource();
- lightSource2 = new LightSource();
- }
-
- public static synchronized void setModelViewProjectionMatrix(Matrix4 modelViewMatrix){
- modelViewProjection.set(modelViewMatrix);
- }
-
- public static synchronized void setTransformationMatrix(Matrix4 transformationMatrix){
- geometricTransformation.set(transformationMatrix);
- }
-
- public static synchronized void setEyePosition(Vector3 newEyePostition){
- eyePosition.set(newEyePostition);
- }
-
- public static synchronized void setLightSource1(LightSource newLightSource1){
- lightSource1.set(newLightSource1);
- }
-
- public static synchronized void setLightSource2(LightSource newLightSource2){
- lightSource2.set(newLightSource2);
- }
-
- public static synchronized Matrix4 getModelViewProjectionMatrix(){
- return modelViewProjection;
- }
-
- public static synchronized Matrix4 getTransformationMatrix(){
- return geometricTransformation;
- }
-
- public static synchronized Vector3 getEyePosition(){
- return eyePosition;
- }
-
- public static synchronized LightSource getLightSource1(){
- return lightSource1;
- }
-
- public static synchronized LightSource getLightSource2(){
- return lightSource2;
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPerPixelShader.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
similarity index 96%
rename from src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPerPixelShader.java
rename to src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
index b123837..a210d02 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPerPixelShader.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
@@ -30,7 +30,7 @@ import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
-public class SingleLightPerPixelShader implements Shader{
+public class DirectionalLightPerPixelShader implements Shader{
private static final int MAX_NUM_BONES = 4;
private static final Matrix4 IDENTITY = new Matrix4();
private static final String VERTEX_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_vert.glsl";
@@ -56,7 +56,7 @@ public class SingleLightPerPixelShader implements Shader{
private int[] u_normalMatrix;
private int[] u_bones;
- public SingleLightPerPixelShader(){
+ public DirectionalLightPerPixelShader(){
skinningProgram = null;
baseProgram = null;
camera = null;
@@ -79,7 +79,7 @@ public class SingleLightPerPixelShader implements Shader{
throw new GdxRuntimeException(skinningProgram.getLog());
if(!baseProgram.isCompiled())
- throw new GdxRuntimeException(skinningProgram.getLog());
+ throw new GdxRuntimeException(baseProgram.getLog());
// Create uniform locations.
u_projTrans = new int[2];
@@ -198,7 +198,7 @@ public class SingleLightPerPixelShader implements Shader{
// Set model dependant uniforms.
program.setUniformMatrix(u_geomTrans[index], renderable.worldTransform);
- program.setUniformMatrix(u_normalMatrix[index], normalMatrix.idt().mul(renderable.worldTransform).inv().tra());
+ program.setUniformMatrix(u_normalMatrix[index], normalMatrix.set(renderable.worldTransform).toNormalMatrix());
program.setUniformf(u_lightPos[index], lightPosition);
program.setUniformf(u_lightDiffuse[index], diffuseLightColor);
program.setUniformf(u_materialDiffuse[index], diffuseColor);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPhongShader.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPhongShader.java
deleted file mode 100644
index 66dcd54..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/SingleLightPhongShader.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.graphics.shaders;
-
-import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
-import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
-import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.glutils.ShaderProgram;
-
-public class SingleLightPhongShader extends CustomShaderBase{
- private static String VERTEX_SHADER_PATH = "shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl";
- private static String FRAGMENT_SHADER_PATH = "shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl";
-
- @Override
- public SingleLightPhongShader loadShader() throws ShaderFailedToLoadException{
- shaderProgram = new ShaderProgram(Gdx.files.internal(VERTEX_SHADER_PATH), Gdx.files.internal(FRAGMENT_SHADER_PATH));
-
- if(!shaderProgram.isCompiled()){
- throw new ShaderFailedToLoadException("SingleLightPerPixelPhongShader failed to load.\n" + shaderProgram.getLog());
- }
-
- return this;
- }
-
- @Override
- public void setUniforms(){
- LightSource light = RenderParameters.getLightSource1();
- float[] diffuseColor = {light.getDiffuseColor().r, light.getDiffuseColor().g, light.getDiffuseColor().b, light.getDiffuseColor().a};
- float[] ambientColor = {light.getAmbientColor().r, light.getAmbientColor().g, light.getAmbientColor().b, light.getAmbientColor().a};
- float[] specularColor = {light.getSpecularColor().r, light.getSpecularColor().g, light.getSpecularColor().b, light.getSpecularColor().a};
- float[] position = {light.getPosition().x, light.getPosition().y, light.getPosition().z, 0.0f};
- float[] shinyness = {light.getShinyness()};
-
- shaderProgram.setUniformMatrix("u_projTrans", RenderParameters.getModelViewProjectionMatrix());
- shaderProgram.setUniformMatrix("u_geomTrans", RenderParameters.getTransformationMatrix());
- shaderProgram.setUniform4fv("u_lightPos", position, 0, 4);
- shaderProgram.setUniform4fv("u_lightDiffuse", diffuseColor, 0, 4);
- shaderProgram.setUniform4fv("u_specular", specularColor, 0, 4);
- shaderProgram.setUniform4fv("u_ambient", ambientColor, 0, 4);
- shaderProgram.setUniform1fv("u_shiny", shinyness, 0, 1);
- shaderProgram.setUniformf("u_cameraPos", RenderParameters.getEyePosition());
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 1c55957..bbdcfae 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -19,11 +19,7 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
-import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
-import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
-import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
-import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
@@ -31,6 +27,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import com.artemis.World;
@@ -38,7 +35,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.mappings.Ouya;
-import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
@@ -63,11 +59,6 @@ public class InGameState extends BaseState{
private static final float FAR = 100.0f;
private static final float FAR_PLUS_NEAR = FAR + NEAR;
private static final float FAR_LESS_NEAR = FAR - NEAR;
- private static final Vector3 LIGHT_POSITION = new Vector3(2.0f, 2.0f, 4.0f);
- private static final Color AMBIENT_COLOR = new Color(0.0f, 0.1f, 0.3f, 1.0f);
- private static final Color DIFFUSE_COLOR = new Color(1.0f, 1.0f, 1.0f, 1.0f);
- private static final Color SPECULAR_COLOR = new Color(1.0f, 0.8f, 0.0f, 1.0f);
- private static final float SHINYNESS = 50.0f;
// Background related fields.
private float uScaling[];
@@ -83,7 +74,6 @@ public class InGameState extends BaseState{
// Game world objects.
private World gameWorld;
- private EntityCreatorBase entityCreator;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
@@ -188,17 +178,18 @@ public class InGameState extends BaseState{
frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = null;
- RenderParameters.setLightSource1(new LightSource(LIGHT_POSITION, AMBIENT_COLOR, DIFFUSE_COLOR, SPECULAR_COLOR, SHINYNESS));
// Set up the game world.
gameWorld = new World();
- entityCreator = new MarkerTestEntityCreator();
- entityCreator.setWorld(gameWorld);
- entityCreator.createAllEntities();
+ GameSettings.initGameSettings();
+ GameSettings.entityCreator.setWorld(gameWorld);
+ GameSettings.entityCreator.createAllEntities();
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new AnimationSystem());
+ // TODO: Add collision system.
+ //gameWorld.setSystem(GameSettings.gameLogicSystem);
markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
@@ -313,8 +304,6 @@ public class InGameState extends BaseState{
// Set rendering parameters.
perspectiveCamera.update(projectionMatrix, true);
- RenderParameters.setModelViewProjectionMatrix(perspectiveCamera.combined);
- RenderParameters.setEyePosition(perspectiveCamera.position);
// Call rendering systems.
markerRenderingSystem.begin(perspectiveCamera, data);
@@ -395,8 +384,8 @@ public class InGameState extends BaseState{
if(modelBatch != null)
modelBatch.dispose();
- if(entityCreator != null)
- entityCreator.dispose();
+ if(GameSettings.entityCreator != null)
+ GameSettings.entityCreator.dispose();
if(videoFrameTexture != null)
videoFrameTexture.dispose();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/MeshComponent.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
similarity index 66%
rename from src/ve/ucv/ciens/ccg/nxtar/components/MeshComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index b96db52..c987bec 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/MeshComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -13,15 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.components;
+package ve.ucv.ciens.ccg.nxtar.systems;
-import com.artemis.Component;
-import com.badlogic.gdx.graphics.Mesh;
+import com.artemis.Aspect;
+import com.artemis.Entity;
-public class MeshComponent extends Component {
- public Mesh model;
-
- public MeshComponent(Mesh model){
- this.model = model;
+public class BombGameLogicSystem extends GameLogicSystemBase {
+
+ @SuppressWarnings("unchecked")
+ public BombGameLogicSystem(){
+ super(Aspect.getAspectForAll(null));
+ }
+
+ @Override
+ protected void process(Entity e){
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/CustomShaderComponent.java b/src/ve/ucv/ciens/ccg/nxtar/systems/GameLogicSystemBase.java
similarity index 59%
rename from src/ve/ucv/ciens/ccg/nxtar/components/CustomShaderComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/systems/GameLogicSystemBase.java
index e66e879..74adcea 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/CustomShaderComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/GameLogicSystemBase.java
@@ -13,19 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.components;
+package ve.ucv.ciens.ccg.nxtar.systems;
-import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
+import com.artemis.Aspect;
+import com.artemis.Entity;
+import com.artemis.systems.EntityProcessingSystem;
-import com.artemis.Component;
+public abstract class GameLogicSystemBase extends EntityProcessingSystem {
-public class CustomShaderComponent extends Component {
- public CustomShaderBase shader;
-
- public CustomShaderComponent(CustomShaderBase shader) throws IllegalArgumentException{
- if(shader == null)
- throw new IllegalArgumentException("Shader cannot be null.");
-
- this.shader = shader;
+ public GameLogicSystemBase(Aspect aspect){
+ super(aspect);
}
+
+ @Override
+ protected abstract void process(Entity e);
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/CustomShaderBase.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
similarity index 53%
rename from src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/CustomShaderBase.java
rename to src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index 648fb22..000675c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/CustomShaderBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -13,20 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.graphics.shaders;
+package ve.ucv.ciens.ccg.nxtar.utils;
-import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
+import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
+import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
-import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+public abstract class GameSettings{
+ public static EntityCreatorBase entityCreator = null;
+ public static GameLogicSystemBase gameLogicSystem = null;
-public abstract class CustomShaderBase{
- protected ShaderProgram shaderProgram;
-
- public abstract CustomShaderBase loadShader() throws ShaderFailedToLoadException;
-
- public abstract void setUniforms();
-
- public ShaderProgram getShaderProgram(){
- return this.shaderProgram;
+ public static void initGameSettings(){
+ entityCreator = new MarkerTestEntityCreator();
+ gameLogicSystem = null;
+ //gameLogicSystem = new BombGameLogicSystem();
}
}
From a614841664df829d05763e65907e6d632f176a58 Mon Sep 17 00:00:00 2001
From: unknown
Date: Mon, 2 Jun 2014 16:46:06 -0430
Subject: [PATCH 02/34] Added more systems and components.
---
.../ccg/nxtar/components/BombComponent.java | 50 ++++
.../components/CollisionModelComponent.java | 38 +++
...mponent.java => RenderModelComponent.java} | 6 +-
.../nxtar/components/VisibilityComponent.java | 30 +++
.../nxtar/entities/BombGameEntityCreator.java | 141 ++++++----
.../entities/MarkerTestEntityCreator.java | 10 +-
.../ciens/ccg/nxtar/states/InGameState.java | 7 +
.../ciens/ccg/nxtar/states/PauseState.java | 251 ++++--------------
.../ccg/nxtar/systems/AnimationSystem.java | 13 +-
.../systems/CollisionDetectionSystem.java | 4 +-
.../ccg/nxtar/systems/GeometrySystem.java | 103 +++++++
.../nxtar/systems/MarkerRenderingSystem.java | 109 ++++----
.../nxtar/systems/ObjectRenderingSystem.java | 77 +++---
.../ccg/nxtar/systems/VisibilitySystem.java | 59 ++++
14 files changed, 542 insertions(+), 356 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/CollisionModelComponent.java
rename src/ve/ucv/ciens/ccg/nxtar/components/{ModelComponent.java => RenderModelComponent.java} (83%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/VisibilityComponent.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java
new file mode 100644
index 0000000..e50513c
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+public class BombComponent extends Component {
+ public enum bomb_type_t{
+ COMBINATION(0), INCLINATION(1), WIRES(2);
+
+ private int value;
+
+ private bomb_type_t(int value){
+ this.value = value;
+ }
+
+ public int getValue(){
+ return this.value;
+ }
+ };
+
+ public int id;
+ public bomb_type_t bombType;
+ public boolean enabled;
+
+ public BombComponent(int id, bomb_type_t bomb_type){
+ this.id = id;
+ this.bombType = bomb_type;
+ this.enabled = true;
+ }
+
+ public BombComponent(BombComponent bomb){
+ this.id = bomb.id;
+ this.bombType = bomb.bombType;
+ this.enabled = bomb.enabled;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/CollisionModelComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/CollisionModelComponent.java
new file mode 100644
index 0000000..a126e05
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/CollisionModelComponent.java
@@ -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;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.ModelInstance;
+
+public class CollisionModelComponent extends Component {
+ public ModelInstance instance;
+
+ public CollisionModelComponent(Model model) throws IllegalArgumentException{
+ if(model == null)
+ throw new IllegalArgumentException("Model is null.");
+
+ this.instance = new ModelInstance(model);
+ }
+
+ public CollisionModelComponent(ModelInstance instance) throws IllegalArgumentException{
+ if(instance == null)
+ throw new IllegalArgumentException("Instance is null.");
+
+ this.instance = instance;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/RenderModelComponent.java
similarity index 83%
rename from src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/components/RenderModelComponent.java
index 4a8cc6e..e070059 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/RenderModelComponent.java
@@ -19,17 +19,17 @@ import com.artemis.Component;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
-public class ModelComponent extends Component {
+public class RenderModelComponent extends Component {
public ModelInstance instance;
- public ModelComponent(Model model) throws IllegalArgumentException{
+ public RenderModelComponent(Model model) throws IllegalArgumentException{
if(model == null)
throw new IllegalArgumentException("Model is null.");
this.instance = new ModelInstance(model);
}
- public ModelComponent(ModelInstance instance) throws IllegalArgumentException{
+ public RenderModelComponent(ModelInstance instance) throws IllegalArgumentException{
if(instance == null)
throw new IllegalArgumentException("Instance is null.");
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/VisibilityComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/VisibilityComponent.java
new file mode 100644
index 0000000..2499f36
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/VisibilityComponent.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+public class VisibilityComponent extends Component {
+ public boolean visible;
+
+ public VisibilityComponent(){
+ this.visible = true;
+ }
+
+ public VisibilityComponent(boolean visibility){
+ this.visible = visibility;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 99e65c1..f6344c4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -16,15 +16,17 @@
package ve.ucv.ciens.ccg.nxtar.entities;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
+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.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import com.artemis.Entity;
-import com.artemis.World;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g3d.Environment;
@@ -43,25 +45,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final String TAG = "BOMB_ENTITY_CREATOR";
private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName();
- /*private enum bomb_type_t{
- COMBINATION(0), INCLINATION(1), WIRES(2);
-
- private int value;
-
- private bomb_type_t(int value){
- this.value = value;
- }
-
- public int getValue(){
- return this.value;
- }
- };*/
-
private class EntityParameters{
public Environment environment;
public Shader shader;
- public Model model1;
- public Model model2;
public int markerCode;
public int nextAnimation;
public boolean loopAnimation;
@@ -69,8 +55,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
public EntityParameters(){
environment = new Environment();
shader = null;
- model1 = null;
- model2 = null;
markerCode = -1;
nextAnimation = -1;
loopAnimation = false;
@@ -84,10 +68,15 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model bombModelCombination;
private Model bombModelInclination;
private Model bombModelWires;
+ private Model bombModelWiresWire1;
+ private Model bombModelWiresWire2;
+ private Model bombModelWiresWire3;
private Model easterEggModel;
+ private int currentBombId;
public BombGameEntityCreator(){
G3dModelLoader loader = new G3dModelLoader(new JsonReader());
+ currentBombId = 0;
parameters = new EntityParameters();
parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
@@ -105,45 +94,42 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Create the models.
// TODO: Set the correct model paths.
- doorModel = loader.loadModel(Gdx.files.internal(""));
- doorFrameModel = loader.loadModel(Gdx.files.internal(""));
- bombModelCombination = loader.loadModel(Gdx.files.internal(""));
- bombModelInclination = loader.loadModel(Gdx.files.internal(""));
- bombModelWires = loader.loadModel(Gdx.files.internal(""));
- easterEggModel = loader.loadModel(Gdx.files.internal(""));
+ // TODO: Load collision models.
+ doorModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ doorFrameModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ bombModelCombination = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ bombModelInclination = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ bombModelWires = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ easterEggModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
}
@Override
public void createAllEntities(){
- // TODO: Create the scene.
-
// TODO: Add the robot arms.
-
+
// Add bombs.
parameters.markerCode = 89;
- parameters.model1 = bombModelCombination;
- addBomb(world, parameters);
+ addBomb(parameters, bomb_type_t.COMBINATION);
parameters.markerCode = 90;
- parameters.model1 = bombModelInclination;
- addBomb(world, parameters);
+ addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
- parameters.model1 = bombModelWires;
- addBomb(world, parameters);
+ addBomb(parameters, bomb_type_t.WIRES);
// Add doors.
- parameters.model1 = doorFrameModel;
- parameters.model2 = doorModel;
parameters.nextAnimation = 0;
parameters.loopAnimation = false;
parameters.markerCode = 89;
- addDoor(world, parameters);
+ addDoor(parameters);
parameters.markerCode = 90;
- addDoor(world, parameters);
+ addDoor(parameters);
parameters.markerCode = 91;
- addDoor(world, parameters);
+ addDoor(parameters);
}
@Override
@@ -162,44 +148,99 @@ public class BombGameEntityCreator extends EntityCreatorBase{
bombModelInclination.dispose();
if(bombModelWires != null)
bombModelWires.dispose();
+ if(bombModelWiresWire1 != null)
+ bombModelWiresWire1.dispose();
+ if(bombModelWiresWire2 != null)
+ bombModelWiresWire2.dispose();
+ if(bombModelWiresWire3 != null)
+ bombModelWiresWire3.dispose();
if(easterEggModel != null)
easterEggModel.dispose();
}
- private void addBomb(World world, EntityParameters parameters){
+ private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb;
+ BombComponent bombComponent = new BombComponent(currentBombId, type);
bomb = world.createEntity();
bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- bomb.addComponent(new ModelComponent(parameters.model1));
bomb.addComponent(new EnvironmentComponent(parameters.environment));
bomb.addComponent(new ShaderComponent(parameters.shader));
bomb.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ bomb.addComponent(bombComponent);
+ bomb.addComponent(new VisibilityComponent());
+
+ if(type == bomb_type_t.COMBINATION){
+ bomb.addComponent(new RenderModelComponent(bombModelCombination));
+ }else if(type == bomb_type_t.INCLINATION){
+ bomb.addComponent(new RenderModelComponent(bombModelInclination));
+ }else if(type == bomb_type_t.WIRES){
+ bomb.addComponent(new RenderModelComponent(bombModelWires));
+ addBombWires(parameters, bombComponent);
+ }else
+ throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
+
bomb.addToWorld();
+ currentBombId++;
}
- private void addDoor(World world, EntityParameters parameters){
- ModelInstance frameModel, doorModel;
- Entity frame, door;
+ private void addBombWires(EntityParameters parameters, BombComponent bomb){
+ // TODO: Add collision models.
+ Entity wire1, wire2, wire3;
- frameModel = new ModelInstance(parameters.model1);
- doorModel = new ModelInstance(parameters.model2);
+ wire1 = world.createEntity();
+ wire1.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ wire1.addComponent(new EnvironmentComponent(parameters.environment));
+ wire1.addComponent(new ShaderComponent(parameters.shader));
+ wire1.addComponent(new RenderModelComponent(bombModelWiresWire1));
+ wire1.addComponent(new BombComponent(bomb));
+ wire1.addComponent(new VisibilityComponent());
+ wire1.addToWorld();
+
+ wire2 = world.createEntity();
+ wire2.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ wire2.addComponent(new EnvironmentComponent(parameters.environment));
+ wire2.addComponent(new ShaderComponent(parameters.shader));
+ wire2.addComponent(new RenderModelComponent(bombModelWiresWire2));
+ wire2.addComponent(new BombComponent(bomb));
+ wire2.addComponent(new VisibilityComponent());
+ wire2.addToWorld();
+
+ wire3 = world.createEntity();
+ wire3.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ wire3.addComponent(new EnvironmentComponent(parameters.environment));
+ wire3.addComponent(new ShaderComponent(parameters.shader));
+ wire3.addComponent(new RenderModelComponent(bombModelWiresWire3));
+ wire3.addComponent(new BombComponent(bomb));
+ wire3.addComponent(new VisibilityComponent());
+ wire3.addToWorld();
+ }
+
+ private void addDoor(EntityParameters parameters){
+ // TODO: Add collision models.
+ ModelInstance doorInstance;
+ Entity frame, door;
frame = world.createEntity();
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- frame.addComponent(new ModelComponent(frameModel));
+ frame.addComponent(new RenderModelComponent(doorFrameModel));
frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader));
+ frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
+
frame.addToWorld();
door = world.createEntity();
door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- door.addComponent(new ModelComponent(doorModel));
+ door.addComponent(new RenderModelComponent(doorModel));
door.addComponent(new EnvironmentComponent(parameters.environment));
door.addComponent(new ShaderComponent(parameters.shader));
door.addComponent(new MarkerCodeComponent(parameters.markerCode));
- door.addComponent(new AnimationComponent(doorModel, parameters.nextAnimation, parameters.loopAnimation));
+ door.addComponent(new VisibilityComponent());
+ doorInstance = door.getComponent(RenderModelComponent.class).instance;
+ door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
+
door.addToWorld();
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
index 2f475f9..bee186a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
@@ -19,7 +19,7 @@ import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
@@ -83,22 +83,22 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
bomb = world.createEntity();
bomb.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
- bomb.addComponent(new ModelComponent(bombModel));
+ bomb.addComponent(new RenderModelComponent(bombModel));
bomb.addComponent(new EnvironmentComponent(environment));
bomb.addComponent(new ShaderComponent(ppShader));
bomb.addComponent(new MarkerCodeComponent(1023));
anim = world.createEntity();
anim.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(0.25f, 0.25f, -0.25f)));
- anim.addComponent(new ModelComponent(animatedModel));
- anim.addComponent(new AnimationComponent(anim.getComponent(ModelComponent.class).instance, 0, true));
+ anim.addComponent(new RenderModelComponent(animatedModel));
+ anim.addComponent(new AnimationComponent(anim.getComponent(RenderModelComponent.class).instance, 0, true));
anim.addComponent(new EnvironmentComponent(environment));
anim.addComponent(new MarkerCodeComponent(89));
anim.addComponent(new ShaderComponent(ppShader));
box = world.createEntity();
box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
- box.addComponent(new ModelComponent(boxModel));
+ box.addComponent(new RenderModelComponent(boxModel));
box.addComponent(new ShaderComponent(ppShader));
box.addComponent(new EnvironmentComponent(environment));
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index bbdcfae..842c093 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -24,9 +24,11 @@ import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.VisibilitySystem;
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -187,6 +189,9 @@ public class InGameState extends BaseState{
GameSettings.entityCreator.createAllEntities();
gameWorld.setSystem(new MarkerPositioningSystem());
+ // TODO: Make and add positioning systems.
+ gameWorld.setSystem(new GeometrySystem());
+ //gameWorld.setSystem(new VisibilitySystem());
gameWorld.setSystem(new AnimationSystem());
// TODO: Add collision system.
//gameWorld.setSystem(GameSettings.gameLogicSystem);
@@ -242,6 +247,8 @@ public class InGameState extends BaseState{
perspectiveCamera.far = FAR;
perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
perspectiveCamera.update();
+
+ gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera);
}
// Attempt to find the markers in the current video frame.
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java b/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java
index a7c51bb..468849e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java
@@ -1,202 +1,49 @@
-/*
- * 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.states;
-
-import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-
-import com.badlogic.gdx.controllers.Controller;
-import com.badlogic.gdx.controllers.PovDirection;
-import com.badlogic.gdx.math.Vector3;
-
-public class PauseState extends BaseState {
-
- public PauseState(final NxtARCore core){
- this.core = core;
- }
-
- @Override
- public void render(float delta) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void resize(int width, int height) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void show() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void hide() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void pause() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void resume() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
-
- }
-
- /*;;;;;;;;;;;;;;;;;;
- ; HELPER METHODS ;
- ;;;;;;;;;;;;;;;;;;*/
-
- @Override
- public void onStateSet(){
- }
-
- @Override
- public void onStateUnset(){
- }
-
- /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; BEGIN INPUT PROCESSOR METHODS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
-
- @Override
- public boolean keyDown(int keycode) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean keyUp(int keycode) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean keyTyped(char character) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean touchDown(int screenX, int screenY, int pointer, int button) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean touchUp(int screenX, int screenY, int pointer, int button) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean mouseMoved(int screenX, int screenY) {
- // TODO Auto-generated method stub
- return false;
- }
- /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; END INPUT PROCESSOR METHODS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
-
- /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; BEGIN CONTROLLER LISTENER METHODS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
- @Override
- public boolean scrolled(int amount) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void connected(Controller controller) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void disconnected(Controller controller) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean buttonDown(Controller controller, int buttonCode) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean buttonUp(Controller controller, int buttonCode) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean axisMoved(Controller controller, int axisCode, float value) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean povMoved(Controller controller, int povCode,
- PovDirection value) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean xSliderMoved(Controller controller, int sliderCode,
- boolean value) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean ySliderMoved(Controller controller, int sliderCode,
- boolean value) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean accelerometerMoved(Controller controller,
- int accelerometerCode, Vector3 value) {
- // TODO Auto-generated method stub
- return false;
- }
- /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; END CONTROLLER LISTENER METHODS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
-}
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+
+public class PauseState extends BaseState {
+
+ public PauseState(final NxtARCore core){
+ this.core = core;
+ }
+
+ @Override
+ public void onStateSet() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onStateUnset() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void render(float delta) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
index 5e2f2a0..064f02c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
@@ -26,24 +27,26 @@ import com.badlogic.gdx.Gdx;
public class AnimationSystem extends EntityProcessingSystem {
@Mapper ComponentMapper animationMapper;
+ @Mapper ComponentMapper visibilityMapper;
@SuppressWarnings("unchecked")
public AnimationSystem(){
- super(Aspect.getAspectForAll(AnimationComponent.class));
+ super(Aspect.getAspectForAll(AnimationComponent.class, VisibilityComponent.class));
}
@Override
protected void process(Entity e) {
AnimationComponent animation = animationMapper.get(e);
+ VisibilityComponent visibility = visibilityMapper.get(e);
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
if(animation.loop)
- animation.controller.setAnimation(animation.animationsIds.get(animation.next), -1);
+ animation.controller.animate(animation.animationsIds.get(animation.next), -1, 1, null,0.1f);
else
- animation.controller.setAnimation(animation.animationsIds.get(animation.next));
+ animation.controller.animate(animation.animationsIds.get(animation.next), 1, 1, null,0.1f);
}
- animation.controller.update(Gdx.graphics.getDeltaTime());
+ if(visibility.visible)
+ animation.controller.update(Gdx.graphics.getDeltaTime());
}
-
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
index c53eaaa..ef9e21d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
@@ -15,7 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
-import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import com.artemis.Aspect;
import com.artemis.Entity;
@@ -25,7 +25,7 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
@SuppressWarnings("unchecked")
public CollisionDetectionSystem(){
- super(Aspect.getAspectForAll(ModelComponent.class));
+ super(Aspect.getAspectForAll(CollisionModelComponent.class));
}
@Override
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java
new file mode 100644
index 0000000..fb547bb
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java
@@ -0,0 +1,103 @@
+/*
+ * 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.systems;
+
+import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
+import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
+
+import com.artemis.Aspect;
+import com.artemis.ComponentMapper;
+import com.artemis.Entity;
+import com.artemis.annotations.Mapper;
+import com.artemis.systems.EntityProcessingSystem;
+import com.badlogic.gdx.graphics.g3d.ModelInstance;
+import com.badlogic.gdx.math.Matrix4;
+
+public class GeometrySystem extends EntityProcessingSystem {
+ @Mapper ComponentMapper geometryMapper;
+ @Mapper ComponentMapper renderModelMapper;
+ @Mapper ComponentMapper colModelMapper;
+
+ /**
+ * A matrix representing 3D translations.
+ */
+ private Matrix4 translationMatrix;
+
+ /**
+ * A matrix representing 3D rotations.
+ */
+ private Matrix4 rotationMatrix;
+
+ /**
+ * A matrix representing 3D scalings.
+ */
+ private Matrix4 scalingMatrix;
+
+ @SuppressWarnings("unchecked")
+ public GeometrySystem(){
+ super(Aspect.getAspectForAll(GeometryComponent.class).one(RenderModelComponent.class, CollisionModelComponent.class));
+
+ translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
+ rotationMatrix = new Matrix4().idt();
+ scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
+ }
+
+ @Override
+ protected void process(Entity e) {
+ GeometryComponent geometry;
+ RenderModelComponent renderModel;
+ CollisionModelComponent colModel;
+
+ geometry = geometryMapper.get(e);
+ renderModel = renderModelMapper.getSafe(e);
+ colModel = colModelMapper.getSafe(e);
+
+ if(renderModel != null)
+ applyWorldTransform(renderModel.instance, geometry);
+ if(colModel != null)
+ applyWorldTransform(colModel.instance, geometry);
+ }
+
+ private void applyWorldTransform(ModelInstance model, GeometryComponent geometry){
+ translationMatrix.setToTranslation(geometry.position);
+
+ rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
+ rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
+ rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
+ rotationMatrix.val[Matrix4.M30] = 0;
+
+ rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
+ rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
+ rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
+ rotationMatrix.val[Matrix4.M31] = 0;
+
+ rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
+ rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
+ rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
+ rotationMatrix.val[Matrix4.M32] = 0;
+
+ rotationMatrix.val[Matrix4.M03] = 0;
+ rotationMatrix.val[Matrix4.M13] = 0;
+ rotationMatrix.val[Matrix4.M23] = 0;
+ rotationMatrix.val[Matrix4.M33] = 1;
+
+ scalingMatrix.setToScaling(geometry.scaling);
+
+ model.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
+ model.calculateTransforms();
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
index d2058bc..b89bdb6 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
@@ -16,10 +16,10 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
-import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -31,14 +31,14 @@ import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
-import com.badlogic.gdx.math.Matrix4;
public class MarkerRenderingSystem extends EntityProcessingSystem {
@Mapper ComponentMapper markerMapper;
- @Mapper ComponentMapper geometryMapper;
- @Mapper ComponentMapper modelMapper;
+// @Mapper ComponentMapper geometryMapper;
+ @Mapper ComponentMapper modelMapper;
@Mapper ComponentMapper environmentMapper;
@Mapper ComponentMapper shaderMapper;
+ @Mapper ComponentMapper visibiltyMapper;
private static final String TAG = "MODEL_BATCH_MARKER_RENDERING_SYSTEM";
private static final String CLASS_NAME = MarkerRenderingSystem.class.getSimpleName();
@@ -46,17 +46,17 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
/**
* A matrix representing 3D translations.
*/
- private Matrix4 translationMatrix;
+ //private Matrix4 translationMatrix;
/**
* A matrix representing 3D rotations.
*/
- private Matrix4 rotationMatrix;
+ //private Matrix4 rotationMatrix;
/**
* A matrix representing 3D scalings.
*/
- private Matrix4 scalingMatrix;
+ //private Matrix4 scalingMatrix;
private MarkerData markers;
@@ -66,14 +66,14 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
@SuppressWarnings("unchecked")
public MarkerRenderingSystem(ModelBatch batch){
- super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, ShaderComponent.class, EnvironmentComponent.class, ModelComponent.class));
+ super(Aspect.getAspectForAll(MarkerCodeComponent.class, /*GeometryComponent.class,*/ ShaderComponent.class, EnvironmentComponent.class, RenderModelComponent.class, VisibilityComponent.class));
markers = null;
camera = null;
this.batch = batch;
- translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
- rotationMatrix = new Matrix4().idt();
- scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
+// translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
+// rotationMatrix = new Matrix4().idt();
+// scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
}
public void begin(PerspectiveCamera camera, MarkerData markers) throws RuntimeException{
@@ -97,62 +97,65 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
@Override
protected void process(Entity e) {
MarkerCodeComponent marker;
- GeometryComponent geometry;
+// GeometryComponent geometry;
EnvironmentComponent environment;
- ModelComponent model;
+ RenderModelComponent model;
ShaderComponent shader;
+ VisibilityComponent visibility;
if(markers == null || camera == null)
return;
Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
marker = markerMapper.get(e);
- geometry = geometryMapper.get(e);
+// geometry = geometryMapper.get(e);
model = modelMapper.get(e);
environment = environmentMapper.get(e);
shader = shaderMapper.get(e);
+ visibility = visibiltyMapper.get(e);
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
- for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
- if(markers.markerCodes[i] != 1){
- if(markers.markerCodes[i] == marker.code){
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
- // Set the geometric transformations.
- translationMatrix.setToTranslation(geometry.position);
+ if(visibility.visible){
+ Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
+ for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
+ if(markers.markerCodes[i] != 1){
+ if(markers.markerCodes[i] == marker.code){
+ Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
+ // Set the geometric transformations.
+// translationMatrix.setToTranslation(geometry.position);
+//
+// rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
+// rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
+// rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
+// rotationMatrix.val[Matrix4.M30] = 0;
+//
+// rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
+// rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
+// rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
+// rotationMatrix.val[Matrix4.M31] = 0;
+//
+// rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
+// rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
+// rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
+// rotationMatrix.val[Matrix4.M32] = 0;
+//
+// rotationMatrix.val[Matrix4.M03] = 0;
+// rotationMatrix.val[Matrix4.M13] = 0;
+// rotationMatrix.val[Matrix4.M23] = 0;
+// rotationMatrix.val[Matrix4.M33] = 1;
+//
+// scalingMatrix.setToScaling(geometry.scaling);
+//
+// // Apply the geometric transformations to the model.
+// model.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
+// model.instance.calculateTransforms();
- rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
- rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
- rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
- rotationMatrix.val[Matrix4.M30] = 0;
-
- rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
- rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
- rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
- rotationMatrix.val[Matrix4.M31] = 0;
-
- rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
- rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
- rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
- rotationMatrix.val[Matrix4.M32] = 0;
-
- rotationMatrix.val[Matrix4.M03] = 0;
- rotationMatrix.val[Matrix4.M13] = 0;
- rotationMatrix.val[Matrix4.M23] = 0;
- rotationMatrix.val[Matrix4.M33] = 1;
-
- scalingMatrix.setToScaling(geometry.scaling);
-
- // Apply the geometric transformations to the model.
- model.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
- model.instance.calculateTransforms();
-
- // Render the marker;
- batch.render(model.instance, environment.environment, shader.shader);
+ // Render the marker;
+ batch.render(model.instance, environment.environment, shader.shader);
+ }
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
}
- }else{
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
}
}
}
-
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
index 63a7d2b..793db24 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
@@ -18,8 +18,9 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
@@ -28,32 +29,32 @@ import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
-import com.badlogic.gdx.math.Matrix4;
/**
* Entity processing system in charge of rendering 3D objects using OpenGL. The
* entities to be rendered must have a geometry, shader and mesh component associated.
*/
public class ObjectRenderingSystem extends EntityProcessingSystem {
- @Mapper ComponentMapper geometryMapper;
+// @Mapper ComponentMapper geometryMapper;
@Mapper ComponentMapper shaderMapper;
- @Mapper ComponentMapper modelMapper;
+ @Mapper ComponentMapper modelMapper;
@Mapper ComponentMapper environmentMapper;
+ @Mapper ComponentMapper visibiltyMapper;
- /**
- * A matrix representing 3D translations.
- */
- private Matrix4 translationMatrix;
-
- /**
- * A matrix representing 3D rotations.
- */
- private Matrix4 rotationMatrix;
-
- /**
- * A matrix representing 3D scalings.
- */
- private Matrix4 scalingMatrix;
+// /**
+// * A matrix representing 3D translations.
+// */
+// private Matrix4 translationMatrix;
+//
+// /**
+// * A matrix representing 3D rotations.
+// */
+// private Matrix4 rotationMatrix;
+//
+// /**
+// * A matrix representing 3D scalings.
+// */
+// private Matrix4 scalingMatrix;
private PerspectiveCamera camera;
@@ -61,13 +62,13 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
@SuppressWarnings("unchecked")
public ObjectRenderingSystem(ModelBatch batch) {
- super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, ModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class));
+ super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class, VisibilityComponent.class).exclude(MarkerCodeComponent.class));
camera = null;
this.batch = batch;
- translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
- rotationMatrix = new Matrix4().idt();
- scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
+// translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
+// rotationMatrix = new Matrix4().idt();
+// scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
}
public void begin(PerspectiveCamera camera) throws RuntimeException{
@@ -92,24 +93,28 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
@Override
protected void process(Entity e) {
EnvironmentComponent environment;
- GeometryComponent geometryComponent;
+// GeometryComponent geometryComponent;
ShaderComponent shaderComponent;
- ModelComponent modelComponent;
+ RenderModelComponent renderModelComponent;
+ VisibilityComponent visibility;
// Get the necessary components.
- geometryComponent = geometryMapper.get(e);
- modelComponent = modelMapper.get(e);
- shaderComponent = shaderMapper.get(e);
- environment = environmentMapper.get(e);
+// geometryComponent = geometryMapper.get(e);
+ renderModelComponent = modelMapper.get(e);
+ shaderComponent = shaderMapper.get(e);
+ environment = environmentMapper.get(e);
+ visibility = visibiltyMapper.get(e);
- // Calculate the geometric transformation for this entity.
- translationMatrix.setToTranslation(geometryComponent.position);
- rotationMatrix.set(geometryComponent.rotation);
- scalingMatrix.setToScaling(geometryComponent.scaling);
- modelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
- modelComponent.instance.calculateTransforms();
+ if(visibility.visible){
+ // Calculate the geometric transformation for this entity.
+// translationMatrix.setToTranslation(geometryComponent.position);
+// rotationMatrix.set(geometryComponent.rotation);
+// scalingMatrix.setToScaling(geometryComponent.scaling);
+// renderModelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
+// renderModelComponent.instance.calculateTransforms();
- // Render this entity.
- batch.render(modelComponent.instance, environment.environment, shaderComponent.shader);
+ // Render this entity.
+ batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
+ }
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java
new file mode 100644
index 0000000..7ae8d3c
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java
@@ -0,0 +1,59 @@
+/*
+ * 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.systems;
+
+import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
+
+import com.artemis.Aspect;
+import com.artemis.ComponentMapper;
+import com.artemis.Entity;
+import com.artemis.annotations.Mapper;
+import com.artemis.systems.EntityProcessingSystem;
+import com.badlogic.gdx.graphics.PerspectiveCamera;
+import com.badlogic.gdx.math.collision.BoundingBox;
+
+public class VisibilitySystem extends EntityProcessingSystem {
+ @Mapper ComponentMapper visibilityMapper;
+ @Mapper ComponentMapper geometryMapper;
+ @Mapper ComponentMapper collisionMapper;
+
+ private PerspectiveCamera camera;
+
+ @SuppressWarnings("unchecked")
+ public VisibilitySystem(){
+ super(Aspect.getAspectForAll(VisibilityComponent.class, CollisionModelComponent.class));
+ this.camera = null;
+ }
+
+ public void setCamera(PerspectiveCamera camera){
+ this.camera = camera;
+ }
+
+ @Override
+ protected void process(Entity e){
+ VisibilityComponent visibility = visibilityMapper.get(e);
+ CollisionModelComponent colModel = collisionMapper.get(e);
+ BoundingBox bBox = new BoundingBox();
+
+ if(camera != null){
+ colModel.instance.calculateBoundingBox(bBox);
+ bBox.mul(colModel.instance.transform);
+ visibility.visible = camera.frustum.boundsInFrustum(bBox);
+ }
+ }
+}
From e65da3234bf23e236bdc44893852aaa829508212 Mon Sep 17 00:00:00 2001
From: unknown
Date: Tue, 3 Jun 2014 16:22:15 -0430
Subject: [PATCH 03/34] Added some model loading and removed an useless file.
---
.../nxtar/entities/BombGameEntityCreator.java | 48 +++++++-------
.../ShaderFailedToLoadException.java | 24 -------
.../DirectionalLightPerPixelShader.java | 63 ++++++++++++-------
.../ciens/ccg/nxtar/states/InGameState.java | 2 +-
.../ccg/nxtar/systems/AnimationSystem.java | 12 ++--
.../ciens/ccg/nxtar/utils/GameSettings.java | 4 +-
6 files changed, 75 insertions(+), 78 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index f6344c4..357f172 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -39,7 +39,7 @@ import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
import com.badlogic.gdx.math.Matrix3;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
-import com.badlogic.gdx.utils.JsonReader;
+import com.badlogic.gdx.utils.UBJsonReader;
public class BombGameEntityCreator extends EntityCreatorBase{
private static final String TAG = "BOMB_ENTITY_CREATOR";
@@ -75,12 +75,12 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private int currentBombId;
public BombGameEntityCreator(){
- G3dModelLoader loader = new G3dModelLoader(new JsonReader());
+ G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
currentBombId = 0;
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(1, 0, -0.5f)));
+ parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(0, 0, -1)));
// Load the shader.
shader = new DirectionalLightPerPixelShader();
@@ -95,15 +95,15 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Create the models.
// TODO: Set the correct model paths.
// TODO: Load collision models.
- doorModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- doorFrameModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- bombModelCombination = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- bombModelInclination = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- bombModelWires = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- easterEggModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
- bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
+ doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
+ doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
+// bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+// bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ bombModelWires = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
+// easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
+ bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
+ bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
}
@Override
@@ -111,23 +111,23 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// TODO: Add the robot arms.
// Add bombs.
- parameters.markerCode = 89;
- addBomb(parameters, bomb_type_t.COMBINATION);
-
- parameters.markerCode = 90;
- addBomb(parameters, bomb_type_t.INCLINATION);
+// parameters.markerCode = 89;
+// addBomb(parameters, bomb_type_t.COMBINATION);
+//
+// parameters.markerCode = 90;
+// addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
addBomb(parameters, bomb_type_t.WIRES);
// Add doors.
- parameters.nextAnimation = 0;
+ parameters.nextAnimation = 1;
parameters.loopAnimation = false;
- parameters.markerCode = 89;
- addDoor(parameters);
- parameters.markerCode = 90;
- addDoor(parameters);
+// parameters.markerCode = 89;
+// addDoor(parameters);
+// parameters.markerCode = 90;
+// addDoor(parameters);
parameters.markerCode = 91;
addDoor(parameters);
}
@@ -170,6 +170,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
bomb.addComponent(bombComponent);
bomb.addComponent(new VisibilityComponent());
+ // Add the collision and render models depending on the bomb type.
if(type == bomb_type_t.COMBINATION){
bomb.addComponent(new RenderModelComponent(bombModelCombination));
}else if(type == bomb_type_t.INCLINATION){
@@ -195,6 +196,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire1.addComponent(new RenderModelComponent(bombModelWiresWire1));
wire1.addComponent(new BombComponent(bomb));
wire1.addComponent(new VisibilityComponent());
+ wire1.addComponent(new MarkerCodeComponent(parameters.markerCode));
wire1.addToWorld();
wire2 = world.createEntity();
@@ -204,6 +206,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire2.addComponent(new RenderModelComponent(bombModelWiresWire2));
wire2.addComponent(new BombComponent(bomb));
wire2.addComponent(new VisibilityComponent());
+ wire2.addComponent(new MarkerCodeComponent(parameters.markerCode));
wire2.addToWorld();
wire3 = world.createEntity();
@@ -213,6 +216,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire3.addComponent(new RenderModelComponent(bombModelWiresWire3));
wire3.addComponent(new BombComponent(bomb));
wire3.addComponent(new VisibilityComponent());
+ wire3.addComponent(new MarkerCodeComponent(parameters.markerCode));
wire3.addToWorld();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java b/src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java
deleted file mode 100644
index c8ca5f3..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.exceptions;
-
-public class ShaderFailedToLoadException extends Exception {
- private static final long serialVersionUID = 9989L;
-
- public ShaderFailedToLoadException(String msg){
- super(msg);
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
index a210d02..0b4a9db 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
@@ -36,6 +36,8 @@ public class DirectionalLightPerPixelShader implements Shader{
private static final String VERTEX_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_vert.glsl";
private static final String FRAGMENT_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_frag.glsl";
private static final String INCLUDE_SKINNING = "#define SKINNING\n";
+ private static final float DEFAULT_SHININESS = 50.0f;
+ private static final Vector3 DEFAULT_LIGHT = new Vector3(1, 1, 1);
private ShaderProgram skinningProgram;
private ShaderProgram baseProgram;
@@ -134,22 +136,8 @@ public class DirectionalLightPerPixelShader implements Shader{
@Override
public boolean canRender(Renderable renderable){
- // Check for all needed lighting and material attributes.
- if(renderable.environment.directionalLights.size < 1)
- return false;
-
- if(!renderable.environment.has(ColorAttribute.AmbientLight))
- return false;
-
- if(!renderable.material.has(ColorAttribute.Diffuse))
- return false;
-
- if(!renderable.material.has(ColorAttribute.Specular))
- return false;
-
- if(!renderable.material.has(FloatAttribute.Shininess))
- return false;
-
+ // Easier to always return true. Missing material properties are replaced by
+ // default values during render.
return true;
}
@@ -169,16 +157,43 @@ public class DirectionalLightPerPixelShader implements Shader{
@Override
public void render(Renderable renderable){
ShaderProgram program;
- int index;
- boolean bonesEnabled;
+ int index;
+ boolean bonesEnabled;
+ Vector3 lightPosition;
+ Color diffuseLightColor;
+ Color diffuseColor;
+ Color specularColor;
+ Color ambientColor;
+ float shininess;
// Get material colors.
- Vector3 lightPosition = renderable.environment.directionalLights.get(0).direction;
- Color diffuseLightColor = renderable.environment.directionalLights.get(0).color;
- Color diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color;
- Color specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color;
- Color ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
- float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
+ if(renderable.environment.directionalLights.size >= 1){
+ lightPosition = renderable.environment.directionalLights.get(0).direction;
+ diffuseLightColor = renderable.environment.directionalLights.get(0).color;
+ }else{
+ lightPosition = DEFAULT_LIGHT;
+ diffuseLightColor = Color.WHITE;
+ }
+
+ if(renderable.material.has(ColorAttribute.Diffuse))
+ diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color;
+ else
+ diffuseColor = Color.WHITE;
+
+ if(renderable.material.has(ColorAttribute.Specular))
+ specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color;
+ else
+ specularColor = Color.BLACK;
+
+ if(renderable.environment.has(ColorAttribute.AmbientLight))
+ ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
+ else
+ ambientColor = Color.BLACK;
+
+ if(renderable.material.has(FloatAttribute.Shininess))
+ shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
+ else
+ shininess = DEFAULT_SHININESS;
if(renderable.mesh.getVertexAttribute(VertexAttributes.Usage.BoneWeight) != null){
program = skinningProgram;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 842c093..8a79d63 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -248,7 +248,7 @@ public class InGameState extends BaseState{
perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
perspectiveCamera.update();
- gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera);
+// gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera);
}
// Attempt to find the markers in the current video frame.
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
index 064f02c..cd73cb3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
@@ -36,14 +36,16 @@ public class AnimationSystem extends EntityProcessingSystem {
@Override
protected void process(Entity e) {
- AnimationComponent animation = animationMapper.get(e);
+ AnimationComponent animation = animationMapper.get(e);
VisibilityComponent visibility = visibilityMapper.get(e);
+ int loopCount = animation.loop ? -1 : 1;
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
- if(animation.loop)
- animation.controller.animate(animation.animationsIds.get(animation.next), -1, 1, null,0.1f);
- else
- animation.controller.animate(animation.animationsIds.get(animation.next), 1, 1, null,0.1f);
+ if(animation.controller.current == null){
+ animation.controller.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null);
+ }else{
+ animation.controller.animate(animation.animationsIds.get(animation.next), loopCount, 1, null, 0.1f);
+ }
}
if(visibility.visible)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index 000675c..3ba0194 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -15,8 +15,8 @@
*/
package ve.ucv.ciens.ccg.nxtar.utils;
+import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
-import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
public abstract class GameSettings{
@@ -24,7 +24,7 @@ public abstract class GameSettings{
public static GameLogicSystemBase gameLogicSystem = null;
public static void initGameSettings(){
- entityCreator = new MarkerTestEntityCreator();
+ entityCreator = new BombGameEntityCreator();
gameLogicSystem = null;
//gameLogicSystem = new BombGameLogicSystem();
}
From 6ecb373b11bec4ebce5e31d5167cc1e9c00b6c57 Mon Sep 17 00:00:00 2001
From: unknown
Date: Tue, 3 Jun 2014 18:49:52 -0430
Subject: [PATCH 04/34] Added visibility testing for marker objects.
---
.../nxtar/entities/BombGameEntityCreator.java | 161 +++++++++++-------
.../graphics/CustomPerspectiveCamera.java | 39 ++++-
.../ciens/ccg/nxtar/states/InGameState.java | 53 ++----
.../ccg/nxtar/systems/GeometrySystem.java | 4 +-
.../systems/MarkerPositioningSystem.java | 27 ++-
.../nxtar/systems/MarkerRenderingSystem.java | 95 +----------
.../ccg/nxtar/systems/VisibilitySystem.java | 59 -------
7 files changed, 168 insertions(+), 270 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 357f172..d8b9d7a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -18,6 +18,7 @@ package ve.ucv.ciens.ccg.nxtar.entities;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
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.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
@@ -63,21 +64,35 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private EntityParameters parameters;
private Shader shader;
- private Model doorModel;
- private Model doorFrameModel;
- private Model bombModelCombination;
- private Model bombModelInclination;
- private Model bombModelWires;
- private Model bombModelWiresWire1;
- private Model bombModelWiresWire2;
- private Model bombModelWiresWire3;
- private Model easterEggModel;
private int currentBombId;
+ // Render models.
+ private Model doorModel = null;
+ private Model doorFrameModel = null;
+ private Model combinationBombModel = null;
+ private Model inclinationBombModel = null;
+ private Model wiresBombModel = null;
+ private Model wiresBombModelWire1 = null;
+ private Model wiresBombModelWire2 = null;
+ private Model wiresBombModelWire3 = null;
+ private Model easterEggModel = null;
+
+ // Collision models.
+ private Model doorCollisionModel = null;
+ private Model doorFrameCollisionModel = null;
+ private Model combinationBombCollisionModel = null;
+ private Model inclinationBombCollisionModel = null;
+ private Model wiresBombCollisionModel = null;
+ private Model wiresBombCollisionModelWire1 = null;
+ private Model wiresBombCollisionModelWire2 = null;
+ private Model wiresBombCollisionModelWire3 = null;
+ private Model easterEggCollisionModel = null;
+
public BombGameEntityCreator(){
G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
currentBombId = 0;
+ // Create and set the lighting.
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)));
@@ -92,18 +107,27 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
parameters.shader = shader;
- // Create the models.
- // TODO: Set the correct model paths.
- // TODO: Load collision models.
+ // Load the render models.
doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
-// bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
-// bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
- bombModelWires = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
-// easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
- bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
- bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
- bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
+ // bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ // bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
+ wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
+ wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
+ wiresBombModelWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
+ // easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+
+ // Load the collision models.
+ doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
+ doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
+ // combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
+ // inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
+ wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
+ wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
+ wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
+ wiresBombCollisionModelWire3 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_3_col.g3db"));
+ // easterEggCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
}
@Override
@@ -111,11 +135,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// TODO: Add the robot arms.
// Add bombs.
-// parameters.markerCode = 89;
-// addBomb(parameters, bomb_type_t.COMBINATION);
-//
-// parameters.markerCode = 90;
-// addBomb(parameters, bomb_type_t.INCLINATION);
+ // parameters.markerCode = 89;
+ // addBomb(parameters, bomb_type_t.COMBINATION);
+ //
+ // parameters.markerCode = 90;
+ // addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
addBomb(parameters, bomb_type_t.WIRES);
@@ -124,44 +148,48 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters.nextAnimation = 1;
parameters.loopAnimation = false;
-// parameters.markerCode = 89;
-// addDoor(parameters);
-// parameters.markerCode = 90;
-// addDoor(parameters);
+ // parameters.markerCode = 89;
+ // addDoor(parameters);
+ // parameters.markerCode = 90;
+ // addDoor(parameters);
parameters.markerCode = 91;
addDoor(parameters);
+
+ // TODO: Add easter egg.
}
@Override
public void dispose() {
- if(shader != null)
- shader.dispose();
+ if(shader != null) shader.dispose();
- // Dispose of the models.
- if(doorModel != null)
- doorModel.dispose();
- if(doorFrameModel != null)
- doorFrameModel.dispose();
- if(bombModelCombination != null)
- bombModelCombination.dispose();
- if(bombModelInclination != null)
- bombModelInclination.dispose();
- if(bombModelWires != null)
- bombModelWires.dispose();
- if(bombModelWiresWire1 != null)
- bombModelWiresWire1.dispose();
- if(bombModelWiresWire2 != null)
- bombModelWiresWire2.dispose();
- if(bombModelWiresWire3 != null)
- bombModelWiresWire3.dispose();
- if(easterEggModel != null)
- easterEggModel.dispose();
+ // Dispose of the render models.
+ if(doorModel != null) doorModel.dispose();
+ if(doorFrameModel != null) doorFrameModel.dispose();
+ if(combinationBombModel != null) combinationBombModel.dispose();
+ if(inclinationBombModel != null) inclinationBombModel.dispose();
+ if(wiresBombModel != null) wiresBombModel.dispose();
+ if(wiresBombModelWire1 != null) wiresBombModelWire1.dispose();
+ if(wiresBombModelWire2 != null) wiresBombModelWire2.dispose();
+ if(wiresBombModelWire3 != null) wiresBombModelWire3.dispose();
+ if(easterEggModel != null) easterEggModel.dispose();
+
+ // Dispose of the collision models.
+ if(doorCollisionModel != null) doorCollisionModel.dispose();
+ if(doorFrameCollisionModel != null) doorFrameCollisionModel.dispose();
+ if(combinationBombCollisionModel != null) combinationBombCollisionModel.dispose();
+ if(inclinationBombCollisionModel != null) inclinationBombCollisionModel.dispose();
+ if(wiresBombCollisionModel != null) wiresBombCollisionModel.dispose();
+ if(wiresBombCollisionModelWire1 != null) wiresBombCollisionModelWire1.dispose();
+ if(wiresBombCollisionModelWire2 != null) wiresBombCollisionModelWire2.dispose();
+ if(wiresBombCollisionModelWire3 != null) wiresBombCollisionModelWire3.dispose();
+ if(easterEggCollisionModel != null) easterEggCollisionModel.dispose();
}
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb;
BombComponent bombComponent = new BombComponent(currentBombId, type);
+ // Create a bomb entity and add it's generic components.
bomb = world.createEntity();
bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
bomb.addComponent(new EnvironmentComponent(parameters.environment));
@@ -172,28 +200,42 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Add the collision and render models depending on the bomb type.
if(type == bomb_type_t.COMBINATION){
- bomb.addComponent(new RenderModelComponent(bombModelCombination));
+ bomb.addComponent(new RenderModelComponent(combinationBombModel));
+ bomb.addComponent(new CollisionModelComponent(combinationBombCollisionModel));
+ addBombCombinationButtons(parameters, bombComponent);
}else if(type == bomb_type_t.INCLINATION){
- bomb.addComponent(new RenderModelComponent(bombModelInclination));
+ bomb.addComponent(new RenderModelComponent(inclinationBombModel));
+ bomb.addComponent(new CollisionModelComponent(inclinationBombCollisionModel));
+ addBombInclinationButton(parameters, bombComponent);
}else if(type == bomb_type_t.WIRES){
- bomb.addComponent(new RenderModelComponent(bombModelWires));
+ bomb.addComponent(new RenderModelComponent(wiresBombModel));
+ bomb.addComponent(new CollisionModelComponent(wiresBombCollisionModel));
addBombWires(parameters, bombComponent);
}else
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
+ // Add the bomb and increase the id for the next one.
bomb.addToWorld();
currentBombId++;
}
+ private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){
+ // TODO: Add the buttons.
+ }
+
+ private void addBombInclinationButton(EntityParameters parameters, BombComponent bomb){
+ // TODO: Add the button.
+ }
+
private void addBombWires(EntityParameters parameters, BombComponent bomb){
- // TODO: Add collision models.
Entity wire1, wire2, wire3;
wire1 = world.createEntity();
wire1.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
wire1.addComponent(new EnvironmentComponent(parameters.environment));
wire1.addComponent(new ShaderComponent(parameters.shader));
- wire1.addComponent(new RenderModelComponent(bombModelWiresWire1));
+ wire1.addComponent(new RenderModelComponent(wiresBombModelWire1));
+ wire1.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire1));
wire1.addComponent(new BombComponent(bomb));
wire1.addComponent(new VisibilityComponent());
wire1.addComponent(new MarkerCodeComponent(parameters.markerCode));
@@ -203,7 +245,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire2.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
wire2.addComponent(new EnvironmentComponent(parameters.environment));
wire2.addComponent(new ShaderComponent(parameters.shader));
- wire2.addComponent(new RenderModelComponent(bombModelWiresWire2));
+ wire2.addComponent(new RenderModelComponent(wiresBombModelWire2));
+ wire2.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire2));
wire2.addComponent(new BombComponent(bomb));
wire2.addComponent(new VisibilityComponent());
wire2.addComponent(new MarkerCodeComponent(parameters.markerCode));
@@ -213,7 +256,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire3.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
wire3.addComponent(new EnvironmentComponent(parameters.environment));
wire3.addComponent(new ShaderComponent(parameters.shader));
- wire3.addComponent(new RenderModelComponent(bombModelWiresWire3));
+ wire3.addComponent(new RenderModelComponent(wiresBombModelWire3));
+ wire3.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire3));
wire3.addComponent(new BombComponent(bomb));
wire3.addComponent(new VisibilityComponent());
wire3.addComponent(new MarkerCodeComponent(parameters.markerCode));
@@ -221,30 +265,29 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void addDoor(EntityParameters parameters){
- // TODO: Add collision models.
ModelInstance doorInstance;
Entity frame, door;
frame = world.createEntity();
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
frame.addComponent(new RenderModelComponent(doorFrameModel));
+ frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel));
frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
-
frame.addToWorld();
door = world.createEntity();
door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
door.addComponent(new RenderModelComponent(doorModel));
+ door.addComponent(new CollisionModelComponent(doorCollisionModel));
door.addComponent(new EnvironmentComponent(parameters.environment));
door.addComponent(new ShaderComponent(parameters.shader));
door.addComponent(new MarkerCodeComponent(parameters.markerCode));
door.addComponent(new VisibilityComponent());
doorInstance = door.getComponent(RenderModelComponent.class).instance;
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
-
door.addToWorld();
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/CustomPerspectiveCamera.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/CustomPerspectiveCamera.java
index bd0f89d..730e8f2 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/CustomPerspectiveCamera.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/graphics/CustomPerspectiveCamera.java
@@ -27,22 +27,47 @@ public class CustomPerspectiveCamera extends PerspectiveCamera{
private final Vector3 tmp = new Vector3();
public CustomPerspectiveCamera(float fieldOfView, float viewportWidth, float viewportHeight){
- this.fieldOfView = fieldOfView;
- this.viewportWidth = viewportWidth;
- this.viewportHeight = viewportHeight;
+ super(fieldOfView, viewportWidth, viewportHeight);
update();
}
+ public void update(Matrix4 customProjection){
+ this.update(customProjection, true);
+ }
+
public void update(Matrix4 customProjection, boolean updateFrustum){
projection.set(customProjection);
view.setToLookAt(position, tmp.set(position).add(direction), up);
- combined.set(projection);
- Matrix4.mul(combined.val, view.val);
+ combined.set(projection).mul(view);
if(updateFrustum){
- invProjectionView.set(combined);
- Matrix4.inv(invProjectionView.val);
+ invProjectionView.set(combined).inv();
frustum.update(invProjectionView);
}
}
+
+ public void setCustomARProjectionMatrix(final float focalPointX, final float focalPointY, final float cameraCenterX, final float cameraCenterY, final float near, final float far, final float w, final float h){
+ final float FAR_PLUS_NEAR = far + near;
+ final float FAR_LESS_NEAR = far - near;
+
+ projection.val[Matrix4.M00] = -2.0f * focalPointX / w;
+ projection.val[Matrix4.M10] = 0.0f;
+ projection.val[Matrix4.M20] = 0.0f;
+ projection.val[Matrix4.M30] = 0.0f;
+
+ projection.val[Matrix4.M01] = 0.0f;
+ projection.val[Matrix4.M11] = 2.0f * focalPointY / h;
+ projection.val[Matrix4.M21] = 0.0f;
+ projection.val[Matrix4.M31] = 0.0f;
+
+ projection.val[Matrix4.M02] = 2.0f * cameraCenterX / w - 1.0f;
+ projection.val[Matrix4.M12] = 2.0f * cameraCenterY / h - 1.0f;
+ projection.val[Matrix4.M22] = -FAR_PLUS_NEAR / FAR_LESS_NEAR;
+ projection.val[Matrix4.M32] = -1.0f;
+
+ projection.val[Matrix4.M03] = 0.0f;
+ projection.val[Matrix4.M13] = 0.0f;
+ projection.val[Matrix4.M23] = -2.0f * far * near / FAR_LESS_NEAR;
+ projection.val[Matrix4.M33] = 0.0f;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 8a79d63..5aef88a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -27,8 +27,8 @@ import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.ObjectPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.VisibilitySystem;
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -49,7 +49,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
-import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
@@ -59,8 +58,6 @@ public class InGameState extends BaseState{
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
private static final float NEAR = 0.01f;
private static final float FAR = 100.0f;
- private static final float FAR_PLUS_NEAR = FAR + NEAR;
- private static final float FAR_LESS_NEAR = FAR - NEAR;
// Background related fields.
private float uScaling[];
@@ -70,7 +67,6 @@ public class InGameState extends BaseState{
// 3D rendering fields.
private ModelBatch modelBatch;
- private Matrix4 projectionMatrix;
private FrameBuffer frameBuffer;
private Sprite frameBufferSprite;
@@ -176,7 +172,6 @@ public class InGameState extends BaseState{
// Set up the 3D rendering.
modelBatch = new ModelBatch();
- projectionMatrix = new Matrix4().idt();
frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = null;
@@ -189,11 +184,10 @@ public class InGameState extends BaseState{
GameSettings.entityCreator.createAllEntities();
gameWorld.setSystem(new MarkerPositioningSystem());
- // TODO: Make and add positioning systems.
+ gameWorld.setSystem(new ObjectPositioningSystem(), true);
gameWorld.setSystem(new GeometrySystem());
- //gameWorld.setSystem(new VisibilitySystem());
gameWorld.setSystem(new AnimationSystem());
- // TODO: Add collision system.
+ // TODO: Make and add object-marker collision detection system.
//gameWorld.setSystem(GameSettings.gameLogicSystem);
markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
@@ -247,8 +241,6 @@ public class InGameState extends BaseState{
perspectiveCamera.far = FAR;
perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
perspectiveCamera.update();
-
-// gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera);
}
// Attempt to find the markers in the current video frame.
@@ -256,6 +248,14 @@ public class InGameState extends BaseState{
// If a valid frame was fetched.
if(data != null && data.outFrame != null){
+ // Set the camera to the correct projection.
+ focalPointX = core.cvProc.getFocalPointX();
+ focalPointY = core.cvProc.getFocalPointY();
+ cameraCenterX = core.cvProc.getCameraCenterX();
+ cameraCenterY = core.cvProc.getCameraCenterY();
+ perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
+ perspectiveCamera.update(perspectiveCamera.projection);
+
// Update the game state.
gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
@@ -283,37 +283,8 @@ public class InGameState extends BaseState{
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
- // Build the projection matrix.
- focalPointX = core.cvProc.getFocalPointX();
- focalPointY = core.cvProc.getFocalPointY();
- cameraCenterX = core.cvProc.getCameraCenterX();
- cameraCenterY = core.cvProc.getCameraCenterY();
-
- projectionMatrix.val[Matrix4.M00] = -2.0f * focalPointX / w;
- projectionMatrix.val[Matrix4.M10] = 0.0f;
- projectionMatrix.val[Matrix4.M20] = 0.0f;
- projectionMatrix.val[Matrix4.M30] = 0.0f;
-
- projectionMatrix.val[Matrix4.M01] = 0.0f;
- projectionMatrix.val[Matrix4.M11] = 2.0f * focalPointY / h;
- projectionMatrix.val[Matrix4.M21] = 0.0f;
- projectionMatrix.val[Matrix4.M31] = 0.0f;
-
- projectionMatrix.val[Matrix4.M02] = 2.0f * cameraCenterX / w - 1.0f;
- projectionMatrix.val[Matrix4.M12] = 2.0f * cameraCenterY / h - 1.0f;
- projectionMatrix.val[Matrix4.M22] = -FAR_PLUS_NEAR / FAR_LESS_NEAR;
- projectionMatrix.val[Matrix4.M32] = -1.0f;
-
- projectionMatrix.val[Matrix4.M03] = 0.0f;
- projectionMatrix.val[Matrix4.M13] = 0.0f;
- projectionMatrix.val[Matrix4.M23] = -2.0f * FAR * NEAR / FAR_LESS_NEAR;
- projectionMatrix.val[Matrix4.M33] = 0.0f;
-
- // Set rendering parameters.
- perspectiveCamera.update(projectionMatrix, true);
-
// Call rendering systems.
- markerRenderingSystem.begin(perspectiveCamera, data);
+ markerRenderingSystem.begin(perspectiveCamera);
markerRenderingSystem.process();
markerRenderingSystem.end();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java
index fb547bb..781ccd3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/GeometrySystem.java
@@ -28,8 +28,8 @@ import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.math.Matrix4;
public class GeometrySystem extends EntityProcessingSystem {
- @Mapper ComponentMapper geometryMapper;
- @Mapper ComponentMapper renderModelMapper;
+ @Mapper ComponentMapper geometryMapper;
+ @Mapper ComponentMapper renderModelMapper;
@Mapper ComponentMapper colModelMapper;
/**
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
index bfde1da..8f71a94 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
@@ -17,6 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -25,20 +26,17 @@ import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
-import com.badlogic.gdx.Gdx;
public class MarkerPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper markerMapper;
- @Mapper ComponentMapper geometryMapper;
-
- private static final String TAG = "MARKER_POSITIONING_SYSTEM";
- private static final String CLASS_NAME = MarkerPositioningSystem.class.getSimpleName();
+ @Mapper ComponentMapper geometryMapper;
+ @Mapper ComponentMapper visibilityMapper;
private MarkerData markers;
@SuppressWarnings("unchecked")
public MarkerPositioningSystem(){
- super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class));
+ super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, VisibilityComponent.class));
markers = null;
}
@@ -51,26 +49,25 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
protected void process(Entity e) {
MarkerCodeComponent marker;
GeometryComponent geometry;
+ VisibilityComponent visibility;
if(markers == null)
return;
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
- marker = markerMapper.get(e);
- geometry = geometryMapper.get(e);
+ marker = markerMapper.get(e);
+ geometry = geometryMapper.get(e);
+ visibility = visibilityMapper.get(e);
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
if(markers.markerCodes[i] != 1){
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Checking marker code: " + Integer.toString(markers.markerCodes[i]));
- Gdx.app.log(TAG, CLASS_NAME + ".process(): This entity's code is: " + Integer.toString(marker.code));
if(markers.markerCodes[i] == marker.code){
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing marker code " + Integer.toString(markers.markerCodes[i]) + ".");
geometry.position.set(markers.translationVectors[i]);
geometry.rotation.set(markers.rotationMatrices[i]);
+ visibility.visible = true;
+ break;
+ }else{
+ visibility.visible = false;
}
- }else{
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
index b89bdb6..968766a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
@@ -16,74 +16,40 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
-import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
-import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
-import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import com.artemis.Aspect;
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.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
public class MarkerRenderingSystem extends EntityProcessingSystem {
- @Mapper ComponentMapper markerMapper;
-// @Mapper ComponentMapper geometryMapper;
+ // @Mapper ComponentMapper markerMapper;
@Mapper ComponentMapper modelMapper;
@Mapper ComponentMapper environmentMapper;
@Mapper ComponentMapper shaderMapper;
@Mapper ComponentMapper visibiltyMapper;
- private static final String TAG = "MODEL_BATCH_MARKER_RENDERING_SYSTEM";
- private static final String CLASS_NAME = MarkerRenderingSystem.class.getSimpleName();
-
- /**
- * A matrix representing 3D translations.
- */
- //private Matrix4 translationMatrix;
-
- /**
- * A matrix representing 3D rotations.
- */
- //private Matrix4 rotationMatrix;
-
- /**
- * A matrix representing 3D scalings.
- */
- //private Matrix4 scalingMatrix;
-
- private MarkerData markers;
-
private PerspectiveCamera camera;
-
private ModelBatch batch;
@SuppressWarnings("unchecked")
public MarkerRenderingSystem(ModelBatch batch){
- super(Aspect.getAspectForAll(MarkerCodeComponent.class, /*GeometryComponent.class,*/ ShaderComponent.class, EnvironmentComponent.class, RenderModelComponent.class, VisibilityComponent.class));
+ super(Aspect.getAspectForAll(ShaderComponent.class, EnvironmentComponent.class, RenderModelComponent.class, VisibilityComponent.class));
- markers = null;
- camera = null;
- this.batch = batch;
-// translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
-// rotationMatrix = new Matrix4().idt();
-// scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
+ camera = null;
+ this.batch = batch;
}
- public void begin(PerspectiveCamera camera, MarkerData markers) throws RuntimeException{
+ public void begin(PerspectiveCamera camera) throws RuntimeException{
if(this.camera != null)
throw new RuntimeException("Begin called twice without calling end.");
- if(this.markers != null)
- throw new RuntimeException("Begin called twice without calling end.");
-
- this.markers = markers;
this.camera = camera;
batch.begin(camera);
}
@@ -91,71 +57,26 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
public void end(){
batch.end();
camera = null;
- markers = null;
}
@Override
protected void process(Entity e) {
- MarkerCodeComponent marker;
-// GeometryComponent geometry;
EnvironmentComponent environment;
RenderModelComponent model;
ShaderComponent shader;
VisibilityComponent visibility;
- if(markers == null || camera == null)
+ if(camera == null)
return;
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
- marker = markerMapper.get(e);
-// geometry = geometryMapper.get(e);
model = modelMapper.get(e);
environment = environmentMapper.get(e);
shader = shaderMapper.get(e);
visibility = visibiltyMapper.get(e);
if(visibility.visible){
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
- for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
- if(markers.markerCodes[i] != 1){
- if(markers.markerCodes[i] == marker.code){
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
- // Set the geometric transformations.
-// translationMatrix.setToTranslation(geometry.position);
-//
-// rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
-// rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
-// rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
-// rotationMatrix.val[Matrix4.M30] = 0;
-//
-// rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
-// rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
-// rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
-// rotationMatrix.val[Matrix4.M31] = 0;
-//
-// rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
-// rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
-// rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
-// rotationMatrix.val[Matrix4.M32] = 0;
-//
-// rotationMatrix.val[Matrix4.M03] = 0;
-// rotationMatrix.val[Matrix4.M13] = 0;
-// rotationMatrix.val[Matrix4.M23] = 0;
-// rotationMatrix.val[Matrix4.M33] = 1;
-//
-// scalingMatrix.setToScaling(geometry.scaling);
-//
-// // Apply the geometric transformations to the model.
-// model.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
-// model.instance.calculateTransforms();
-
- // Render the marker;
- batch.render(model.instance, environment.environment, shader.shader);
- }
- }else{
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
- }
- }
+ // Render the marker;
+ batch.render(model.instance, environment.environment, shader.shader);
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java
deleted file mode 100644
index 7ae8d3c..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/VisibilitySystem.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.systems;
-
-import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
-import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
-import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
-
-import com.artemis.Aspect;
-import com.artemis.ComponentMapper;
-import com.artemis.Entity;
-import com.artemis.annotations.Mapper;
-import com.artemis.systems.EntityProcessingSystem;
-import com.badlogic.gdx.graphics.PerspectiveCamera;
-import com.badlogic.gdx.math.collision.BoundingBox;
-
-public class VisibilitySystem extends EntityProcessingSystem {
- @Mapper ComponentMapper visibilityMapper;
- @Mapper ComponentMapper geometryMapper;
- @Mapper ComponentMapper collisionMapper;
-
- private PerspectiveCamera camera;
-
- @SuppressWarnings("unchecked")
- public VisibilitySystem(){
- super(Aspect.getAspectForAll(VisibilityComponent.class, CollisionModelComponent.class));
- this.camera = null;
- }
-
- public void setCamera(PerspectiveCamera camera){
- this.camera = camera;
- }
-
- @Override
- protected void process(Entity e){
- VisibilityComponent visibility = visibilityMapper.get(e);
- CollisionModelComponent colModel = collisionMapper.get(e);
- BoundingBox bBox = new BoundingBox();
-
- if(camera != null){
- colModel.instance.calculateBoundingBox(bBox);
- bBox.mul(colModel.instance.transform);
- visibility.visible = camera.frustum.boundsInFrustum(bBox);
- }
- }
-}
From a798cce715d371a1591a669c0d1b301dc9ca1265 Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 4 Jun 2014 16:29:31 -0430
Subject: [PATCH 05/34] Added rendering of the inclination bomb.
---
.../nxtar/entities/BombGameEntityCreator.java | 82 +++++++++++--------
.../systems/ObjectPositioningSystem.java | 44 ++++++++++
2 files changed, 92 insertions(+), 34 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index d8b9d7a..8ae9f8c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -71,6 +71,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model doorFrameModel = null;
private Model combinationBombModel = null;
private Model inclinationBombModel = null;
+ private Model inclinationBombButtonModel = null;
private Model wiresBombModel = null;
private Model wiresBombModelWire1 = null;
private Model wiresBombModelWire2 = null;
@@ -78,15 +79,16 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model easterEggModel = null;
// Collision models.
- private Model doorCollisionModel = null;
- private Model doorFrameCollisionModel = null;
- private Model combinationBombCollisionModel = null;
- private Model inclinationBombCollisionModel = null;
- private Model wiresBombCollisionModel = null;
- private Model wiresBombCollisionModelWire1 = null;
- private Model wiresBombCollisionModelWire2 = null;
- private Model wiresBombCollisionModelWire3 = null;
- private Model easterEggCollisionModel = null;
+ private Model doorCollisionModel = null;
+ private Model doorFrameCollisionModel = null;
+ private Model combinationBombCollisionModel = null;
+ private Model inclinationBombCollisionModel = null;
+ private Model inclinationBombButtonCollisionModel = null;
+ private Model wiresBombCollisionModel = null;
+ private Model wiresBombCollisionModelWire1 = null;
+ private Model wiresBombCollisionModelWire2 = null;
+ private Model wiresBombCollisionModelWire3 = null;
+ private Model easterEggCollisionModel = null;
public BombGameEntityCreator(){
G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
@@ -108,26 +110,28 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters.shader = shader;
// Load the render models.
- doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
- doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
- // bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
- // bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
- wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
- wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
- wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
- wiresBombModelWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
- // easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
+ doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
+ // bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ inclinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_2_body.g3db"));
+ inclinationBombButtonModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/big_btn.g3db"));
+ wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
+ wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
+ wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
+ wiresBombModelWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
+ // easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
// Load the collision models.
- doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
- doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
- // combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
- // inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
- wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
- wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
- wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
- wiresBombCollisionModelWire3 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_3_col.g3db"));
- // easterEggCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
+ doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
+ doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
+ // combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
+ inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_2_body_col.g3db"));
+ inclinationBombButtonCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/big_btn_col.g3db"));
+ wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
+ wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
+ wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
+ wiresBombCollisionModelWire3 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_3_col.g3db"));
+ // easterEggCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
}
@Override
@@ -137,10 +141,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Add bombs.
// parameters.markerCode = 89;
// addBomb(parameters, bomb_type_t.COMBINATION);
- //
- // parameters.markerCode = 90;
- // addBomb(parameters, bomb_type_t.INCLINATION);
+ parameters.markerCode = 90;
+ addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
addBomb(parameters, bomb_type_t.WIRES);
@@ -150,11 +153,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// parameters.markerCode = 89;
// addDoor(parameters);
- // parameters.markerCode = 90;
- // addDoor(parameters);
+ parameters.markerCode = 90;
+ addDoor(parameters);
parameters.markerCode = 91;
addDoor(parameters);
-
+
// TODO: Add easter egg.
}
@@ -224,7 +227,18 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void addBombInclinationButton(EntityParameters parameters, BombComponent bomb){
- // TODO: Add the button.
+ Entity button;
+
+ button = world.createEntity();
+ button.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ button.addComponent(new EnvironmentComponent(parameters.environment));
+ button.addComponent(new ShaderComponent(parameters.shader));
+ button.addComponent(new RenderModelComponent(inclinationBombButtonModel));
+ button.addComponent(new CollisionModelComponent(inclinationBombButtonCollisionModel));
+ button.addComponent(new BombComponent(bomb));
+ button.addComponent(new VisibilityComponent());
+ button.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ button.addToWorld();
}
private void addBombWires(EntityParameters parameters, BombComponent bomb){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java
new file mode 100644
index 0000000..624cbce
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java
@@ -0,0 +1,44 @@
+/*
+ * 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.systems;
+
+import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
+
+import com.artemis.Aspect;
+import com.artemis.ComponentMapper;
+import com.artemis.Entity;
+import com.artemis.annotations.Mapper;
+import com.artemis.systems.EntityProcessingSystem;
+
+public class ObjectPositioningSystem extends EntityProcessingSystem {
+ @Mapper ComponentMapper geometryMapper;
+
+ @SuppressWarnings("unchecked")
+ public ObjectPositioningSystem(){
+ super(Aspect.getAspectForAll(GeometryComponent.class));
+ }
+
+ public void setUserInput(){
+ // TODO: Desing a representation for user input.
+ // TODO: Store user input for processing.
+ }
+
+ @Override
+ protected void process(Entity e) {
+ GeometryComponent geometry = geometryMapper.get(e);
+ // TODO: Set the geometry fields based on user input.
+ }
+}
From fbb03f884e0471327664c5b1a5c5647a9989c463 Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 4 Jun 2014 16:53:35 -0430
Subject: [PATCH 06/34] Simplified some functions.
---
.../nxtar/entities/BombGameEntityCreator.java | 65 ++++++++-----------
1 file changed, 26 insertions(+), 39 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 8ae9f8c..dcbb7c8 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -141,7 +141,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Add bombs.
// parameters.markerCode = 89;
// addBomb(parameters, bomb_type_t.COMBINATION);
-
parameters.markerCode = 90;
addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
@@ -229,55 +228,43 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addBombInclinationButton(EntityParameters parameters, BombComponent bomb){
Entity button;
- button = world.createEntity();
- button.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- button.addComponent(new EnvironmentComponent(parameters.environment));
- button.addComponent(new ShaderComponent(parameters.shader));
- button.addComponent(new RenderModelComponent(inclinationBombButtonModel));
- button.addComponent(new CollisionModelComponent(inclinationBombButtonCollisionModel));
- button.addComponent(new BombComponent(bomb));
- button.addComponent(new VisibilityComponent());
- button.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ button = addBombParaphernalia(inclinationBombButtonModel, inclinationBombButtonCollisionModel, bomb, parameters);
+
+ // TODO: Add button parameters.
+
button.addToWorld();
}
private void addBombWires(EntityParameters parameters, BombComponent bomb){
Entity wire1, wire2, wire3;
- wire1 = world.createEntity();
- wire1.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- wire1.addComponent(new EnvironmentComponent(parameters.environment));
- wire1.addComponent(new ShaderComponent(parameters.shader));
- wire1.addComponent(new RenderModelComponent(wiresBombModelWire1));
- wire1.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire1));
- wire1.addComponent(new BombComponent(bomb));
- wire1.addComponent(new VisibilityComponent());
- wire1.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ wire1 = addBombParaphernalia(wiresBombModelWire1, wiresBombCollisionModelWire1, bomb, parameters);
+ wire2 = addBombParaphernalia(wiresBombModelWire2, wiresBombCollisionModelWire2, bomb, parameters);
+ wire3 = addBombParaphernalia(wiresBombModelWire3, wiresBombCollisionModelWire3, bomb, parameters);
+
+ // TODO: Add Wire parameters.
+
wire1.addToWorld();
-
- wire2 = world.createEntity();
- wire2.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- wire2.addComponent(new EnvironmentComponent(parameters.environment));
- wire2.addComponent(new ShaderComponent(parameters.shader));
- wire2.addComponent(new RenderModelComponent(wiresBombModelWire2));
- wire2.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire2));
- wire2.addComponent(new BombComponent(bomb));
- wire2.addComponent(new VisibilityComponent());
- wire2.addComponent(new MarkerCodeComponent(parameters.markerCode));
wire2.addToWorld();
-
- wire3 = world.createEntity();
- wire3.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
- wire3.addComponent(new EnvironmentComponent(parameters.environment));
- wire3.addComponent(new ShaderComponent(parameters.shader));
- wire3.addComponent(new RenderModelComponent(wiresBombModelWire3));
- wire3.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire3));
- wire3.addComponent(new BombComponent(bomb));
- wire3.addComponent(new VisibilityComponent());
- wire3.addComponent(new MarkerCodeComponent(parameters.markerCode));
wire3.addToWorld();
}
+ private Entity addBombParaphernalia(Model renderModel, Model collisionModel, BombComponent bomb, EntityParameters parameters){
+ Entity thing;
+
+ thing = world.createEntity();
+ thing.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ thing.addComponent(new EnvironmentComponent(parameters.environment));
+ thing.addComponent(new ShaderComponent(parameters.shader));
+ thing.addComponent(new RenderModelComponent(renderModel));
+ thing.addComponent(new CollisionModelComponent(collisionModel));
+ thing.addComponent(new BombComponent(bomb));
+ thing.addComponent(new VisibilityComponent());
+ thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
+
+ return thing;
+ }
+
private void addDoor(EntityParameters parameters){
ModelInstance doorInstance;
Entity frame, door;
From 2b14a080b4cde2e2353a5a67d6d0ed87ccaa0c5e Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 5 Jun 2014 18:15:17 -0430
Subject: [PATCH 07/34] All bomb types successfully loaded and rendered.
---
.../nxtar/entities/BombGameEntityCreator.java | 92 ++++++++++++++-----
1 file changed, 67 insertions(+), 25 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index dcbb7c8..70bf72a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -70,6 +70,10 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model doorModel = null;
private Model doorFrameModel = null;
private Model combinationBombModel = null;
+ private Model combinationButton1Model = null;
+ private Model combinationButton2Model = null;
+ private Model combinationButton3Model = null;
+ private Model combinationButton4Model = null;
private Model inclinationBombModel = null;
private Model inclinationBombButtonModel = null;
private Model wiresBombModel = null;
@@ -82,6 +86,10 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model doorCollisionModel = null;
private Model doorFrameCollisionModel = null;
private Model combinationBombCollisionModel = null;
+ private Model combinationButton1CollisionModel = null;
+ private Model combinationButton2CollisionModel = null;
+ private Model combinationButton3CollisionModel = null;
+ private Model combinationButton4CollisionModel = null;
private Model inclinationBombCollisionModel = null;
private Model inclinationBombButtonCollisionModel = null;
private Model wiresBombCollisionModel = null;
@@ -112,9 +120,16 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Load the render models.
doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
- // bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+
+ combinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_body.g3db"));
+ combinationButton1Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_1.g3db"));
+ combinationButton2Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_2.g3db"));
+ combinationButton3Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_3.g3db"));
+ combinationButton4Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_4.g3db"));
+
inclinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_2_body.g3db"));
inclinationBombButtonModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/big_btn.g3db"));
+
wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
@@ -124,9 +139,16 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Load the collision models.
doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
- // combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
+
+ combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_body_col.g3db"));
+ combinationButton1CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db"));
+ combinationButton2CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db"));
+ combinationButton3CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db"));
+ combinationButton4CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db"));
+
inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_2_body_col.g3db"));
inclinationBombButtonCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/big_btn_col.g3db"));
+
wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
@@ -139,8 +161,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// TODO: Add the robot arms.
// Add bombs.
- // parameters.markerCode = 89;
- // addBomb(parameters, bomb_type_t.COMBINATION);
+ parameters.markerCode = 89;
+ addBomb(parameters, bomb_type_t.COMBINATION);
parameters.markerCode = 90;
addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
@@ -150,8 +172,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters.nextAnimation = 1;
parameters.loopAnimation = false;
- // parameters.markerCode = 89;
- // addDoor(parameters);
+ parameters.markerCode = 89;
+ addDoor(parameters);
parameters.markerCode = 90;
addDoor(parameters);
parameters.markerCode = 91;
@@ -165,26 +187,34 @@ public class BombGameEntityCreator extends EntityCreatorBase{
if(shader != null) shader.dispose();
// Dispose of the render models.
- if(doorModel != null) doorModel.dispose();
- if(doorFrameModel != null) doorFrameModel.dispose();
- if(combinationBombModel != null) combinationBombModel.dispose();
- if(inclinationBombModel != null) inclinationBombModel.dispose();
- if(wiresBombModel != null) wiresBombModel.dispose();
- if(wiresBombModelWire1 != null) wiresBombModelWire1.dispose();
- if(wiresBombModelWire2 != null) wiresBombModelWire2.dispose();
- if(wiresBombModelWire3 != null) wiresBombModelWire3.dispose();
- if(easterEggModel != null) easterEggModel.dispose();
+ if(doorModel != null) doorModel.dispose();
+ if(doorFrameModel != null) doorFrameModel.dispose();
+ if(combinationBombModel != null) combinationBombModel.dispose();
+ if(combinationButton1Model != null) combinationButton1Model.dispose();
+ if(combinationButton2Model != null) combinationButton2Model.dispose();
+ if(combinationButton3Model != null) combinationButton3Model.dispose();
+ if(combinationButton4Model != null) combinationButton4Model.dispose();
+ if(inclinationBombModel != null) inclinationBombModel.dispose();
+ if(wiresBombModel != null) wiresBombModel.dispose();
+ if(wiresBombModelWire1 != null) wiresBombModelWire1.dispose();
+ if(wiresBombModelWire2 != null) wiresBombModelWire2.dispose();
+ if(wiresBombModelWire3 != null) wiresBombModelWire3.dispose();
+ if(easterEggModel != null) easterEggModel.dispose();
// Dispose of the collision models.
- if(doorCollisionModel != null) doorCollisionModel.dispose();
- if(doorFrameCollisionModel != null) doorFrameCollisionModel.dispose();
- if(combinationBombCollisionModel != null) combinationBombCollisionModel.dispose();
- if(inclinationBombCollisionModel != null) inclinationBombCollisionModel.dispose();
- if(wiresBombCollisionModel != null) wiresBombCollisionModel.dispose();
- if(wiresBombCollisionModelWire1 != null) wiresBombCollisionModelWire1.dispose();
- if(wiresBombCollisionModelWire2 != null) wiresBombCollisionModelWire2.dispose();
- if(wiresBombCollisionModelWire3 != null) wiresBombCollisionModelWire3.dispose();
- if(easterEggCollisionModel != null) easterEggCollisionModel.dispose();
+ if(doorCollisionModel != null) doorCollisionModel.dispose();
+ if(doorFrameCollisionModel != null) doorFrameCollisionModel.dispose();
+ if(combinationBombCollisionModel != null) combinationBombCollisionModel.dispose();
+ if(combinationButton1CollisionModel != null) combinationButton1CollisionModel.dispose();
+ if(combinationButton2CollisionModel != null) combinationButton2CollisionModel.dispose();
+ if(combinationButton3CollisionModel != null) combinationButton3CollisionModel.dispose();
+ if(combinationButton4CollisionModel != null) combinationButton4CollisionModel.dispose();
+ if(inclinationBombCollisionModel != null) inclinationBombCollisionModel.dispose();
+ if(wiresBombCollisionModel != null) wiresBombCollisionModel.dispose();
+ if(wiresBombCollisionModelWire1 != null) wiresBombCollisionModelWire1.dispose();
+ if(wiresBombCollisionModelWire2 != null) wiresBombCollisionModelWire2.dispose();
+ if(wiresBombCollisionModelWire3 != null) wiresBombCollisionModelWire3.dispose();
+ if(easterEggCollisionModel != null) easterEggCollisionModel.dispose();
}
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
@@ -222,7 +252,19 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){
- // TODO: Add the buttons.
+ Entity button1, button2, button3, button4;
+
+ button1 = addBombParaphernalia(combinationButton1Model, combinationButton1CollisionModel, bomb, parameters);
+ button2 = addBombParaphernalia(combinationButton2Model, combinationButton2CollisionModel, bomb, parameters);
+ button3 = addBombParaphernalia(combinationButton3Model, combinationButton3CollisionModel, bomb, parameters);
+ button4 = addBombParaphernalia(combinationButton4Model, combinationButton4CollisionModel, bomb, parameters);
+
+ // TODO: Add button parameters.
+
+ button1.addToWorld();
+ button2.addToWorld();
+ button3.addToWorld();
+ button4.addToWorld();
}
private void addBombInclinationButton(EntityParameters parameters, BombComponent bomb){
From be5ae2955e0267cc1987b92d32a5af9354698947 Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 5 Jun 2014 18:46:39 -0430
Subject: [PATCH 08/34] Added code to debug the collision models.
---
.../nxtar/entities/BombGameEntityCreator.java | 42 ++++++++++++++++++-
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 70bf72a..337c08c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -43,8 +43,11 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.UBJsonReader;
public class BombGameEntityCreator extends EntityCreatorBase{
- private static final String TAG = "BOMB_ENTITY_CREATOR";
- private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName();
+ private static final String TAG = "BOMB_ENTITY_CREATOR";
+ private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName();
+ private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false;
+ private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
+ private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
private class EntityParameters{
public Environment environment;
@@ -235,14 +238,23 @@ public class BombGameEntityCreator extends EntityCreatorBase{
bomb.addComponent(new RenderModelComponent(combinationBombModel));
bomb.addComponent(new CollisionModelComponent(combinationBombCollisionModel));
addBombCombinationButtons(parameters, bombComponent);
+ if(DEBUG_RENDER_BOMB_COLLISION_MODELS)
+ addDebugCollisionModelRenderingEntity(combinationBombCollisionModel, parameters, false);
+
}else if(type == bomb_type_t.INCLINATION){
bomb.addComponent(new RenderModelComponent(inclinationBombModel));
bomb.addComponent(new CollisionModelComponent(inclinationBombCollisionModel));
addBombInclinationButton(parameters, bombComponent);
+ if(DEBUG_RENDER_BOMB_COLLISION_MODELS)
+ addDebugCollisionModelRenderingEntity(inclinationBombCollisionModel, parameters, false);
+
}else if(type == bomb_type_t.WIRES){
bomb.addComponent(new RenderModelComponent(wiresBombModel));
bomb.addComponent(new CollisionModelComponent(wiresBombCollisionModel));
addBombWires(parameters, bombComponent);
+ if(DEBUG_RENDER_BOMB_COLLISION_MODELS)
+ addDebugCollisionModelRenderingEntity(wiresBombCollisionModel, parameters, false);
+
}else
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
@@ -304,6 +316,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new VisibilityComponent());
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
+ addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
+
return thing;
}
@@ -332,5 +347,28 @@ public class BombGameEntityCreator extends EntityCreatorBase{
doorInstance = door.getComponent(RenderModelComponent.class).instance;
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
door.addToWorld();
+
+ if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
+ addDebugCollisionModelRenderingEntity(doorFrameCollisionModel, parameters, false);
+ addDebugCollisionModelRenderingEntity(doorCollisionModel, parameters, true);
+ }
+ }
+
+ private void addDebugCollisionModelRenderingEntity(Model collisionModel, EntityParameters parameters, boolean animation){
+ ModelInstance instance;
+ Entity thing;
+
+ thing = world.createEntity();
+ thing.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ thing.addComponent(new EnvironmentComponent(parameters.environment));
+ thing.addComponent(new ShaderComponent(parameters.shader));
+ thing.addComponent(new RenderModelComponent(collisionModel));
+ thing.addComponent(new VisibilityComponent());
+ thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ if(animation){
+ instance = thing.getComponent(RenderModelComponent.class).instance;
+ thing.addComponent(new AnimationComponent(instance, parameters.nextAnimation, parameters.loopAnimation));
+ }
+ thing.addToWorld();
}
}
From 4cba697f5738282efc4a2b45956f18436c237cc3 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 6 Jun 2014 11:41:58 -0430
Subject: [PATCH 09/34] Bomb game assets loaded with asset manager. Camera
calibration is automagic.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 51 +++---
.../nxtar/entities/BombGameEntityCreator.java | 155 +++++++++++-------
.../ccg/nxtar/entities/EntityCreatorBase.java | 51 +++++-
.../entities/MarkerTestEntityCreator.java | 12 +-
.../interfaces/ApplicationEventsListener.java | 20 ++-
.../ccg/nxtar/network/RobotControlThread.java | 2 +-
.../ccg/nxtar/network/SensorReportThread.java | 2 +-
.../nxtar/network/VideoStreamingThread.java | 2 +-
.../nxtar/states/CameraCalibrationState.java | 16 +-
.../ciens/ccg/nxtar/states/InGameState.java | 9 +-
.../ccg/nxtar/states/MainMenuStateBase.java | 21 ++-
.../ciens/ccg/nxtar/utils/GameSettings.java | 47 +++++-
12 files changed, 274 insertions(+), 114 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 315e89d..427bfa3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
import ve.ucv.ciens.ccg.nxtar.states.PauseState;
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 aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenEquations;
@@ -121,7 +122,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
/**
* Wrapper around the Operating System methods.
*/
- private ActionResolver osFunction;
+ private ActionResolver actionResolver;
// Networking related fields.
/**
@@ -206,10 +207,10 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
// Check if the concrete application implements all required interfaces.
try{
- this.osFunction = (ActionResolver)concreteApp;
+ this.actionResolver = (ActionResolver)concreteApp;
}catch(ClassCastException cc){
Gdx.app.debug(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the Toaster interface. Toasting disabled.");
- this.osFunction = null;
+ this.actionResolver = null;
}
try{
@@ -229,6 +230,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* sets the application states.
*/
public void create(){
+ GameSettings.initGameSettings(this);
+
// Create the state objects.
states = new BaseState[game_states_t.getNumStates()];
if(Ouya.runningOnOuya)
@@ -268,7 +271,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
// Start networking.
- osFunction.enableMulticast();
+ actionResolver.enableMulticast();
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
@@ -327,6 +330,10 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
public void render(){
super.render();
+ // Load the assets.
+ if(!GameSettings.getEntityCreator().areEntitiesCreated())
+ GameSettings.getEntityCreator().updateAssetManager();
+
// If the current state set a value for nextState then switch to that state.
if(nextState != null){
states[currState.getValue()].onStateUnset();
@@ -430,6 +437,9 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
font.dispose();
}
+ if(GameSettings.getEntityCreator() != null)
+ GameSettings.getEntityCreator().dispose();
+
// Dispose screens.
for(int i = 0; i < states.length; i++){
states[i].dispose();
@@ -440,29 +450,32 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
; APPLICATION EVENTS LISTENER INTERFACE METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
- // TODO: Disable start game button until camera has been sucessfully calibrated.
- // TODO: Add calibration listener callback.
-
- /**
- * Callback used by the networking threads to notify sucessfull connections
- * to the application
- *
- * @param streamName The name of the thread notifying a connection.
- */
@Override
- public synchronized void networkStreamConnected(String streamName){
+ public synchronized void onNetworkStreamConnected(String streamName){
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");
connections += 1;
if(connections >= 3){
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
serviceDiscoveryThread.finish();
- osFunction.disableMulticast();
- osFunction.showShortToast("Client connected");
+ if(actionResolver != null) actionResolver.disableMulticast();
+ if(actionResolver != null) actionResolver.showShortToast("Client connected");
((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onClientConnected();
}
}
+ @Override
+ public void onAssetsLoaded(){
+ if(actionResolver != null) actionResolver.showShortToast("All assets sucessfully loaded.");
+ ((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onAssetsLoaded();
+ }
+
+ @Override
+ public void onCameraCalibrated(){
+ if(actionResolver != null) actionResolver.showShortToast("Camera successfully calibrated.");
+ ((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onCameraCalibrated();
+ }
+
/*;;;;;;;;;;;;;;;;;;
; HELPER METHODS ;
;;;;;;;;;;;;;;;;;;*/
@@ -474,9 +487,9 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* @param longToast True for a lasting toast. False for a short toast.
*/
public void toast(String msg, boolean longToast){
- if(osFunction != null){
- if(longToast) osFunction.showLongToast(msg);
- else osFunction.showShortToast(msg);
+ if(actionResolver != null){
+ if(longToast) actionResolver.showLongToast(msg);
+ else actionResolver.showShortToast(msg);
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 337c08c..8de8349 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import com.artemis.Entity;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
@@ -36,11 +37,9 @@ import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
import com.badlogic.gdx.math.Matrix3;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
-import com.badlogic.gdx.utils.UBJsonReader;
public class BombGameEntityCreator extends EntityCreatorBase{
private static final String TAG = "BOMB_ENTITY_CREATOR";
@@ -83,7 +82,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model wiresBombModelWire1 = null;
private Model wiresBombModelWire2 = null;
private Model wiresBombModelWire3 = null;
- private Model easterEggModel = null;
+ // private Model easterEggModel = null;
// Collision models.
private Model doorCollisionModel = null;
@@ -99,11 +98,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model wiresBombCollisionModelWire1 = null;
private Model wiresBombCollisionModelWire2 = null;
private Model wiresBombCollisionModelWire3 = null;
- private Model easterEggCollisionModel = null;
+ // private Model easterEggCollisionModel = null;
public BombGameEntityCreator(){
- G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
currentBombId = 0;
+ manager = new AssetManager();
// Create and set the lighting.
parameters = new EntityParameters();
@@ -121,42 +120,42 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters.shader = shader;
// Load the render models.
- doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
- doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
+ manager.load("models/render_models/bomb_game/door.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/door_frame1.g3db", Model.class);
- combinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_body.g3db"));
- combinationButton1Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_1.g3db"));
- combinationButton2Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_2.g3db"));
- combinationButton3Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_3.g3db"));
- combinationButton4Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_4.g3db"));
+ manager.load("models/render_models/bomb_game/bomb_3_body.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/bomb_3_btn_1.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/bomb_3_btn_2.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/bomb_3_btn_3.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/bomb_3_btn_4.g3db", Model.class);
- inclinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_2_body.g3db"));
- inclinationBombButtonModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/big_btn.g3db"));
+ manager.load("models/render_models/bomb_game/bomb_2_body.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/big_btn.g3db", Model.class);
- wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
- wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
- wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
- wiresBombModelWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
- // easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
+ manager.load("models/render_models/bomb_game/bomb_1_body.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/cable_1.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/cable_2.g3db", Model.class);
+ manager.load("models/render_models/bomb_game/cable_3.g3db", Model.class);
+ // manager.load("models/render_models/bomb_game/", Model.class);
// Load the collision models.
- doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
- doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
+ manager.load("models/collision_models/bomb_game/door_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
- combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_body_col.g3db"));
- combinationButton1CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db"));
- combinationButton2CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db"));
- combinationButton3CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db"));
- combinationButton4CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db"));
+ manager.load("models/collision_models/bomb_game/bomb_3_body_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db", Model.class);
- inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_2_body_col.g3db"));
- inclinationBombButtonCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/big_btn_col.g3db"));
+ manager.load("models/collision_models/bomb_game/bomb_2_body_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/big_btn_col.g3db", Model.class);
- wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
- wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
- wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
- wiresBombCollisionModelWire3 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_3_col.g3db"));
- // easterEggCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
+ manager.load("models/collision_models/bomb_game/bomb_1_body_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/cable_1_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/cable_2_col.g3db", Model.class);
+ manager.load("models/collision_models/bomb_game/cable_3_col.g3db", Model.class);
+ // manager.load("models/collision_models/bomb_game/door.g3db", Model.class);
}
@Override
@@ -183,41 +182,14 @@ public class BombGameEntityCreator extends EntityCreatorBase{
addDoor(parameters);
// TODO: Add easter egg.
+
+ entitiesCreated = true;
}
@Override
public void dispose() {
if(shader != null) shader.dispose();
-
- // Dispose of the render models.
- if(doorModel != null) doorModel.dispose();
- if(doorFrameModel != null) doorFrameModel.dispose();
- if(combinationBombModel != null) combinationBombModel.dispose();
- if(combinationButton1Model != null) combinationButton1Model.dispose();
- if(combinationButton2Model != null) combinationButton2Model.dispose();
- if(combinationButton3Model != null) combinationButton3Model.dispose();
- if(combinationButton4Model != null) combinationButton4Model.dispose();
- if(inclinationBombModel != null) inclinationBombModel.dispose();
- if(wiresBombModel != null) wiresBombModel.dispose();
- if(wiresBombModelWire1 != null) wiresBombModelWire1.dispose();
- if(wiresBombModelWire2 != null) wiresBombModelWire2.dispose();
- if(wiresBombModelWire3 != null) wiresBombModelWire3.dispose();
- if(easterEggModel != null) easterEggModel.dispose();
-
- // Dispose of the collision models.
- if(doorCollisionModel != null) doorCollisionModel.dispose();
- if(doorFrameCollisionModel != null) doorFrameCollisionModel.dispose();
- if(combinationBombCollisionModel != null) combinationBombCollisionModel.dispose();
- if(combinationButton1CollisionModel != null) combinationButton1CollisionModel.dispose();
- if(combinationButton2CollisionModel != null) combinationButton2CollisionModel.dispose();
- if(combinationButton3CollisionModel != null) combinationButton3CollisionModel.dispose();
- if(combinationButton4CollisionModel != null) combinationButton4CollisionModel.dispose();
- if(inclinationBombCollisionModel != null) inclinationBombCollisionModel.dispose();
- if(wiresBombCollisionModel != null) wiresBombCollisionModel.dispose();
- if(wiresBombCollisionModelWire1 != null) wiresBombCollisionModelWire1.dispose();
- if(wiresBombCollisionModelWire2 != null) wiresBombCollisionModelWire2.dispose();
- if(wiresBombCollisionModelWire3 != null) wiresBombCollisionModelWire3.dispose();
- if(easterEggCollisionModel != null) easterEggCollisionModel.dispose();
+ manager.dispose();
}
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
@@ -371,4 +343,61 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
thing.addToWorld();
}
+
+ private void getModels(){
+ // Load the render models.
+ doorModel = manager.get("models/render_models/bomb_game/door.g3db", Model.class);
+ doorFrameModel = manager.get("models/render_models/bomb_game/door_frame1.g3db", Model.class);
+
+ combinationBombModel = manager.get("models/render_models/bomb_game/bomb_3_body.g3db", Model.class);
+ combinationButton1Model = manager.get("models/render_models/bomb_game/bomb_3_btn_1.g3db", Model.class);
+ combinationButton2Model = manager.get("models/render_models/bomb_game/bomb_3_btn_2.g3db", Model.class);
+ combinationButton3Model = manager.get("models/render_models/bomb_game/bomb_3_btn_3.g3db", Model.class);
+ combinationButton4Model = manager.get("models/render_models/bomb_game/bomb_3_btn_4.g3db", Model.class);
+
+ inclinationBombModel = manager.get("models/render_models/bomb_game/bomb_2_body.g3db", Model.class);
+ inclinationBombButtonModel = manager.get("models/render_models/bomb_game/big_btn.g3db", Model.class);
+
+ wiresBombModel = manager.get("models/render_models/bomb_game/bomb_1_body.g3db", Model.class);
+ wiresBombModelWire1 = manager.get("models/render_models/bomb_game/cable_1.g3db", Model.class);
+ wiresBombModelWire2 = manager.get("models/render_models/bomb_game/cable_2.g3db", Model.class);
+ wiresBombModelWire3 = manager.get("models/render_models/bomb_game/cable_3.g3db", Model.class);
+ // easterEggModel = manager.get("models/render_models/bomb_game/", Model.class);
+
+ // Load the collision models.
+ doorCollisionModel = manager.get("models/collision_models/bomb_game/door_col.g3db", Model.class);
+ doorFrameCollisionModel = manager.get("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
+
+ combinationBombCollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_body_col.g3db", Model.class);
+ combinationButton1CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db", Model.class);
+ combinationButton2CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db", Model.class);
+ combinationButton3CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db", Model.class);
+ combinationButton4CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db", Model.class);
+
+ inclinationBombCollisionModel = manager.get("models/collision_models/bomb_game/bomb_2_body_col.g3db", Model.class);
+ inclinationBombButtonCollisionModel = manager.get("models/collision_models/bomb_game/big_btn_col.g3db", Model.class);
+
+ wiresBombCollisionModel = manager.get("models/collision_models/bomb_game/bomb_1_body_col.g3db", Model.class);
+ wiresBombCollisionModelWire1 = manager.get("models/collision_models/bomb_game/cable_1_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);
+ // easterEggCollisionModel = manager.get("models/collision_models/bomb_game/door.g3db", Model.class);
+ }
+
+ @Override
+ public boolean updateAssetManager(){
+ boolean doneLoading;
+
+ if(core == null)
+ throw new NullPointerException("Core has not been set.");
+
+ doneLoading = manager.update();
+ if(doneLoading){
+ getModels();
+ createAllEntities();
+ core.onAssetsLoaded();
+ }
+
+ return doneLoading;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
index 413a080..4c37fd5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
@@ -15,12 +15,28 @@
*/
package ve.ucv.ciens.ccg.nxtar.entities;
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
+
import com.artemis.World;
+import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.utils.Disposable;
+/**
+ *
+ */
public abstract class EntityCreatorBase implements Disposable{
- protected World world;
+ protected World world = null;
+ protected ApplicationEventsListener core = null;
+ protected boolean entitiesCreated = false;
+ protected AssetManager manager = null;
+ /**
+ * Sets the Artemis {@link World} to use to create entities.
+ *
+ * @param world The Artemis {@link World}.
+ * @throws IllegalArgumentException if world is null.
+ */
public void setWorld(World world) throws IllegalArgumentException{
if(world == null)
throw new IllegalArgumentException("World cannot be null.");
@@ -28,7 +44,38 @@ public abstract class EntityCreatorBase implements Disposable{
this.world = world;
}
- public abstract void createAllEntities();
+ /**
+ * Sets the application core to listen for asset loading events.
+ *
+ * @param core The application core to be used as listener.
+ * @throws IllegalArgumentException if core is null.
+ */
+ public void setCore(NxtARCore core) throws IllegalArgumentException{
+ if(core == null) throw new IllegalArgumentException("Core is null.");
+ this.core = core;
+ }
+ /**
+ * Updates the state of the {@link AssetManager}.
+ *
+ * @return true if the {@link AssetManager} has finished loading.
+ */
+ public abstract boolean updateAssetManager();
+
+ /**
+ * Unloads all assets loaded for the scenario.
+ */
public abstract void dispose();
+
+ /**
+ * @return true if the createAllEntities method has been called.
+ */
+ public boolean areEntitiesCreated(){
+ return entitiesCreated;
+ }
+
+ /**
+ * Creates all entities for a game scenario.
+ */
+ protected abstract void createAllEntities();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
index bee186a..4f8eb81 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
@@ -51,7 +51,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
private DirectionalLightPerPixelShader ppShader;
@Override
- public void createAllEntities() {
+ protected void createAllEntities() {
ModelBuilder builder;
Entity bomb, box, anim;
G3dModelLoader loader;
@@ -108,6 +108,8 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
bomb.addToWorld();
anim.addToWorld();
box.addToWorld();
+
+ entitiesCreated = true;
}
@Override
@@ -124,4 +126,12 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
if(ppShader != null)
ppShader.dispose();
}
+
+ @Override
+ public boolean updateAssetManager(){
+ createAllEntities();
+ if(core != null) core.onAssetsLoaded();
+
+ return true;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java b/src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java
index f759925..77f9014 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java
@@ -16,5 +16,23 @@
package ve.ucv.ciens.ccg.nxtar.interfaces;
public interface ApplicationEventsListener {
- public void networkStreamConnected(String streamName);
+ /**
+ * Callback used by the networking threads to notify sucessfull connections
+ * to the application
+ *
+ * @param streamName The name of the thread notifying a connection.
+ */
+ public void onNetworkStreamConnected(String streamName);
+
+ /**
+ * Callback used by the assets loader to notify that all
+ * required game assets are ready to be used.
+ */
+ public void onAssetsLoaded();
+
+ /**
+ * Callback used by the camera calibration state to notify that the
+ * camera has been succesfully calibrated.
+ */
+ public void onCameraCalibrated();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
index 52bfa8e..7b69deb 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
@@ -97,7 +97,7 @@ public class RobotControlThread extends Thread {
try{
client = server.accept();
client.setTcpNoDelay(true);
- if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
+ if(netListener != null) netListener.onNetworkStreamConnected(THREAD_NAME);
os = new ObjectOutputStream(client.getOutputStream());
is = new ObjectInputStream(client.getInputStream());
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
index f980e63..b8ee6a9 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
@@ -100,7 +100,7 @@ public class SensorReportThread extends Thread {
try{
client = server.accept();
client.setTcpNoDelay(true);
- if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
+ if(netListener != null) netListener.onNetworkStreamConnected(THREAD_NAME);
reader = client.getInputStream();
}catch(IOException io){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
index ac2eb60..3230826 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
@@ -220,7 +220,7 @@ public class VideoStreamingThread extends Thread{
//Gdx.app.debug(TAG, CLASS_NAME + ".run() :: Receiving.");
if(netListener != null && !coreNotified && frameMonitor.getCurrentFrame() != null){
coreNotified = true;
- netListener.networkStreamConnected(THREAD_NAME);
+ netListener.onNetworkStreamConnected(THREAD_NAME);
}
receiveUdp();
frames++;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java b/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
index 42bbdd1..54436d3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
@@ -88,6 +88,7 @@ public class CameraCalibrationState extends BaseState{
private VideoFrameMonitor frameMonitor;
private float[][] calibrationSamples;
+ @SuppressWarnings("unused")
private boolean takeSample;
private int lastSampleTaken;
@@ -215,11 +216,6 @@ public class CameraCalibrationState extends BaseState{
// Fetch the current video frame.
frame = frameMonitor.getCurrentFrame();
- // Apply the undistortion method if the camera has been calibrated already.
- /*if(core.cvProc.isCameraCalibrated()){
- frame = core.cvProc.undistortFrame(frame);
- }*/
-
// Find the calibration points in the video frame.
CalibrationData data = core.cvProc.findCalibrationPattern(frame);
@@ -231,7 +227,7 @@ public class CameraCalibrationState extends BaseState{
}
// If the user requested a sample be taken.
- if(takeSample && !core.cvProc.isCameraCalibrated() && data.calibrationPoints != null){
+ if(/*takeSample && */!core.cvProc.isCameraCalibrated() && data.calibrationPoints != null){
// Disable sample taking.
takeSample = false;
Gdx.app.log(TAG, CLASS_NAME + ".render(): Sample taken.");
@@ -255,8 +251,8 @@ public class CameraCalibrationState extends BaseState{
Gdx.app.log(TAG, CLASS_NAME + "render(): Last sample taken.");
core.cvProc.calibrateCamera(calibrationSamples, frame);
- msg = "Camera successfully calibrated";
- core.toast(msg, true);
+ core.onCameraCalibrated();
+ core.nextState = game_states_t.MAIN_MENU;
}
}
@@ -299,14 +295,14 @@ public class CameraCalibrationState extends BaseState{
}
// Render the user interface.
- if(!Ouya.runningOnOuya){
+ /*if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
core.batch.begin();{
takeSampleButton.draw(core.batch, 1.0f);
}core.batch.end();
}else{
// TODO: Render OUYA gui.
- }
+ }*/
// Save this frame as previous to avoid processing the same frame twice when network latency is high.
prevFrame = frame;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 5aef88a..f993a9b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -177,11 +177,7 @@ public class InGameState extends BaseState{
frameBufferSprite = null;
// Set up the game world.
- gameWorld = new World();
-
- GameSettings.initGameSettings();
- GameSettings.entityCreator.setWorld(gameWorld);
- GameSettings.entityCreator.createAllEntities();
+ gameWorld = GameSettings.getGameWorld();
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new ObjectPositioningSystem(), true);
@@ -362,9 +358,6 @@ public class InGameState extends BaseState{
if(modelBatch != null)
modelBatch.dispose();
- if(GameSettings.entityCreator != null)
- GameSettings.entityCreator.dispose();
-
if(videoFrameTexture != null)
videoFrameTexture.dispose();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
index db558f4..fdb3889 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
@@ -49,6 +49,8 @@ public abstract class MainMenuStateBase extends BaseState{
// Helper fields.
protected boolean clientConnected;
+ protected boolean cameraCalibrated;
+ protected boolean assetsLoaded;
private float u_scaling[];
// Buttons and other gui components.
@@ -170,7 +172,6 @@ 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;
-
win2world = new Vector3(0.0f, 0.0f, 0.0f);
touchPointWorldCoords = new Vector2();
startButtonTouched = false;
@@ -179,6 +180,8 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButtonTouchPointer = -1;
clientConnected = false;
+ cameraCalibrated = false;
+ assetsLoaded = false;
stateActive = false;
}
@@ -240,10 +243,24 @@ public abstract class MainMenuStateBase extends BaseState{
public void onClientConnected(){
clientConnected = true;
- startButton.setDisabled(false);
calibrationButton.setDisabled(false);
}
+ public void onCameraCalibrated(){
+ cameraCalibrated = true;
+ calibrationButton.setDisabled(true);
+ startGame();
+ }
+
+ public void onAssetsLoaded(){
+ assetsLoaded = true;
+ startGame();
+ }
+
+ private void startGame(){
+ startButton.setDisabled(!(cameraCalibrated && assetsLoaded));
+ }
+
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
; INPUT LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index 3ba0194..77dba40 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -15,17 +15,54 @@
*/
package ve.ucv.ciens.ccg.nxtar.utils;
+import com.artemis.World;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
public abstract class GameSettings{
- public static EntityCreatorBase entityCreator = null;
- public static GameLogicSystemBase gameLogicSystem = null;
+ private static EntityCreatorBase entityCreator = null;
+ private static GameLogicSystemBase gameLogicSystem = null;
+ private static World gameWorld = null;
- public static void initGameSettings(){
- entityCreator = new BombGameEntityCreator();
- gameLogicSystem = null;
+ public static void initGameSettings(NxtARCore core) throws IllegalArgumentException{
+ if(core == null)
+ throw new IllegalArgumentException("Core is null.");
+
+ if(getGameWorld() == null)
+ gameWorld = new World();
+
+ if(getEntityCreator() == null){
+ entityCreator = new BombGameEntityCreator();
+ entityCreator.setWorld(GameSettings.getGameWorld());
+ entityCreator.setCore(core);
+ }
+
+ if(getGameLogicSystem() == null)
+ gameLogicSystem = null;
//gameLogicSystem = new BombGameLogicSystem();
}
+
+ /**
+ * @return the entityCreator
+ */
+ public static EntityCreatorBase getEntityCreator() {
+ return entityCreator;
+ }
+
+ /**
+ * @return the gameLogicSystem
+ */
+ public static GameLogicSystemBase getGameLogicSystem() {
+ return gameLogicSystem;
+ }
+
+ /**
+ * @return the gameWorld
+ */
+ public static World getGameWorld() {
+ return gameWorld;
+ }
}
From d4edcf49095baafae720c15e930891f9ecf6b7e0 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 6 Jun 2014 12:43:45 -0430
Subject: [PATCH 10/34] Fixed interface details. Removed pause state.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 8 +-
.../nxtar/entities/BombGameEntityCreator.java | 34 +-
.../nxtar/states/CameraCalibrationState.java | 196 +---------
.../ccg/nxtar/states/MainMenuStateBase.java | 119 +++---
.../ccg/nxtar/states/OuyaMainMenuState.java | 346 +++++++++---------
.../ciens/ccg/nxtar/states/PauseState.java | 49 ---
.../ccg/nxtar/states/TabletMainMenuState.java | 145 ++++----
7 files changed, 325 insertions(+), 572 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 427bfa3..3b7296d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -15,9 +15,9 @@
*/
package ve.ucv.ciens.ccg.nxtar;
-import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
-import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver;
+import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
+import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread;
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
@@ -27,7 +27,6 @@ import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
-import ve.ucv.ciens.ccg.nxtar.states.PauseState;
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState;
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -74,7 +73,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Valid game states.
*/
public enum game_states_t {
- MAIN_MENU(0), IN_GAME(1), PAUSED(2), CALIBRATION(3);
+ MAIN_MENU(0), IN_GAME(1), CALIBRATION(2);
private int value;
@@ -239,7 +238,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
else
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
- states[game_states_t.PAUSED.getValue()] = new PauseState(this);
states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
// Register controller listeners.
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 8de8349..81c42fe 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -186,6 +186,23 @@ public class BombGameEntityCreator extends EntityCreatorBase{
entitiesCreated = true;
}
+ @Override
+ public boolean updateAssetManager() throws NullPointerException{
+ boolean doneLoading;
+
+ if(core == null)
+ throw new NullPointerException("Core has not been set.");
+
+ doneLoading = manager.update();
+ if(doneLoading){
+ getModels();
+ createAllEntities();
+ core.onAssetsLoaded();
+ }
+
+ return doneLoading;
+ }
+
@Override
public void dispose() {
if(shader != null) shader.dispose();
@@ -383,21 +400,4 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombCollisionModelWire3 = manager.get("models/collision_models/bomb_game/cable_3_col.g3db", Model.class);
// easterEggCollisionModel = manager.get("models/collision_models/bomb_game/door.g3db", Model.class);
}
-
- @Override
- public boolean updateAssetManager(){
- boolean doneLoading;
-
- if(core == null)
- throw new NullPointerException("Core has not been set.");
-
- doneLoading = manager.update();
- if(doneLoading){
- getModels();
- createAllEntities();
- core.onAssetsLoaded();
- }
-
- return doneLoading;
- }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java b/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
index 54436d3..0ce207d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
@@ -26,28 +26,16 @@ import ve.ucv.ciens.ccg.nxtar.utils.Size;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
-import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.mappings.Ouya;
-import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
-import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
-import com.badlogic.gdx.math.Rectangle;
-import com.badlogic.gdx.math.Vector2;
-import com.badlogic.gdx.math.Vector3;
-import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
-import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
-import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
public class CameraCalibrationState extends BaseState{
private static final String TAG = "CAMERA_CALIBRATION_STATE";
@@ -55,6 +43,7 @@ public class CameraCalibrationState extends BaseState{
private static final String SHADER_PATH = "shaders/bckg/bckg";
private NxtARCore core;
+ private boolean cameraCalibrated;
private float u_scaling[];
protected Sprite background;
@@ -69,36 +58,16 @@ public class CameraCalibrationState extends BaseState{
private Sprite renderableVideoFrame;
private Pixmap videoFrame;
- // Gui components.
- private TextButton takeSampleButton;
- private Rectangle takeSampleButtonBBox;
- private Texture buttonEnabledTexture;
- private Texture buttonDisabledTexture;
- private Texture buttonPressedTexture;
- private NinePatch buttonEnabled9p;
- private NinePatch buttonDisabled9p;
- private NinePatch buttonPressed9p;
- private BitmapFont font;
-
- // Button touch helper fields.
- private boolean takeSampleButtonTouched;
- private int takeSampleButtonPointer;
-
// Monitors.
private VideoFrameMonitor frameMonitor;
private float[][] calibrationSamples;
- @SuppressWarnings("unused")
- private boolean takeSample;
private int lastSampleTaken;
public CameraCalibrationState(final NxtARCore core){
- TextButtonStyle tbs;
- FreeTypeFontGenerator generator;
- FreeTypeFontParameter param;
-
this.core = core;
frameMonitor = VideoFrameMonitor.getInstance();
+ cameraCalibrated = false;
// Set up the cameras.
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
@@ -125,46 +94,6 @@ public class CameraCalibrationState 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;
- // Set up the sampling button.
- // Create the font.
- param = new FreeTypeFontParameter();
- param.characters = ProjectConstants.FONT_CHARS;
- param.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
- param.flip = false;
- generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
- font = generator.generateFont(param);
- generator.dispose();
-
- // Load the textures.
- buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
- buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
- buttonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
- buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
- buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
- buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
-
- // Create the button style.
- tbs = new TextButtonStyle();
- tbs.font = font;
- tbs.up = new NinePatchDrawable(buttonEnabled9p);
- tbs.checked = new NinePatchDrawable(buttonPressed9p);
- tbs.disabled = new NinePatchDrawable(buttonDisabled9p);
- tbs.disabledFontColor = new Color(0, 0, 0, 1);
-
- // Create the button itself.
- takeSampleButton = new TextButton("Take calibration sample", tbs);
- takeSampleButton.setText("Take calibration sample");
- takeSampleButton.setDisabled(true);
- takeSampleButtonBBox = new Rectangle(0, 0, takeSampleButton.getWidth(), takeSampleButton.getHeight());
- takeSampleButton.setPosition(-(takeSampleButton.getWidth() / 2), -(Gdx.graphics.getHeight()/2) - 1 + (takeSampleButton.getHeight() / 2));
- takeSampleButtonBBox.setPosition(takeSampleButton.getX(), takeSampleButton.getY());
-
- // Set up the touch collision detection variables.
- win2world = new Vector3(0.0f, 0.0f, 0.0f);
- touchPointWorldCoords = new Vector2();
- takeSampleButtonTouched = false;
- takeSampleButtonPointer = -1;
-
// Initialize the calibration samples vector.
calibrationSamples = new float[ProjectConstants.CALIBRATION_SAMPLES][];
for(int i = 0; i < calibrationSamples.length; i++){
@@ -178,8 +107,8 @@ public class CameraCalibrationState extends BaseState{
Gdx.input.setCatchBackKey(true);
Gdx.input.setCatchMenuKey(true);
- takeSample = false;
lastSampleTaken = 0;
+ cameraCalibrated = false;
for(int i = 0; i < calibrationSamples.length; i++){
for(int j = 0; j < calibrationSamples[i].length; j++){
@@ -193,7 +122,6 @@ public class CameraCalibrationState extends BaseState{
@Override
public void render(float delta){
- String msg;
byte[] frame;
byte[] prevFrame = null;
Size dimensions = null;
@@ -219,17 +147,8 @@ public class CameraCalibrationState extends BaseState{
// Find the calibration points in the video frame.
CalibrationData data = core.cvProc.findCalibrationPattern(frame);
- // Disable the sampling button if the calibration pattern was not found.
- if(data.calibrationPoints != null && !core.cvProc.isCameraCalibrated()){
- takeSampleButton.setDisabled(false);
- }else{
- takeSampleButton.setDisabled(true);
- }
-
// If the user requested a sample be taken.
- if(/*takeSample && */!core.cvProc.isCameraCalibrated() && data.calibrationPoints != null){
- // Disable sample taking.
- takeSample = false;
+ if(!cameraCalibrated && data.calibrationPoints != null){
Gdx.app.log(TAG, CLASS_NAME + ".render(): Sample taken.");
// Save the calibration points to the samples array.
@@ -242,15 +161,12 @@ public class CameraCalibrationState extends BaseState{
// Move to the next sample.
lastSampleTaken++;
- msg = Integer.toString(lastSampleTaken) + " samples taken. ";
- msg += Integer.toString(ProjectConstants.CALIBRATION_SAMPLES - lastSampleTaken) + " samples left.";
- core.toast(msg, false);
-
// If enough samples has been taken then calibrate the camera.
if(lastSampleTaken == ProjectConstants.CALIBRATION_SAMPLES){
Gdx.app.log(TAG, CLASS_NAME + "render(): Last sample taken.");
core.cvProc.calibrateCamera(calibrationSamples, frame);
+ cameraCalibrated = core.cvProc.isCameraCalibrated();
core.onCameraCalibrated();
core.nextState = game_states_t.MAIN_MENU;
}
@@ -281,11 +197,8 @@ public class CameraCalibrationState extends BaseState{
}
// Render the frame.
- if(!Ouya.runningOnOuya){
- core.batch.setProjectionMatrix(camera.combined);
- }else{
- core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
- }
+ if(!Ouya.runningOnOuya) core.batch.setProjectionMatrix(camera.combined);
+ else core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
core.batch.begin();{
renderableVideoFrame.draw(core.batch);
}core.batch.end();
@@ -294,35 +207,10 @@ public class CameraCalibrationState extends BaseState{
videoFrameTexture.dispose();
}
- // Render the user interface.
- /*if(!Ouya.runningOnOuya){
- core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
- core.batch.begin();{
- takeSampleButton.draw(core.batch, 1.0f);
- }core.batch.end();
- }else{
- // TODO: Render OUYA gui.
- }*/
-
// Save this frame as previous to avoid processing the same frame twice when network latency is high.
prevFrame = frame;
}
- @Override
- public void resize(int width, int height){ }
-
- @Override
- public void show(){ }
-
- @Override
- public void hide(){ }
-
- @Override
- public void pause(){ }
-
- @Override
- public void resume(){ }
-
@Override
public void dispose(){
if(videoFrameTexture != null)
@@ -343,74 +231,4 @@ public class CameraCalibrationState extends BaseState{
}
return false;
}
-
- @Override
- public boolean touchDown(int screenX, int screenY, int pointer, int button){
- unprojectTouch(screenX, screenY);
-
- Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
- Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
-
- if(!takeSampleButton.isDisabled() && takeSampleButtonBBox.contains(touchPointWorldCoords) && !takeSampleButtonTouched){
- takeSampleButton.setChecked(true);
- takeSampleButtonTouched = true;
- takeSampleButtonPointer = pointer;
- Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Sample button pressed.");
- }
-
- return true;
- }
-
- @Override
- public boolean touchUp(int screenX, int screenY, int pointer, int button){
- unprojectTouch(screenX, screenY);
-
- Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
- Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
-
- if(!takeSampleButton.isDisabled() && takeSampleButtonBBox.contains(touchPointWorldCoords) && takeSampleButtonTouched){
- takeSampleButton.setChecked(false);
- takeSampleButtonTouched = false;
- takeSampleButtonPointer = -1;
- takeSample = true;
- Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Sample button released.");
- }
-
- return true;
- }
-
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer){
- unprojectTouch(screenX, screenY);
-
- if(!takeSampleButton.isDisabled() && takeSampleButtonTouched && pointer == takeSampleButtonPointer && !takeSampleButtonBBox.contains(touchPointWorldCoords)){
- takeSampleButtonPointer = -1;
- takeSampleButtonTouched = false;
- takeSampleButton.setChecked(false);
- Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Sample button released.");
- }
-
- return true;
- }
-
- @Override
- public boolean buttonDown(Controller controller, int buttonCode){
- // TODO: Handle OUYA controls.
-
- return false;
- }
-
- @Override
- public boolean buttonUp(Controller controller, int buttonCode){
- // TODO: Handle OUYA controls.
-
- return false;
- }
-
- @Override
- public boolean axisMoved(Controller controller, int axisCode, float value){
- // TODO: Handle OUYA controls.
-
- return false;
- }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
index fdb3889..56c1614 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
@@ -51,49 +51,46 @@ public abstract class MainMenuStateBase extends BaseState{
protected boolean clientConnected;
protected boolean cameraCalibrated;
protected boolean assetsLoaded;
- private float u_scaling[];
+ private float u_scaling[];
// Buttons and other gui components.
protected TextButton startButton;
- protected Rectangle startButtonBBox;
- protected Sprite clientConnectedLedOn;
- protected Sprite clientConnectedLedOff;
-
+ protected Rectangle startButtonBBox;
protected TextButton calibrationButton;
- protected Rectangle calibrationButtonBBox;
- protected Sprite cameraCalibratedLedOn;
- protected Sprite cameraCalibratedLedOff;
+ protected Rectangle calibrationButtonBBox;
+ protected Sprite cameraCalibratedLedOn;
+ protected Sprite cameraCalibratedLedOff;
+ protected Sprite assetsLoadedLedOn;
+ protected Sprite assetsLoadedLedOff;
protected Sprite background;
// Graphic data for the start button.
- private Texture menuButtonEnabledTexture;
- private Texture menuButtonDisabledTexture;
- private Texture menuButtonPressedTexture;
- private NinePatch menuButtonEnabled9p;
- private NinePatch menuButtonDisabled9p;
- private NinePatch menuButtonPressed9p;
+ private Texture menuButtonEnabledTexture;
+ private Texture menuButtonDisabledTexture;
+ private Texture menuButtonPressedTexture;
+ private NinePatch menuButtonEnabled9p;
+ private NinePatch menuButtonDisabled9p;
+ private NinePatch menuButtonPressed9p;
private BitmapFont font;
// Other graphics.
- private Texture cameraCalibratedLedOffTexture;
- private Texture cameraCalibratedLedOnTexture;
- private Texture clientConnectedLedOffTexture;
- private Texture clientConnectedLedOnTexture;
- private Texture backgroundTexture;
+ private Texture ledOffTexture;
+ private Texture ledOnTexture;
+ private Texture backgroundTexture;
private ShaderProgram backgroundShader;
// Button touch helper fields.
protected boolean startButtonTouched;
- protected int startButtonTouchPointer;
+ protected int startButtonTouchPointer;
protected boolean calibrationButtonTouched;
- protected int calibrationButtonTouchPointer;
+ protected int calibrationButtonTouchPointer;
public MainMenuStateBase(){
- TextureRegion region;
- TextButtonStyle tbs;
- FreeTypeFontGenerator generator;
- FreeTypeFontParameter param;
+ TextureRegion region;
+ TextButtonStyle textButtonStyle;
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
@@ -108,50 +105,49 @@ public abstract class MainMenuStateBase extends BaseState{
menuButtonPressed9p = new NinePatch(new TextureRegion(menuButtonPressedTexture, 0, 0, menuButtonPressedTexture.getWidth(), menuButtonPressedTexture.getHeight()), 49, 49, 45, 45);
// Create the start button font.
- param = new FreeTypeFontParameter();
- param.characters = ProjectConstants.FONT_CHARS;
- param.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
- param.flip = false;
- generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
- font = generator.generateFont(param);
- generator.dispose();
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+ font = fontGenerator.generateFont(fontParameters);
+ fontGenerator.dispose();
// Create the start button.
- tbs = new TextButtonStyle();
- tbs.font = font;
- tbs.up = new NinePatchDrawable(menuButtonEnabled9p);
- tbs.checked = new NinePatchDrawable(menuButtonPressed9p);
- tbs.disabled = new NinePatchDrawable(menuButtonDisabled9p);
- tbs.disabledFontColor = new Color(0, 0, 0, 1);
+ textButtonStyle = new TextButtonStyle();
+ textButtonStyle.font = font;
+ textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p);
+ textButtonStyle.checked = new NinePatchDrawable(menuButtonPressed9p);
+ textButtonStyle.disabled = new NinePatchDrawable(menuButtonDisabled9p);
+ textButtonStyle.disabledFontColor = new Color(0, 0, 0, 1);
- startButton = new TextButton("Start server", tbs);
+ startButton = new TextButton("Start server", textButtonStyle);
startButton.setText("Start game");
startButton.setDisabled(true);
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
// Create the calibration button.
- calibrationButton = new TextButton("Calibrate camera", tbs);
+ calibrationButton = new TextButton("Calibrate camera", textButtonStyle);
calibrationButton.setText("Calibrate camera");
calibrationButton.setDisabled(true);
calibrationButtonBBox = new Rectangle(0, 0, calibrationButton.getWidth(), calibrationButton.getHeight());
// Create the connection leds.
- clientConnectedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
- region = new TextureRegion(clientConnectedLedOnTexture);
- clientConnectedLedOn = new Sprite(region);
+ ledOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
+ ledOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
- clientConnectedLedOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
- region = new TextureRegion(clientConnectedLedOffTexture);
- clientConnectedLedOff = new Sprite(region);
-
- cameraCalibratedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
- region = new TextureRegion(cameraCalibratedLedOnTexture);
+ region = new TextureRegion(ledOnTexture);
cameraCalibratedLedOn = new Sprite(region);
- cameraCalibratedLedOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
- region = new TextureRegion(cameraCalibratedLedOffTexture);
+ region = new TextureRegion(ledOffTexture);
cameraCalibratedLedOff = new Sprite(region);
+ region = new TextureRegion(ledOnTexture);
+ assetsLoadedLedOn = new Sprite(region);
+
+ region = new TextureRegion(ledOffTexture);
+ assetsLoadedLedOff = new Sprite(region);
+
// Set up the background.
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
@@ -188,29 +184,13 @@ public abstract class MainMenuStateBase extends BaseState{
@Override
public abstract void render(float delta);
- @Override
- public void resize(int width, int height){ }
-
- @Override
- public void show(){ }
- @Override
- public void hide(){ }
-
- @Override
- public void pause(){ }
-
- @Override
- public void resume(){ }
-
@Override
public void dispose(){
menuButtonEnabledTexture.dispose();
menuButtonDisabledTexture.dispose();
menuButtonPressedTexture.dispose();
- clientConnectedLedOnTexture.dispose();
- clientConnectedLedOffTexture.dispose();
- cameraCalibratedLedOnTexture.dispose();
- cameraCalibratedLedOffTexture.dispose();
+ ledOnTexture.dispose();
+ ledOffTexture.dispose();
backgroundTexture.dispose();
if(backgroundShader != null) backgroundShader.dispose();
font.dispose();
@@ -248,7 +228,6 @@ public abstract class MainMenuStateBase extends BaseState{
public void onCameraCalibrated(){
cameraCalibrated = true;
- calibrationButton.setDisabled(true);
startGame();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
index 223c3a8..acc8233 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
@@ -1,171 +1,175 @@
-/*
- * 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.states;
-
-import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.controllers.Controller;
-import com.badlogic.gdx.controllers.mappings.Ouya;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g2d.Sprite;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
-
-public class OuyaMainMenuState extends MainMenuStateBase{
- private static final String CLASS_NAME = OuyaMainMenuState.class.getSimpleName();
-
- private Texture ouyaOButtonTexture;
- private Sprite ouyaOButton;
- private boolean oButtonPressed;
- private int oButtonSelection;
-
- public OuyaMainMenuState(final NxtARCore core){
- super();
-
- this.core = core;
-
- startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
- startButtonBBox.setPosition(startButton.getX(), startButton.getY());
-
- calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
- calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
-
- float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
- clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
- clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
-
- clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
- clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
-
- // TODO: Set calibration led attributes.
-
- ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
- TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
- ouyaOButton = new Sprite(region);
- ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
-
- oButtonSelection = 0;
- oButtonPressed = false;
- }
-
- @Override
- public void render(float delta) {
- Gdx.gl.glClearColor(1, 1, 1, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
- core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
- core.batch.begin();{
- core.batch.disableBlending();
- drawBackground(core.batch);
- core.batch.enableBlending();
-
- if(clientConnected){
- clientConnectedLedOn.draw(core.batch);
- }else{
- clientConnectedLedOff.draw(core.batch);
- }
-
- // TODO: Render calibration leds.
-
- startButton.draw(core.batch, 1.0f);
- calibrationButton.draw(core.batch, 1.0f);
-
- if(oButtonSelection == 0){
- ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
- }else if(oButtonSelection == 1){
- ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2));
- }
- ouyaOButton.draw(core.batch);
-
- }core.batch.end();
- }
-
- @Override
- public void dispose(){
- super.dispose();
- ouyaOButtonTexture.dispose();
- }
-
- /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; BEGIN CONTROLLER LISTENER METHODS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
-
- @Override
- public boolean buttonDown(Controller controller, int buttonCode){
- // TODO: Test this.
-
- if(stateActive){
- if(buttonCode == Ouya.BUTTON_O){
- Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
-
- if(oButtonSelection == 0){
- if(!clientConnected){
- core.toast("Can't start the game. No client is connected.", true);
- }else{
- oButtonPressed = true;
- startButton.setChecked(true);
- }
- }else if(oButtonSelection == 1){
- if(!clientConnected){
- core.toast("Can't calibrate the camera. No client is connected.", true);
- }else{
- oButtonPressed = true;
- calibrationButton.setChecked(true);
- }
- }
- }else if(buttonCode == Ouya.BUTTON_DPAD_UP){
- Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
- oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
- }else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
- Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
- oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
- }
-
- return true;
- }else{
- return false;
- }
- }
-
- @Override
- public boolean buttonUp(Controller controller, int buttonCode){
- // TODO: Test this.
-
- if(stateActive){
- if(buttonCode == Ouya.BUTTON_O){
- Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
-
- if(oButtonPressed){
- oButtonPressed = false;
-
- if(oButtonSelection == 0){
- startButton.setChecked(false);
- core.nextState = game_states_t.IN_GAME;
- }else if(oButtonSelection == 1){
- calibrationButton.setChecked(false);
- core.nextState = game_states_t.IN_GAME;
- }
- }
- }
-
- return true;
- }else{
- return false;
- }
- }
-}
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.controllers.Controller;
+import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+
+public class OuyaMainMenuState extends MainMenuStateBase{
+ private static final String CLASS_NAME = OuyaMainMenuState.class.getSimpleName();
+
+ private Texture ouyaOButtonTexture;
+ private Sprite ouyaOButton;
+ private boolean oButtonPressed;
+ private int oButtonSelection;
+ private float ledYPos;
+
+ public OuyaMainMenuState(final NxtARCore core){
+ super();
+
+ this.core = core;
+
+ // Set buttons.
+ startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
+ startButtonBBox.setPosition(startButton.getX(), startButton.getY());
+ calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
+ calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
+
+ //Set leds.
+ ledYPos = (-(Gdx.graphics.getHeight() / 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);
+ cameraCalibratedLedOff.setPosition(-cameraCalibratedLedOff.getWidth() - 5, ledYPos);
+ assetsLoadedLedOn.setSize(assetsLoadedLedOn.getWidth() * 0.5f, assetsLoadedLedOn.getHeight() * 0.5f);
+ assetsLoadedLedOn.setPosition(5, ledYPos);
+ assetsLoadedLedOff.setSize(assetsLoadedLedOff.getWidth() * 0.5f, assetsLoadedLedOff.getHeight() * 0.5f);
+ assetsLoadedLedOff.setPosition(5, ledYPos);
+
+ // Set OUYA's O button.
+ ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
+ TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
+ ouyaOButton = new Sprite(region);
+ ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ oButtonSelection = 0;
+ oButtonPressed = false;
+ }
+
+ @Override
+ public void render(float delta) {
+ Gdx.gl.glClearColor(1, 1, 1, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ core.batch.begin();{
+ // Render background.
+ core.batch.disableBlending();
+ drawBackground(core.batch);
+ core.batch.enableBlending();
+
+ // Render leds.
+ if(cameraCalibrated) cameraCalibratedLedOn.draw(core.batch);
+ else cameraCalibratedLedOff.draw(core.batch);
+ if(assetsLoaded) assetsLoadedLedOn.draw(core.batch);
+ else assetsLoadedLedOff.draw(core.batch);
+
+ // Render buttons.
+ startButton.draw(core.batch, 1.0f);
+ calibrationButton.draw(core.batch, 1.0f);
+
+ // Render O button.
+ if(oButtonSelection == 0){
+ ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
+ }else if(oButtonSelection == 1){
+ ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2));
+ }
+ ouyaOButton.draw(core.batch);
+
+ }core.batch.end();
+ }
+
+ @Override
+ public void dispose(){
+ super.dispose();
+ ouyaOButtonTexture.dispose();
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; BEGIN CONTROLLER LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean buttonDown(Controller controller, int buttonCode){
+ // TODO: Test this.
+
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
+
+ if(oButtonSelection == 0){
+ if(!clientConnected){
+ core.toast("Can't start the game. No client is connected.", true);
+ }else{
+ oButtonPressed = true;
+ startButton.setChecked(true);
+ }
+ }else if(oButtonSelection == 1){
+ if(!clientConnected){
+ core.toast("Can't calibrate the camera. No client is connected.", true);
+ }else{
+ oButtonPressed = true;
+ calibrationButton.setChecked(true);
+ }
+ }
+ }else if(buttonCode == Ouya.BUTTON_DPAD_UP){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
+ oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
+ }else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
+ oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
+ }
+
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean buttonUp(Controller controller, int buttonCode){
+ // TODO: Test this.
+
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
+
+ if(oButtonPressed){
+ oButtonPressed = false;
+
+ if(oButtonSelection == 0){
+ startButton.setChecked(false);
+ core.nextState = game_states_t.IN_GAME;
+ }else if(oButtonSelection == 1){
+ calibrationButton.setChecked(false);
+ core.nextState = game_states_t.IN_GAME;
+ }
+ }
+ }
+
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java b/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java
deleted file mode 100644
index 468849e..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/states/PauseState.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.states;
-
-import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-
-public class PauseState extends BaseState {
-
- public PauseState(final NxtARCore core){
- this.core = core;
- }
-
- @Override
- public void onStateSet() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onStateUnset() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void render(float delta) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
-
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
index 84ebb63..c9cc886 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
@@ -1,71 +1,74 @@
-/*
- * 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.states;
-
-import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.GL20;
-
-public class TabletMainMenuState extends MainMenuStateBase{
-
- public TabletMainMenuState(final NxtARCore core){
- super();
-
- this.core = core;
-
- startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
- startButtonBBox.setPosition(startButton.getX(), startButton.getY());
-
- calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
- calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
-
- float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
- clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
- clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
-
- clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
- clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
-
- // TODO: Set calibration led attributes.
- }
-
- @Override
- public void render(float delta){
- Gdx.gl.glClearColor(1, 1, 1, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
- core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
- core.batch.begin();{
-
- core.batch.disableBlending();
- drawBackground(core.batch);
- core.batch.enableBlending();
-
- if(clientConnected){
- clientConnectedLedOn.draw(core.batch);
- }else{
- clientConnectedLedOff.draw(core.batch);
- }
-
- // TODO: Render calibration led.
-
- startButton.draw(core.batch, 1.0f);
- calibrationButton.draw(core.batch, 1.0f);
-
- }core.batch.end();
- }
-}
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.GL20;
+
+public class TabletMainMenuState extends MainMenuStateBase{
+ private float ledYPos;
+
+ public TabletMainMenuState(final NxtARCore core){
+ super();
+
+ this.core = core;
+
+ // Set buttons.
+ startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
+ startButtonBBox.setPosition(startButton.getX(), startButton.getY());
+ calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
+ calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
+
+ // Set leds.
+ ledYPos = (-(Gdx.graphics.getHeight() / 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);
+ cameraCalibratedLedOff.setPosition(-cameraCalibratedLedOff.getWidth() - 5, ledYPos);
+ assetsLoadedLedOn.setSize(assetsLoadedLedOn.getWidth() * 0.5f, assetsLoadedLedOn.getHeight() * 0.5f);
+ assetsLoadedLedOn.setPosition(5, ledYPos);
+ assetsLoadedLedOff.setSize(assetsLoadedLedOff.getWidth() * 0.5f, assetsLoadedLedOff.getHeight() * 0.5f);
+ assetsLoadedLedOff.setPosition(5, ledYPos);
+ }
+
+ @Override
+ public void render(float delta){
+ Gdx.gl.glClearColor(1, 1, 1, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ core.batch.begin();{
+
+ // Render background.
+ core.batch.disableBlending();
+ drawBackground(core.batch);
+ core.batch.enableBlending();
+
+ // Render leds.
+ if(cameraCalibrated) cameraCalibratedLedOn.draw(core.batch);
+ else cameraCalibratedLedOff.draw(core.batch);
+ if(assetsLoaded) assetsLoadedLedOn.draw(core.batch);
+ else assetsLoadedLedOff.draw(core.batch);
+
+ // Render buttons.
+ startButton.draw(core.batch, 1.0f);
+ calibrationButton.draw(core.batch, 1.0f);
+
+ }core.batch.end();
+ }
+}
From aa5871b49af74f37062e6ecad9f749d0b5bb33e4 Mon Sep 17 00:00:00 2001
From: Miguel Angel Astor Romero
Date: Fri, 6 Jun 2014 19:10:11 -0430
Subject: [PATCH 11/34] Started modelling user input.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 2 +-
.../nxtar/entities/BombGameEntityCreator.java | 116 ++++++++++--------
.../ccg/nxtar/factories/UserInputFactory.java | 35 ++++++
.../factories/products/GamepadUserInput.java | 30 +++++
.../factories/products/KeyboardUserInput.java | 34 +++++
.../factories/products/TouchUserInput.java | 26 ++++
.../nxtar/factories/products/UserInput.java | 23 ++++
.../ciens/ccg/nxtar/states/InGameState.java | 28 +++--
.../nxtar/systems/ObjectRenderingSystem.java | 52 +-------
...em.java => RobotArmPositioningSystem.java} | 29 ++++-
10 files changed, 261 insertions(+), 114 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java
rename src/ve/ucv/ciens/ccg/nxtar/systems/{ObjectPositioningSystem.java => RobotArmPositioningSystem.java} (61%)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 3b7296d..50cb1ec 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -86,7 +86,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
public static int getNumStates(){
- return 4;
+ return 3;
}
};
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 81c42fe..f1ec915 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -64,62 +64,49 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
}
- private EntityParameters parameters;
- private Shader shader;
- private int currentBombId;
+ private Shader shader;
+ private int currentBombId;
// Render models.
- private Model doorModel = null;
- private Model doorFrameModel = null;
- private Model combinationBombModel = null;
- private Model combinationButton1Model = null;
- private Model combinationButton2Model = null;
- private Model combinationButton3Model = null;
- private Model combinationButton4Model = null;
- private Model inclinationBombModel = null;
- private Model inclinationBombButtonModel = null;
- private Model wiresBombModel = null;
- private Model wiresBombModelWire1 = null;
- private Model wiresBombModelWire2 = null;
- private Model wiresBombModelWire3 = null;
- // private Model easterEggModel = null;
+ private Model robotArmModel = null;
+ private Model doorModel = null;
+ private Model doorFrameModel = null;
+ private Model combinationBombModel = null;
+ private Model combinationButton1Model = null;
+ private Model combinationButton2Model = null;
+ private Model combinationButton3Model = null;
+ private Model combinationButton4Model = null;
+ private Model inclinationBombModel = null;
+ private Model inclinationBombButtonModel = null;
+ private Model wiresBombModel = null;
+ private Model wiresBombModelWire1 = null;
+ private Model wiresBombModelWire2 = null;
+ private Model wiresBombModelWire3 = null;
+ private Model easterEggModel = null;
// Collision models.
- private Model doorCollisionModel = null;
- private Model doorFrameCollisionModel = null;
- private Model combinationBombCollisionModel = null;
- private Model combinationButton1CollisionModel = null;
- private Model combinationButton2CollisionModel = null;
- private Model combinationButton3CollisionModel = null;
- private Model combinationButton4CollisionModel = null;
- private Model inclinationBombCollisionModel = null;
- private Model inclinationBombButtonCollisionModel = null;
- private Model wiresBombCollisionModel = null;
- private Model wiresBombCollisionModelWire1 = null;
- private Model wiresBombCollisionModelWire2 = null;
- private Model wiresBombCollisionModelWire3 = null;
- // private Model easterEggCollisionModel = null;
+ private Model robotArmCollisionModel = null;
+ private Model doorCollisionModel = null;
+ private Model doorFrameCollisionModel = null;
+ private Model combinationBombCollisionModel = null;
+ private Model combinationButton1CollisionModel = null;
+ private Model combinationButton2CollisionModel = null;
+ private Model combinationButton3CollisionModel = null;
+ private Model combinationButton4CollisionModel = null;
+ private Model inclinationBombCollisionModel = null;
+ private Model inclinationBombButtonCollisionModel = null;
+ private Model wiresBombCollisionModel = null;
+ private Model wiresBombCollisionModelWire1 = null;
+ private Model wiresBombCollisionModelWire2 = null;
+ private Model wiresBombCollisionModelWire3 = null;
+ private Model easterEggCollisionModel = null;
public BombGameEntityCreator(){
currentBombId = 0;
manager = new AssetManager();
- // Create and set the lighting.
- 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;
-
// Load the render models.
+ manager.load("models/render_models/bomb_game/robot_arm.g3db", Model.class);
manager.load("models/render_models/bomb_game/door.g3db", Model.class);
manager.load("models/render_models/bomb_game/door_frame1.g3db", Model.class);
@@ -139,6 +126,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// manager.load("models/render_models/bomb_game/", Model.class);
// Load the collision models.
+ manager.load("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
manager.load("models/collision_models/bomb_game/door_col.g3db", Model.class);
manager.load("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
@@ -160,7 +148,24 @@ public class BombGameEntityCreator extends EntityCreatorBase{
@Override
public void createAllEntities(){
- // TODO: Add the robot arms.
+ EntityParameters parameters;
+
+ // Create and set the lighting.
+ 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);
// Add bombs.
parameters.markerCode = 89;
@@ -209,6 +214,17 @@ public class BombGameEntityCreator extends EntityCreatorBase{
manager.dispose();
}
+ private void addRobotArm(EntityParameters parameters){
+ Entity robotArm = world.createEntity();
+
+ robotArm.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ robotArm.addComponent(new EnvironmentComponent(parameters.environment));
+ robotArm.addComponent(new ShaderComponent(parameters.shader));
+ robotArm.addComponent(new RenderModelComponent(robotArmModel));
+ robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
+ robotArm.addToWorld();
+ }
+
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb;
BombComponent bombComponent = new BombComponent(currentBombId, type);
@@ -362,7 +378,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void getModels(){
- // Load the render models.
+ // Get the render models.
+ robotArmModel = manager.get("models/render_models/bomb_game/robot_arm.g3db", Model.class);
doorModel = manager.get("models/render_models/bomb_game/door.g3db", Model.class);
doorFrameModel = manager.get("models/render_models/bomb_game/door_frame1.g3db", Model.class);
@@ -381,7 +398,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombModelWire3 = manager.get("models/render_models/bomb_game/cable_3.g3db", Model.class);
// easterEggModel = manager.get("models/render_models/bomb_game/", Model.class);
- // Load the collision models.
+ // Get the collision models.
+ robotArmCollisionModel = manager.get("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
doorCollisionModel = manager.get("models/collision_models/bomb_game/door_col.g3db", Model.class);
doorFrameCollisionModel = manager.get("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java b/src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java
new file mode 100644
index 0000000..26eee80
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.factories;
+
+import ve.ucv.ciens.ccg.nxtar.factories.products.GamepadUserInput;
+import ve.ucv.ciens.ccg.nxtar.factories.products.KeyboardUserInput;
+import ve.ucv.ciens.ccg.nxtar.factories.products.TouchUserInput;
+import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
+
+public abstract class UserInputFactory{
+ public static UserInput createTouchUserInput(){
+ return new TouchUserInput();
+ }
+
+ public static UserInput createGamepadUserInput(){
+ return new GamepadUserInput();
+ }
+
+ public static UserInput createKeyboardUserInput(){
+ return new KeyboardUserInput();
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java
new file mode 100644
index 0000000..f39a496
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java
@@ -0,0 +1,30 @@
+/*
+ * 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.factories.products;
+
+public class GamepadUserInput extends UserInput {
+ public float axisLeftX;
+ public float axisLeftY;
+ public float axisRightX;
+ public float axisRightY;
+
+ public GamepadUserInput(){
+ this.axisLeftX = 0.0f;
+ this.axisLeftY = 0.0f;
+ this.axisRightX = 0.0f;
+ this.axisRightY = 0.0f;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java
new file mode 100644
index 0000000..813c6fb
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java
@@ -0,0 +1,34 @@
+/*
+ * 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.factories.products;
+
+public class KeyboardUserInput extends UserInput {
+ public boolean keyLeft;
+ public boolean keyRight;
+ public boolean keyUp;
+ public boolean keyDown;
+ public boolean keyA;
+ public boolean keyZ;
+
+ public KeyboardUserInput(){
+ this.keyLeft = false;
+ this.keyRight = false;
+ this.keyUp = false;
+ this.keyDown = false;
+ this.keyA = false;
+ this.keyZ = false;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java
new file mode 100644
index 0000000..4a4ab2d
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java
@@ -0,0 +1,26 @@
+/*
+ * 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.factories.products;
+
+import com.badlogic.gdx.math.collision.Ray;
+
+public class TouchUserInput extends UserInput {
+ public Ray movementRay;
+
+ public TouchUserInput(){
+ movementRay = null;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java b/src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java
new file mode 100644
index 0000000..8213aa8
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java
@@ -0,0 +1,23 @@
+/*
+ * 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.factories.products;
+
+import ve.ucv.ciens.ccg.nxtar.factories.UserInputFactory;
+
+/**
+ * Tag class for the {@link UserInputFactory} products.
+ */
+public abstract class UserInput{}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index f993a9b..8d00f7c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -19,6 +19,8 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.factories.UserInputFactory;
+import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
@@ -27,8 +29,8 @@ import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.ObjectPositioningSystem;
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;
@@ -74,6 +76,7 @@ public class InGameState extends BaseState{
private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
+ private RobotArmPositioningSystem robotArmPositioningSystem;
// Cameras.
private OrthographicCamera unitaryOrthoCamera;
@@ -179,8 +182,9 @@ public class InGameState extends BaseState{
// Set up the game world.
gameWorld = GameSettings.getGameWorld();
+ robotArmPositioningSystem = new RobotArmPositioningSystem();
gameWorld.setSystem(new MarkerPositioningSystem());
- gameWorld.setSystem(new ObjectPositioningSystem(), true);
+ gameWorld.setSystem(robotArmPositioningSystem, true);
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
// TODO: Make and add object-marker collision detection system.
@@ -442,6 +446,7 @@ public class InGameState extends BaseState{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
MotorEvent event;
+ UserInput input;
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
@@ -529,8 +534,14 @@ public class InGameState extends BaseState{
event.setPower((byte)0x00);
queue.addEvent(event);
}
+
}else{
- // TODO: Send input to the input handler system.
+ input = UserInputFactory.createTouchUserInput();
+
+ // TODO: Calculate movement ray.
+
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
return true;
@@ -640,8 +651,6 @@ public class InGameState extends BaseState{
motorButtonsPointers[6] = -1;
motorButtonsTouched[6] = false;
- }else{
- // TODO: Pass input to the input handler system.
}
return true;
@@ -748,8 +757,6 @@ public class InGameState extends BaseState{
motorButtonsPointers[6] = -1;
motorButtonsTouched[6] = false;
- }else{
- // TODO: Pass input to the input handler system.
}
return true;
@@ -846,8 +853,9 @@ public class InGameState extends BaseState{
event.setMotor(motor_t.RECENTER);
event.setPower((byte)0x00);
queue.addEvent(event);
- }else{
- // TODO: Pass input to the input handler system.
+
+ }else if(buttonCode == Ouya.BUTTON_A){
+ core.nextState = game_states_t.MAIN_MENU;
}
return true;
@@ -923,8 +931,6 @@ public class InGameState extends BaseState{
}else if(buttonCode == Ouya.BUTTON_Y){
motorGamepadButtonPressed[6] = false;
- }else{
- // TODO: Pass input to the input handler system.
}
return true;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
index 793db24..bdf9654 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
@@ -16,11 +16,9 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
-import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
-import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
@@ -35,40 +33,19 @@ import com.badlogic.gdx.graphics.g3d.ModelBatch;
* entities to be rendered must have a geometry, shader and mesh component associated.
*/
public class ObjectRenderingSystem extends EntityProcessingSystem {
-// @Mapper ComponentMapper geometryMapper;
@Mapper ComponentMapper shaderMapper;
@Mapper ComponentMapper modelMapper;
@Mapper ComponentMapper environmentMapper;
- @Mapper ComponentMapper visibiltyMapper;
-
-// /**
-// * A matrix representing 3D translations.
-// */
-// private Matrix4 translationMatrix;
-//
-// /**
-// * A matrix representing 3D rotations.
-// */
-// private Matrix4 rotationMatrix;
-//
-// /**
-// * A matrix representing 3D scalings.
-// */
-// private Matrix4 scalingMatrix;
private PerspectiveCamera camera;
-
private ModelBatch batch;
@SuppressWarnings("unchecked")
public ObjectRenderingSystem(ModelBatch batch) {
- super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class, VisibilityComponent.class).exclude(MarkerCodeComponent.class));
+ super(Aspect.getAspectForAll(ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class));
- camera = null;
- this.batch = batch;
-// translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
-// rotationMatrix = new Matrix4().idt();
-// scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
+ camera = null;
+ this.batch = batch;
}
public void begin(PerspectiveCamera camera) throws RuntimeException{
@@ -84,37 +61,18 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
camera = null;
}
- /**
- * Renders the entity passed by parameter, calculating it's corresponding geometric
- * transformation and setting and calling it's associated shader program.
- *
- * @param e The entity to be processed.
- */
@Override
protected void process(Entity e) {
EnvironmentComponent environment;
-// GeometryComponent geometryComponent;
ShaderComponent shaderComponent;
RenderModelComponent renderModelComponent;
- VisibilityComponent visibility;
// Get the necessary components.
-// geometryComponent = geometryMapper.get(e);
renderModelComponent = modelMapper.get(e);
shaderComponent = shaderMapper.get(e);
environment = environmentMapper.get(e);
- visibility = visibiltyMapper.get(e);
- if(visibility.visible){
- // Calculate the geometric transformation for this entity.
-// translationMatrix.setToTranslation(geometryComponent.position);
-// rotationMatrix.set(geometryComponent.rotation);
-// scalingMatrix.setToScaling(geometryComponent.scaling);
-// renderModelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
-// renderModelComponent.instance.calculateTransforms();
-
- // Render this entity.
- batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
- }
+ // Render this entity.
+ batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
similarity index 61%
rename from src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java
rename to src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index 624cbce..0278434 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -16,6 +16,10 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
+import ve.ucv.ciens.ccg.nxtar.factories.products.GamepadUserInput;
+import ve.ucv.ciens.ccg.nxtar.factories.products.KeyboardUserInput;
+import ve.ucv.ciens.ccg.nxtar.factories.products.TouchUserInput;
+import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
@@ -23,22 +27,35 @@ import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
-public class ObjectPositioningSystem extends EntityProcessingSystem {
+public class RobotArmPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper geometryMapper;
+ private UserInput input;
+
@SuppressWarnings("unchecked")
- public ObjectPositioningSystem(){
+ public RobotArmPositioningSystem(){
super(Aspect.getAspectForAll(GeometryComponent.class));
}
- public void setUserInput(){
- // TODO: Desing a representation for user input.
- // TODO: Store user input for processing.
+ public void setUserInput(UserInput input){
+ this.input = input;
}
@Override
protected void process(Entity e) {
GeometryComponent geometry = geometryMapper.get(e);
- // TODO: Set the geometry fields based on user input.
+
+ if(input == null) return;
+
+ if(input instanceof TouchUserInput){
+
+ }else if(input instanceof GamepadUserInput){
+
+ }else if(input instanceof KeyboardUserInput){
+
+ }else
+ throw new ClassCastException("Input is not a valid UserInput instance.");
+
+ input = null;
}
}
From 8abf594c8a128b88afaa885aa44089450ce222fb Mon Sep 17 00:00:00 2001
From: unknown
Date: Tue, 10 Jun 2014 16:59:21 -0430
Subject: [PATCH 12/34] Added collision detection.
---
.../AutomaticMovementComponent.java | 35 ++++++
.../CollisionDetectionComponent.java} | 12 +-
.../nxtar/entities/BombGameEntityCreator.java | 38 ++++--
.../products => input}/GamepadUserInput.java | 2 +-
.../products => input}/KeyboardUserInput.java | 2 +-
.../TouchUserInput.java} | 23 ++--
.../products => input}/UserInput.java | 9 +-
.../nxtar/network/VideoStreamingThread.java | 8 --
.../network/monitors/VideoFrameMonitor.java | 4 -
.../ciens/ccg/nxtar/states/InGameState.java | 68 ++++++++---
.../ccg/nxtar/states/MainMenuStateBase.java | 2 +-
.../systems/CollisionDetectionSystem.java | 51 +++++++-
.../systems/RobotArmPositioningSystem.java | 114 +++++++++++++++---
.../ciens/ccg/nxtar/utils/GameSettings.java | 5 +-
src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java | 24 ++++
15 files changed, 310 insertions(+), 87 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
rename src/ve/ucv/ciens/ccg/nxtar/{factories/products/TouchUserInput.java => components/CollisionDetectionComponent.java} (73%)
rename src/ve/ucv/ciens/ccg/nxtar/{factories/products => input}/GamepadUserInput.java (94%)
rename src/ve/ucv/ciens/ccg/nxtar/{factories/products => input}/KeyboardUserInput.java (95%)
rename src/ve/ucv/ciens/ccg/nxtar/{factories/UserInputFactory.java => input/TouchUserInput.java} (51%)
rename src/ve/ucv/ciens/ccg/nxtar/{factories/products => input}/UserInput.java (74%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
new file mode 100644
index 0000000..99f654f
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+import com.badlogic.gdx.math.Vector3;
+
+public class AutomaticMovementComponent extends Component {
+ public boolean moving;
+ public boolean forward;
+ public Vector3 startPoint;
+ public Vector3 endPoint;
+ public float distance;
+
+ public AutomaticMovementComponent(){
+ this.moving = false;
+ this.forward = true;
+ this.startPoint = new Vector3();
+ this.endPoint = new Vector3();
+ this.distance = 0.0f;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/components/CollisionDetectionComponent.java
similarity index 73%
rename from src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java
rename to src/ve/ucv/ciens/ccg/nxtar/components/CollisionDetectionComponent.java
index 4a4ab2d..4fee5a1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/factories/products/TouchUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/CollisionDetectionComponent.java
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.factories.products;
+package ve.ucv.ciens.ccg.nxtar.components;
-import com.badlogic.gdx.math.collision.Ray;
+import com.artemis.Component;
-public class TouchUserInput extends UserInput {
- public Ray movementRay;
+public class CollisionDetectionComponent extends Component {
+ public boolean colliding;
- public TouchUserInput(){
- movementRay = null;
+ public CollisionDetectionComponent(){
+ this.colliding = false;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index f1ec915..8f64be1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -16,8 +16,10 @@
package ve.ucv.ciens.ccg.nxtar.entities;
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.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
@@ -26,8 +28,10 @@ import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
+import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import com.artemis.Entity;
+import com.artemis.managers.GroupManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
@@ -64,8 +68,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
}
- private Shader shader;
- private int currentBombId;
+ private Shader shader;
+ private int currentBombId;
+ private GroupManager groupManager;
// Render models.
private Model robotArmModel = null;
@@ -82,7 +87,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model wiresBombModelWire1 = null;
private Model wiresBombModelWire2 = null;
private Model wiresBombModelWire3 = null;
- private Model easterEggModel = null;
+ private Model monkeyModel = null;
// Collision models.
private Model robotArmCollisionModel = null;
@@ -99,7 +104,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model wiresBombCollisionModelWire1 = null;
private Model wiresBombCollisionModelWire2 = null;
private Model wiresBombCollisionModelWire3 = null;
- private Model easterEggCollisionModel = null;
public BombGameEntityCreator(){
currentBombId = 0;
@@ -123,7 +127,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
manager.load("models/render_models/bomb_game/cable_1.g3db", Model.class);
manager.load("models/render_models/bomb_game/cable_2.g3db", Model.class);
manager.load("models/render_models/bomb_game/cable_3.g3db", Model.class);
- // manager.load("models/render_models/bomb_game/", Model.class);
+ manager.load("models/render_models/bomb_game/monkey.g3db", Model.class);
// Load the collision models.
manager.load("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
@@ -143,12 +147,14 @@ public class BombGameEntityCreator extends EntityCreatorBase{
manager.load("models/collision_models/bomb_game/cable_1_col.g3db", Model.class);
manager.load("models/collision_models/bomb_game/cable_2_col.g3db", Model.class);
manager.load("models/collision_models/bomb_game/cable_3_col.g3db", Model.class);
- // manager.load("models/collision_models/bomb_game/door.g3db", Model.class);
}
@Override
public void createAllEntities(){
EntityParameters parameters;
+ Entity monkey;
+
+ groupManager = world.getManager(GroupManager.class);
// Create and set the lighting.
parameters = new EntityParameters();
@@ -186,7 +192,15 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters.markerCode = 91;
addDoor(parameters);
- // TODO: Add easter egg.
+ // Add the monkey.
+ monkey = world.createEntity();
+ monkey.addComponent(new RenderModelComponent(monkeyModel));
+ monkey.addComponent(new GeometryComponent());
+ monkey.addComponent(new MarkerCodeComponent(1023));
+ monkey.addComponent(new VisibilityComponent());
+ monkey.addComponent(new ShaderComponent(shader));
+ monkey.addComponent(new EnvironmentComponent(parameters.environment));
+ monkey.addToWorld();
entitiesCreated = true;
}
@@ -217,11 +231,13 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
- robotArm.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
+ robotArm.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel));
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
+ robotArm.addComponent(new AutomaticMovementComponent());
+ robotArm.addComponent(new CollisionDetectionComponent());
robotArm.addToWorld();
}
@@ -264,6 +280,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
// Add the bomb and increase the id for the next one.
+ groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT);
bomb.addToWorld();
currentBombId++;
}
@@ -320,6 +337,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new BombComponent(bomb));
thing.addComponent(new VisibilityComponent());
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECT);
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
@@ -351,6 +369,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
door.addComponent(new VisibilityComponent());
doorInstance = door.getComponent(RenderModelComponent.class).instance;
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
+ groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECT);
door.addToWorld();
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
@@ -396,7 +415,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombModelWire1 = manager.get("models/render_models/bomb_game/cable_1.g3db", Model.class);
wiresBombModelWire2 = manager.get("models/render_models/bomb_game/cable_2.g3db", Model.class);
wiresBombModelWire3 = manager.get("models/render_models/bomb_game/cable_3.g3db", Model.class);
- // easterEggModel = manager.get("models/render_models/bomb_game/", Model.class);
+ monkeyModel = manager.get("models/render_models/bomb_game/monkey.g3db", Model.class);
// Get the collision models.
robotArmCollisionModel = manager.get("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
@@ -416,6 +435,5 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombCollisionModelWire1 = manager.get("models/collision_models/bomb_game/cable_1_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);
- // easterEggCollisionModel = manager.get("models/collision_models/bomb_game/door.g3db", Model.class);
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java
similarity index 94%
rename from src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java
rename to src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java
index f39a496..59b79d2 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/factories/products/GamepadUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.factories.products;
+package ve.ucv.ciens.ccg.nxtar.input;
public class GamepadUserInput extends UserInput {
public float axisLeftX;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java
similarity index 95%
rename from src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java
rename to src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java
index 813c6fb..31949ea 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/factories/products/KeyboardUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.factories.products;
+package ve.ucv.ciens.ccg.nxtar.input;
public class KeyboardUserInput extends UserInput {
public boolean keyLeft;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java b/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
similarity index 51%
rename from src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java
rename to src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
index 26eee80..16492f2 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/factories/UserInputFactory.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
@@ -13,23 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.factories;
+package ve.ucv.ciens.ccg.nxtar.input;
-import ve.ucv.ciens.ccg.nxtar.factories.products.GamepadUserInput;
-import ve.ucv.ciens.ccg.nxtar.factories.products.KeyboardUserInput;
-import ve.ucv.ciens.ccg.nxtar.factories.products.TouchUserInput;
-import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
+import com.badlogic.gdx.math.Vector3;
-public abstract class UserInputFactory{
- public static UserInput createTouchUserInput(){
- return new TouchUserInput();
+public class TouchUserInput extends UserInput {
+ public Vector3 userTouchEndPoint;
+
+ public TouchUserInput(){
+ this.userTouchEndPoint = null;
}
- public static UserInput createGamepadUserInput(){
- return new GamepadUserInput();
+ public TouchUserInput(Vector3 userTouchEndPoint){
+ this.userTouchEndPoint = new Vector3(userTouchEndPoint);
}
- public static UserInput createKeyboardUserInput(){
- return new KeyboardUserInput();
+ public TouchUserInput(float x, float y, float z){
+ this.userTouchEndPoint = new Vector3(x, y, z);
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java
similarity index 74%
rename from src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java
rename to src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java
index 8213aa8..6e38daa 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/factories/products/UserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java
@@ -13,11 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.factories.products;
+package ve.ucv.ciens.ccg.nxtar.input;
-import ve.ucv.ciens.ccg.nxtar.factories.UserInputFactory;
-
-/**
- * Tag class for the {@link UserInputFactory} products.
- */
-public abstract class UserInput{}
+public abstract class UserInput{ }
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
index 3230826..4110053 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
-import java.net.Socket;
import ve.ucv.ciens.ccg.networkdata.VideoFrameDataMessage;
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
@@ -41,7 +40,6 @@ public class VideoStreamingThread extends Thread{
private boolean pause;
private boolean coreNotified;
private Object protocolPauseMonitor;
- private Socket client;
private VideoFrameMonitor frameMonitor;
private long then;
private long now;
@@ -236,12 +234,6 @@ public class VideoStreamingThread extends Thread{
}
}
- try{
- client.close();
- }catch(IOException io){
- Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error closing client socket.", io);
- }
-
Gdx.app.debug(TAG, CLASS_NAME + ".run() :: Thread finished.");
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/monitors/VideoFrameMonitor.java b/src/ve/ucv/ciens/ccg/nxtar/network/monitors/VideoFrameMonitor.java
index a0902ec..4d598ff 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/monitors/VideoFrameMonitor.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/monitors/VideoFrameMonitor.java
@@ -61,14 +61,11 @@ public class VideoFrameMonitor{
public void setNewFrame(byte[] frame){
byte[] temp;
- Gdx.app.debug(TAG, CLASS_NAME + ".setNewFrame() :: Loading new frame in frameA.");
frameA = frame;
temp = frameA;
synchronized(frameMonitor){
- Gdx.app.debug(TAG, CLASS_NAME + ".setNewFrame() :: Swapping frameA and frameB.");
frameA = frameB;
frameB = temp;
- Gdx.app.debug(TAG, CLASS_NAME + ".setNewFrame() :: Swapping done.");
}
}
@@ -76,7 +73,6 @@ public class VideoFrameMonitor{
byte[] frame;
synchronized(frameMonitor){
- //Gdx.app.debug(TAG, CLASS_NAME + ".getCurrentFrame() :: Fetching frameB.");
frame = frameB;
}
return frame;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 8d00f7c..08644af 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -19,13 +19,14 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
-import ve.ucv.ciens.ccg.nxtar.factories.UserInputFactory;
-import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
+import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
+import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
@@ -60,6 +61,7 @@ public class InGameState extends BaseState{
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
private static final float NEAR = 0.01f;
private static final float FAR = 100.0f;
+ private static final Vector3 TEMP_VEC_3 = new Vector3();
// Background related fields.
private float uScaling[];
@@ -79,7 +81,7 @@ public class InGameState extends BaseState{
private RobotArmPositioningSystem robotArmPositioningSystem;
// Cameras.
- private OrthographicCamera unitaryOrthoCamera;
+ private OrthographicCamera unitaryOrthographicCamera;
private OrthographicCamera pixelPerfectOrthoCamera;
private CustomPerspectiveCamera perspectiveCamera;
@@ -118,7 +120,7 @@ public class InGameState extends BaseState{
// Set up the cameras.
pixelPerfectOrthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- unitaryOrthoCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
+ unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
if(!Ouya.runningOnOuya) setUpButtons();
@@ -183,15 +185,15 @@ public class InGameState extends BaseState{
gameWorld = GameSettings.getGameWorld();
robotArmPositioningSystem = new RobotArmPositioningSystem();
+ markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
+ objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
+
gameWorld.setSystem(new MarkerPositioningSystem());
- gameWorld.setSystem(robotArmPositioningSystem, true);
+ gameWorld.setSystem(robotArmPositioningSystem, Ouya.runningOnOuya);
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
- // TODO: Make and add object-marker collision detection system.
+ gameWorld.setSystem(new CollisionDetectionSystem());
//gameWorld.setSystem(GameSettings.gameLogicSystem);
-
- markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
- objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
gameWorld.setSystem(markerRenderingSystem, true);
gameWorld.setSystem(objectRenderingSystem, true);
@@ -325,7 +327,7 @@ public class InGameState extends BaseState{
// Set the correct camera for the device.
if(!Ouya.runningOnOuya){
- core.batch.setProjectionMatrix(unitaryOrthoCamera.combined);
+ core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
}else{
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
}
@@ -446,11 +448,11 @@ public class InGameState extends BaseState{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
MotorEvent event;
- UserInput input;
+ TouchUserInput input;
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
- unitaryOrthoCamera.unproject(win2world);
+ unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
@@ -536,12 +538,21 @@ public class InGameState extends BaseState{
}
}else{
- input = UserInputFactory.createTouchUserInput();
+ touchPointWorldCoords.set(win2world.x, win2world.y);
+ if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
+ Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer.");
- // TODO: Calculate movement ray.
+ TEMP_VEC_3.set(screenX, screenY, 1.0f);
+ perspectiveCamera.unproject(TEMP_VEC_3, frameBufferSprite.getX(), frameBufferSprite.getY(), frameBufferSprite.getWidth() * Gdx.graphics.getWidth(), frameBufferSprite.getHeight() * Gdx.graphics.getHeight());
+ TEMP_VEC_3.rotate(Vector3.Z, 90).nor();
+ TEMP_VEC_3.y = -TEMP_VEC_3.y;
+ //Gdx.app.log("TAG", CLASS_NAME + "touchDown(): Unprojected" + Utils.vector2String(TEMP_VEC_3));
- robotArmPositioningSystem.setUserInput(input);
- robotArmPositioningSystem.process();
+ input = new TouchUserInput(TEMP_VEC_3);
+ robotArmPositioningSystem.setUserInput(input);
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point outside framebuffer.");
+ }
}
return true;
@@ -556,7 +567,7 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
- unitaryOrthoCamera.unproject(win2world);
+ unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
@@ -665,7 +676,7 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
- unitaryOrthoCamera.unproject(win2world);
+ unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
if(pointer == motorButtonsPointers[0] && !motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
@@ -941,7 +952,26 @@ public class InGameState extends BaseState{
@Override
public boolean axisMoved(Controller controller, int axisCode, float value){
- // TODO: Pass input to the input handler system.
+ GamepadUserInput userInput;
+
+ if(Math.abs(value) > Ouya.STICK_DEADZONE){
+ userInput = new GamepadUserInput();
+ if(axisCode == Ouya.AXIS_LEFT_X){
+ userInput.axisLeftX = value;
+ }else if(axisCode == Ouya.AXIS_LEFT_Y){
+ userInput.axisLeftY = value;
+ }else if(axisCode == Ouya.AXIS_RIGHT_X){
+ userInput.axisRightX = value;
+ }else if(axisCode == Ouya.AXIS_RIGHT_Y){
+ userInput.axisRightY = value;
+ }
+
+ robotArmPositioningSystem.setUserInput(userInput);
+ robotArmPositioningSystem.process();
+
+ return true;
+ }
+
return false;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
index 56c1614..09098c4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
@@ -312,7 +312,7 @@ public abstract class MainMenuStateBase extends BaseState{
@Override
public boolean keyDown(int keycode){
if(keycode == Input.Keys.BACK){
- // Ignore.
+ Gdx.app.exit();
return true;
}
return false;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
index ef9e21d..7b01e3d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
@@ -15,23 +15,68 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
+import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
+import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect;
+import com.artemis.ComponentMapper;
import com.artemis.Entity;
+import com.artemis.annotations.Mapper;
+import com.artemis.managers.GroupManager;
import com.artemis.systems.EntityProcessingSystem;
+import com.artemis.utils.ImmutableBag;
+import com.badlogic.gdx.math.collision.BoundingBox;
public class CollisionDetectionSystem extends EntityProcessingSystem {
+ public static final String COLLIDABLE_OBJECT = "COLLIDABLE";
+
+ @Mapper ComponentMapper collisionModelMapper;
+ @Mapper ComponentMapper collisionDetectionMapper;
+ @Mapper ComponentMapper visibilityMapper;
+
+ private GroupManager groupManager;
@SuppressWarnings("unchecked")
public CollisionDetectionSystem(){
- super(Aspect.getAspectForAll(CollisionModelComponent.class));
+ super(Aspect.getAspectForAll(CollisionModelComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
}
@Override
protected void process(Entity e) {
- // TODO Auto-generated method stub
+
+ VisibilityComponent visibility;
+ CollisionModelComponent collision;
+ CollisionModelComponent target;
+ CollisionDetectionComponent onCollision;
+ BoundingBox colBB = new BoundingBox();
+ BoundingBox targetBB = new BoundingBox();
+ ImmutableBag collidables;
+
+ groupManager = this.world.getManager(GroupManager.class);
+ collidables = groupManager.getEntities(COLLIDABLE_OBJECT);
+
+ collision = collisionModelMapper.get(e);
+ onCollision = collisionDetectionMapper.get(e);
+
+ for(int i = 0; i < collidables.size(); ++i){
+ target = collisionModelMapper.getSafe(collidables.get(i));
+ visibility = visibilityMapper.getSafe(collidables.get(i));
+
+ if(target == null || visibility == null) continue;
+
+ if(visibility.visible){
+ collision.instance.calculateBoundingBox(colBB);
+ target.instance.calculateBoundingBox(targetBB);
+
+ if(colBB.contains(targetBB)){
+ onCollision.colliding = true;
+ }else{
+ onCollision.colliding = false;
+ }
+ }
+ }
}
-
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index 0278434..d08fd34 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -15,26 +15,38 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
+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.factories.products.GamepadUserInput;
-import ve.ucv.ciens.ccg.nxtar.factories.products.KeyboardUserInput;
-import ve.ucv.ciens.ccg.nxtar.factories.products.TouchUserInput;
-import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
+import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
+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.utils.Utils;
import com.artemis.Aspect;
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.Vector3;
public class RobotArmPositioningSystem extends EntityProcessingSystem {
- @Mapper ComponentMapper geometryMapper;
+ private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
+ private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
+ private static final float STEP_SIZE = 0.05f;
+
+ @Mapper ComponentMapper geometryMapper;
+ @Mapper ComponentMapper autoMapper;
+ @Mapper ComponentMapper collisionMapper;
private UserInput input;
@SuppressWarnings("unchecked")
public RobotArmPositioningSystem(){
- super(Aspect.getAspectForAll(GeometryComponent.class));
+ super(Aspect.getAspectForAll(GeometryComponent.class, AutomaticMovementComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
}
public void setUserInput(UserInput input){
@@ -42,20 +54,94 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
}
@Override
- protected void process(Entity e) {
- GeometryComponent geometry = geometryMapper.get(e);
+ protected void process(Entity e) throws ClassCastException{
+ Vector3 endPoint;
+ GamepadUserInput tempGP;
+ KeyboardUserInput tempKey;
+ GeometryComponent geometry = geometryMapper.get(e);
+ AutomaticMovementComponent auto = autoMapper.get(e);
+ CollisionDetectionComponent collision = collisionMapper.get(e);
- if(input == null) return;
+ if(input == null){
+ if(auto.moving) autoMove(geometry, auto, collision);
+ else return;
- if(input instanceof TouchUserInput){
+ }else{
+ if(input instanceof TouchUserInput){
+ if(!auto.moving){
+ endPoint = ((TouchUserInput) input).userTouchEndPoint;
+ endPoint.set(endPoint.x, endPoint.y, -4.5f);
+ auto.startPoint.set(geometry.position);
+ auto.endPoint.set(endPoint);
+ auto.moving = true;
+ auto.forward = true;
- }else if(input instanceof GamepadUserInput){
+ Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
+ }else autoMove(geometry, auto, collision);
- }else if(input instanceof KeyboardUserInput){
+ }else if(input instanceof GamepadUserInput){
+ tempGP = (GamepadUserInput) input;
+ geometry.position.x += !collision.colliding ? tempGP.axisLeftY * STEP_SIZE : 0.0f;
+ geometry.position.y += !collision.colliding ? tempGP.axisLeftX * STEP_SIZE : 0.0f;
+ geometry.position.z += !collision.colliding ? tempGP.axisRightY * STEP_SIZE : 0.0f;
+ clampPosition(geometry);
- }else
- throw new ClassCastException("Input is not a valid UserInput instance.");
+ }else if(input instanceof KeyboardUserInput){
+ tempKey = (KeyboardUserInput) input;
+ geometry.position.x -= tempKey.keyUp && !collision.colliding ? STEP_SIZE : 0.0f;
+ geometry.position.x += tempKey.keyDown && !collision.colliding ? STEP_SIZE : 0.0f;
+ geometry.position.y -= tempKey.keyLeft && !collision.colliding ? STEP_SIZE : 0.0f;
+ geometry.position.y += tempKey.keyRight && !collision.colliding ? STEP_SIZE : 0.0f;
+ geometry.position.z -= tempKey.keyZ && !collision.colliding ? STEP_SIZE : 0.0f;
+ geometry.position.z += tempKey.keyA && !collision.colliding ? STEP_SIZE : 0.0f;
+ clampPosition(geometry);
+
+ }else
+ throw new ClassCastException("Input is not a valid UserInput instance.");
+ }
input = null;
}
+
+ private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
+ float step;
+
+ if(auto.moving){
+ if(auto.forward)
+ step = STEP_SIZE;
+ else
+ step = -STEP_SIZE;
+
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
+
+ auto.distance += step;
+
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
+
+ geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
+ geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
+ geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
+
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
+
+ if(auto.distance >= 1.0f || collision.colliding){
+ auto.forward = false;
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
+ }else if(auto.distance <= 0.0f){
+ auto.forward = true;
+ auto.moving = false;
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
+ }
+
+ }else return;
+ }
+
+ private void clampPosition(GeometryComponent geometry){
+ geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
+ geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
+ geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
+ geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
+ geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
+ geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index 77dba40..bde53b3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.utils;
import com.artemis.World;
+import com.artemis.managers.GroupManager;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
@@ -31,8 +32,10 @@ public abstract class GameSettings{
if(core == null)
throw new IllegalArgumentException("Core is null.");
- if(getGameWorld() == null)
+ if(getGameWorld() == null){
gameWorld = new World();
+ gameWorld.setManager(new GroupManager());
+ }
if(getEntityCreator() == null){
entityCreator = new BombGameEntityCreator();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
new file mode 100644
index 0000000..15a7ed7
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
@@ -0,0 +1,24 @@
+/*
+ * 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.utils;
+
+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) + ")";
+ }
+}
From 36eea36c15f9b74d37ffc8e6b250b39f6e0d461c Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 11 Jun 2014 11:18:12 -0430
Subject: [PATCH 13/34] Added freeInstance to network. Modelling game logic.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 6 +++
.../nxtar/components/AnimationComponent.java | 32 +++++++++---
.../BombGameObjectTypeComponent.java | 36 ++++++++++++++
.../nxtar/components/MarkerCodeComponent.java | 9 +++-
.../nxtar/entities/BombGameEntityCreator.java | 28 +++++++----
.../ccg/nxtar/network/RobotControlThread.java | 11 ++++-
.../ccg/nxtar/network/SensorReportThread.java | 11 ++++-
.../nxtar/network/ServiceDiscoveryThread.java | 32 ++++++------
.../nxtar/network/VideoStreamingThread.java | 16 ++++--
.../ciens/ccg/nxtar/states/InGameState.java | 2 +-
.../ccg/nxtar/systems/AnimationSystem.java | 13 ++++-
.../nxtar/systems/BombGameLogicSystem.java | 49 ++++++++++++++++++-
.../systems/CollisionDetectionSystem.java | 18 ++++---
.../systems/RobotArmPositioningSystem.java | 45 +++++++++++------
.../ciens/ccg/nxtar/utils/GameSettings.java | 10 ++--
15 files changed, 251 insertions(+), 67 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 50cb1ec..f49a3b8 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -425,8 +425,14 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
*/
public void dispose(){
// Finish network threads.
+ serviceDiscoveryThread.finish();
videoThread.finish();
robotThread.finish();
+ sensorThread.finish();
+ ServiceDiscoveryThread.freeInstance();
+ VideoStreamingThread.freeInstance();
+ RobotControlThread.freeInstance();
+ SensorReportThread.freeInstance();
// Dispose graphic objects.
fadeTexture.dispose();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/AnimationComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/AnimationComponent.java
index 36e6ea9..8c646e5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/AnimationComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/AnimationComponent.java
@@ -24,11 +24,16 @@ import com.badlogic.gdx.graphics.g3d.utils.AnimationController;
public class AnimationComponent extends Component {
public AnimationController controller;
+ public AnimationController collisionController;
public List animationsIds;
public int current;
public int next;
public boolean loop;
+ public AnimationComponent(ModelInstance instance, ModelInstance collisionInstance){
+ this(instance, -1, false, collisionInstance);
+ }
+
public AnimationComponent(ModelInstance instance) throws IllegalArgumentException{
this(instance, -1, false);
}
@@ -40,19 +45,32 @@ public class AnimationComponent extends Component {
public AnimationComponent(ModelInstance instance, int next, boolean loop) throws IllegalArgumentException{
if(instance == null)
throw new IllegalArgumentException("Instance is null.");
- else if(next < 0)
- throw new IllegalArgumentException("Next is less than 0.");
else if(next > instance.animations.size)
throw new IllegalArgumentException("Next is greater than the number of animations for this model.");
- controller = new AnimationController(instance);
- animationsIds = new LinkedList();
- current = -1;
- this.next = next;
- this.loop = loop;
+ controller = new AnimationController(instance);
+ collisionController = null;
+ animationsIds = new LinkedList();
+ current = -1;
+ this.next = next;
+ this.loop = loop;
for(int i = 0; i < instance.animations.size; i++){
animationsIds.add(instance.animations.get(i).id);
}
}
+
+ public AnimationComponent(ModelInstance instance, int next, boolean loop, ModelInstance collisionInstance) throws IllegalArgumentException{
+ this(instance, next, loop);
+
+ if(instance.animations.size != collisionInstance.animations.size)
+ throw new IllegalArgumentException("Animation number doesn't match between render model and collision model.");
+
+ for(int i = 0; i < instance.animations.size; i++){
+ if(!instance.animations.get(i).id.contentEquals(collisionInstance.animations.get(i).id))
+ throw new IllegalArgumentException("Animations don't match between render model and collision model.");
+ }
+
+ collisionController = new AnimationController(collisionInstance);
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
new file mode 100644
index 0000000..01a0c03
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+public class BombGameObjectTypeComponent extends Component {
+ public static final int BOMB_WIRE_1 = 10;
+ public static final int BOMB_WIRE_2 = 11;
+ public static final int BOMB_WIRE_3 = 12;
+ public static final int BIG_BUTTON = 20;
+ public static final int COM_BUTTON_1 = 30;
+ public static final int COM_BUTTON_2 = 31;
+ public static final int COM_BUTTON_3 = 32;
+ public static final int COM_BUTTON_4 = 33;
+ public static final int DOOR = 40;
+
+ public int type;
+
+ public BombGameObjectTypeComponent(int type){
+ this.type = type;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/MarkerCodeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/MarkerCodeComponent.java
index 400f503..9dfdc0e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/MarkerCodeComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/MarkerCodeComponent.java
@@ -18,11 +18,18 @@ package ve.ucv.ciens.ccg.nxtar.components;
import com.artemis.Component;
public class MarkerCodeComponent extends Component {
- public int code;
+ public int code;
+ public boolean enabled;
public MarkerCodeComponent(int code) throws IllegalArgumentException{
if(code < 0 || code > 1024)
throw new IllegalArgumentException("Marker code must be between [0, 1024].");
this.code = code;
+ this.enabled = true;
+ }
+
+ public MarkerCodeComponent(int code, boolean enabled){
+ this(code);
+ this.enabled = enabled;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 8f64be1..cd1ae29 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -19,6 +19,7 @@ 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.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
@@ -182,7 +183,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
addBomb(parameters, bomb_type_t.WIRES);
// Add doors.
- parameters.nextAnimation = 1;
+ parameters.nextAnimation = -1;
parameters.loopAnimation = false;
parameters.markerCode = 89;
@@ -293,7 +294,10 @@ public class BombGameEntityCreator extends EntityCreatorBase{
button3 = addBombParaphernalia(combinationButton3Model, combinationButton3CollisionModel, bomb, parameters);
button4 = addBombParaphernalia(combinationButton4Model, combinationButton4CollisionModel, bomb, parameters);
- // TODO: Add button parameters.
+ button1.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_1));
+ button2.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_2));
+ button3.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_3));
+ button4.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_4));
button1.addToWorld();
button2.addToWorld();
@@ -305,9 +309,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
Entity button;
button = addBombParaphernalia(inclinationBombButtonModel, inclinationBombButtonCollisionModel, bomb, parameters);
-
- // TODO: Add button parameters.
-
+ button.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BIG_BUTTON));
button.addToWorld();
}
@@ -318,7 +320,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire2 = addBombParaphernalia(wiresBombModelWire2, wiresBombCollisionModelWire2, bomb, parameters);
wire3 = addBombParaphernalia(wiresBombModelWire3, wiresBombCollisionModelWire3, bomb, parameters);
- // TODO: Add Wire parameters.
+ wire1.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BOMB_WIRE_1));
+ wire2.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BOMB_WIRE_2));
+ wire3.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BOMB_WIRE_3));
wire1.addToWorld();
wire2.addToWorld();
@@ -337,6 +341,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new BombComponent(bomb));
thing.addComponent(new VisibilityComponent());
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ thing.addComponent(new CollisionDetectionComponent());
groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECT);
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
@@ -346,7 +351,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void addDoor(EntityParameters parameters){
- ModelInstance doorInstance;
+ ModelInstance doorInstance, doorColInstance;
Entity frame, door;
frame = world.createEntity();
@@ -367,8 +372,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
door.addComponent(new ShaderComponent(parameters.shader));
door.addComponent(new MarkerCodeComponent(parameters.markerCode));
door.addComponent(new VisibilityComponent());
- doorInstance = door.getComponent(RenderModelComponent.class).instance;
- door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
+ doorInstance = door.getComponent(RenderModelComponent.class).instance;
+ doorColInstance = door.getComponent(CollisionModelComponent.class).instance;
+ door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation, doorColInstance));
+ door.addComponent(new CollisionDetectionComponent());
+ door.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR));
groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECT);
door.addToWorld();
@@ -415,7 +423,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombModelWire1 = manager.get("models/render_models/bomb_game/cable_1.g3db", Model.class);
wiresBombModelWire2 = manager.get("models/render_models/bomb_game/cable_2.g3db", Model.class);
wiresBombModelWire3 = manager.get("models/render_models/bomb_game/cable_3.g3db", Model.class);
- monkeyModel = manager.get("models/render_models/bomb_game/monkey.g3db", Model.class);
+ monkeyModel = manager.get("models/render_models/bomb_game/monkey.g3db", Model.class);
// Get the collision models.
robotArmCollisionModel = manager.get("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
index 7b69deb..21591d6 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
@@ -34,6 +34,7 @@ public class RobotControlThread extends Thread {
public static final String THREAD_NAME = "RobotControlThread";
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
private static final String CLASS_NAME = RobotControlThread.class.getSimpleName();
+ private static int refCount = 0;
private ApplicationEventsListener netListener;
private ServerSocket server;
@@ -62,13 +63,21 @@ public class RobotControlThread extends Thread {
}
private static class SingletonHolder{
- public static final RobotControlThread INSTANCE = new RobotControlThread();
+ public static RobotControlThread INSTANCE;
}
public static RobotControlThread getInstance(){
+ if(refCount == 0)
+ SingletonHolder.INSTANCE = new RobotControlThread();
+ refCount++;
return SingletonHolder.INSTANCE;
}
+ public static void freeInstance(){
+ refCount--;
+ if(refCount == 0) SingletonHolder.INSTANCE = null;
+ }
+
public void addNetworkConnectionListener(ApplicationEventsListener listener){
netListener = listener;
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
index b8ee6a9..175835d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
@@ -29,6 +29,7 @@ public class SensorReportThread extends Thread {
public static final String THREAD_NAME = "SensorReportThread";
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
private static final String CLASS_NAME = SensorReportThread.class.getSimpleName();
+ private static int refCount = 0;
private ApplicationEventsListener netListener;
private ServerSocket server;
@@ -56,13 +57,21 @@ public class SensorReportThread extends Thread {
}
private static class SingletonHolder{
- public final static SensorReportThread INSTANCE = new SensorReportThread();
+ public static SensorReportThread INSTANCE;
}
public static SensorReportThread getInstance(){
+ if(refCount == 0)
+ SingletonHolder.INSTANCE = new SensorReportThread();
+ refCount++;
return SingletonHolder.INSTANCE;
}
+ public static void freeInstance(){
+ refCount--;
+ if(refCount == 0) SingletonHolder.INSTANCE = null;
+ }
+
public void addNetworkConnectionListener(ApplicationEventsListener listener){
netListener = listener;
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/ServiceDiscoveryThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/ServiceDiscoveryThread.java
index e740513..8a54bcf 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/ServiceDiscoveryThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/ServiceDiscoveryThread.java
@@ -38,35 +38,28 @@ import com.badlogic.gdx.Gdx;
* @author miky
*/
public class ServiceDiscoveryThread extends Thread {
- /**
- * The name used to identify this thread.
- */
- public static final String THREAD_NAME = "ServiceDiscoveryThread";
- /**
- * Tag used for logging.
- */
+ public static final String THREAD_NAME = "ServiceDiscoveryThread";
private static final String TAG = "NXTAR_CORE_UDPTHREAD";
- /**
- * Class name used for logging.
- */
private static final String CLASS_NAME = ServiceDiscoveryThread.class.getSimpleName();
- /**
- * Maximum number of transmission attempts before ending the thread abruptly.
- */
- private static final int MAX_RETRIES = 5;
+ private static final int MAX_RETRIES = 5;
+
+ private static int refCount = 0;
/**
* A semaphore object used to synchronize acces to this thread finish flag.
*/
private Object semaphore;
+
/**
* The finish flag.
*/
private boolean done;
+
/**
* The UDP server socket used for the ad hoc service discovery protocol.
*/
private DatagramSocket udpServer;
+
/**
* Holder for the multicast address used in the protocol.
*/
@@ -101,7 +94,7 @@ public class ServiceDiscoveryThread extends Thread {
* Singleton holder for this class.
*/
private static class SingletonHolder{
- public static final ServiceDiscoveryThread INSTANCE = new ServiceDiscoveryThread();
+ public static ServiceDiscoveryThread INSTANCE;
}
/**
@@ -110,9 +103,17 @@ public class ServiceDiscoveryThread extends Thread {
* @return The singleton instance.
*/
public static ServiceDiscoveryThread getInstance(){
+ if(refCount == 0)
+ SingletonHolder.INSTANCE = new ServiceDiscoveryThread();
+ refCount++;
return SingletonHolder.INSTANCE;
}
+ public static void freeInstance(){
+ refCount--;
+ if(refCount == 0) SingletonHolder.INSTANCE = null;
+ }
+
/**
* This thread's run method.
*
@@ -138,6 +139,7 @@ public class ServiceDiscoveryThread extends Thread {
// Verify if the thread should end. If that is the case, close the server.
synchronized(semaphore){
if(done){
+ Gdx.app.log(TAG, CLASS_NAME + ".run(): Closing.");
udpServer.close();
break;
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
index 4110053..65354e6 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java
@@ -32,6 +32,7 @@ public class VideoStreamingThread extends Thread{
public static final String THREAD_NAME = "VideoStreamingThread";
private static final String TAG = "NXTAR_CORE_VIDEOTHREAD";
private static final String CLASS_NAME = VideoStreamingThread.class.getSimpleName();
+ private static int refCount = 0;
private ApplicationEventsListener netListener;
private DatagramSocket socket;
@@ -70,13 +71,21 @@ public class VideoStreamingThread extends Thread{
}
private static class SingletonHolder{
- public static final VideoStreamingThread INSTANCE = new VideoStreamingThread();
+ public static VideoStreamingThread INSTANCE;
}
public static VideoStreamingThread getInstance(){
+ if(refCount == 0)
+ SingletonHolder.INSTANCE = new VideoStreamingThread();
+ refCount++;
return SingletonHolder.INSTANCE;
}
+ public static void freeInstance(){
+ refCount--;
+ if(refCount == 0) SingletonHolder.INSTANCE = null;
+ }
+
public void addNetworkConnectionListener(ApplicationEventsListener listener){
netListener = listener;
}
@@ -139,6 +148,7 @@ public class VideoStreamingThread extends Thread{
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Reading message size from socket.");
try{
packet = new DatagramPacket(size, size.length);
+ socket.setSoTimeout(1000);
socket.receive(packet);
}catch(IOException io){
Gdx.app.error(TAG, CLASS_NAME + ".receiveUdp() :: IOException receiving size " + io.getMessage());
@@ -198,7 +208,7 @@ public class VideoStreamingThread extends Thread{
public int getFps(){
return fps;
}
-
+
public int getLostFrames(){
return lostFrames;
}
@@ -242,7 +252,7 @@ public class VideoStreamingThread extends Thread{
pause = true;
}
}
-
+
public void play(){
synchronized (pauseMonitor){
pause = false;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 08644af..9f185ec 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -193,7 +193,7 @@ public class InGameState extends BaseState{
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem());
- //gameWorld.setSystem(GameSettings.gameLogicSystem);
+ //gameWorld.setSystem(GameSettings.getGameLogicSystem());
gameWorld.setSystem(markerRenderingSystem, true);
gameWorld.setSystem(objectRenderingSystem, true);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
index cd73cb3..75bde35 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
@@ -46,9 +46,20 @@ public class AnimationSystem extends EntityProcessingSystem {
}else{
animation.controller.animate(animation.animationsIds.get(animation.next), loopCount, 1, null, 0.1f);
}
+
+ if(animation.collisionController != null){
+ if(animation.collisionController.current == null){
+ animation.collisionController.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null);
+ }else{
+ animation.collisionController.animate(animation.animationsIds.get(animation.next), loopCount, 1, null, 0.1f);
+ }
+ }
}
- if(visibility.visible)
+ if(visibility.visible){
animation.controller.update(Gdx.graphics.getDeltaTime());
+ if(animation.collisionController != null)
+ animation.collisionController.update(Gdx.graphics.getDeltaTime());
+ }
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index c987bec..3b16f99 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -15,17 +15,64 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
+import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
+import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
+import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
+
import com.artemis.Aspect;
+import com.artemis.ComponentMapper;
import com.artemis.Entity;
+import com.artemis.annotations.Mapper;
+import com.badlogic.gdx.Gdx;
public class BombGameLogicSystem extends GameLogicSystemBase {
+ private static final String TAG = "BOMB_GAME_LOGIC";
+ private static final String CLASS_NAME = BombGameLogicSystem.class.getSimpleName();
+
+ @Mapper ComponentMapper typeMapper;
+ @Mapper ComponentMapper animationMapper;
+ @Mapper ComponentMapper visibilityMapper;
+ @Mapper ComponentMapper markerMapper;
+ @Mapper ComponentMapper collisionMapper;
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
- super(Aspect.getAspectForAll(null));
+ super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
}
@Override
protected void process(Entity e){
+ BombGameObjectTypeComponent typeComponent;
+
+ typeComponent = typeMapper.get(e);
+
+ switch(typeComponent.type){
+ case BombGameObjectTypeComponent.DOOR:
+ processDoor(e);
+ break;
+ default: break;
+ }
+ }
+
+ private void processDoor(Entity d){
+ CollisionDetectionComponent collision = collisionMapper.getSafe(d);
+ AnimationComponent animation = animationMapper.getSafe(d);
+ VisibilityComponent visibility = visibilityMapper.getSafe(d);
+ MarkerCodeComponent marker = markerMapper.getSafe(d);
+
+ if(marker == null || collision == null || animation == null || visibility == null){
+ Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Door is missing some components.");
+ return;
+ }
+
+ if(marker.enabled && visibility.visible && collision.colliding && animation.current != 1){
+ animation.next = 1;
+ animation.loop = false;
+ Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Animating door.");
+ }
+
+ return;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
index 7b01e3d..47fc616 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
@@ -15,6 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
+import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
@@ -35,6 +36,7 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
@Mapper ComponentMapper collisionModelMapper;
@Mapper ComponentMapper collisionDetectionMapper;
@Mapper ComponentMapper visibilityMapper;
+ @Mapper ComponentMapper typeMapper;
private GroupManager groupManager;
@@ -45,12 +47,11 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
@Override
protected void process(Entity e) {
-
-
VisibilityComponent visibility;
CollisionModelComponent collision;
CollisionModelComponent target;
CollisionDetectionComponent onCollision;
+ CollisionDetectionComponent onCollisionTarget;
BoundingBox colBB = new BoundingBox();
BoundingBox targetBB = new BoundingBox();
ImmutableBag collidables;
@@ -62,19 +63,22 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
onCollision = collisionDetectionMapper.get(e);
for(int i = 0; i < collidables.size(); ++i){
- target = collisionModelMapper.getSafe(collidables.get(i));
- visibility = visibilityMapper.getSafe(collidables.get(i));
+ target = collisionModelMapper.getSafe(collidables.get(i));
+ visibility = visibilityMapper.getSafe(collidables.get(i));
+ onCollisionTarget = collisionDetectionMapper.getSafe(collidables.get(i));
- if(target == null || visibility == null) continue;
+ if(target == null || visibility == null || onCollisionTarget == null) continue;
if(visibility.visible){
collision.instance.calculateBoundingBox(colBB);
target.instance.calculateBoundingBox(targetBB);
if(colBB.contains(targetBB)){
- onCollision.colliding = true;
+ onCollision.colliding = true;
+ onCollisionTarget.colliding = true;
}else{
- onCollision.colliding = false;
+ onCollision.colliding = false;
+ onCollisionTarget.colliding = false;
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index d08fd34..7f34e9e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -34,9 +34,10 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector3;
public class RobotArmPositioningSystem extends EntityProcessingSystem {
- private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
- private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
- private static final float STEP_SIZE = 0.05f;
+ private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
+ private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
+ private static final float STEP_SIZE = 0.05f;
+ private static final Vector3 END_POINT = new Vector3(-1.0f, 0.0f, 0.0f);
@Mapper ComponentMapper geometryMapper;
@Mapper ComponentMapper autoMapper;
@@ -81,20 +82,36 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
}else if(input instanceof GamepadUserInput){
tempGP = (GamepadUserInput) input;
- geometry.position.x += !collision.colliding ? tempGP.axisLeftY * STEP_SIZE : 0.0f;
- geometry.position.y += !collision.colliding ? tempGP.axisLeftX * STEP_SIZE : 0.0f;
- geometry.position.z += !collision.colliding ? tempGP.axisRightY * STEP_SIZE : 0.0f;
- clampPosition(geometry);
+
+ if(!collision.colliding && !auto.moving){
+ geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
+ geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
+ geometry.position.z += tempGP.axisRightY * STEP_SIZE;
+ clampPosition(geometry);
+ }else{
+ auto.moving = true;
+ auto.forward = false;
+ auto.startPoint.set(geometry.position);
+ auto.endPoint.set(END_POINT);
+ }
}else if(input instanceof KeyboardUserInput){
tempKey = (KeyboardUserInput) input;
- geometry.position.x -= tempKey.keyUp && !collision.colliding ? STEP_SIZE : 0.0f;
- geometry.position.x += tempKey.keyDown && !collision.colliding ? STEP_SIZE : 0.0f;
- geometry.position.y -= tempKey.keyLeft && !collision.colliding ? STEP_SIZE : 0.0f;
- geometry.position.y += tempKey.keyRight && !collision.colliding ? STEP_SIZE : 0.0f;
- geometry.position.z -= tempKey.keyZ && !collision.colliding ? STEP_SIZE : 0.0f;
- geometry.position.z += tempKey.keyA && !collision.colliding ? STEP_SIZE : 0.0f;
- clampPosition(geometry);
+
+ if(!collision.colliding && !auto.moving){
+ 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;
+ clampPosition(geometry);
+ }else{
+ auto.moving = true;
+ auto.forward = false;
+ auto.startPoint.set(geometry.position);
+ auto.endPoint.set(END_POINT);
+ }
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index bde53b3..5c5e0b4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -15,14 +15,15 @@
*/
package ve.ucv.ciens.ccg.nxtar.utils;
-import com.artemis.World;
-import com.artemis.managers.GroupManager;
-
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
+import ve.ucv.ciens.ccg.nxtar.systems.BombGameLogicSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
+import com.artemis.World;
+import com.artemis.managers.GroupManager;
+
public abstract class GameSettings{
private static EntityCreatorBase entityCreator = null;
private static GameLogicSystemBase gameLogicSystem = null;
@@ -44,8 +45,7 @@ public abstract class GameSettings{
}
if(getGameLogicSystem() == null)
- gameLogicSystem = null;
- //gameLogicSystem = new BombGameLogicSystem();
+ gameLogicSystem = new BombGameLogicSystem();
}
/**
From 3f522da4851d9861a7ba88abf9811f43a12b07cf Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 11 Jun 2014 14:28:43 -0430
Subject: [PATCH 14/34] Collision detection works for real now.
---
.../nxtar/entities/BombGameEntityCreator.java | 2 +-
.../systems/CollisionDetectionSystem.java | 34 ++++++++++++++-----
.../systems/RobotArmPositioningSystem.java | 8 ++---
3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index cd1ae29..c739bd9 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -232,7 +232,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
- robotArm.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3(), new Vector3(1, 1, 1)));
+ robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.5f), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel));
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
index 47fc616..bf005c0 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
@@ -15,7 +15,6 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
-import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
@@ -28,6 +27,7 @@ import com.artemis.annotations.Mapper;
import com.artemis.managers.GroupManager;
import com.artemis.systems.EntityProcessingSystem;
import com.artemis.utils.ImmutableBag;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.collision.BoundingBox;
public class CollisionDetectionSystem extends EntityProcessingSystem {
@@ -36,13 +36,16 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
@Mapper ComponentMapper collisionModelMapper;
@Mapper ComponentMapper collisionDetectionMapper;
@Mapper ComponentMapper visibilityMapper;
- @Mapper ComponentMapper typeMapper;
private GroupManager groupManager;
+ private BoundingBox colBB;
+ private BoundingBox targetBB;
@SuppressWarnings("unchecked")
public CollisionDetectionSystem(){
super(Aspect.getAspectForAll(CollisionModelComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
+ colBB = new BoundingBox();
+ targetBB = new BoundingBox();
}
@Override
@@ -52,34 +55,49 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
CollisionModelComponent target;
CollisionDetectionComponent onCollision;
CollisionDetectionComponent onCollisionTarget;
- BoundingBox colBB = new BoundingBox();
- BoundingBox targetBB = new BoundingBox();
ImmutableBag collidables;
- groupManager = this.world.getManager(GroupManager.class);
- collidables = groupManager.getEntities(COLLIDABLE_OBJECT);
-
+ // Get this entity's known necessary components.
collision = collisionModelMapper.get(e);
onCollision = collisionDetectionMapper.get(e);
+ // Get all other entities this entity can collide with.
+ groupManager = this.world.getManager(GroupManager.class);
+ collidables = groupManager.getEntities(COLLIDABLE_OBJECT);
+
for(int i = 0; i < collidables.size(); ++i){
+ // Try to get the necessary components for the collidable entity.
target = collisionModelMapper.getSafe(collidables.get(i));
visibility = visibilityMapper.getSafe(collidables.get(i));
onCollisionTarget = collisionDetectionMapper.getSafe(collidables.get(i));
+ // If any of the needed components does not exist then proceed to the next entity.
if(target == null || visibility == null || onCollisionTarget == null) continue;
+ // Id the target is visible then examine the collision. Else there is no collision possible.
if(visibility.visible){
+ // Get the bounding box for both entities.
collision.instance.calculateBoundingBox(colBB);
target.instance.calculateBoundingBox(targetBB);
- if(colBB.contains(targetBB)){
+ // Apply the model matrix to the bounding boxes.
+ colBB.mul(collision.instance.transform);
+ targetBB.mul(target.instance.transform);
+
+ // If the bounding boxes intersect then there is a collision.
+ if(colBB.intersects(targetBB) || targetBB.intersects(colBB)){
+ Gdx.app.log("TAG", "Collision hit.");
onCollision.colliding = true;
onCollisionTarget.colliding = true;
+ break;
}else{
+ Gdx.app.log("TAG", "Collision miss.");
onCollision.colliding = false;
onCollisionTarget.colliding = false;
}
+ }else{
+ onCollision.colliding = false;
+ onCollisionTarget.colliding = false;
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index 7f34e9e..ac7d84d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -141,13 +141,13 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
- if(auto.distance >= 1.0f || collision.colliding){
- auto.forward = false;
- Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
- }else if(auto.distance <= 0.0f){
+ if(auto.distance <= 0.0f){
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;
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
}
}else return;
From 95bb97536cca7276f88f5a330519a9fb3c7115b6 Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 11 Jun 2014 15:21:59 -0430
Subject: [PATCH 15/34] Started modelling object interaction.
---
.../ciens/ccg/nxtar/states/InGameState.java | 2 +-
.../nxtar/systems/BombGameLogicSystem.java | 20 ++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 9f185ec..1a7c579 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -193,7 +193,7 @@ public class InGameState extends BaseState{
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem());
- //gameWorld.setSystem(GameSettings.getGameLogicSystem());
+ gameWorld.setSystem(GameSettings.getGameLogicSystem());
gameWorld.setSystem(markerRenderingSystem, true);
gameWorld.setSystem(objectRenderingSystem, true);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index 3b16f99..ad2eaf5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -49,10 +49,28 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
typeComponent = typeMapper.get(e);
switch(typeComponent.type){
+ case BombGameObjectTypeComponent.BOMB_WIRE_1:
+ break;
+ case BombGameObjectTypeComponent.BOMB_WIRE_2:
+ break;
+ case BombGameObjectTypeComponent.BOMB_WIRE_3:
+ break;
+ case BombGameObjectTypeComponent.BIG_BUTTON:
+ break;
+ case BombGameObjectTypeComponent.COM_BUTTON_1:
+ break;
+ case BombGameObjectTypeComponent.COM_BUTTON_2:
+ break;
+ case BombGameObjectTypeComponent.COM_BUTTON_3:
+ break;
+ case BombGameObjectTypeComponent.COM_BUTTON_4:
+ break;
case BombGameObjectTypeComponent.DOOR:
processDoor(e);
break;
- default: break;
+ default:
+ Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
+ break;
}
}
From 6c63ebf907dffe5f635ed44e2c7c1665471d932a Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 11 Jun 2014 17:28:26 -0430
Subject: [PATCH 16/34] Finally fixed restart problem. Basic inclination bombs.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 7 +-
.../BombGameObjectTypeComponent.java | 1 +
.../nxtar/entities/BombGameEntityCreator.java | 13 ++-
.../ccg/nxtar/network/RobotControlThread.java | 6 +-
.../ccg/nxtar/network/SensorReportThread.java | 13 +++
.../ccg/nxtar/systems/AnimationSystem.java | 2 +
.../nxtar/systems/BombGameLogicSystem.java | 85 +++++++++++++++++--
.../systems/CollisionDetectionSystem.java | 4 +-
8 files changed, 116 insertions(+), 15 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index f49a3b8..e9e7f0a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -405,8 +405,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
public void pause(){
if(videoThread != null)
videoThread.pause();
- // TODO: Ignore pausing paused threads.
- // TODO: Pause the other threads.
}
/**
@@ -416,8 +414,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
public void resume(){
if(videoThread != null)
videoThread.play();
- // TODO: Ignore resuming resumed threads.
- // TODO: Resume the other threads.
}
/**
@@ -429,6 +425,9 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
videoThread.finish();
robotThread.finish();
sensorThread.finish();
+ videoThread = null;
+ robotThread = null;
+ sensorThread = null;
ServiceDiscoveryThread.freeInstance();
VideoStreamingThread.freeInstance();
RobotControlThread.freeInstance();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
index 01a0c03..a0c923f 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
@@ -27,6 +27,7 @@ public class BombGameObjectTypeComponent extends Component {
public static final int COM_BUTTON_3 = 32;
public static final int COM_BUTTON_4 = 33;
public static final int DOOR = 40;
+ public static final int DOOR_FRAME = 41;
public int type;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index c739bd9..9cc04d2 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -52,6 +52,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
+ public static final String DOORS_GROUP = "DOORS";
private class EntityParameters{
public Environment environment;
@@ -281,7 +282,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
// 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();
currentBombId++;
}
@@ -342,7 +343,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new VisibilityComponent());
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
thing.addComponent(new CollisionDetectionComponent());
- groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECT);
+ groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ groupManager.add(thing, Integer.toString(parameters.markerCode));
if(DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(collisionModel, parameters, false);
@@ -358,10 +360,13 @@ public class BombGameEntityCreator extends EntityCreatorBase{
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
frame.addComponent(new RenderModelComponent(doorFrameModel));
frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel));
+ frame.addComponent(new CollisionDetectionComponent());
frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
+ frame.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR_FRAME));
+ groupManager.add(frame, Integer.toString(parameters.markerCode));
frame.addToWorld();
door = world.createEntity();
@@ -377,7 +382,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation, doorColInstance));
door.addComponent(new CollisionDetectionComponent());
door.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR));
- groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECT);
+ groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ groupManager.add(door, Integer.toString(parameters.markerCode));
+ groupManager.add(door, DOORS_GROUP);
door.addToWorld();
if(DEBUG_RENDER_DOOR_COLLISION_MODELS){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
index 21591d6..2852cad 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java
@@ -96,6 +96,11 @@ public class RobotControlThread extends Thread {
public void finish(){
done = true;
+ try{
+ server.close();
+ }catch(IOException io){
+ Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error closing client: " + io.getMessage(), io);
+ }
}
@Override
@@ -177,7 +182,6 @@ public class RobotControlThread extends Thread {
}
}
-
try{
client.close();
}catch(IOException io){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
index 175835d..84409ad 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java
@@ -90,6 +90,11 @@ public class SensorReportThread extends Thread {
public void finish(){
done = true;
+ try{
+ server.close();
+ }catch(IOException io){
+ Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException closing sockets: " + io.getMessage(), io);
+ }
}
public byte getLightSensorReading(){
@@ -131,5 +136,13 @@ public class SensorReportThread extends Thread {
lightReading = reading[0];
}
}
+
+ try{
+ reader.close();
+ client.close();
+ server.close();
+ }catch(IOException io){
+ Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException closing sockets: " + io.getMessage(), io);
+ }
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
index 75bde35..899a7ff 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
@@ -41,6 +41,8 @@ public class AnimationSystem extends EntityProcessingSystem {
int loopCount = animation.loop ? -1 : 1;
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
+ animation.current = animation.next;
+
if(animation.controller.current == null){
animation.controller.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null);
}else{
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index ad2eaf5..cc0032e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -20,11 +20,14 @@ import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
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 com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
+import com.artemis.managers.GroupManager;
+import com.artemis.utils.ImmutableBag;
import com.badlogic.gdx.Gdx;
public class BombGameLogicSystem extends GameLogicSystemBase {
@@ -37,6 +40,9 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
@Mapper ComponentMapper markerMapper;
@Mapper ComponentMapper collisionMapper;
+ private MarkerCodeComponent tempMarker;
+ private BombGameObjectTypeComponent tempType;
+
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
@@ -56,6 +62,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
case BombGameObjectTypeComponent.BOMB_WIRE_3:
break;
case BombGameObjectTypeComponent.BIG_BUTTON:
+ processInclinationBomb(e);
break;
case BombGameObjectTypeComponent.COM_BUTTON_1:
break;
@@ -68,12 +75,50 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
case BombGameObjectTypeComponent.DOOR:
processDoor(e);
break;
+ case BombGameObjectTypeComponent.DOOR_FRAME:
+ break;
default:
Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
break;
}
}
+ private void processInclinationBomb(Entity b){
+ CollisionDetectionComponent collision = collisionMapper.getSafe(b);
+ MarkerCodeComponent marker = markerMapper.getSafe(b);
+ GroupManager manager = world.getManager(GroupManager.class);
+ ImmutableBag related;
+
+ if(marker == null || collision == null ){
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb is missing some components.");
+ return;
+ }
+
+ if(isDoorOpen(marker.code, manager) && marker.enabled && collision.colliding){
+ marker.enabled = false;
+ manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+
+ // Disable all related entities.
+ related = manager.getEntities(Integer.toString(marker.code));
+ for(int i = 0; i < related.size(); i++){
+ tempMarker = markerMapper.getSafe(related.get(i));
+ tempType = typeMapper.getSafe(related.get(i));
+
+ // Enable collisions with the door frame. Disable collisions with other related objects.
+ if(tempMarker != null) tempMarker.enabled = false;
+ if(tempType != null){
+ if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
+ manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ }else{
+ manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ }
+ }
+ }
+
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Disabling inclination bomb.");
+ }
+ }
+
private void processDoor(Entity d){
CollisionDetectionComponent collision = collisionMapper.getSafe(d);
AnimationComponent animation = animationMapper.getSafe(d);
@@ -85,12 +130,42 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
return;
}
- if(marker.enabled && visibility.visible && collision.colliding && animation.current != 1){
- animation.next = 1;
- animation.loop = false;
- Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Animating door.");
+ if(visibility.visible){
+ if(marker.enabled){
+ if(collision.colliding){
+ animation.next = 1;
+ animation.loop = false;
+ collision.colliding = false;
+ world.getManager(GroupManager.class).remove(d, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Opening door.");
+ }
+ }else{
+ if(animation.current != 0){
+ animation.next = 0;
+ animation.loop = false;
+ Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Closing door.");
+ }
+ }
+ }
+ }
+
+ private boolean isDoorOpen(int markerCode, GroupManager manager){
+ AnimationComponent animation;
+ boolean doorOpen = false;
+ ImmutableBag doors = manager.getEntities(BombGameEntityCreator.DOORS_GROUP);
+
+ for(int i = 0; i < doors.size(); i++){
+ tempMarker = markerMapper.getSafe(doors.get(i));
+ animation = animationMapper.getSafe(doors.get(i));
+
+ if(animation == null || tempMarker == null) return false;
+
+ if(tempMarker.code == markerCode && animation.current == 1 && animation.controller.current.loopCount == 0){
+ doorOpen = true;
+ break;
+ }
}
- return;
+ return doorOpen;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
index bf005c0..d1b24b2 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
@@ -31,7 +31,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.collision.BoundingBox;
public class CollisionDetectionSystem extends EntityProcessingSystem {
- public static final String COLLIDABLE_OBJECT = "COLLIDABLE";
+ public static final String COLLIDABLE_OBJECTS_GROUP = "COLLIDABLE";
@Mapper ComponentMapper collisionModelMapper;
@Mapper ComponentMapper collisionDetectionMapper;
@@ -63,7 +63,7 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
// Get all other entities this entity can collide with.
groupManager = this.world.getManager(GroupManager.class);
- collidables = groupManager.getEntities(COLLIDABLE_OBJECT);
+ collidables = groupManager.getEntities(COLLIDABLE_OBJECTS_GROUP);
for(int i = 0; i < collidables.size(); ++i){
// Try to get the necessary components for the collidable entity.
From 7f20a09eb93830014db7a972c1914eb01d75a924 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 13 Jun 2014 16:47:23 -0430
Subject: [PATCH 17/34] Scrapped robot arm movement.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 2 +
.../AutomaticMovementComponent.java | 35 ----
.../nxtar/entities/BombGameEntityCreator.java | 6 +-
.../DirectionalLightPerPixelShader.java | 4 +-
.../ciens/ccg/nxtar/states/InGameState.java | 18 +-
.../systems/RobotArmPositioningSystem.java | 159 +++++++++---------
.../ciens/ccg/nxtar/utils/GameSettings.java | 6 +
7 files changed, 98 insertions(+), 132 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index e9e7f0a..2b33f35 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -447,6 +447,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
for(int i = 0; i < states.length; i++){
states[i].dispose();
}
+
+ GameSettings.clearGameSettings();
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
deleted file mode 100644
index 99f654f..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.components;
-
-import com.artemis.Component;
-import com.badlogic.gdx.math.Vector3;
-
-public class AutomaticMovementComponent extends Component {
- public boolean moving;
- public boolean forward;
- public Vector3 startPoint;
- public Vector3 endPoint;
- public float distance;
-
- public AutomaticMovementComponent(){
- this.moving = false;
- this.forward = true;
- this.startPoint = new Vector3();
- this.endPoint = new Vector3();
- this.distance = 0.0f;
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 9cc04d2..d6f75c3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -16,7 +16,6 @@
package ve.ucv.ciens.ccg.nxtar.entities;
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;
@@ -52,7 +51,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
- public static final String DOORS_GROUP = "DOORS";
+ public static final String DOORS_GROUP = "DOORS";
private class EntityParameters{
public Environment environment;
@@ -233,12 +232,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
- robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.5f), new Matrix3(), new Vector3(1, 1, 1)));
+ robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -0.5f), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel));
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
- robotArm.addComponent(new AutomaticMovementComponent());
robotArm.addComponent(new CollisionDetectionComponent());
robotArm.addToWorld();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
index 0b4a9db..e3d523f 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java
@@ -167,7 +167,7 @@ public class DirectionalLightPerPixelShader implements Shader{
float shininess;
// Get material colors.
- if(renderable.environment.directionalLights.size >= 1){
+ if(renderable.environment != null && renderable.environment.directionalLights != null && renderable.environment.directionalLights.size >= 1){
lightPosition = renderable.environment.directionalLights.get(0).direction;
diffuseLightColor = renderable.environment.directionalLights.get(0).color;
}else{
@@ -185,7 +185,7 @@ public class DirectionalLightPerPixelShader implements Shader{
else
specularColor = Color.BLACK;
- if(renderable.environment.has(ColorAttribute.AmbientLight))
+ if(renderable.environment != null && renderable.environment.has(ColorAttribute.AmbientLight))
ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
else
ambientColor = Color.BLACK;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 1a7c579..af571ec 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -82,7 +82,7 @@ public class InGameState extends BaseState{
// Cameras.
private OrthographicCamera unitaryOrthographicCamera;
- private OrthographicCamera pixelPerfectOrthoCamera;
+ private OrthographicCamera pixelPerfectOrthographicCamera;
private CustomPerspectiveCamera perspectiveCamera;
// Video stream graphics.
@@ -119,7 +119,7 @@ public class InGameState extends BaseState{
videoFrame = null;
// Set up the cameras.
- pixelPerfectOrthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
if(!Ouya.runningOnOuya) setUpButtons();
@@ -217,7 +217,7 @@ public class InGameState extends BaseState{
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Render the background.
- core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{
if(backgroundShader != null){
core.batch.setShader(backgroundShader);
@@ -293,6 +293,7 @@ public class InGameState extends BaseState{
objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process();
objectRenderingSystem.end();
+
}frameBuffer.end();
// Set the frame buffer object texture to a renderable sprite.
@@ -329,7 +330,7 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
}else{
- core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
}
// Render the video frame and the frame buffer.
@@ -344,7 +345,7 @@ public class InGameState extends BaseState{
// Render the interface buttons.
if(!Ouya.runningOnOuya){
- core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{
motorA.draw(core.batch);
motorB.draw(core.batch);
@@ -541,13 +542,6 @@ public class InGameState extends BaseState{
touchPointWorldCoords.set(win2world.x, win2world.y);
if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer.");
-
- TEMP_VEC_3.set(screenX, screenY, 1.0f);
- perspectiveCamera.unproject(TEMP_VEC_3, frameBufferSprite.getX(), frameBufferSprite.getY(), frameBufferSprite.getWidth() * Gdx.graphics.getWidth(), frameBufferSprite.getHeight() * Gdx.graphics.getHeight());
- TEMP_VEC_3.rotate(Vector3.Z, 90).nor();
- TEMP_VEC_3.y = -TEMP_VEC_3.y;
- //Gdx.app.log("TAG", CLASS_NAME + "touchDown(): Unprojected" + Utils.vector2String(TEMP_VEC_3));
-
input = new TouchUserInput(TEMP_VEC_3);
robotArmPositioningSystem.setUserInput(input);
}else{
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index ac7d84d..2ae5322 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -15,7 +15,6 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
-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;
@@ -23,14 +22,12 @@ import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
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.utils.Utils;
import com.artemis.Aspect;
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.Vector3;
public class RobotArmPositioningSystem extends EntityProcessingSystem {
@@ -38,16 +35,17 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
private static final float STEP_SIZE = 0.05f;
private static final Vector3 END_POINT = new Vector3(-1.0f, 0.0f, 0.0f);
+ private static final float MAX_Z = -4.5f;
@Mapper ComponentMapper geometryMapper;
- @Mapper ComponentMapper autoMapper;
+// @Mapper ComponentMapper autoMapper;
@Mapper ComponentMapper collisionMapper;
private UserInput input;
@SuppressWarnings("unchecked")
public RobotArmPositioningSystem(){
- super(Aspect.getAspectForAll(GeometryComponent.class, AutomaticMovementComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
+ super(Aspect.getAspectForAll(GeometryComponent.class, /*AutomaticMovementComponent.class,*/ CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
}
public void setUserInput(UserInput input){
@@ -60,58 +58,61 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
GamepadUserInput tempGP;
KeyboardUserInput tempKey;
GeometryComponent geometry = geometryMapper.get(e);
- AutomaticMovementComponent auto = autoMapper.get(e);
+// AutomaticMovementComponent auto = autoMapper.get(e);
CollisionDetectionComponent collision = collisionMapper.get(e);
if(input == null){
- if(auto.moving) autoMove(geometry, auto, collision);
- else return;
+ /*if(auto.moving) autoMove(geometry, auto, collision);
+ else */return;
}else{
if(input instanceof TouchUserInput){
- if(!auto.moving){
- endPoint = ((TouchUserInput) input).userTouchEndPoint;
- endPoint.set(endPoint.x, endPoint.y, -4.5f);
- auto.startPoint.set(geometry.position);
- auto.endPoint.set(endPoint);
- auto.moving = true;
- auto.forward = true;
-
- Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
- }else autoMove(geometry, auto, collision);
+// if(!auto.moving){
+// endPoint = ((TouchUserInput) input).userTouchEndPoint;
+// endPoint.set(endPoint.x, endPoint.y, MAX_Z);
+// auto.startPoint.set(geometry.position);
+// auto.endPoint.set(endPoint);
+// auto.moving = true;
+// auto.forward = true;
+//
+// auto.target.set(endPoint).sub(auto.startPoint);
+// auto.epsilon = 0.05f;
+//
+// Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
+// }else autoMove(geometry, auto, collision);
}else if(input instanceof GamepadUserInput){
- tempGP = (GamepadUserInput) input;
-
- if(!collision.colliding && !auto.moving){
- geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
- geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
- geometry.position.z += tempGP.axisRightY * STEP_SIZE;
- clampPosition(geometry);
- }else{
- auto.moving = true;
- auto.forward = false;
- auto.startPoint.set(geometry.position);
- auto.endPoint.set(END_POINT);
- }
+// tempGP = (GamepadUserInput) input;
+//
+// if(!collision.colliding && !auto.moving){
+// geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
+// geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
+// geometry.position.z += tempGP.axisRightY * STEP_SIZE;
+// clampPosition(geometry);
+// }else{
+// auto.moving = true;
+// auto.forward = false;
+// auto.startPoint.set(geometry.position);
+// auto.endPoint.set(END_POINT);
+// }
}else if(input instanceof KeyboardUserInput){
- tempKey = (KeyboardUserInput) input;
-
- if(!collision.colliding && !auto.moving){
- 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;
- clampPosition(geometry);
- }else{
- auto.moving = true;
- auto.forward = false;
- auto.startPoint.set(geometry.position);
- auto.endPoint.set(END_POINT);
- }
+// tempKey = (KeyboardUserInput) input;
+//
+// if(!collision.colliding && !auto.moving){
+// 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;
+// clampPosition(geometry);
+// }else{
+// auto.moving = true;
+// auto.forward = false;
+// auto.startPoint.set(geometry.position);
+// auto.endPoint.set(END_POINT);
+// }
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
@@ -120,38 +121,38 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
input = null;
}
- private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
- float step;
-
- if(auto.moving){
- if(auto.forward)
- step = STEP_SIZE;
- else
- step = -STEP_SIZE;
-
- Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
-
- auto.distance += step;
-
- Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
-
- geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
- geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
- geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
-
- Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
-
- if(auto.distance <= 0.0f){
- 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;
- Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
- }
-
- }else return;
- }
+// private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
+// float step;
+//
+// if(auto.moving){
+// if(auto.forward)
+// step = STEP_SIZE;
+// else
+// step = -STEP_SIZE;
+//
+// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
+//
+// auto.distance += step;
+//
+// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
+//
+// geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
+// geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
+// geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
+//
+// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
+//
+// if(auto.distance <= 0.0f){
+// 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;
+// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
+// }
+//
+// }else return;
+// }
private void clampPosition(GeometryComponent geometry){
geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index 5c5e0b4..d40b4ca 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -48,6 +48,12 @@ public abstract class GameSettings{
gameLogicSystem = new BombGameLogicSystem();
}
+ public static void clearGameSettings(){
+ entityCreator = null;
+ gameLogicSystem = null;
+ gameWorld = null;
+ }
+
/**
* @return the entityCreator
*/
From fd197211b5ade90e46961c583638a07cc0673166 Mon Sep 17 00:00:00 2001
From: unknown
Date: Mon, 16 Jun 2014 15:47:07 -0430
Subject: [PATCH 18/34] Touch controls ready.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 3 -
.../AutomaticMovementComponent.java | 51 ++
.../nxtar/entities/BombGameEntityCreator.java | 4 +-
.../ciens/ccg/nxtar/input/TouchUserInput.java | 2 +-
.../ciens/ccg/nxtar/states/InGameState.java | 731 ++++++++++++------
.../systems/RobotArmPositioningSystem.java | 183 ++---
.../ciens/ccg/nxtar/utils/GameSettings.java | 2 +
7 files changed, 640 insertions(+), 336 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 2b33f35..fac2280 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -440,9 +440,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
font.dispose();
}
- if(GameSettings.getEntityCreator() != null)
- GameSettings.getEntityCreator().dispose();
-
// Dispose screens.
for(int i = 0; i < states.length; i++){
states[i].dispose();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
new file mode 100644
index 0000000..01addc9
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/AutomaticMovementComponent.java
@@ -0,0 +1,51 @@
+/*
+ * 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;
+import com.badlogic.gdx.math.Vector3;
+
+public class AutomaticMovementComponent extends Component{
+ public boolean moving;
+ public boolean forward;
+ public float distance;
+ public Vector3 startPoint;
+ public Vector3 endPoint;
+
+ public AutomaticMovementComponent(Vector3 startPoint, Vector3 endPoint, boolean moving){
+ this.moving = moving;
+ this.forward = true;
+ this.distance = 0.0f;
+ this.startPoint = startPoint;
+ this.endPoint = endPoint;
+ }
+
+ public AutomaticMovementComponent(Vector3 startPoint, Vector3 endPoint){
+ this(startPoint, endPoint, false);
+ }
+
+ public AutomaticMovementComponent(boolean moving){
+ this(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(), moving);
+ }
+
+ public AutomaticMovementComponent(Vector3 endPoint){
+ this(new Vector3(0.0f, 0.0f, 0.0f), endPoint, false);
+ }
+
+ public AutomaticMovementComponent(){
+ this(false);
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index d6f75c3..31c5610 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.entities;
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;
@@ -232,12 +233,13 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
- robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -0.5f), new Matrix3(), new Vector3(1, 1, 1)));
+ robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -1.0f), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel));
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
robotArm.addComponent(new CollisionDetectionComponent());
+ robotArm.addComponent(new AutomaticMovementComponent());
robotArm.addToWorld();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
index 16492f2..4143d0b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
@@ -21,7 +21,7 @@ public class TouchUserInput extends UserInput {
public Vector3 userTouchEndPoint;
public TouchUserInput(){
- this.userTouchEndPoint = null;
+ this.userTouchEndPoint = new Vector3();
}
public TouchUserInput(Vector3 userTouchEndPoint){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index af571ec..f4a3338 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -21,7 +21,9 @@ import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
+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.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
@@ -61,11 +63,27 @@ public class InGameState extends BaseState{
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
private static final float NEAR = 0.01f;
private static final float FAR = 100.0f;
- private static final Vector3 TEMP_VEC_3 = new Vector3();
+
+ /**
+ * Represents the two possible control modes for the robot.
+ */
+ private enum robot_control_mode_t{
+ WHEEL_CONTROL(0), ARM_CONTROL(1);
+
+ private int value;
+
+ private robot_control_mode_t(int value){
+ this.value = value;
+ }
+
+ public int getValue(){
+ return this.value;
+ }
+ }
// Background related fields.
+ private Sprite background;
private float uScaling[];
- protected Sprite background;
private Texture backgroundTexture;
private ShaderProgram backgroundShader;
@@ -74,11 +92,12 @@ public class InGameState extends BaseState{
private FrameBuffer frameBuffer;
private Sprite frameBufferSprite;
- // Game world objects.
+ // Game related fields.
private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
private RobotArmPositioningSystem robotArmPositioningSystem;
+ private robot_control_mode_t controlMode;
// Cameras.
private OrthographicCamera unitaryOrthographicCamera;
@@ -91,20 +110,24 @@ public class InGameState extends BaseState{
private Pixmap videoFrame;
// Interface buttons.
- private Texture buttonTexture;
- private Texture buttonTexture2;
- private Sprite motorA;
- private Sprite motorB;
- private Sprite motorC;
- private Sprite motorD;
- private Sprite headA;
- private Sprite headB;
- private Sprite headC;
+ private Texture mainControlButtonTexture;
+ private Texture headControlButtonTexture;
+ private Texture wheelControlButtonTexture;
+ private Texture armControlButtonTexture;
+ private Sprite motorAButton;
+ private Sprite motorBButton;
+ private Sprite motorCButton;
+ private Sprite motorDButton;
+ private Sprite headAButton;
+ private Sprite headBButton;
+ private Sprite headCButton;
+ private Sprite wheelControlButton;
+ private Sprite armControlButton;
// Button touch helper fields.
- private boolean[] motorButtonsTouched;
- private int[] motorButtonsPointers;
- private boolean[] motorGamepadButtonPressed;
+ private boolean[] buttonsTouched;
+ private int[] buttonPointers;
+ private boolean[] gamepadButtonPressed;
// Monitors.
private VideoFrameMonitor frameMonitor;
@@ -114,6 +137,7 @@ public class InGameState extends BaseState{
this.core = core;
frameMonitor = VideoFrameMonitor.getInstance();
queue = MotorEventQueue.getInstance();
+ controlMode = robot_control_mode_t.WHEEL_CONTROL;
// Set up rendering fields;
videoFrame = null;
@@ -128,32 +152,34 @@ public class InGameState extends BaseState{
win2world = new Vector3(0.0f, 0.0f, 0.0f);
touchPointWorldCoords = new Vector2();
- motorButtonsTouched = new boolean[7];
- motorButtonsTouched[0] = false;
- motorButtonsTouched[1] = false;
- motorButtonsTouched[2] = false;
- motorButtonsTouched[3] = false;
- motorButtonsTouched[4] = false;
- motorButtonsTouched[5] = false;
- motorButtonsTouched[6] = false;
+ buttonsTouched = new boolean[8];
+ buttonsTouched[0] = false;
+ buttonsTouched[1] = false;
+ buttonsTouched[2] = false;
+ buttonsTouched[3] = false;
+ buttonsTouched[4] = false;
+ buttonsTouched[5] = false;
+ buttonsTouched[6] = false;
+ buttonsTouched[7] = false;
- motorButtonsPointers = new int[7];
- motorButtonsPointers[0] = -1;
- motorButtonsPointers[1] = -1;
- motorButtonsPointers[2] = -1;
- motorButtonsPointers[3] = -1;
- motorButtonsPointers[4] = -1;
- motorButtonsPointers[5] = -1;
- motorButtonsPointers[6] = -1;
+ buttonPointers = new int[8];
+ buttonPointers[0] = -1;
+ buttonPointers[1] = -1;
+ buttonPointers[2] = -1;
+ buttonPointers[3] = -1;
+ buttonPointers[4] = -1;
+ buttonPointers[5] = -1;
+ buttonPointers[6] = -1;
+ buttonPointers[7] = -1;
- motorGamepadButtonPressed = new boolean[7];
- motorGamepadButtonPressed[0] = false;
- motorGamepadButtonPressed[1] = false;
- motorGamepadButtonPressed[2] = false;
- motorGamepadButtonPressed[3] = false;
- motorGamepadButtonPressed[4] = false;
- motorGamepadButtonPressed[5] = false;
- motorGamepadButtonPressed[6] = false;
+ gamepadButtonPressed = new boolean[7];
+ gamepadButtonPressed[0] = false;
+ gamepadButtonPressed[1] = false;
+ gamepadButtonPressed[2] = false;
+ gamepadButtonPressed[3] = false;
+ gamepadButtonPressed[4] = false;
+ gamepadButtonPressed[5] = false;
+ gamepadButtonPressed[6] = false;
// Set up the background.
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
@@ -347,13 +373,22 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{
- motorA.draw(core.batch);
- motorB.draw(core.batch);
- motorC.draw(core.batch);
- motorD.draw(core.batch);
- headA.draw(core.batch);
- headB.draw(core.batch);
- headC.draw(core.batch);
+ 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);
+
+ 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()){
+ wheelControlButton.draw(core.batch);
+ }else{
+ throw new IllegalStateException("Unrecognized control mode: " + Integer.toString(controlMode.getValue()));
+ }
+
}core.batch.end();
}
@@ -368,13 +403,20 @@ public class InGameState extends BaseState{
if(videoFrameTexture != null)
videoFrameTexture.dispose();
- if(buttonTexture != null)
- buttonTexture.dispose();
+ if(mainControlButtonTexture != null)
+ mainControlButtonTexture.dispose();
- if(buttonTexture2 != null)
- buttonTexture2.dispose();
+ if(headControlButtonTexture != null)
+ headControlButtonTexture.dispose();
- backgroundTexture.dispose();
+ if(wheelControlButtonTexture != null)
+ wheelControlButtonTexture.dispose();
+
+ if(armControlButtonTexture != null)
+ armControlButtonTexture.dispose();
+
+ if(backgroundTexture != null)
+ backgroundTexture.dispose();
if(backgroundShader != null)
backgroundShader.dispose();
@@ -404,42 +446,52 @@ public class InGameState extends BaseState{
}
private void setUpButtons(){
- buttonTexture = new Texture(Gdx.files.internal("data/gfx/gui/PBCrichton_Flat_Button.png"));
- buttonTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ // Set the main control buttons.
+ mainControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/PBCrichton_Flat_Button.png"));
+ mainControlButtonTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
- TextureRegion region = new TextureRegion(buttonTexture, 0, 0, buttonTexture.getWidth(), buttonTexture.getHeight());
+ TextureRegion region = new TextureRegion(mainControlButtonTexture, 0, 0, mainControlButtonTexture.getWidth(), mainControlButtonTexture.getHeight());
- motorA = new Sprite(region);
- motorA.setSize(motorA.getWidth() * 0.7f, motorA.getHeight() * 0.7f);
+ motorAButton = new Sprite(region);
+ motorAButton.setSize(motorAButton.getWidth() * 0.7f, motorAButton.getHeight() * 0.7f);
+ motorBButton = new Sprite(region);
+ motorBButton.setSize(motorBButton.getWidth() * 0.7f, motorBButton.getHeight() * 0.7f);
+ motorCButton = new Sprite(region);
+ motorCButton.setSize(motorCButton.getWidth() * 0.7f, motorCButton.getHeight() * 0.7f);
+ motorDButton = new Sprite(region);
+ motorDButton.setSize(motorDButton.getWidth() * 0.7f, motorDButton.getHeight() * 0.7f);
- motorB = new Sprite(region);
- motorB.setSize(motorB.getWidth() * 0.7f, motorB.getHeight() * 0.7f);
+ motorAButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 10, -(Gdx.graphics.getHeight() / 2) + motorBButton.getHeight() + 20);
+ motorBButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 20 + (motorAButton.getWidth() / 2), -(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());
- motorC = new Sprite(region);
- motorC.setSize(motorC.getWidth() * 0.7f, motorC.getHeight() * 0.7f);
+ // Set the head control buttons.
+ headControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/orange_glowy_button.png"));
- motorD = new Sprite(region);
- motorD.setSize(motorD.getWidth() * 0.7f, motorD.getHeight() * 0.7f);
+ headAButton = new Sprite(headControlButtonTexture);
+ headAButton.setSize(headAButton.getWidth() * 0.3f, headAButton.getHeight() * 0.6f);
+ headBButton = new Sprite(headControlButtonTexture);
+ headBButton.setSize(headBButton.getWidth() * 0.3f, headBButton.getHeight() * 0.6f);
- motorA.setPosition(-(Gdx.graphics.getWidth() / 2) + 10, -(Gdx.graphics.getHeight() / 2) + motorB.getHeight() + 20);
- motorB.setPosition(-(Gdx.graphics.getWidth() / 2) + 20 + (motorA.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10);
- motorC.setPosition((Gdx.graphics.getWidth() / 2) - (1.5f * (motorD.getWidth())) - 20, -(Gdx.graphics.getHeight() / 2) + 10);
- motorD.setPosition((Gdx.graphics.getWidth() / 2) - motorD.getWidth() - 10, -(Gdx.graphics.getHeight() / 2) + 20 + motorC.getHeight());
+ headAButton.setPosition(-headAButton.getWidth() - 10, motorAButton.getY() + (headAButton.getHeight() / 2));
+ headBButton.setPosition(10, motorAButton.getY() + (headAButton.getHeight() / 2));
- buttonTexture2 = new Texture(Gdx.files.internal("data/gfx/gui/orange_glowy_button.png"));
+ headCButton = new Sprite(headControlButtonTexture);
+ headCButton.setSize(headCButton.getWidth() * 0.3f, headCButton.getHeight() * 0.6f);
+ headCButton.setPosition(-(headCButton.getWidth() / 2), headAButton.getY() - headAButton.getHeight() - 10);
- headA = new Sprite(buttonTexture2);
- headA.setSize(headA.getWidth() * 0.3f, headA.getHeight() * 0.6f);
+ // Set the control mode buttons.
+ wheelControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/wheel.png"));
+ armControlButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/arm.png"));
- headB = new Sprite(buttonTexture2);
- headB.setSize(headB.getWidth() * 0.3f, headB.getHeight() * 0.6f);
+ wheelControlButton = new Sprite(wheelControlButtonTexture);
+ wheelControlButton.setSize(wheelControlButton.getWidth() * 0.3f, wheelControlButton.getHeight() * 0.3f);
+ armControlButton = new Sprite(armControlButtonTexture);
+ armControlButton.setSize(armControlButton.getWidth() * 0.3f, armControlButton.getHeight() * 0.3f);
- headA.setPosition(-headA.getWidth() - 10, motorA.getY() + (headA.getHeight() / 2));
- headB.setPosition(10, motorA.getY() + (headA.getHeight() / 2));
-
- headC = new Sprite(buttonTexture2);
- headC.setSize(headC.getWidth() * 0.3f, headC.getHeight() * 0.6f);
- headC.setPosition(-(headC.getWidth() / 2), headA.getY() - headA.getHeight() - 10);
+ wheelControlButton.setPosition(-(wheelControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
+ armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -449,7 +501,7 @@ public class InGameState extends BaseState{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
MotorEvent event;
- TouchUserInput input;
+ UserInput input;
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
@@ -459,78 +511,112 @@ public class InGameState extends BaseState{
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
- if(motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
+ if(motorAButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor A button pressed");
- motorButtonsTouched[0] = true;
- motorButtonsPointers[0] = pointer;
+ buttonsTouched[0] = true;
+ buttonPointers[0] = pointer;
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_A);
- event.setPower((byte)100);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_A);
+ event.setPower((byte)100);
+ queue.addEvent(event);
- }else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+
+ ((KeyboardUserInput)input).keyUp = true;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
+ }
+
+ }else if(motorBButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor B button pressed");
- motorButtonsTouched[1] = true;
- motorButtonsPointers[1] = pointer;
+ buttonsTouched[1] = true;
+ buttonPointers[1] = pointer;
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_A);
- event.setPower((byte)-100);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_A);
+ event.setPower((byte)-100);
+ queue.addEvent(event);
- }else if(motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyLeft = true;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
+ }
+
+ }else if(motorCButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor C button pressed");
- motorButtonsTouched[2] = true;
- motorButtonsPointers[2] = pointer;
+ buttonsTouched[2] = true;
+ buttonPointers[2] = pointer;
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_C);
- event.setPower((byte)-100);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_C);
+ event.setPower((byte)-100);
+ queue.addEvent(event);
- }else if(motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyRight = true;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
+ }
+
+ }else if(motorDButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor D button pressed");
- motorButtonsTouched[3] = true;
- motorButtonsPointers[3] = pointer;
+ buttonsTouched[3] = true;
+ buttonPointers[3] = pointer;
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_C);
- event.setPower((byte)100);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_C);
+ event.setPower((byte)100);
+ queue.addEvent(event);
- }else if(headA.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+
+ ((KeyboardUserInput)input).keyDown = true;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
+ }
+
+ }else if(headAButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Head A button pressed");
- motorButtonsTouched[4] = true;
- motorButtonsPointers[4] = pointer;
+ buttonsTouched[4] = true;
+ buttonPointers[4] = pointer;
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
- event.setPower((byte)-40);
+ event.setPower((byte)-25);
queue.addEvent(event);
- }else if(headB.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(headBButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Head B button pressed");
- motorButtonsTouched[5] = true;
- motorButtonsPointers[5] = pointer;
+ buttonsTouched[5] = true;
+ buttonPointers[5] = pointer;
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
- event.setPower((byte)40);
+ event.setPower((byte)25);
queue.addEvent(event);
- }else if(headC.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(headCButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Head C button pressed");
- if(!motorButtonsTouched[4] && !motorButtonsTouched[5]){
- motorButtonsTouched[6] = true;
- motorButtonsPointers[6] = pointer;
+ if(!buttonsTouched[4] && !buttonsTouched[5]){
+ buttonsTouched[6] = true;
+ buttonPointers[6] = pointer;
event = new MotorEvent();
event.setMotor(motor_t.RECENTER);
@@ -538,12 +624,21 @@ public class InGameState extends BaseState{
queue.addEvent(event);
}
+ }else if(wheelControlButton.getBoundingRectangle().contains(touchPointWorldCoords) || armControlButton.getBoundingRectangle().contains(touchPointWorldCoords)){
+
+ buttonsTouched[7] = true;
+ buttonPointers[7] = pointer;
+ controlMode = controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue() ? robot_control_mode_t.ARM_CONTROL : robot_control_mode_t.WHEEL_CONTROL;
+
}else{
+
touchPointWorldCoords.set(win2world.x, win2world.y);
+
if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer.");
- input = new TouchUserInput(TEMP_VEC_3);
+ input = new TouchUserInput();
robotArmPositioningSystem.setUserInput(input);
+
}else{
Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point outside framebuffer.");
}
@@ -558,6 +653,7 @@ public class InGameState extends BaseState{
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button){
MotorEvent event;
+ UserInput input;
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
@@ -567,95 +663,131 @@ public class InGameState extends BaseState{
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
- if(motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
+ if(motorAButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor A button released");
- motorButtonsPointers[0] = -1;
- motorButtonsTouched[0] = false;
+ buttonPointers[0] = -1;
+ buttonsTouched[0] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[1]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_A);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[1]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_A);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyUp = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(motorBButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor B button released");
- motorButtonsPointers[1] = -1;
- motorButtonsTouched[1] = false;
+ buttonPointers[1] = -1;
+ buttonsTouched[1] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[0]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_A);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[0]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_A);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyLeft = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(motorCButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor C button released");
- motorButtonsPointers[2] = -1;
- motorButtonsTouched[2] = false;
+ buttonPointers[2] = -1;
+ buttonsTouched[2] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[3]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_C);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[3]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_C);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyRight = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(motorDButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor D button released");
- motorButtonsPointers[3] = -1;
- motorButtonsTouched[3] = false;
+ buttonPointers[3] = -1;
+ buttonsTouched[3] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[2]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_C);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[2]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_C);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyDown = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(headA.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(headAButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head A button released");
- motorButtonsPointers[4] = -1;
- motorButtonsTouched[4] = false;
+ buttonPointers[4] = -1;
+ buttonsTouched[4] = false;
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[5]){
+ if(!buttonsTouched[5]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte) 0);
queue.addEvent(event);
}
- }else if(headB.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(headBButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head B button released");
- motorButtonsPointers[5] = -1;
- motorButtonsTouched[5] = false;
+ buttonPointers[5] = -1;
+ buttonsTouched[5] = false;
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[4]){
+ if(!buttonsTouched[4]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte) 0);
queue.addEvent(event);
}
- }else if(headC.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(headCButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head C button released");
- motorButtonsPointers[6] = -1;
- motorButtonsTouched[6] = false;
+ buttonPointers[6] = -1;
+ buttonsTouched[6] = false;
+
+ }else if(wheelControlButton.getBoundingRectangle().contains(touchPointWorldCoords) || armControlButton.getBoundingRectangle().contains(touchPointWorldCoords)){
+ buttonPointers[7] = -1;
+ buttonsTouched[7] = false;
}
return true;
@@ -667,101 +799,138 @@ public class InGameState extends BaseState{
@Override
public boolean touchDragged(int screenX, int screenY, int pointer){
MotorEvent event;
+ UserInput input;
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
- if(pointer == motorButtonsPointers[0] && !motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
+ if(pointer == buttonPointers[0] && !motorAButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor A button released");
- motorButtonsPointers[0] = -1;
- motorButtonsTouched[0] = false;
+ buttonPointers[0] = -1;
+ buttonsTouched[0] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[1]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_A);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[1]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_A);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyUp = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(pointer == motorButtonsPointers[1] && !motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(pointer == buttonPointers[1] && !motorBButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor B button released");
- motorButtonsPointers[1] = -1;
- motorButtonsTouched[1] = false;
+ buttonPointers[1] = -1;
+ buttonsTouched[1] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[0]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_A);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[0]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_A);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyLeft = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(pointer == motorButtonsPointers[2] && !motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(pointer == buttonPointers[2] && !motorCButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor C button released");
- motorButtonsPointers[2] = -1;
- motorButtonsTouched[2] = false;
+ buttonPointers[2] = -1;
+ buttonsTouched[2] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[3]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_C);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[3]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_C);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyRight = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(pointer == motorButtonsPointers[3] && !motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(pointer == buttonPointers[3] && !motorDButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor D button released");
- motorButtonsPointers[3] = -1;
- motorButtonsTouched[3] = false;
+ buttonPointers[3] = -1;
+ buttonsTouched[3] = false;
- // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[2]){
- event = new MotorEvent();
- event.setMotor(motor_t.MOTOR_C);
- event.setPower((byte) 0);
- queue.addEvent(event);
+ if(controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue()){
+ // Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
+ if(!buttonsTouched[2]){
+ event = new MotorEvent();
+ event.setMotor(motor_t.MOTOR_C);
+ event.setPower((byte) 0);
+ queue.addEvent(event);
+ }
+
+ }else if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue()){
+ input = new KeyboardUserInput();
+ ((KeyboardUserInput)input).keyDown = false;
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
}
- }else if(pointer == motorButtonsPointers[4] && !headA.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(pointer == buttonPointers[4] && !headAButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Head A button released");
- motorButtonsPointers[4] = -1;
- motorButtonsTouched[4] = false;
+ buttonPointers[4] = -1;
+ buttonsTouched[4] = false;
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[5]){
+ if(!buttonsTouched[5]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte) 0);
queue.addEvent(event);
}
- }else if(pointer == motorButtonsPointers[5] && !headB.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(pointer == buttonPointers[5] && !headBButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Head B button released");
- motorButtonsPointers[5] = -1;
- motorButtonsTouched[5] = false;
+ buttonPointers[5] = -1;
+ buttonsTouched[5] = false;
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
- if(!motorButtonsTouched[4]){
+ if(!buttonsTouched[4]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte) 0);
queue.addEvent(event);
}
- }else if(pointer == motorButtonsPointers[6] && !headC.getBoundingRectangle().contains(touchPointWorldCoords)){
+ }else if(pointer == buttonPointers[6] && !headCButton.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Head C button released");
- motorButtonsPointers[6] = -1;
- motorButtonsTouched[6] = false;
+ buttonPointers[6] = -1;
+ buttonsTouched[6] = false;
+
+ }else if(pointer == buttonPointers[7] && !(wheelControlButton.getBoundingRectangle().contains(touchPointWorldCoords) || armControlButton.getBoundingRectangle().contains(touchPointWorldCoords))){
+ buttonPointers[7] = -1;
+ buttonsTouched[7] = false;
}
return true;
@@ -772,12 +941,94 @@ public class InGameState extends BaseState{
@Override
public boolean keyDown(int keycode){
+ KeyboardUserInput input = null;
+
if(keycode == Input.Keys.BACK){
core.nextState = game_states_t.MAIN_MENU;
return true;
}
- return false;
+ switch(keycode){
+ case Input.Keys.LEFT:
+ input = new KeyboardUserInput();
+ input.keyLeft = true;
+ break;
+ case Input.Keys.RIGHT:
+ input = new KeyboardUserInput();
+ input.keyRight = true;
+ break;
+ case Input.Keys.UP:
+ input = new KeyboardUserInput();
+ input.keyUp = true;
+ break;
+ case Input.Keys.DOWN:
+ input = new KeyboardUserInput();
+ input.keyDown = true;
+ break;
+ case Input.Keys.A:
+ input = new KeyboardUserInput();
+ input.keyA = true;
+ break;
+ case Input.Keys.Z:
+ input = new KeyboardUserInput();
+ input.keyZ = true;
+ break;
+ default:
+ return false;
+ }
+
+ if(input != null){
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean keyUp(int keycode){
+ KeyboardUserInput input = null;
+
+ if(keycode == Input.Keys.BACK){
+ core.nextState = game_states_t.MAIN_MENU;
+ return true;
+ }
+
+ switch(keycode){
+ case Input.Keys.LEFT:
+ input = new KeyboardUserInput();
+ input.keyLeft = false;
+ break;
+ case Input.Keys.RIGHT:
+ input = new KeyboardUserInput();
+ input.keyRight = false;
+ break;
+ case Input.Keys.UP:
+ input = new KeyboardUserInput();
+ input.keyUp = false;
+ break;
+ case Input.Keys.DOWN:
+ input = new KeyboardUserInput();
+ input.keyDown = false;
+ break;
+ case Input.Keys.A:
+ input = new KeyboardUserInput();
+ input.keyA = false;
+ break;
+ case Input.Keys.Z:
+ input = new KeyboardUserInput();
+ input.keyZ = false;
+ break;
+ default:
+ return false;
+ }
+
+ if(input != null){
+ robotArmPositioningSystem.setUserInput(input);
+ robotArmPositioningSystem.process();
+ }
+
+ return true;
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -792,9 +1043,9 @@ public class InGameState extends BaseState{
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
if(buttonCode == Ouya.BUTTON_L1){
- motorGamepadButtonPressed[0] = true;
+ gamepadButtonPressed[0] = true;
- if(!motorGamepadButtonPressed[4]){
+ if(!gamepadButtonPressed[4]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_A);
event.setPower((byte)-100);
@@ -802,9 +1053,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_R1){
- motorGamepadButtonPressed[1] = true;
+ gamepadButtonPressed[1] = true;
- if(!motorGamepadButtonPressed[5]){
+ if(!gamepadButtonPressed[5]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_C);
event.setPower((byte)-100);
@@ -812,9 +1063,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_DPAD_LEFT){
- motorGamepadButtonPressed[2] = false;
+ gamepadButtonPressed[2] = false;
- if(!motorGamepadButtonPressed[3]){
+ if(!gamepadButtonPressed[3]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte)-40);
@@ -822,9 +1073,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_DPAD_RIGHT){
- motorGamepadButtonPressed[3] = false;
+ gamepadButtonPressed[3] = false;
- if(!motorGamepadButtonPressed[2]){
+ if(!gamepadButtonPressed[2]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte)40);
@@ -832,9 +1083,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_L2){
- motorGamepadButtonPressed[4] = false;
+ gamepadButtonPressed[4] = false;
- if(!motorGamepadButtonPressed[0]){
+ if(!gamepadButtonPressed[0]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_A);
event.setPower((byte)100);
@@ -842,9 +1093,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_R2){
- motorGamepadButtonPressed[5] = false;
+ gamepadButtonPressed[5] = false;
- if(!motorGamepadButtonPressed[1]){
+ if(!gamepadButtonPressed[1]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_C);
event.setPower((byte)100);
@@ -852,7 +1103,7 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_Y){
- motorGamepadButtonPressed[6] = true;
+ gamepadButtonPressed[6] = true;
event = new MotorEvent();
event.setMotor(motor_t.RECENTER);
@@ -877,9 +1128,9 @@ public class InGameState extends BaseState{
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
if(buttonCode == Ouya.BUTTON_L1){
- motorGamepadButtonPressed[0] = false;
+ gamepadButtonPressed[0] = false;
- if(!motorGamepadButtonPressed[4]){
+ if(!gamepadButtonPressed[4]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_A);
event.setPower((byte)0);
@@ -887,9 +1138,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_R1){
- motorGamepadButtonPressed[1] = false;
+ gamepadButtonPressed[1] = false;
- if(!motorGamepadButtonPressed[5]){
+ if(!gamepadButtonPressed[5]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_C);
event.setPower((byte)0);
@@ -897,27 +1148,27 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_DPAD_LEFT){
- motorGamepadButtonPressed[2] = false;
+ gamepadButtonPressed[2] = false;
- if(!motorGamepadButtonPressed[3]){
+ if(!gamepadButtonPressed[3]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte)0);
queue.addEvent(event);
}
}else if(buttonCode == Ouya.BUTTON_DPAD_RIGHT){
- motorGamepadButtonPressed[3] = false;
+ gamepadButtonPressed[3] = false;
- if(!motorGamepadButtonPressed[2]){
+ if(!gamepadButtonPressed[2]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
event.setPower((byte)0);
queue.addEvent(event);
}
}else if(buttonCode == Ouya.BUTTON_L2){
- motorGamepadButtonPressed[4] = false;
+ gamepadButtonPressed[4] = false;
- if(!motorGamepadButtonPressed[0]){
+ if(!gamepadButtonPressed[0]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_A);
event.setPower((byte)0);
@@ -925,9 +1176,9 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_R2){
- motorGamepadButtonPressed[5] = false;
+ gamepadButtonPressed[5] = false;
- if(!motorGamepadButtonPressed[1]){
+ if(!gamepadButtonPressed[1]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_C);
event.setPower((byte)0);
@@ -935,7 +1186,7 @@ public class InGameState extends BaseState{
}
}else if(buttonCode == Ouya.BUTTON_Y){
- motorGamepadButtonPressed[6] = false;
+ gamepadButtonPressed[6] = false;
}
return true;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index 2ae5322..f5c2256 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -15,6 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
+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;
@@ -22,30 +23,33 @@ import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
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.utils.Utils;
import com.artemis.Aspect;
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.Vector3;
public class RobotArmPositioningSystem extends EntityProcessingSystem {
- private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
- private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
- private static final float STEP_SIZE = 0.05f;
- private static final Vector3 END_POINT = new Vector3(-1.0f, 0.0f, 0.0f);
- private static final float MAX_Z = -4.5f;
+ private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
+ private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
+ private static final float INTERPOLATION_STEP = 0.05f;
+ private static final float STEP_SIZE = 0.05f;
+ private static final Vector3 END_POINT = new Vector3(0.0f, 0.0f, -0.5f);
+ private static final float MAX_Z = -4.5f;
@Mapper ComponentMapper geometryMapper;
-// @Mapper ComponentMapper autoMapper;
+ @Mapper ComponentMapper autoMapper;
@Mapper ComponentMapper collisionMapper;
private UserInput input;
@SuppressWarnings("unchecked")
public RobotArmPositioningSystem(){
- super(Aspect.getAspectForAll(GeometryComponent.class, /*AutomaticMovementComponent.class,*/ CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
+ super(Aspect.getAspectForAll(GeometryComponent.class, AutomaticMovementComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
}
public void setUserInput(UserInput input){
@@ -58,61 +62,58 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
GamepadUserInput tempGP;
KeyboardUserInput tempKey;
GeometryComponent geometry = geometryMapper.get(e);
-// AutomaticMovementComponent auto = autoMapper.get(e);
+ AutomaticMovementComponent auto = autoMapper.get(e);
CollisionDetectionComponent collision = collisionMapper.get(e);
if(input == null){
- /*if(auto.moving) autoMove(geometry, auto, collision);
- else */return;
+ if(auto.moving) autoMove(geometry, auto, collision);
+ else return;
}else{
if(input instanceof TouchUserInput){
-// if(!auto.moving){
-// endPoint = ((TouchUserInput) input).userTouchEndPoint;
-// endPoint.set(endPoint.x, endPoint.y, MAX_Z);
-// auto.startPoint.set(geometry.position);
-// auto.endPoint.set(endPoint);
-// auto.moving = true;
-// auto.forward = true;
-//
-// auto.target.set(endPoint).sub(auto.startPoint);
-// auto.epsilon = 0.05f;
-//
-// Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
-// }else autoMove(geometry, auto, collision);
+ if(!auto.moving){
+ endPoint = ((TouchUserInput) input).userTouchEndPoint;
+ endPoint.set(endPoint.x, endPoint.y, MAX_Z);
+ auto.startPoint.set(geometry.position);
+ auto.endPoint.set(endPoint);
+ auto.moving = true;
+ auto.forward = true;
+
+ Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
+ }else autoMove(geometry, auto, collision);
}else if(input instanceof GamepadUserInput){
-// tempGP = (GamepadUserInput) input;
-//
-// if(!collision.colliding && !auto.moving){
-// geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
-// geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
-// geometry.position.z += tempGP.axisRightY * STEP_SIZE;
-// clampPosition(geometry);
-// }else{
-// auto.moving = true;
-// auto.forward = false;
-// auto.startPoint.set(geometry.position);
-// auto.endPoint.set(END_POINT);
-// }
+ 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;
+ //clampPosition(geometry);
+ }else{
+ auto.moving = true;
+ auto.forward = false;
+ auto.startPoint.set(geometry.position);
+ auto.endPoint.set(END_POINT);
+ }
}else if(input instanceof KeyboardUserInput){
-// tempKey = (KeyboardUserInput) input;
-//
-// if(!collision.colliding && !auto.moving){
-// 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;
-// clampPosition(geometry);
-// }else{
-// auto.moving = true;
-// auto.forward = false;
-// auto.startPoint.set(geometry.position);
-// auto.endPoint.set(END_POINT);
-// }
+ 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;
+ //clampPosition(geometry);
+ }else{
+ auto.moving = true;
+ auto.forward = false;
+ auto.startPoint.set(geometry.position);
+ auto.endPoint.set(END_POINT);
+ }
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
@@ -121,45 +122,45 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
input = null;
}
-// private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
-// float step;
-//
-// if(auto.moving){
-// if(auto.forward)
-// step = STEP_SIZE;
-// else
-// step = -STEP_SIZE;
-//
-// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
-//
-// auto.distance += step;
-//
-// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
-//
-// geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
-// geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
-// geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
-//
-// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
-//
-// if(auto.distance <= 0.0f){
-// 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;
-// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
-// }
-//
-// }else return;
-// }
+ private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
+ float step;
- private void clampPosition(GeometryComponent geometry){
- geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
- geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
- geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
- geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
- geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
- geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
+ if(auto.moving){
+ if(auto.forward)
+ step = INTERPOLATION_STEP;
+ else
+ step = -INTERPOLATION_STEP;
+
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
+
+ auto.distance += step;
+
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
+
+ geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
+ geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
+ geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
+
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
+
+ if(auto.distance <= 0.0f){
+ 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;
+ Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
+ }
+
+ }else return;
}
+
+// private void clampPosition(GeometryComponent geometry){
+// geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
+// geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
+// geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
+// geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
+// geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
+// geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
+// }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index d40b4ca..a366967 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -49,9 +49,11 @@ public abstract class GameSettings{
}
public static void clearGameSettings(){
+ entityCreator.dispose();
entityCreator = null;
gameLogicSystem = null;
gameWorld = null;
+ System.gc();
}
/**
From 29c4bea104c53c62f6f77703c9ff787fd0738061 Mon Sep 17 00:00:00 2001
From: unknown
Date: Mon, 16 Jun 2014 16:57:47 -0430
Subject: [PATCH 19/34] Added processing for the remaining bombs.
---
.../nxtar/entities/BombGameEntityCreator.java | 8 +-
.../ccg/nxtar/systems/AnimationSystem.java | 2 +
.../nxtar/systems/BombGameLogicSystem.java | 201 +++++++++++++++---
.../systems/RobotArmPositioningSystem.java | 17 +-
4 files changed, 180 insertions(+), 48 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 31c5610..2182716 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
+import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import com.artemis.Entity;
@@ -53,6 +54,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
public static final String DOORS_GROUP = "DOORS";
+ 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 = 1;
private class EntityParameters{
public Environment environment;
@@ -184,7 +188,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
addBomb(parameters, bomb_type_t.WIRES);
// Add doors.
- parameters.nextAnimation = -1;
+ parameters.nextAnimation = AnimationSystem.NO_ANIMATION;
parameters.loopAnimation = false;
parameters.markerCode = 89;
@@ -233,7 +237,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
- robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -1.0f), new Matrix3(), new Vector3(1, 1, 1)));
+ robotArm.addComponent(new GeometryComponent(new Vector3(ROBOT_ARM_START_POINT), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel));
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
index 899a7ff..f314e9b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
@@ -26,6 +26,8 @@ import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
public class AnimationSystem extends EntityProcessingSystem {
+ public static final int NO_ANIMATION = -1;
+
@Mapper ComponentMapper animationMapper;
@Mapper ComponentMapper visibilityMapper;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index cc0032e..8f2d6e7 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -42,10 +42,12 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
private MarkerCodeComponent tempMarker;
private BombGameObjectTypeComponent tempType;
+ private GroupManager manager;
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
+ manager = world.getManager(GroupManager.class);
}
@Override
@@ -56,75 +58,171 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
switch(typeComponent.type){
case BombGameObjectTypeComponent.BOMB_WIRE_1:
- break;
case BombGameObjectTypeComponent.BOMB_WIRE_2:
- break;
case BombGameObjectTypeComponent.BOMB_WIRE_3:
+ processWireBomb(e);
break;
+
case BombGameObjectTypeComponent.BIG_BUTTON:
processInclinationBomb(e);
break;
+
case BombGameObjectTypeComponent.COM_BUTTON_1:
- break;
case BombGameObjectTypeComponent.COM_BUTTON_2:
- break;
case BombGameObjectTypeComponent.COM_BUTTON_3:
- break;
case BombGameObjectTypeComponent.COM_BUTTON_4:
+ processCombinationBomb(e);
break;
+
case BombGameObjectTypeComponent.DOOR:
processDoor(e);
break;
- case BombGameObjectTypeComponent.DOOR_FRAME:
- break;
+
default:
- Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
break;
}
}
- private void processInclinationBomb(Entity b){
- CollisionDetectionComponent collision = collisionMapper.getSafe(b);
- MarkerCodeComponent marker = markerMapper.getSafe(b);
- GroupManager manager = world.getManager(GroupManager.class);
+ /**
+ * Checks if the current player interaction disables a wire based bomb.
+ *
+ * @param b An Artemis {@link Entity} that possibly represents any of a Wire Bomb's wires.
+ */
+ private void processWireBomb(Entity b){
+ int relatedWires = 0;
+ CollisionDetectionComponent collision;
+ MarkerCodeComponent marker;
+ BombGameObjectTypeComponent wireType;
ImmutableBag related;
+ // Get this wire's parameters.
+ collision = collisionMapper.getSafe(b);
+ marker = markerMapper.getSafe(b);
+ wireType = typeMapper.getSafe(b);
+
+ // if any of the parameters is missing then skip.
+ if(marker == null || collision == null || wireType == null){
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Wire bomb is missing some components.");
+ return;
+ }
+
+ // If this bomb is still enabled and it's door is already open then process it.
+ if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
+ manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(b, Integer.toString(marker.code));
+ b.deleteFromWorld();
+ related = manager.getEntities(Integer.toString(marker.code));
+
+ // Check the state of the other wires associated with this bomb.
+ for(int i = 0; i < related.size(); i++){
+ tempType = typeMapper.getSafe(related.get(i));
+
+ if(tempType == null) continue;
+
+ if(tempType.type >= BombGameObjectTypeComponent.BOMB_WIRE_1 && tempType.type <= BombGameObjectTypeComponent.BOMB_WIRE_3){
+ if(tempType.type != wireType.type){
+ relatedWires++;
+ }
+ }
+ }
+
+ if(relatedWires == 0)
+ disableBomb(marker.code);
+ }
+ }
+
+ /**
+ * Checks if the current player interaction disables a combination bomb.
+ *
+ * @param b An Artemis {@link Entity} that possibly represents any of a Combination Bomb's buttons.
+ */
+ private void processCombinationBomb(Entity b){
+ int relatedButtons = 0;
+ CollisionDetectionComponent collision;
+ MarkerCodeComponent marker;
+ BombGameObjectTypeComponent buttonType;
+ ImmutableBag related;
+
+ // Get this wire's parameters.
+ collision = collisionMapper.getSafe(b);
+ marker = markerMapper.getSafe(b);
+ buttonType = typeMapper.getSafe(b);
+
+ // if any of the parameters is missing then skip.
+ if(marker == null || collision == null || buttonType == null){
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Wire bomb is missing some components.");
+ return;
+ }
+
+ // If this bomb is still enabled and it's door is already open then process it.
+ if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
+ manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(b, Integer.toString(marker.code));
+ b.deleteFromWorld();
+ related = manager.getEntities(Integer.toString(marker.code));
+
+ // Check the state of the other wires associated with this bomb.
+ for(int i = 0; i < related.size(); i++){
+ tempType = typeMapper.getSafe(related.get(i));
+
+ if(tempType == null) continue;
+
+ if(tempType.type >= BombGameObjectTypeComponent.COM_BUTTON_1 && tempType.type <= BombGameObjectTypeComponent.COM_BUTTON_4){
+ if(tempType.type != buttonType.type){
+ relatedButtons++;
+ }
+ }
+ }
+
+ if(relatedButtons == 0)
+ disableBomb(marker.code);
+ }
+ }
+
+ /**
+ * Checks if the current player interaction disables an inclination bomb.
+ *
+ * @param b An Artemis {@link Entity} that possibly represents an Inclination Bomb's big button.
+ */
+ private void processInclinationBomb(Entity b){
+ // Get the components of the big button.
+ CollisionDetectionComponent collision = collisionMapper.getSafe(b);
+ MarkerCodeComponent marker = markerMapper.getSafe(b);
+
+ // If any of the components is missing, skip this entity.
if(marker == null || collision == null ){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb is missing some components.");
return;
}
- if(isDoorOpen(marker.code, manager) && marker.enabled && collision.colliding){
+ // If this bomb is still enabled and it's door is already open then process it.
+ if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
+ // Disable the bomb and remove it from collision detection.
marker.enabled = false;
manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(b, Integer.toString(marker.code));
+ b.deleteFromWorld();
// Disable all related entities.
- related = manager.getEntities(Integer.toString(marker.code));
- for(int i = 0; i < related.size(); i++){
- tempMarker = markerMapper.getSafe(related.get(i));
- tempType = typeMapper.getSafe(related.get(i));
+ disableBomb(marker.code);
- // Enable collisions with the door frame. Disable collisions with other related objects.
- if(tempMarker != null) tempMarker.enabled = false;
- if(tempType != null){
- if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
- manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
- }else{
- manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
- }
- }
- }
-
- Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Disabling inclination bomb.");
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb disabled.");
}
}
+ /**
+ * Set's the animation for a door depending on it's collision and marker state.
+ *
+ * @param d An Artemis {@link Entity} possibly representing a door.
+ */
private void processDoor(Entity d){
+ // Get the components of the door.
CollisionDetectionComponent collision = collisionMapper.getSafe(d);
AnimationComponent animation = animationMapper.getSafe(d);
VisibilityComponent visibility = visibilityMapper.getSafe(d);
MarkerCodeComponent marker = markerMapper.getSafe(d);
+ // If any of the components is missing, skip this entity.
if(marker == null || collision == null || animation == null || visibility == null){
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Door is missing some components.");
return;
@@ -133,15 +231,18 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
if(visibility.visible){
if(marker.enabled){
if(collision.colliding){
- animation.next = 1;
+ // If the door is visible and enabled and the player is colliding with it then set
+ // it's opening animation;
+ animation.next = BombGameEntityCreator.DOOR_OPEN_ANIMATION;
animation.loop = false;
collision.colliding = false;
world.getManager(GroupManager.class).remove(d, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Opening door.");
}
}else{
+ // If the door is disabled and open, then set it's closing animation.
if(animation.current != 0){
- animation.next = 0;
+ animation.next = BombGameEntityCreator.DOOR_CLOSE_ANIMATION;
animation.loop = false;
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Closing door.");
}
@@ -149,18 +250,27 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
}
+ /**
+ * Checks if a door is either open or closed depending on the completeness of it's animation.
+ *
+ * @param markerCode The code of the door to check. Must be between 0 and 1023.
+ * @param manager An Artemis {@link GroupManager} to use to get all related entities.
+ * @return true if the opening animation of the door has finished playing.
+ */
private boolean isDoorOpen(int markerCode, GroupManager manager){
AnimationComponent animation;
boolean doorOpen = false;
ImmutableBag doors = manager.getEntities(BombGameEntityCreator.DOORS_GROUP);
+ // For every door.
for(int i = 0; i < doors.size(); i++){
tempMarker = markerMapper.getSafe(doors.get(i));
animation = animationMapper.getSafe(doors.get(i));
if(animation == null || tempMarker == null) return false;
- if(tempMarker.code == markerCode && animation.current == 1 && animation.controller.current.loopCount == 0){
+ // If this is the door we are looking for and it's opening animation is finished then this door is open.
+ if(tempMarker.code == markerCode && animation.current == BombGameEntityCreator.DOOR_OPEN_ANIMATION && animation.controller.current.loopCount == 0){
doorOpen = true;
break;
}
@@ -168,4 +278,31 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
return doorOpen;
}
+
+ /**
+ * Disables all entities associated with the corresponding marker code.
+ *
+ * @param markerCode
+ */
+ private void disableBomb(int markerCode){
+ ImmutableBag related = manager.getEntities(Integer.toString(markerCode));
+
+ // Disable every entity sharing this marker code except for the corresponding door frame.
+ for(int i = 0; i < related.size(); i++){
+ tempMarker = markerMapper.getSafe(related.get(i));
+ tempType = typeMapper.getSafe(related.get(i));
+
+ // Enable collisions with the corresponding door frame entity. Disable collisions with other related entities.
+ if(tempMarker != null) tempMarker.enabled = false;
+ if(tempType != null){
+ if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
+ manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(related.get(i), Integer.toString(markerCode));
+ related.get(i).deleteFromWorld();
+ }else{
+ manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ }
+ }
+ }
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index f5c2256..8a5e612 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -19,6 +19,7 @@ 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;
@@ -38,7 +39,6 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
private static final float INTERPOLATION_STEP = 0.05f;
private static final float STEP_SIZE = 0.05f;
- private static final Vector3 END_POINT = new Vector3(0.0f, 0.0f, -0.5f);
private static final float MAX_Z = -4.5f;
@Mapper ComponentMapper geometryMapper;
@@ -89,12 +89,11 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
geometry.position.z += tempGP.axisRightY * STEP_SIZE;
- //clampPosition(geometry);
}else{
auto.moving = true;
auto.forward = false;
auto.startPoint.set(geometry.position);
- auto.endPoint.set(END_POINT);
+ auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
}
}else if(input instanceof KeyboardUserInput){
@@ -107,12 +106,11 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
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;
- //clampPosition(geometry);
}else{
auto.moving = true;
auto.forward = false;
auto.startPoint.set(geometry.position);
- auto.endPoint.set(END_POINT);
+ auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
}
}else
@@ -154,13 +152,4 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
}else return;
}
-
-// private void clampPosition(GeometryComponent geometry){
-// geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
-// geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
-// geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
-// geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
-// geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
-// geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
-// }
}
From 8bd799f146d8bdf296b85bc298038598b927f723 Mon Sep 17 00:00:00 2001
From: unknown
Date: Tue, 17 Jun 2014 17:57:57 -0430
Subject: [PATCH 20/34] All bombs sucessfully implemented.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 7 +-
.../BombGameObjectTypeComponent.java | 1 +
.../nxtar/components/FadeEffectComponent.java | 72 +++++
.../nxtar/entities/BombGameEntityCreator.java | 2 +-
.../ciens/ccg/nxtar/states/InGameState.java | 101 ++++++-
.../nxtar/systems/BombGameLogicSystem.java | 259 ++++++++++++++----
.../systems/FadeEffectRenderingSystem.java | 57 ++++
.../systems/RobotArmPositioningSystem.java | 1 +
.../ccg/nxtar/utils/ProjectConstants.java | 3 +-
9 files changed, 441 insertions(+), 62 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index fac2280..14f25f5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -390,10 +390,11 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
batch.setProjectionMatrix(pixelPerfectCamera.combined);
batch.begin();{
// Draw the FPS overlay.
- font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
- font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
- font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), overlayX, overlayY - (2 * font.getCapHeight()) - 10);
+ font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
+ font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
+ 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);
}batch.end();
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
index a0c923f..5fd7862 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
@@ -28,6 +28,7 @@ public class BombGameObjectTypeComponent extends Component {
public static final int COM_BUTTON_4 = 33;
public static final int DOOR = 40;
public static final int DOOR_FRAME = 41;
+ public static final int FADE_EFFECT = 90;
public int type;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java
new file mode 100644
index 0000000..1490354
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java
@@ -0,0 +1,72 @@
+/*
+ * 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 aurelienribon.tweenengine.Tween;
+import aurelienribon.tweenengine.TweenEquations;
+import aurelienribon.tweenengine.primitives.MutableFloat;
+
+import com.artemis.Component;
+
+public class FadeEffectComponent extends Component{
+ private MutableFloat alpha;
+ private Tween fadeIn;
+ private Tween fadeOut;
+
+ public FadeEffectComponent(boolean fadeIn){
+ if(fadeIn){
+ this.alpha = new MutableFloat(1.0f);
+ this.fadeIn = Tween.to(alpha, 0, 2.0f).target(0.0f).ease(TweenEquations.easeInQuint);
+ this.fadeOut = null;
+ }else{
+ this.alpha = new MutableFloat(0.0f);
+ this.fadeOut = Tween.to(alpha, 0, 2.5f).target(1.0f).ease(TweenEquations.easeInQuint);
+ this.fadeIn = null;
+ }
+ }
+
+ public float getFloatValue(){
+ return alpha.floatValue();
+ }
+
+ public void update(float delta){
+ if(fadeIn != null)
+ fadeIn.update(delta);
+
+ if(fadeOut != null)
+ fadeOut.update(delta);
+ }
+
+ public void startEffect(){
+ if(fadeIn != null)
+ fadeIn.start();
+
+ if(fadeOut != null)
+ fadeOut.start();
+ }
+
+ public boolean isEffectStarted(){
+ return fadeIn != null ? fadeIn.isStarted() : fadeOut.isStarted();
+ }
+
+ public boolean isEffectFadeIn(){
+ return fadeIn != null;
+ }
+
+ public boolean isEffectFinished(){
+ return fadeIn != null ? fadeIn.isFinished() : fadeOut.isFinished();
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 2182716..fc4e6f4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -56,7 +56,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
public static final String DOORS_GROUP = "DOORS";
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 = 1;
+ public static final int DOOR_CLOSE_ANIMATION = 0;
private class EntityParameters{
public Environment environment;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index f4a3338..ab8529a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
@@ -61,6 +62,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 float NEAR = 0.01f;
private static final float FAR = 100.0f;
@@ -91,12 +93,16 @@ public class InGameState extends BaseState{
private ModelBatch modelBatch;
private FrameBuffer frameBuffer;
private Sprite frameBufferSprite;
+ private FrameBuffer robotArmFrameBuffer;
+ private Sprite robotArmFrameBufferSprite;
+ private ShaderProgram alphaShader;
// Game related fields.
private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
private RobotArmPositioningSystem robotArmPositioningSystem;
+ private FadeEffectRenderingSystem fadeEffectRenderingSystem;
private robot_control_mode_t controlMode;
// Cameras.
@@ -114,6 +120,8 @@ public class InGameState extends BaseState{
private Texture headControlButtonTexture;
private Texture wheelControlButtonTexture;
private Texture armControlButtonTexture;
+ private Texture correctAngleLedOnTexture;
+ private Texture correctAngleLedOffTexture;
private Sprite motorAButton;
private Sprite motorBButton;
private Sprite motorCButton;
@@ -123,6 +131,8 @@ public class InGameState extends BaseState{
private Sprite headCButton;
private Sprite wheelControlButton;
private Sprite armControlButton;
+ private Sprite correctAngleLedOnSprite;
+ private Sprite correctAngleLedOffSprite;
// Button touch helper fields.
private boolean[] buttonsTouched;
@@ -192,7 +202,7 @@ public class InGameState extends BaseState{
// Set up the shader.
backgroundShader = new ShaderProgram(Gdx.files.internal(BACKGROUND_SHADER_PATH + "_vert.glsl"), Gdx.files.internal(BACKGROUND_SHADER_PATH + "_frag.glsl"));
if(!backgroundShader.isCompiled()){
- Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
+ Gdx.app.error(TAG, CLASS_NAME + ".InGameState() :: Failed to compile the background shader.");
Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
backgroundShader = null;
}
@@ -201,11 +211,21 @@ public class InGameState extends BaseState{
uScaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
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;
+ }
+
// Set up the 3D rendering.
modelBatch = new ModelBatch();
frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = null;
+ robotArmFrameBuffer = null;
+ robotArmFrameBufferSprite = null;
// Set up the game world.
gameWorld = GameSettings.getGameWorld();
@@ -213,6 +233,7 @@ public class InGameState extends BaseState{
robotArmPositioningSystem = new RobotArmPositioningSystem();
markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
+ fadeEffectRenderingSystem = new FadeEffectRenderingSystem();
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(robotArmPositioningSystem, Ouya.runningOnOuya);
@@ -222,6 +243,7 @@ public class InGameState extends BaseState{
gameWorld.setSystem(GameSettings.getGameLogicSystem());
gameWorld.setSystem(markerRenderingSystem, true);
gameWorld.setSystem(objectRenderingSystem, true);
+ gameWorld.setSystem(fadeEffectRenderingSystem, true);
gameWorld.initialize();
}
@@ -263,6 +285,9 @@ 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);
+
perspectiveCamera = new CustomPerspectiveCamera(67, w, h);
perspectiveCamera.translate(0.0f, 0.0f, 0.0f);
perspectiveCamera.near = NEAR;
@@ -315,12 +340,19 @@ public class InGameState extends BaseState{
markerRenderingSystem.begin(perspectiveCamera);
markerRenderingSystem.process();
markerRenderingSystem.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();
-
- }frameBuffer.end();
+ }robotArmFrameBuffer.end();
// Set the frame buffer object texture to a renderable sprite.
region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
@@ -332,6 +364,16 @@ public class InGameState extends BaseState{
frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
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);
+
// Set the position and orientation of the renderable video frame and the frame buffer.
if(!Ouya.runningOnOuya){
renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
@@ -341,6 +383,10 @@ public class InGameState extends BaseState{
frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth() );
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());
}else{
float xSize = Gdx.graphics.getHeight() * (w / h);
renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
@@ -350,6 +396,10 @@ public class InGameState extends BaseState{
frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
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);
}
// Set the correct camera for the device.
@@ -363,6 +413,13 @@ public class InGameState extends BaseState{
core.batch.begin();{
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);
+
}core.batch.end();
// Clear the video frame from memory.
@@ -389,9 +446,16 @@ public class InGameState extends BaseState{
throw new IllegalStateException("Unrecognized control mode: " + Integer.toString(controlMode.getValue()));
}
+ if(Math.abs(Gdx.input.getRoll()) < ProjectConstants.MAX_ABS_ROLL){
+ correctAngleLedOnSprite.draw(core.batch);
+ }else{
+ correctAngleLedOffSprite.draw(core.batch);
+ }
}core.batch.end();
}
+ fadeEffectRenderingSystem.process();
+
data = null;
}
@@ -421,8 +485,22 @@ 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(correctAngleLedOffTexture != null)
+ correctAngleLedOffTexture.dispose();
+
+ if(correctAngleLedOnTexture != null)
+ correctAngleLedOnTexture.dispose();
+
+ fadeEffectRenderingSystem.dispose();
}
/*;;;;;;;;;;;;;;;;;;
@@ -454,10 +532,13 @@ public class InGameState extends BaseState{
motorAButton = new Sprite(region);
motorAButton.setSize(motorAButton.getWidth() * 0.7f, motorAButton.getHeight() * 0.7f);
+
motorBButton = new Sprite(region);
motorBButton.setSize(motorBButton.getWidth() * 0.7f, motorBButton.getHeight() * 0.7f);
+
motorCButton = new Sprite(region);
motorCButton.setSize(motorCButton.getWidth() * 0.7f, motorCButton.getHeight() * 0.7f);
+
motorDButton = new Sprite(region);
motorDButton.setSize(motorDButton.getWidth() * 0.7f, motorDButton.getHeight() * 0.7f);
@@ -487,11 +568,25 @@ public class InGameState extends BaseState{
wheelControlButton = new Sprite(wheelControlButtonTexture);
wheelControlButton.setSize(wheelControlButton.getWidth() * 0.3f, wheelControlButton.getHeight() * 0.3f);
+
armControlButton = new Sprite(armControlButtonTexture);
armControlButton.setSize(armControlButton.getWidth() * 0.3f, armControlButton.getHeight() * 0.3f);
wheelControlButton.setPosition(-(wheelControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
+
+ // Set up the correct angle leds.
+ correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png"));
+ correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png"));
+
+ correctAngleLedOnSprite = new Sprite(correctAngleLedOnTexture);
+ correctAngleLedOffSprite = new Sprite(correctAngleLedOffTexture);
+
+ 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);
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index 8f2d6e7..79eb391 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -18,42 +18,66 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
+import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
+import com.artemis.World;
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";
private static final String CLASS_NAME = BombGameLogicSystem.class.getSimpleName();
+ private enum combination_button_state_t{
+ CORRECT(0), INCORRECT(1), DISABLED(2);
+
+ private int value;
+
+ private combination_button_state_t(int value){
+ this.value = value;
+ }
+
+ public int getValue(){
+ return this.value;
+ }
+ }
+
@Mapper ComponentMapper typeMapper;
@Mapper ComponentMapper animationMapper;
@Mapper ComponentMapper visibilityMapper;
@Mapper ComponentMapper markerMapper;
@Mapper ComponentMapper collisionMapper;
+ @Mapper ComponentMapper fadeMapper;
private MarkerCodeComponent tempMarker;
private BombGameObjectTypeComponent tempType;
private GroupManager manager;
+ private int then;
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
- manager = world.getManager(GroupManager.class);
+ manager = null;
+ then = 0;
}
@Override
protected void process(Entity e){
BombGameObjectTypeComponent typeComponent;
+ if(manager == null)
+ manager = world.getManager(GroupManager.class);
+
typeComponent = typeMapper.get(e);
switch(typeComponent.type){
@@ -78,6 +102,10 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
processDoor(e);
break;
+ case BombGameObjectTypeComponent.FADE_EFFECT:
+ processFade(e);
+ break;
+
default:
break;
}
@@ -89,11 +117,9 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
* @param b An Artemis {@link Entity} that possibly represents any of a Wire Bomb's wires.
*/
private void processWireBomb(Entity b){
- int relatedWires = 0;
CollisionDetectionComponent collision;
MarkerCodeComponent marker;
BombGameObjectTypeComponent wireType;
- ImmutableBag related;
// Get this wire's parameters.
collision = collisionMapper.getSafe(b);
@@ -107,27 +133,22 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
// If this bomb is still enabled and it's door is already open then process it.
- if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
- manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
- manager.remove(b, Integer.toString(marker.code));
- b.deleteFromWorld();
- related = manager.getEntities(Integer.toString(marker.code));
+ try{
+ if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
+ manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(b, Integer.toString(marker.code));
+ b.deleteFromWorld();
- // Check the state of the other wires associated with this bomb.
- for(int i = 0; i < related.size(); i++){
- tempType = typeMapper.getSafe(related.get(i));
-
- if(tempType == null) continue;
-
- if(tempType.type >= BombGameObjectTypeComponent.BOMB_WIRE_1 && tempType.type <= BombGameObjectTypeComponent.BOMB_WIRE_3){
- if(tempType.type != wireType.type){
- relatedWires++;
- }
+ if(wireType.type != BombGameObjectTypeComponent.BOMB_WIRE_1){
+ Gdx.app.log(TAG, CLASS_NAME + ".processWireBomb(): Wire bomb exploded.");
+ createFadeOutEffect();
}
- }
- if(relatedWires == 0)
disableBomb(marker.code);
+ Gdx.app.log(TAG, CLASS_NAME + ".processWireBomb(): Wire bomb disabled.");
+ }
+ }catch(IllegalArgumentException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".processWireBomb(): IllegalArgumentException caught: " + e.getMessage());
}
}
@@ -137,16 +158,15 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
* @param b An Artemis {@link Entity} that possibly represents any of a Combination Bomb's buttons.
*/
private void processCombinationBomb(Entity b){
- int relatedButtons = 0;
+ combination_button_state_t state;
CollisionDetectionComponent collision;
MarkerCodeComponent marker;
BombGameObjectTypeComponent buttonType;
- ImmutableBag related;
// Get this wire's parameters.
collision = collisionMapper.getSafe(b);
marker = markerMapper.getSafe(b);
- buttonType = typeMapper.getSafe(b);
+ buttonType = typeMapper.getSafe(b);
// if any of the parameters is missing then skip.
if(marker == null || collision == null || buttonType == null){
@@ -155,27 +175,27 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
// If this bomb is still enabled and it's door is already open then process it.
- if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
- manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
- manager.remove(b, Integer.toString(marker.code));
- b.deleteFromWorld();
- related = manager.getEntities(Integer.toString(marker.code));
+ try{
+ if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
+ manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(b, Integer.toString(marker.code));
+ b.deleteFromWorld();
- // Check the state of the other wires associated with this bomb.
- for(int i = 0; i < related.size(); i++){
- tempType = typeMapper.getSafe(related.get(i));
+ // Check the state of the other buttons associated with this bomb.
- if(tempType == null) continue;
+ state = checkCombinationBombButtons(buttonType.type, marker.code);
- if(tempType.type >= BombGameObjectTypeComponent.COM_BUTTON_1 && tempType.type <= BombGameObjectTypeComponent.COM_BUTTON_4){
- if(tempType.type != buttonType.type){
- relatedButtons++;
- }
+ if(state.getValue() == combination_button_state_t.INCORRECT.getValue()){
+ Gdx.app.log(TAG, CLASS_NAME + ".processCombinationBomb(): Combination bomb exploded.");
+ createFadeOutEffect();
+ disableBomb(marker.code);
+ }else if(state.getValue() == combination_button_state_t.DISABLED.getValue()){
+ Gdx.app.log(TAG, CLASS_NAME + ".processCombinationBomb(): Combination bomb disabled.");
+ disableBomb(marker.code);
}
}
-
- if(relatedButtons == 0)
- disableBomb(marker.code);
+ }catch(IllegalArgumentException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".processCombinationBomb(): IllegalArgumentException caught: " + e.getMessage());
}
}
@@ -188,6 +208,7 @@ 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 ){
@@ -196,17 +217,29 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
// If this bomb is still enabled and it's door is already open then process it.
- if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
- // Disable the bomb and remove it from collision detection.
- marker.enabled = false;
- manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
- manager.remove(b, Integer.toString(marker.code));
- b.deleteFromWorld();
+ try{
+ if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
+ // Disable the bomb and remove it from collision detection.
+ marker.enabled = false;
+ manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
+ manager.remove(b, Integer.toString(marker.code));
+ b.deleteFromWorld();
- // Disable all related entities.
- disableBomb(marker.code);
+ angle = Gdx.input.getRoll();
+ Gdx.app.log("ROTATION", "Roll: " + Float.toString(angle));
- Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb disabled.");
+ if(Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Math.abs(angle) > ProjectConstants.MAX_ABS_ROLL){
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
+ createFadeOutEffect();
+ }
+
+ // Disable all related entities.
+ disableBomb(marker.code);
+
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb disabled.");
+ }
+ }catch(IllegalArgumentException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".processInclinationBomb(): IllegalArgumentException caught: " + e.getMessage());
}
}
@@ -241,7 +274,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
}else{
// If the door is disabled and open, then set it's closing animation.
- if(animation.current != 0){
+ if(animation.current != BombGameEntityCreator.DOOR_CLOSE_ANIMATION){
animation.next = BombGameEntityCreator.DOOR_CLOSE_ANIMATION;
animation.loop = false;
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Closing door.");
@@ -256,12 +289,16 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
* @param markerCode The code of the door to check. Must be between 0 and 1023.
* @param manager An Artemis {@link GroupManager} to use to get all related entities.
* @return true if the opening animation of the door has finished playing.
+ * @throws IllegalArgumentException If marker code is not in the range [0, 1023], inclusive.
*/
- private boolean isDoorOpen(int markerCode, GroupManager manager){
+ private boolean isDoorOpen(int markerCode, GroupManager manager) throws IllegalArgumentException{
AnimationComponent animation;
boolean doorOpen = false;
ImmutableBag doors = manager.getEntities(BombGameEntityCreator.DOORS_GROUP);
+ if(markerCode < 0 || markerCode > 1023)
+ throw new IllegalArgumentException("Marker code is not within range [0, 1023]: " + Integer.toString(markerCode));
+
// For every door.
for(int i = 0; i < doors.size(); i++){
tempMarker = markerMapper.getSafe(doors.get(i));
@@ -283,10 +320,14 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
* Disables all entities associated with the corresponding marker code.
*
* @param markerCode
+ * @throws IllegalArgumentException If marker code is not in the range [0, 1023], inclusive.
*/
- private void disableBomb(int markerCode){
+ private void disableBomb(int markerCode) throws IllegalArgumentException{
ImmutableBag related = manager.getEntities(Integer.toString(markerCode));
+ if(markerCode < 0 || markerCode > 1023)
+ throw new IllegalArgumentException("Marker code is not within range [0, 1023]: " + Integer.toString(markerCode));
+
// Disable every entity sharing this marker code except for the corresponding door frame.
for(int i = 0; i < related.size(); i++){
tempMarker = markerMapper.getSafe(related.get(i));
@@ -295,14 +336,124 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
// Enable collisions with the corresponding door frame entity. Disable collisions with other related entities.
if(tempMarker != null) tempMarker.enabled = false;
if(tempType != null){
- if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
+ if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME && tempType.type != BombGameObjectTypeComponent.DOOR){
manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
manager.remove(related.get(i), Integer.toString(markerCode));
- related.get(i).deleteFromWorld();
- }else{
+ }else if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}
}
}
}
+
+ /**
+ * Checks if a combination bomb is being disabled in the correct sequence.
+ *
+ * @param buttonType A number between {@link BombGameObjectTypeComponent.COM_BUTTON_1} and {@link BombGameObjectTypeComponent.COM_BUTTON_4}.
+ * @param markerCode A marker code between [0, 1023], inclusive.
+ * @return The current state of the bomb.
+ * @throws IllegalArgumentException If marker code is not in range or if buttonType is not valid.
+ */
+ private combination_button_state_t checkCombinationBombButtons(int buttonType, int markerCode) throws IllegalArgumentException{
+ combination_button_state_t state;
+ boolean correctSequence = true;
+ int remainingButtons = 0;
+ ImmutableBag related;
+
+ if(buttonType < BombGameObjectTypeComponent.COM_BUTTON_1 || buttonType > BombGameObjectTypeComponent.COM_BUTTON_4)
+ throw new IllegalArgumentException("Button is not a valid combination bomb button: " + Integer.toString(buttonType));
+
+ if(markerCode < 0 || markerCode > 1023)
+ throw new IllegalArgumentException("Marker code is not within range [0, 1023]: " + Integer.toString(markerCode));
+
+ related = manager.getEntities(Integer.toString(markerCode));
+
+ // Check the state of the other buttons associated with this bomb.
+ for(int i = 0; i < related.size(); i++){
+ tempType = typeMapper.getSafe(related.get(i));
+
+ if(tempType == null) continue;
+
+ if(tempType.type >= BombGameObjectTypeComponent.COM_BUTTON_1 && tempType.type <= BombGameObjectTypeComponent.COM_BUTTON_4){
+ if(tempType.type >= buttonType){
+ // If this remaining button is a correct one then skip it.
+ remainingButtons++;
+ continue;
+ }else{
+ // If this remaining button is an incorrect one then the sequence is wrong.
+ correctSequence = false;
+ break;
+ }
+ }else continue;
+ }
+
+ if(!correctSequence)
+ state = combination_button_state_t.INCORRECT;
+ else
+ if(remainingButtons == 0)
+ state = combination_button_state_t.DISABLED;
+ else
+ state = combination_button_state_t.CORRECT;
+
+ return state;
+ }
+
+ /**
+ * Adds a new fade out entity to the {@link World}.
+ */
+ private void createFadeOutEffect(){
+ Entity effect = world.createEntity();
+ effect.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.FADE_EFFECT));
+ effect.addComponent(new FadeEffectComponent(false));
+ effect.addToWorld();
+ }
+
+ /**
+ * Adds a new fade in entity to the {@link World}.
+ */
+ private void createFadeInEffect(){
+ Entity effect = world.createEntity();
+ effect.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.FADE_EFFECT));
+ effect.addComponent(new FadeEffectComponent(true));
+ effect.addToWorld();
+ }
+
+ /**
+ * Updates a fade effect entity.
+ *
+ * @param f An Artemis {@link Entity} possibly referencing a fade effect.
+ */
+ private void processFade(Entity f){
+ FadeEffectComponent fade = fadeMapper.getSafe(f);
+
+ if(fade != null){
+ if(!fade.isEffectStarted())
+ fade.startEffect();
+
+ if(!fade.isEffectFinished()){
+ // If the fade has not finished then just update it.
+ Gdx.app.log(TAG, CLASS_NAME + ".processFade(): Updating fade.");
+ fade.update(Gdx.graphics.getDeltaTime());
+ }else{
+ // If the fade finished.
+ if(fade.isEffectFadeIn()){
+ // If the effect was a fade in then just remove it.
+ Gdx.app.log(TAG, CLASS_NAME + ".processFade(): deleting fade in.");
+ f.deleteFromWorld();
+ }else{
+ // If the effect was a fade out then wait for one second and then remove it and start a fade in.
+ then += (int)(Gdx.graphics.getDeltaTime() * 1000.0f);
+ if(then >= 1500){
+ Gdx.app.log(TAG, CLASS_NAME + ".processFade(): Deleting fade out.");
+ f.deleteFromWorld();
+ Gdx.app.log(TAG, CLASS_NAME + ".processFade(): Creating fade in.");
+ createFadeInEffect();
+ then = 0;
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".processFade(): Waiting after fade out: " + Integer.toString(then));
+ }
+ }
+ }
+ }
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java
new file mode 100644
index 0000000..32b49bd
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java
@@ -0,0 +1,57 @@
+package ve.ucv.ciens.ccg.nxtar.systems;
+
+import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent;
+
+import com.artemis.Aspect;
+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.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.Pixmap;
+import com.badlogic.gdx.graphics.Pixmap.Format;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.utils.Disposable;
+
+public class FadeEffectRenderingSystem extends EntityProcessingSystem implements Disposable{
+ @Mapper ComponentMapper fadeMapper;
+
+ private SpriteBatch batch;
+ private Texture fadeTexture;
+ private OrthographicCamera camera;
+
+ @SuppressWarnings("unchecked")
+ public FadeEffectRenderingSystem(){
+ super(Aspect.getAspectForAll(FadeEffectComponent.class));
+
+ this.batch = new SpriteBatch();
+ this.batch.enableBlending();
+ this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+
+ Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
+ pixmap.setColor(1, 1, 1, 1);
+ pixmap.fill();
+ fadeTexture = new Texture(pixmap);
+ pixmap.dispose();
+ }
+
+ @Override
+ public void dispose(){
+ this.fadeTexture.dispose();
+ this.batch.dispose();
+ }
+
+ @Override
+ protected void process(Entity e) {
+ FadeEffectComponent fade = fadeMapper.get(e);
+
+ this.batch.setProjectionMatrix(this.camera.combined);
+ this.batch.begin();{
+ this.batch.setColor(1, 1, 1, fade.getFloatValue());
+ this.batch.draw(fadeTexture, -(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
+ this.batch.setColor(1, 1, 1, 1);
+ }this.batch.end();
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index 8a5e612..c7171e7 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -147,6 +147,7 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
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.");
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
index 8d3c2c6..7ed1fe1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
@@ -28,9 +28,10 @@ public abstract class ProjectConstants{
public static final int EXIT_SUCCESS = 0;
public static final int EXIT_FAILURE = 1;
- public static final boolean DEBUG = true;
+ public static final boolean DEBUG = false;
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 OVERSCAN;
public static final int MENU_BUTTON_FONT_SIZE;
From a247d24770c44293dc28a26bc0efcf0da293b5f9 Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 18 Jun 2014 12:04:18 -0430
Subject: [PATCH 21/34] Debug overlay always rendered regardless of debug
status.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 45 ++++++++-----------
.../ccg/nxtar/states/OuyaMainMenuState.java | 4 --
.../ciens/ccg/nxtar/utils/GameSettings.java | 2 +-
3 files changed, 20 insertions(+), 31 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 14f25f5..7a22d53 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -255,17 +255,15 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
ShaderProgram.pedantic = false;
// Set up the overlay font.
- if(ProjectConstants.DEBUG){
- overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
- overlayY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
+ overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
+ overlayY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
- font = new BitmapFont();
- font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
- if(!Ouya.runningOnOuya){
- font.setScale(1.0f);
- }else{
- font.setScale(2.5f);
- }
+ font = new BitmapFont();
+ font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
+ if(!Ouya.runningOnOuya){
+ font.setScale(1.0f);
+ }else{
+ font.setScale(2.5f);
}
// Start networking.
@@ -386,17 +384,15 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
// Render the debug overlay.
- if(ProjectConstants.DEBUG){
- batch.setProjectionMatrix(pixelPerfectCamera.combined);
- batch.begin();{
- // Draw the FPS overlay.
- font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
- font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
- 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);
- }batch.end();
- }
+ batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ batch.begin();{
+ // Draw the FPS overlay.
+ font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
+ font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
+ 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);
+ }batch.end();
}
/**
@@ -437,9 +433,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
// Dispose graphic objects.
fadeTexture.dispose();
batch.dispose();
- if(ProjectConstants.DEBUG){
- font.dispose();
- }
+ font.dispose();
// Dispose screens.
for(int i = 0; i < states.length; i++){
@@ -484,8 +478,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
;;;;;;;;;;;;;;;;;;*/
/**
- * Show a toast message on screen using the O.S. functionality
- * provider.
+ * Show a toast message on screen using the {@link ActionResolver}.
* @param msg The message to show.
* @param longToast True for a lasting toast. False for a short toast.
*/
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
index acc8233..a92ec4f 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
@@ -111,8 +111,6 @@ public class OuyaMainMenuState extends MainMenuStateBase{
@Override
public boolean buttonDown(Controller controller, int buttonCode){
- // TODO: Test this.
-
if(stateActive){
if(buttonCode == Ouya.BUTTON_O){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
@@ -148,8 +146,6 @@ public class OuyaMainMenuState extends MainMenuStateBase{
@Override
public boolean buttonUp(Controller controller, int buttonCode){
- // TODO: Test this.
-
if(stateActive){
if(buttonCode == Ouya.BUTTON_O){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index a366967..9af2342 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -40,7 +40,7 @@ public abstract class GameSettings{
if(getEntityCreator() == null){
entityCreator = new BombGameEntityCreator();
- entityCreator.setWorld(GameSettings.getGameWorld());
+ entityCreator.setWorld(gameWorld);
entityCreator.setCore(core);
}
From 83199df36dbb41f7842911e311281f9422f6873c Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 18 Jun 2014 18:27:30 -0430
Subject: [PATCH 22/34] Cleaned the code a bit.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 11 ++--
.../nxtar/entities/BombGameEntityCreator.java | 2 +-
.../ccg/nxtar/entities/EntityCreatorBase.java | 4 +-
.../ucv/ciens/ccg/nxtar/input/UserInput.java | 3 ++
.../ciens/ccg/nxtar/states/InGameState.java | 51 ++++++++++++++++---
5 files changed, 57 insertions(+), 14 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 7a22d53..3d866b4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -417,11 +417,17 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Clear graphic resources
*/
public void dispose(){
+ // Dispose screens.
+ for(int i = 0; i < states.length; i++){
+ states[i].dispose();
+ }
+
// Finish network threads.
serviceDiscoveryThread.finish();
videoThread.finish();
robotThread.finish();
sensorThread.finish();
+ serviceDiscoveryThread = null;
videoThread = null;
robotThread = null;
sensorThread = null;
@@ -435,11 +441,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
batch.dispose();
font.dispose();
- // Dispose screens.
- for(int i = 0; i < states.length; i++){
- states[i].dispose();
- }
-
GameSettings.clearGameSettings();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index fc4e6f4..030c03e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -93,7 +93,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model wiresBombModelWire1 = null;
private Model wiresBombModelWire2 = null;
private Model wiresBombModelWire3 = null;
- private Model monkeyModel = null;
+ private Model monkeyModel = null;
// Collision models.
private Model robotArmCollisionModel = null;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
index 4c37fd5..8063e26 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
@@ -37,7 +37,7 @@ public abstract class EntityCreatorBase implements Disposable{
* @param world The Artemis {@link World}.
* @throws IllegalArgumentException if world is null.
*/
- public void setWorld(World world) throws IllegalArgumentException{
+ public final void setWorld(World world) throws IllegalArgumentException{
if(world == null)
throw new IllegalArgumentException("World cannot be null.");
@@ -50,7 +50,7 @@ public abstract class EntityCreatorBase implements Disposable{
* @param core The application core to be used as listener.
* @throws IllegalArgumentException if core is null.
*/
- public void setCore(NxtARCore core) throws IllegalArgumentException{
+ public final void setCore(NxtARCore core) throws IllegalArgumentException{
if(core == null) throw new IllegalArgumentException("Core is null.");
this.core = core;
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java
index 6e38daa..b1ac203 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java
@@ -15,4 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar.input;
+/**
+ * Tag class for different user interaction wrapper classes.
+ */
public abstract class UserInput{ }
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index ab8529a..c9fc8bb 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -25,6 +25,7 @@ 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;
@@ -84,7 +85,7 @@ public class InGameState extends BaseState{
}
// Background related fields.
- private Sprite background;
+ private Sprite background;
private float uScaling[];
private Texture backgroundTexture;
private ShaderProgram backgroundShader;
@@ -122,6 +123,7 @@ public class InGameState extends BaseState{
private Texture armControlButtonTexture;
private Texture correctAngleLedOnTexture;
private Texture correctAngleLedOffTexture;
+ private Texture crossSectionFloorTexture;
private Sprite motorAButton;
private Sprite motorBButton;
private Sprite motorCButton;
@@ -133,6 +135,9 @@ public class InGameState extends BaseState{
private Sprite armControlButton;
private Sprite correctAngleLedOnSprite;
private Sprite correctAngleLedOffSprite;
+ private Sprite crossSectionFloorLed;
+ private Sprite normalFloorLed;
+ private Sprite itemNearbyFloorLed;
// Button touch helper fields.
private boolean[] buttonsTouched;
@@ -142,12 +147,14 @@ public class InGameState extends BaseState{
// Monitors.
private VideoFrameMonitor frameMonitor;
private MotorEventQueue queue;
+ 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();
// Set up rendering fields;
videoFrame = null;
@@ -156,8 +163,6 @@ public class InGameState extends BaseState{
pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
- if(!Ouya.runningOnOuya) setUpButtons();
-
// Set up input handling support fields.
win2world = new Vector3(0.0f, 0.0f, 0.0f);
touchPointWorldCoords = new Vector2();
@@ -227,6 +232,26 @@ public class InGameState extends BaseState{
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"));
+ correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png"));
+ crossSectionFloorTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Cyan.png"));
+
+ crossSectionFloorLed = new Sprite(crossSectionFloorTexture);
+ normalFloorLed = new Sprite(correctAngleLedOffTexture);
+ itemNearbyFloorLed = new Sprite(correctAngleLedOnTexture);
+
+ crossSectionFloorLed.setSize(crossSectionFloorLed.getWidth() * 0.25f, crossSectionFloorLed.getHeight() * 0.25f);
+ 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);
+
+ if(!Ouya.runningOnOuya)
+ setUpButtons();
+
// Set up the game world.
gameWorld = GameSettings.getGameWorld();
@@ -454,6 +479,17 @@ public class InGameState extends BaseState{
}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;
@@ -461,6 +497,9 @@ public class InGameState extends BaseState{
@Override
public void dispose(){
+ SensorReportThread.freeInstance();
+ sensorThread = null;
+
if(modelBatch != null)
modelBatch.dispose();
@@ -482,6 +521,9 @@ public class InGameState extends BaseState{
if(backgroundTexture != null)
backgroundTexture.dispose();
+ if(crossSectionFloorTexture != null)
+ crossSectionFloorTexture.dispose();
+
if(backgroundShader != null)
backgroundShader.dispose();
@@ -576,9 +618,6 @@ public class InGameState extends BaseState{
armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
// Set up the correct angle leds.
- correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png"));
- correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png"));
-
correctAngleLedOnSprite = new Sprite(correctAngleLedOnTexture);
correctAngleLedOffSprite = new Sprite(correctAngleLedOffTexture);
From 6a392856eea1a9d759df0d4deb761fa659428f28 Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 19 Jun 2014 18:29:06 -0430
Subject: [PATCH 23/34] Fixes for OUYA. Added labels. Started modelling player.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 9 +-
.../components/BombGamePlayerComponent.java | 47 ++++
.../nxtar/components/PlayerComponentBase.java | 38 +++
.../nxtar/entities/BombGameEntityCreator.java | 61 ++++-
.../ccg/nxtar/entities/EntityCreatorBase.java | 5 +
.../entities/MarkerTestEntityCreator.java | 3 +
.../ccg/nxtar/input/GamepadUserInput.java | 2 +
.../ccg/nxtar/input/KeyboardUserInput.java | 8 +-
.../ciens/ccg/nxtar/input/TouchUserInput.java | 2 +-
.../ciens/ccg/nxtar/states/InGameState.java | 256 ++++++++++--------
.../ccg/nxtar/states/MainMenuStateBase.java | 7 +-
.../ccg/nxtar/states/OuyaMainMenuState.java | 7 +-
.../ccg/nxtar/states/TabletMainMenuState.java | 3 +-
.../nxtar/systems/BombGameLogicSystem.java | 8 +-
.../nxtar/systems/BombGamePlayerSystem.java | 48 ++++
.../systems/MarkerPositioningSystem.java | 29 +-
.../ccg/nxtar/systems/PlayerSystemBase.java | 52 ++++
.../systems/RobotArmPositioningSystem.java | 62 +++--
.../ccg/nxtar/utils/ProjectConstants.java | 2 +-
src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java | 18 ++
20 files changed, 501 insertions(+), 166 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/components/PlayerComponentBase.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 3d866b4..9ee47ef 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -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;
/**
* Core of the application.
*
- * This class has three basic resposibilities:
+ * This class has three basic responsibilities:
*
* - Handling the main game loop.
* - Starting and destroying the networking threads.
@@ -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();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java
new file mode 100644
index 0000000..82144ed
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java
@@ -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;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/PlayerComponentBase.java b/src/ve/ucv/ciens/ccg/nxtar/components/PlayerComponentBase.java
new file mode 100644
index 0000000..008f6f0
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/PlayerComponentBase.java
@@ -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;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index 030c03e..d95079b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -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 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();
+ 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();
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
index 8063e26..0d32630 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
@@ -78,4 +78,9 @@ public abstract class EntityCreatorBase implements Disposable{
* Creates all entities for a game scenario.
*/
protected abstract void createAllEntities();
+
+ /**
+ * Recreates all entities in the game.
+ */
+ public abstract void resetAllEntities();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
index 4f8eb81..afd0f8b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
@@ -134,4 +134,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
return true;
}
+
+ @Override
+ public void resetAllEntities() { }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java
index 59b79d2..8e16006 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/GamepadUserInput.java
@@ -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;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java
index 31949ea..3c2c6d7 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/KeyboardUserInput.java
@@ -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;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
index 4143d0b..221da6c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/input/TouchUserInput.java
@@ -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();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index c9fc8bb..bbdd025 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -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;
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
index 09098c4..60b6b5c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
@@ -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
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
index a92ec4f..00e829c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
@@ -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;
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
index c9cc886..60e2f46 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
@@ -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);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index 79eb391..6f7818d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -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();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
new file mode 100644
index 0000000..e8cee15
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
@@ -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 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);
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
index 8f71a94..126b437 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
@@ -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 markerMapper;
@@ -33,12 +37,18 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper 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{
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
new file mode 100644
index 0000000..c273e6a
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
@@ -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);
+
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index c7171e7..fc59807 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -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 geometryMapper;
@Mapper ComponentMapper 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.");
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
index 7ed1fe1..dc13c2c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
@@ -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;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
index 15a7ed7..8509427 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
@@ -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;
+ }
}
From 99236420d11704c39c2e9fb67f063574b7252156 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 20 Jun 2014 11:32:02 -0430
Subject: [PATCH 24/34] Fixed device orientation calculation. Other assorted
fixes.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 10 +-
.../nxtar/components/FadeEffectComponent.java | 57 +++
.../nxtar/states/AutomaticActionState.java | 432 ++++++++++++++++++
.../ciens/ccg/nxtar/states/InGameState.java | 144 ++----
.../nxtar/systems/BombGamePlayerSystem.java | 37 +-
.../systems/FadeEffectRenderingSystem.java | 7 +-
.../systems/MarkerPositioningSystem.java | 29 +-
.../ciens/ccg/nxtar/utils/GameSettings.java | 37 ++
src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java | 37 +-
9 files changed, 650 insertions(+), 140 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 9ee47ef..da7bbfc 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -238,7 +238,15 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
else
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
- states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
+
+ try{
+ states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
+ }catch(IllegalStateException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state: " + e.getMessage());
+ Gdx.app.exit();
+ return;
+ }
+
states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
// Register controller listeners.
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java b/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java
index 1490354..ba0fabf 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/components/FadeEffectComponent.java
@@ -20,12 +20,19 @@ import aurelienribon.tweenengine.TweenEquations;
import aurelienribon.tweenengine.primitives.MutableFloat;
import com.artemis.Component;
+import com.badlogic.gdx.graphics.Color;
public class FadeEffectComponent extends Component{
private MutableFloat alpha;
private Tween fadeIn;
private Tween fadeOut;
+ public Color color;
+ /**
+ * Creates a fade to/from white depending on the parameter.
+ *
+ * @param fadeIn True to create a fade FROM white, false for a fade TO white.
+ */
public FadeEffectComponent(boolean fadeIn){
if(fadeIn){
this.alpha = new MutableFloat(1.0f);
@@ -36,12 +43,50 @@ public class FadeEffectComponent extends Component{
this.fadeOut = Tween.to(alpha, 0, 2.5f).target(1.0f).ease(TweenEquations.easeInQuint);
this.fadeIn = null;
}
+ color = new Color(Color.WHITE);
}
+ /**
+ * Creates a fade effect with the desired parameters.
+ *
+ * @param fadeIn True to create a fade FROM color, false for a fade TO color.
+ * @param color The color of the effect.
+ */
+ public FadeEffectComponent(boolean fadeIn, Color color){
+ this(fadeIn);
+ this.color.set(color);
+ }
+
+ /**
+ * Creates a fade out effect of the desired color.
+ *
+ * @param color The color of the effect.
+ */
+ public FadeEffectComponent(Color color){
+ this(false, color);
+ }
+
+ /**
+ * Creates a white fade out effect.
+ */
+ public FadeEffectComponent(){
+ this(false);
+ }
+
+ /**
+ * The current transparency of the effect.
+ *
+ * @return The transparency.
+ */
public float getFloatValue(){
return alpha.floatValue();
}
+ /**
+ * Interpolates the transparency of the effect by the given delta time in seconds.
+ *
+ * @param delta
+ */
public void update(float delta){
if(fadeIn != null)
fadeIn.update(delta);
@@ -50,6 +95,9 @@ public class FadeEffectComponent extends Component{
fadeOut.update(delta);
}
+ /**
+ * Initializes the effect.
+ */
public void startEffect(){
if(fadeIn != null)
fadeIn.start();
@@ -58,14 +106,23 @@ public class FadeEffectComponent extends Component{
fadeOut.start();
}
+ /**
+ * @return True if the effect has been initialized. False otherwise.
+ */
public boolean isEffectStarted(){
return fadeIn != null ? fadeIn.isStarted() : fadeOut.isStarted();
}
+ /**
+ * @return True if this effect is a fade in. False if it is a fade out.
+ */
public boolean isEffectFadeIn(){
return fadeIn != null;
}
+ /**
+ * @return True if the effect's interpolation is over. False otherwise.
+ */
public boolean isEffectFinished(){
return fadeIn != null ? fadeIn.isFinished() : fadeOut.isFinished();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
new file mode 100644
index 0000000..73b9354
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
@@ -0,0 +1,432 @@
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
+import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
+import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
+import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
+import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
+import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.artemis.World;
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.controllers.Controller;
+import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.Pixmap;
+import com.badlogic.gdx.graphics.Pixmap.Format;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.Texture.TextureFilter;
+import com.badlogic.gdx.graphics.Texture.TextureWrap;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
+import com.badlogic.gdx.graphics.glutils.FrameBuffer;
+import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.Vector3;
+
+public class AutomaticActionState extends BaseState{
+ private static final String TAG = "IN_GAME_STATE";
+ private static final String CLASS_NAME = AutomaticActionState.class.getSimpleName();
+ private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
+ private static final float NEAR = 0.01f;
+ private static final float FAR = 100.0f;
+
+ // Background related fields.
+ private Sprite background;
+ private float uScaling[];
+ private Texture backgroundTexture;
+ private ShaderProgram backgroundShader;
+
+ // 3D rendering fields.
+ private ModelBatch modelBatch;
+ private FrameBuffer frameBuffer;
+ private Sprite frameBufferSprite;
+
+ // Game related fields.
+ private World gameWorld;
+ private MarkerRenderingSystem markerRenderingSystem;
+ private ObjectRenderingSystem objectRenderingSystem;
+ private RobotArmPositioningSystem robotArmPositioningSystem;
+ private FadeEffectRenderingSystem fadeEffectRenderingSystem;
+
+ // Cameras.
+ private OrthographicCamera unitaryOrthographicCamera;
+ private OrthographicCamera pixelPerfectOrthographicCamera;
+ private CustomPerspectiveCamera perspectiveCamera;
+
+ // Video stream graphics.
+ private Texture videoFrameTexture;
+ private Sprite renderableVideoFrame;
+ private Pixmap videoFrame;
+
+ // Button touch helper fields.
+ private boolean[] buttonsTouched;
+ private int[] buttonPointers;
+ private boolean[] gamepadButtonPressed;
+
+ // Monitors.
+ private VideoFrameMonitor frameMonitor;
+ // private MotorEventQueue queue;
+ // private SensorReportThread sensorThread;
+
+ public AutomaticActionState(final NxtARCore core){
+ this.core = core;
+ frameMonitor = VideoFrameMonitor.getInstance();
+ // queue = MotorEventQueue.getInstance();
+ // sensorThread = SensorReportThread.getInstance();
+
+ // Set up rendering fields;
+ videoFrame = null;
+
+ // Set up the cameras.
+ pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
+
+ // Set up input handling support fields.
+ win2world = new Vector3(0.0f, 0.0f, 0.0f);
+ touchPointWorldCoords = new Vector2();
+
+ buttonsTouched = new boolean[1];
+ buttonsTouched[0] = false;
+
+ buttonPointers = new int[1];
+ buttonPointers[0] = -1;
+
+ gamepadButtonPressed = new boolean[1];
+ gamepadButtonPressed[0] = false;
+
+ // Set up the background.
+ backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
+ backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
+ backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ background = new Sprite(backgroundTexture);
+ background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
+
+ // Set up the shader.
+ backgroundShader = new ShaderProgram(Gdx.files.internal(BACKGROUND_SHADER_PATH + "_vert.glsl"), Gdx.files.internal(BACKGROUND_SHADER_PATH + "_frag.glsl"));
+ if(!backgroundShader.isCompiled()){
+ Gdx.app.error(TAG, CLASS_NAME + ".InGameState() :: Failed to compile the background shader.");
+ Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
+ backgroundShader = null;
+ }
+
+ uScaling = new float[2];
+ uScaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
+ uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
+
+ // Set up the 3D rendering.
+ modelBatch = new ModelBatch();
+ frameBuffer = null;
+ perspectiveCamera = null;
+ frameBufferSprite = null;
+
+ // Set up the game world.
+ gameWorld = GameSettings.getGameWorld();
+
+ robotArmPositioningSystem = new RobotArmPositioningSystem();
+ markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
+ objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
+ fadeEffectRenderingSystem = new FadeEffectRenderingSystem();
+
+ gameWorld.setSystem(new MarkerPositioningSystem());
+ gameWorld.setSystem(robotArmPositioningSystem, Ouya.runningOnOuya);
+ gameWorld.setSystem(new GeometrySystem());
+ gameWorld.setSystem(new AnimationSystem());
+ gameWorld.setSystem(new CollisionDetectionSystem());
+ gameWorld.setSystem(GameSettings.getGameLogicSystem());
+ gameWorld.setSystem(markerRenderingSystem, true);
+ gameWorld.setSystem(objectRenderingSystem, true);
+ gameWorld.setSystem(fadeEffectRenderingSystem, true);
+
+ gameWorld.initialize();
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;
+ ; BASE STATE METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public void render(float delta){
+ int w, h;
+ byte[] frame;
+ MarkerData data;
+ TextureRegion region;
+ float focalPointX, focalPointY, cameraCenterX, cameraCenterY;
+
+ // Clear the screen.
+ Gdx.gl.glClearColor(1, 1, 1, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ // Render the background.
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
+ core.batch.begin();{
+ if(backgroundShader != null){
+ core.batch.setShader(backgroundShader);
+ backgroundShader.setUniform2fv("u_scaling", uScaling, 0, 2);
+ }
+ background.draw(core.batch);
+ if(backgroundShader != null) core.batch.setShader(null);
+ }core.batch.end();
+
+ // Fetch the current video frame.
+ frame = frameMonitor.getCurrentFrame();
+ w = frameMonitor.getFrameDimensions().getWidth();
+ h = frameMonitor.getFrameDimensions().getHeight();
+
+ // Create the 3D perspective camera and the frame buffer object if they don't exist.
+ if(perspectiveCamera == null && frameBuffer == null){
+ frameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
+ frameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
+
+ perspectiveCamera = new CustomPerspectiveCamera(67, w, h);
+ perspectiveCamera.translate(0.0f, 0.0f, 0.0f);
+ perspectiveCamera.near = NEAR;
+ perspectiveCamera.far = FAR;
+ perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
+ perspectiveCamera.update();
+ }
+
+ // Attempt to find the markers in the current video frame.
+ data = core.cvProc.findMarkersInFrame(frame);
+
+ // If a valid frame was fetched.
+ if(data != null && data.outFrame != null){
+ // Set the camera to the correct projection.
+ focalPointX = core.cvProc.getFocalPointX();
+ focalPointY = core.cvProc.getFocalPointY();
+ cameraCenterX = core.cvProc.getCameraCenterX();
+ cameraCenterY = core.cvProc.getCameraCenterY();
+ perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
+ perspectiveCamera.update(perspectiveCamera.projection);
+
+ // Update the game state.
+ gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
+ gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
+ gameWorld.process();
+
+ // Decode the video frame.
+ videoFrame = new Pixmap(data.outFrame, 0, w * h);
+ videoFrameTexture = new Texture(videoFrame);
+ videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ videoFrame.dispose();
+
+ // Convert the decoded frame into a renderable texture.
+ region = new TextureRegion(videoFrameTexture, 0, 0, w, h);
+ if(renderableVideoFrame == null)
+ renderableVideoFrame = new Sprite(region);
+ else
+ renderableVideoFrame.setRegion(region);
+ renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2, renderableVideoFrame.getHeight() / 2);
+ renderableVideoFrame.setPosition(0, 0);
+
+ // Set the 3D frame buffer for rendering.
+ frameBuffer.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.
+ markerRenderingSystem.begin(perspectiveCamera);
+ markerRenderingSystem.process();
+ markerRenderingSystem.end();
+ }frameBuffer.end();
+
+ // Set the frame buffer object texture to a renderable sprite.
+ region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
+ region.flip(false, true);
+ if(frameBufferSprite == null)
+ frameBufferSprite = new Sprite(region);
+ else
+ frameBufferSprite.setRegion(region);
+ frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
+ frameBufferSprite.setPosition(0, 0);
+
+ // Set the position and orientation of the renderable video frame and the frame buffer.
+ if(!Ouya.runningOnOuya){
+ renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
+ renderableVideoFrame.rotate90(true);
+ renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, 0.5f - renderableVideoFrame.getHeight());
+
+ frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth() );
+ frameBufferSprite.rotate90(true);
+ frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
+ }else{
+ float xSize = Gdx.graphics.getHeight() * (w / h);
+ renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
+ renderableVideoFrame.rotate90(true);
+ renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
+
+ frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
+ frameBufferSprite.rotate90(true);
+ frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
+ }
+
+ // Set the correct camera for the device.
+ if(!Ouya.runningOnOuya){
+ core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
+ }else{
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
+ }
+
+ // Render the video frame and the frame buffer.
+ core.batch.begin();{
+ renderableVideoFrame.draw(core.batch);
+ frameBufferSprite.draw(core.batch);
+ }core.batch.end();
+
+ // Clear the video frame from memory.
+ videoFrameTexture.dispose();
+ }
+
+ data = null;
+ }
+
+ @Override
+ public void dispose(){
+ if(modelBatch != null)
+ modelBatch.dispose();
+
+ if(videoFrameTexture != null)
+ videoFrameTexture.dispose();
+
+ if(backgroundTexture != null)
+ backgroundTexture.dispose();
+
+ if(backgroundShader != null)
+ backgroundShader.dispose();
+
+ if(frameBuffer != null)
+ frameBuffer.dispose();
+
+ fadeEffectRenderingSystem.dispose();
+ }
+
+ /*;;;;;;;;;;;;;;;;;;
+ ; HELPER METHODS ;
+ ;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public void onStateSet(){
+ stateActive = true;
+ Gdx.input.setInputProcessor(this);
+ Gdx.input.setCatchBackKey(true);
+ Gdx.input.setCatchMenuKey(true);
+ }
+
+ @Override
+ public void onStateUnset(){
+ stateActive = false;
+ Gdx.input.setInputProcessor(null);
+ Gdx.input.setCatchBackKey(false);
+ Gdx.input.setCatchMenuKey(false);
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; INPUT PROCESSOR METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean touchDown(int screenX, int screenY, int pointer, int button){
+ if(!Ouya.runningOnOuya){
+ win2world.set(screenX, screenY, 0.0f);
+ unitaryOrthographicCamera.unproject(win2world);
+ touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean touchUp(int screenX, int screenY, int pointer, int button){
+ if(!Ouya.runningOnOuya){
+ win2world.set(screenX, screenY, 0.0f);
+ unitaryOrthographicCamera.unproject(win2world);
+ touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean touchDragged(int screenX, int screenY, int pointer){
+ if(!Ouya.runningOnOuya){
+ win2world.set(screenX, screenY, 0.0f);
+ unitaryOrthographicCamera.unproject(win2world);
+ touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean keyDown(int keycode){
+ if(keycode == Input.Keys.BACK){
+ core.nextState = game_states_t.MAIN_MENU;
+ return true;
+ }
+
+ return false;
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; CONTROLLER LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean buttonDown(Controller controller, int buttonCode){
+ if(stateActive){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
+
+ if(buttonCode == Ouya.BUTTON_O){
+
+ }
+
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean buttonUp(Controller controller, int buttonCode){
+ if(stateActive){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
+
+ if(buttonCode == Ouya.BUTTON_O){ }
+
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index bbdd025..157028f 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -27,10 +27,7 @@ import ve.ucv.ciens.ccg.nxtar.input.UserInput;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
-import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
@@ -94,9 +91,6 @@ public class InGameState extends BaseState{
private ModelBatch modelBatch;
private FrameBuffer frameBuffer;
private Sprite frameBufferSprite;
- // private FrameBuffer robotArmFrameBuffer;
- // private Sprite robotArmFrameBufferSprite;
- // private ShaderProgram alphaShader;
// Game related fields.
private World gameWorld;
@@ -126,7 +120,7 @@ public class InGameState extends BaseState{
private Texture armControlButtonTexture;
private Texture correctAngleLedOnTexture;
private Texture correctAngleLedOffTexture;
- private Texture crossSectionFloorTexture;
+ private Texture orientationSliderTexture;
// Gui renderable sprites.
private Sprite motorAButton;
@@ -144,9 +138,7 @@ public class InGameState extends BaseState{
private Sprite armControlButton;
private Sprite correctAngleLedOnSprite;
private Sprite correctAngleLedOffSprite;
- private Sprite crossSectionFloorLed;
- private Sprite normalFloorLed;
- private Sprite itemNearbyFloorLed;
+ private Sprite orientationSlider;
// Button touch helper fields.
private boolean[] buttonsTouched;
@@ -156,14 +148,12 @@ public class InGameState extends BaseState{
// Monitors.
private VideoFrameMonitor frameMonitor;
private MotorEventQueue queue;
- // private SensorReportThread sensorThread;
- public InGameState(final NxtARCore core){
+ public InGameState(final NxtARCore core) throws IllegalStateException{
this.core = core;
frameMonitor = VideoFrameMonitor.getInstance();
queue = MotorEventQueue.getInstance();
controlMode = robot_control_mode_t.WHEEL_CONTROL;
- // sensorThread = SensorReportThread.getInstance();
// Set up rendering fields;
videoFrame = null;
@@ -225,61 +215,26 @@ public class InGameState extends BaseState{
uScaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
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;
- // }
-
// Set up the 3D rendering.
modelBatch = new ModelBatch();
frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = 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"));
- correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png"));
- crossSectionFloorTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Cyan.png"));
-
- crossSectionFloorLed = new Sprite(crossSectionFloorTexture);
- normalFloorLed = new Sprite(correctAngleLedOffTexture);
- itemNearbyFloorLed = new Sprite(correctAngleLedOnTexture);
-
- crossSectionFloorLed.setSize(crossSectionFloorLed.getWidth() * 0.25f, crossSectionFloorLed.getHeight() * 0.25f);
- 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), (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);
+ // Set up he buttons.
if(!Ouya.runningOnOuya)
setUpButtons();
// Set up the game world.
gameWorld = GameSettings.getGameWorld();
- robotArmPositioningSystem = new RobotArmPositioningSystem();
- markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
- objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
- fadeEffectRenderingSystem = new FadeEffectRenderingSystem();
+ robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class);
+ markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
+ objectRenderingSystem = gameWorld.getSystem(ObjectRenderingSystem.class);
+ fadeEffectRenderingSystem = gameWorld.getSystem(FadeEffectRenderingSystem.class);
- gameWorld.setSystem(new MarkerPositioningSystem());
- gameWorld.setSystem(robotArmPositioningSystem, Ouya.runningOnOuya);
- gameWorld.setSystem(new GeometrySystem());
- gameWorld.setSystem(new AnimationSystem());
- gameWorld.setSystem(new CollisionDetectionSystem());
- gameWorld.setSystem(GameSettings.getGameLogicSystem());
- gameWorld.setSystem(markerRenderingSystem, true);
- gameWorld.setSystem(objectRenderingSystem, true);
- gameWorld.setSystem(fadeEffectRenderingSystem, true);
-
- gameWorld.initialize();
+ if(robotArmPositioningSystem == null || markerRenderingSystem == null || objectRenderingSystem == null || fadeEffectRenderingSystem == null)
+ throw new IllegalStateException("One or more essential systems are null.");
}
/*;;;;;;;;;;;;;;;;;;;;;;
@@ -288,7 +243,10 @@ public class InGameState extends BaseState{
@Override
public void render(float delta){
+ final float MIN_SLIDER_X = correctAngleLedOnSprite != null ? -(Utils.getScreenWidth() / 2) + 5 + correctAngleLedOnSprite.getWidth() : -(Utils.getScreenWidth() / 2) + 5;
+ final float MAX_SLIDER_X = correctAngleLedOnSprite != null ? (Utils.getScreenWidth() / 2) - 5 - correctAngleLedOnSprite.getWidth(): (Utils.getScreenWidth() / 2) - 5;
int w, h;
+ float t, xSliderPos;
byte[] frame;
MarkerData data;
TextureRegion region;
@@ -319,9 +277,6 @@ 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);
-
perspectiveCamera = new CustomPerspectiveCamera(67, w, h);
perspectiveCamera.translate(0.0f, 0.0f, 0.0f);
perspectiveCamera.near = NEAR;
@@ -382,18 +337,6 @@ public class InGameState extends BaseState{
}
}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();
-
// Set the frame buffer object texture to a renderable sprite.
region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
region.flip(false, true);
@@ -404,16 +347,6 @@ public class InGameState extends BaseState{
frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
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);
-
// Set the position and orientation of the renderable video frame and the frame buffer.
if(!Ouya.runningOnOuya){
renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
@@ -424,9 +357,6 @@ 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());
}else{
float xSize = Gdx.graphics.getHeight() * (w / h);
renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
@@ -436,10 +366,6 @@ public class InGameState extends BaseState{
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);
}
// Set the correct camera for the device.
@@ -453,16 +379,6 @@ public class InGameState extends BaseState{
core.batch.begin();{
renderableVideoFrame.draw(core.batch);
frameBufferSprite.draw(core.batch);
-
- // 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();
// Clear the video frame from memory.
@@ -497,13 +413,21 @@ public class InGameState extends BaseState{
headCButton.draw(core.batch);
// Draw device rotation led.
- if(Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) < ProjectConstants.MAX_ABS_ROLL){
- correctAngleLedOnSprite.draw(core.batch);
+ if(Utils.isDeviceRollValid()){
+ if(Math.abs(Gdx.input.getRoll()) < ProjectConstants.MAX_ABS_ROLL)
+ correctAngleLedOnSprite.draw(core.batch);
+ else
+ correctAngleLedOffSprite.draw(core.batch);
+
+ t = (Gdx.input.getRoll() + 60.0f) / 120.0f;
+ xSliderPos = (MIN_SLIDER_X * t) + (MAX_SLIDER_X * (1.0f - t));
+ xSliderPos = xSliderPos < MIN_SLIDER_X ? MIN_SLIDER_X : (xSliderPos > MAX_SLIDER_X ? MAX_SLIDER_X : xSliderPos);
+ orientationSlider.setPosition(xSliderPos, orientationSlider.getY());
+ orientationSlider.draw(core.batch);
}else{
correctAngleLedOffSprite.draw(core.batch);
+ orientationSlider.draw(core.batch);
}
-
- // TODO: Draw rotation slider.
}core.batch.end();
}
@@ -544,8 +468,8 @@ public class InGameState extends BaseState{
if(backgroundTexture != null)
backgroundTexture.dispose();
- if(crossSectionFloorTexture != null)
- crossSectionFloorTexture.dispose();
+ if(orientationSliderTexture != null)
+ orientationSliderTexture.dispose();
if(backgroundShader != null)
backgroundShader.dispose();
@@ -553,16 +477,11 @@ public class InGameState extends BaseState{
if(frameBuffer != null)
frameBuffer.dispose();
- // if(robotArmFrameBuffer != null)
- // robotArmFrameBuffer.dispose();
-
if(correctAngleLedOffTexture != null)
correctAngleLedOffTexture.dispose();
if(correctAngleLedOnTexture != null)
correctAngleLedOnTexture.dispose();
-
- fadeEffectRenderingSystem.dispose();
}
/*;;;;;;;;;;;;;;;;;;
@@ -657,6 +576,9 @@ public class InGameState extends BaseState{
armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
// Set up the correct angle leds.
+ correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png"));
+ correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png"));
+
correctAngleLedOnSprite = new Sprite(correctAngleLedOnTexture);
correctAngleLedOffSprite = new Sprite(correctAngleLedOffTexture);
@@ -665,6 +587,12 @@ public class InGameState extends BaseState{
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);
+
+ // Set up orientation slider.
+ orientationSliderTexture = new Texture(Gdx.files.internal("data/gfx/gui/slider_black.png"));
+ orientationSlider = new Sprite(orientationSliderTexture);
+ orientationSlider.setSize(orientationSlider.getWidth() * 0.25f, orientationSlider.getHeight() * 0.25f);
+ orientationSlider.setPosition(-(orientationSlider.getWidth() / 2), (Utils.getScreenHeight() / 2) - orientationSlider.getHeight() - 5);
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
index e8cee15..db2a7cc 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
@@ -18,22 +18,47 @@ 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 ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.utils.Disposable;
-public class BombGamePlayerSystem extends PlayerSystemBase{
+public class BombGamePlayerSystem extends PlayerSystemBase implements Disposable{
+ private static final float HEART_Y_POS = (Utils.getScreenHeight() / 2) - 69;
@Mapper ComponentMapper playerMapper;
+ private SpriteBatch batch;
+ private Texture heartTexture;
+ private Sprite heart;
+
public BombGamePlayerSystem(NxtARCore core){
super(BombGamePlayerComponent.class, core);
+ batch = new SpriteBatch();
+ heartTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_heart_1.png"));
+ heart = new Sprite(heartTexture);
+ heart.setSize(heart.getWidth() * 0.5f, heart.getHeight() * 0.5f);
}
@Override
protected void process(Entity e) {
+ float heartXPos;
BombGamePlayerComponent player = playerMapper.get(e);
+ // Render remaining lives.
+ heartXPos = -(Utils.getScreenWidth() / 2) + 5;
+ for(int i = 0; i < player.lives; ++i){
+ heart.setPosition(heartXPos, HEART_Y_POS);
+ heart.draw(batch);
+ heartXPos += heart.getWidth() + 5;
+ }
+
+ // Check ending conditions.
if(player.lives == 0){
player.gameFinished = true;
player.victory = false;
@@ -42,7 +67,17 @@ public class BombGamePlayerSystem extends PlayerSystemBase{
player.victory = true;
}
+ // If met ending conditions then end the game.
if(player.gameFinished)
finishGame(player.victory);
}
+
+ @Override
+ public void dispose() {
+ if(batch != null)
+ batch.dispose();
+
+ if(heartTexture != null)
+ heartTexture.dispose();
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java
index 32b49bd..3b5741a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/FadeEffectRenderingSystem.java
@@ -45,11 +45,16 @@ public class FadeEffectRenderingSystem extends EntityProcessingSystem implements
@Override
protected void process(Entity e) {
+ float r, g, b;
FadeEffectComponent fade = fadeMapper.get(e);
+ r = fade.color.r;
+ g = fade.color.g;
+ b = fade.color.b;
+
this.batch.setProjectionMatrix(this.camera.combined);
this.batch.begin();{
- this.batch.setColor(1, 1, 1, fade.getFloatValue());
+ this.batch.setColor(r, g, b, fade.getFloatValue());
this.batch.draw(fadeTexture, -(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
this.batch.setColor(1, 1, 1, 1);
}this.batch.end();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
index 126b437..8f71a94 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java
@@ -26,10 +26,6 @@ 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 markerMapper;
@@ -37,18 +33,12 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper 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){
@@ -71,25 +61,8 @@ 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(mAux);
+ geometry.rotation.set(markers.rotationMatrices[i]);
visibility.visible = true;
break;
}else{
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
index 9af2342..94fe904 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
@@ -18,21 +18,38 @@ package ve.ucv.ciens.ccg.nxtar.utils;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
+import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.BombGameLogicSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
+import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
+import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
+import com.artemis.EntitySystem;
import com.artemis.World;
import com.artemis.managers.GroupManager;
+import com.artemis.utils.ImmutableBag;
+import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
+import com.badlogic.gdx.utils.Disposable;
public abstract class GameSettings{
private static EntityCreatorBase entityCreator = null;
private static GameLogicSystemBase gameLogicSystem = null;
private static World gameWorld = null;
+ private static ModelBatch modelBatch = null;
public static void initGameSettings(NxtARCore core) throws IllegalArgumentException{
if(core == null)
throw new IllegalArgumentException("Core is null.");
+ if(modelBatch == null)
+ modelBatch = new ModelBatch();
+
if(getGameWorld() == null){
gameWorld = new World();
gameWorld.setManager(new GroupManager());
@@ -46,9 +63,29 @@ public abstract class GameSettings{
if(getGameLogicSystem() == null)
gameLogicSystem = new BombGameLogicSystem();
+
+ gameWorld.setSystem(new MarkerPositioningSystem());
+ gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
+ gameWorld.setSystem(new GeometrySystem());
+ gameWorld.setSystem(new AnimationSystem());
+ gameWorld.setSystem(new CollisionDetectionSystem());
+ gameWorld.setSystem(gameLogicSystem);
+ gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true);
+ gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true);
+ gameWorld.setSystem(new FadeEffectRenderingSystem(), true);
+
+ gameWorld.initialize();
}
public static void clearGameSettings(){
+ ImmutableBag systems = gameWorld.getSystems();
+
+ for(int i = 0; i < systems.size(); i++){
+ if(systems.get(i) instanceof Disposable){
+ ((Disposable)systems.get(i)).dispose();
+ }
+ }
+
entityCreator.dispose();
entityCreator = null;
gameLogicSystem = null;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
index 8509427..137fd52 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
@@ -19,23 +19,58 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Peripheral;
import com.badlogic.gdx.math.Vector3;
+/**
+ * Assorted common auxiliary functions.
+ */
public abstract class Utils{
+ private static final float MIN_PITCH = -80.0f;
+ private static final float MAX_PITCH = 5.0f;
+ private static final float MIN_AZIMUTH = -155.0f;
+ private static final float MAX_AZIMUTH = -40.0f;
+
+ /**
+ * Converts a libGDX {@link Vector3} to a String representation form easy logging.
+ *
+ * @param v The vector to convert.
+ * @return A string representation of the form "(v.x, v.y, v.z)".
+ */
public static String vector2String(Vector3 v){
return "(" + Float.toString(v.x) + ", " + Float.toString(v.y) + ", " + Float.toString(v.z) + ")";
}
+ /**
+ * @return The width of the screen accounting for screen overscan.
+ */
public static int getScreenWidth(){
return (int)(Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN);
}
+ /**
+ * @return The height of the screen accounting for screen overscan.
+ */
public static int getScreenHeight(){
return (int)(Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
}
+ /**
+ * Checks if the device's orientation is available and wihtin some arbitrary ranges.
+ *
+ * @return True if the device can detect it's orientation and it's within range. False otherwise.
+ */
public static boolean isDeviceRollValid(){
boolean rollValid = Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Gdx.input.isPeripheralAvailable(Peripheral.Compass);
+ float azimuth, pitch;
- // TODO: Check device orientation for limits.
+ if(rollValid){
+ azimuth = Gdx.input.getAzimuth();
+ pitch = Gdx.input.getPitch();
+
+ if(pitch < MIN_PITCH || pitch > MAX_PITCH)
+ rollValid = false;
+
+ if(rollValid && (azimuth < MIN_AZIMUTH || azimuth > MAX_AZIMUTH))
+ rollValid = false;
+ }
return rollValid;
}
From 6e30e6b56b40261d5bf1b04a16d36565a06bc872 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 20 Jun 2014 12:03:17 -0430
Subject: [PATCH 25/34] Added the player entity and it's logic to the world.
---
.../nxtar/entities/BombGameEntityCreator.java | 12 ++++---
.../nxtar/systems/BombGameLogicSystem.java | 33 +++++++++++++++++--
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
index d95079b..c5ac8af 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
@@ -57,11 +58,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
- public static final String DOORS_GROUP = "DOORS";
- 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;
+ public static final String DOORS_GROUP = "DOORS";
+ 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;
@@ -222,6 +223,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
if(player == null){
player = world.createEntity();
player.addComponent(new BombGamePlayerComponent(3));
+ groupManager.add(player, PlayerComponentBase.PLAYER_GROUP);
player.addToWorld();
}else{
player.getComponent(BombGamePlayerComponent.class).reset();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
index 6f7818d..a77b4f4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
@@ -17,9 +17,11 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
+import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -62,7 +64,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
private MarkerCodeComponent tempMarker;
private BombGameObjectTypeComponent tempType;
private GroupManager manager;
- private int then;
+ private int then;
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
@@ -142,6 +144,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
if(wireType.type != BombGameObjectTypeComponent.BOMB_WIRE_1){
Gdx.app.log(TAG, CLASS_NAME + ".processWireBomb(): Wire bomb exploded.");
createFadeOutEffect();
+ reducePlayerLivesByOne();
}
disableBomb(marker.code);
@@ -189,6 +192,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
Gdx.app.log(TAG, CLASS_NAME + ".processCombinationBomb(): Combination bomb exploded.");
createFadeOutEffect();
disableBomb(marker.code);
+ reducePlayerLivesByOne();
}else if(state.getValue() == combination_button_state_t.DISABLED.getValue()){
Gdx.app.log(TAG, CLASS_NAME + ".processCombinationBomb(): Combination bomb disabled.");
disableBomb(marker.code);
@@ -227,6 +231,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
if(Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
createFadeOutEffect();
+ reducePlayerLivesByOne();
}
// Disable all related entities.
@@ -312,6 +317,30 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
return doorOpen;
}
+ /**
+ * Updates the player's lives count.
+ */
+ private void reducePlayerLivesByOne(){
+ Entity player;
+ BombGamePlayerComponent playerComponent;
+ ImmutableBag players;
+
+ players = manager.getEntities(PlayerComponentBase.PLAYER_GROUP);
+ if(players != null && players.size() > 0 && players.get(0) != null){
+ player = players.get(0);
+ playerComponent = player.getComponent(BombGamePlayerComponent.class);
+
+ if(playerComponent != null){
+ playerComponent.lives -= 1;
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".reducePlayerLivesByOne(): Players is missing required components.");
+ }
+
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".reducePlayerLivesByOne(): No players found.");
+ }
+ }
+
/**
* Disables all entities associated with the corresponding marker code.
*
@@ -400,7 +429,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
private void createFadeOutEffect(){
Entity effect = world.createEntity();
effect.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.FADE_EFFECT));
- effect.addComponent(new FadeEffectComponent(false));
+ effect.addComponent(new FadeEffectComponent());
effect.addToWorld();
}
From 4d006a34617f4b6248798bf52f3966e598d1f230 Mon Sep 17 00:00:00 2001
From: unknown
Date: Mon, 23 Jun 2014 16:07:06 -0430
Subject: [PATCH 26/34] Added automatic actions. Not tested yet.
---
.../ucv/ciens/ccg/networkdata/MotorEvent.java | 2 +-
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 55 ++-
.../entities/MarkerTestEntityCreator.java | 140 -------
.../game/AutomaticActionPerformerBase.java | 39 ++
.../GameGlobals.java} | 60 ++-
.../nxtar/game/ScenarioImplementation.java | 29 ++
.../bombgame}/BombComponent.java | 2 +-
.../BombGameAutomaticActionPerformer.java | 154 ++++++++
.../bombgame}/BombGameEntityCreator.java | 8 +-
.../bombgame}/BombGameLogicSystem.java | 7 +-
.../BombGameObjectTypeComponent.java | 2 +-
.../bombgame}/BombGamePlayerComponent.java | 4 +-
.../bombgame}/BombGamePlayerSystem.java | 5 +-
.../nxtar/states/AutomaticActionState.java | 352 +++++++++++++++---
.../ciens/ccg/nxtar/states/InGameState.java | 13 +-
.../ccg/nxtar/states/MainMenuStateBase.java | 48 ++-
.../ccg/nxtar/states/OuyaMainMenuState.java | 17 +-
.../ccg/nxtar/states/TabletMainMenuState.java | 5 +-
.../ccg/nxtar/systems/PlayerSystemBase.java | 4 +-
19 files changed, 692 insertions(+), 254 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
rename src/ve/ucv/ciens/ccg/nxtar/{utils/GameSettings.java => game/GameGlobals.java} (62%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
rename src/ve/ucv/ciens/ccg/nxtar/{components => game/bombgame}/BombComponent.java (96%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
rename src/ve/ucv/ciens/ccg/nxtar/{entities => game/bombgame}/BombGameEntityCreator.java (98%)
rename src/ve/ucv/ciens/ccg/nxtar/{systems => game/bombgame}/BombGameLogicSystem.java (98%)
rename src/ve/ucv/ciens/ccg/nxtar/{components => game/bombgame}/BombGameObjectTypeComponent.java (96%)
rename src/ve/ucv/ciens/ccg/nxtar/{components => game/bombgame}/BombGamePlayerComponent.java (92%)
rename src/ve/ucv/ciens/ccg/nxtar/{systems => game/bombgame}/BombGamePlayerSystem.java (93%)
diff --git a/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java b/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java
index 50f1c60..40761b6 100644
--- a/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java
+++ b/src/ve/ucv/ciens/ccg/networkdata/MotorEvent.java
@@ -5,7 +5,7 @@ import java.io.Serializable;
public class MotorEvent implements Serializable{
private static final long serialVersionUID = 9989L;
- public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC, RECENTER};
+ public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC, RECENTER, ROTATE_90};
private motor_t motor;
private byte power;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index da7bbfc..db77ca5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -15,6 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver;
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
@@ -22,13 +23,13 @@ import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread;
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
+import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionState;
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState;
-import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import aurelienribon.tweenengine.Tween;
@@ -74,7 +75,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Valid game states.
*/
public enum game_states_t {
- MAIN_MENU(0), IN_GAME(1), CALIBRATION(2);
+ MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3);
private int value;
@@ -87,7 +88,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
public static int getNumStates(){
- return 3;
+ return 4;
}
};
@@ -230,7 +231,28 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* sets the application states.
*/
public void create(){
- GameSettings.initGameSettings(this);
+ try {
+ GameGlobals.initGameSettings(this);
+ } catch (IllegalArgumentException e) {
+ Gdx.app.log(TAG, CLASS_NAME + ".create(): Illegal argument initializing globals: ", e);
+ Gdx.app.exit();
+ return;
+ } catch (InstantiationException e) {
+ Gdx.app.log(TAG, CLASS_NAME + ".create(): Instantiation exception initializing globals: ", e);
+ Gdx.app.exit();
+ return;
+ } catch (IllegalAccessException e) {
+ Gdx.app.log(TAG, CLASS_NAME + ".create(): Illegal access exception initializing globals: ", e);
+ Gdx.app.exit();
+ return;
+ }
+
+ // Set up rendering fields and settings.
+ batch = new SpriteBatch();
+ batch.enableBlending();
+ batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
+ pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ ShaderProgram.pedantic = false;
// Create the state objects.
states = new BaseState[game_states_t.getNumStates()];
@@ -242,27 +264,26 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
try{
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
}catch(IllegalStateException e){
- Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state: " + e.getMessage());
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: " + e.getMessage());
Gdx.app.exit();
return;
}
states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
+ try{
+ states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this);
+ }catch(IllegalStateException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: " + e.getMessage());
+ Gdx.app.exit();
+ return;
+ }
+
// Register controller listeners.
for(BaseState state : states){
Controllers.addListener(state);
}
- // Set up rendering fields and settings.
- batch = new SpriteBatch();
- batch.enableBlending();
- batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
-
- pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
-
- ShaderProgram.pedantic = false;
-
// Set up the overlay font.
overlayX = -(Utils.getScreenWidth() / 2) + 10;
overlayY = (Utils.getScreenHeight() / 2) - 10;
@@ -336,8 +357,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
super.render();
// Load the assets.
- if(!GameSettings.getEntityCreator().areEntitiesCreated())
- GameSettings.getEntityCreator().updateAssetManager();
+ if(!GameGlobals.getEntityCreator().areEntitiesCreated())
+ GameGlobals.getEntityCreator().updateAssetManager();
// If the current state set a value for nextState then switch to that state.
if(nextState != null){
@@ -452,7 +473,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
batch.dispose();
font.dispose();
- GameSettings.clearGameSettings();
+ GameGlobals.clearGameSettings();
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
deleted file mode 100644
index afd0f8b..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.entities;
-
-import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
-import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
-import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
-import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
-import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
-import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
-
-import com.artemis.Entity;
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.VertexAttribute;
-import com.badlogic.gdx.graphics.VertexAttributes;
-import com.badlogic.gdx.graphics.VertexAttributes.Usage;
-import com.badlogic.gdx.graphics.g3d.Environment;
-import com.badlogic.gdx.graphics.g3d.Material;
-import com.badlogic.gdx.graphics.g3d.Model;
-import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
-import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
-import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
-import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
-import com.badlogic.gdx.math.Matrix3;
-import com.badlogic.gdx.math.Vector3;
-import com.badlogic.gdx.utils.JsonReader;
-
-public class MarkerTestEntityCreator extends EntityCreatorBase {
- private static final String TAG = "MARKER_TEST_ENTITY_CREATOR";
- private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName();
-
- private Model bombModel;
- private Model animatedModel;
- private Model boxModel;
- private DirectionalLightPerPixelShader ppShader;
-
- @Override
- protected void createAllEntities() {
- ModelBuilder builder;
- Entity bomb, box, anim;
- G3dModelLoader loader;
- Environment environment;
- Material material;
-
- // Create mesh.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
-
- loader = new G3dModelLoader(new JsonReader());
-
- bombModel = loader.loadModel(Gdx.files.internal("models/Bomb_test_2.g3dj"));
- animatedModel = loader.loadModel(Gdx.files.internal("models/cube.g3dj"));
-
- material = new Material(new FloatAttribute(FloatAttribute.Shininess, 50.0f), new ColorAttribute(ColorAttribute.Diffuse, 1.0f, 1.0f, 1.0f, 1.0f), new ColorAttribute(ColorAttribute.Specular, 1.0f, 1.0f, 1.0f, 1.0f));
-
- builder = new ModelBuilder();
- boxModel = builder.createBox(0.5f, 0.5f, 6.0f, material, new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")).getMask());
-
- // Load the shader.
- ppShader = new DirectionalLightPerPixelShader();
- ppShader.init();
-
- environment = new Environment();
- environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
- environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, -0.5f)));
-
- // Create the entities.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
- bomb = world.createEntity();
- bomb.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
- bomb.addComponent(new RenderModelComponent(bombModel));
- bomb.addComponent(new EnvironmentComponent(environment));
- bomb.addComponent(new ShaderComponent(ppShader));
- bomb.addComponent(new MarkerCodeComponent(1023));
-
- anim = world.createEntity();
- anim.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(0.25f, 0.25f, -0.25f)));
- anim.addComponent(new RenderModelComponent(animatedModel));
- anim.addComponent(new AnimationComponent(anim.getComponent(RenderModelComponent.class).instance, 0, true));
- anim.addComponent(new EnvironmentComponent(environment));
- anim.addComponent(new MarkerCodeComponent(89));
- anim.addComponent(new ShaderComponent(ppShader));
-
- box = world.createEntity();
- box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
- box.addComponent(new RenderModelComponent(boxModel));
- box.addComponent(new ShaderComponent(ppShader));
- box.addComponent(new EnvironmentComponent(environment));
-
- // Add the entities to the world.
- Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
- //sphere.addToWorld();
- bomb.addToWorld();
- anim.addToWorld();
- box.addToWorld();
-
- entitiesCreated = true;
- }
-
- @Override
- public void dispose() {
- if(boxModel != null)
- boxModel.dispose();
-
- if(animatedModel != null)
- animatedModel.dispose();
-
- if(bombModel != null)
- bombModel.dispose();
-
- if(ppShader != null)
- ppShader.dispose();
- }
-
- @Override
- public boolean updateAssetManager(){
- createAllEntities();
- if(core != null) core.onAssetsLoaded();
-
- return true;
- }
-
- @Override
- public void resetAllEntities() { }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
new file mode 100644
index 0000000..13f12ed
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 Miguel Angel Astor Romero
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ve.ucv.ciens.ccg.nxtar.game;
+
+import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
+
+public abstract class AutomaticActionPerformerBase {
+ public enum automatic_action_t{
+ NO_ACTION,
+ GO_FORWARD,
+ GO_BACKWARDS,
+ STOP,
+ TURN_LEFT,
+ TURN_RIGHT,
+ BACKWARDS_LEFT,
+ BACKWARDS_RIGHT,
+ ROTATE_90,
+ RECENTER,
+ LOOK_RIGHT,
+ LOOK_LEFT,
+ STOP_LOOKING;
+ }
+
+ public abstract boolean performAutomaticAction(int lightSensorReading, MarkerData markers);
+ public abstract automatic_action_t getNextAction();
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
similarity index 62%
rename from src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
index 94fe904..5f5c3ff 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
@@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.utils;
+package ve.ucv.ciens.ccg.nxtar.game;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.BombGameLogicSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
@@ -37,13 +35,14 @@ import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable;
-public abstract class GameSettings{
- private static EntityCreatorBase entityCreator = null;
- private static GameLogicSystemBase gameLogicSystem = null;
- private static World gameWorld = null;
- private static ModelBatch modelBatch = null;
+public abstract class GameGlobals{
+ private static EntityCreatorBase entityCreator = null;
+ private static GameLogicSystemBase gameLogicSystem = null;
+ private static World gameWorld = null;
+ private static ModelBatch modelBatch = null;
+ private static AutomaticActionPerformerBase automaticActionPerformer = null;
- public static void initGameSettings(NxtARCore core) throws IllegalArgumentException{
+ public static void initGameSettings(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{
if(core == null)
throw new IllegalArgumentException("Core is null.");
@@ -56,13 +55,42 @@ public abstract class GameSettings{
}
if(getEntityCreator() == null){
- entityCreator = new BombGameEntityCreator();
+ try {
+ entityCreator = (EntityCreatorBase) ScenarioImplementation.entityCreatorClass.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating entity creator.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing entity creator.");
+ throw e;
+ }
entityCreator.setWorld(gameWorld);
entityCreator.setCore(core);
}
- if(getGameLogicSystem() == null)
- gameLogicSystem = new BombGameLogicSystem();
+ if(getGameLogicSystem() == null){
+ try {
+ gameLogicSystem = (GameLogicSystemBase) ScenarioImplementation.gameLogicSystemClass.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating game logic system.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing game logic system.");
+ throw e;
+ }
+ }
+
+ if(automaticActionPerformer == null){
+ try {
+ automaticActionPerformer = (AutomaticActionPerformerBase) ScenarioImplementation.automaticActionPerformerClass.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating automatic action performer.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing automatic action performer.");
+ throw e;
+ }
+ }
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
@@ -70,6 +98,7 @@ public abstract class GameSettings{
gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem());
gameWorld.setSystem(gameLogicSystem);
+ // TODO: Add player processing system.
gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true);
gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true);
gameWorld.setSystem(new FadeEffectRenderingSystem(), true);
@@ -113,4 +142,11 @@ public abstract class GameSettings{
public static World getGameWorld() {
return gameWorld;
}
+
+ /**
+ * @return the automaticActionPerformer
+ */
+ public static AutomaticActionPerformerBase getAutomaticActionPerformer() {
+ return automaticActionPerformer;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
new file mode 100644
index 0000000..303bd50
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 Miguel Angel Astor Romero
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ve.ucv.ciens.ccg.nxtar.game;
+
+import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionPerformer;
+import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameLogicSystem;
+
+@SuppressWarnings("rawtypes")
+public final class ScenarioImplementation{
+ public static Class gameLogicSystemClass = BombGameLogicSystem.class;
+ public static Class entityCreatorClass = BombGameEntityCreator.class;
+ public static Class automaticActionPerformerClass = BombGameAutomaticActionPerformer.class;
+
+ private ScenarioImplementation(){}
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java
similarity index 96%
rename from src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java
index e50513c..4ffd0a3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/BombComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.components;
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import com.artemis.Component;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
new file mode 100644
index 0000000..3e04729
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2014 Miguel Angel Astor Romero
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import com.badlogic.gdx.Gdx;
+
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+
+public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBase {
+ private static final int GOAL_FLOOR_MIN_LUMINANCE = 85;
+ private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 45;
+
+ private enum action_state_t{
+ START, WALK_FORWARD, DETECT_MARKER, FINISHING, END;
+ }
+
+ private automatic_action_t nextAction;
+ private action_state_t state;
+ private List detectedMarkers;
+ private float then;
+
+ public BombGameAutomaticActionPerformer(){
+ nextAction = automatic_action_t.NO_ACTION;
+ state = action_state_t.START;
+ detectedMarkers = new LinkedList();
+ then = 0.0f;
+ }
+
+ @Override
+ public boolean performAutomaticAction(int lightSensorReading, MarkerData markers) throws IllegalStateException, IllegalArgumentException{
+ boolean finish = false;
+ int detectedCode = -1;
+ float now, deltaT;
+
+ if(markers == null)
+ throw new IllegalArgumentException("Markers is null");
+
+ switch(state){
+ case START:
+ nextAction = automatic_action_t.ROTATE_90;
+ state = action_state_t.WALK_FORWARD;
+ finish = false;
+ break;
+
+ case WALK_FORWARD:
+ if(lightSensorReading >= GOAL_FLOOR_MIN_LUMINANCE){
+ nextAction = automatic_action_t.STOP;
+ state = action_state_t.END;
+ }else{
+ if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE && lightSensorReading < GOAL_FLOOR_MIN_LUMINANCE){
+ nextAction = automatic_action_t.STOP;
+ state = action_state_t.DETECT_MARKER;
+ then = Gdx.graphics.getDeltaTime();
+ }else{
+ nextAction = automatic_action_t.GO_FORWARD;
+ }
+ }
+ finish = false;
+ break;
+
+ case DETECT_MARKER:
+ for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
+ // Check if this marker has not been detected already.
+ for(Integer code : detectedMarkers){
+ if(markers.markerCodes[i] == code){
+ i = ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS;
+ break;
+ }
+ }
+
+ // If the marker has not been detected before then examine it.
+ if(i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS){
+ detectedCode = markers.markerCodes[i];
+ // TODO: If marker is a bomb then add it to the summary.
+ }
+ }
+
+ if(detectedCode == -1)
+ detectedMarkers.add(detectedCode);
+
+ if(lightSensorReading < MARKER_NEARBY_FLOOR_MIN_LUMINANCE){
+ state = action_state_t.WALK_FORWARD;
+ nextAction = automatic_action_t.STOP;
+ then = 0.0f;
+ }else{
+ now = Gdx.graphics.getDeltaTime();
+ deltaT = now - then;
+ if(deltaT >= 2.0f){
+ nextAction = automatic_action_t.GO_FORWARD;
+ then = Gdx.graphics.getDeltaTime();
+ }
+ }
+
+ finish = false;
+
+ break;
+
+ case FINISHING:
+ detectedMarkers.clear();
+ state = action_state_t.END;
+ nextAction = automatic_action_t.RECENTER;
+ finish = false;
+ break;
+
+ case END:
+ state = action_state_t.START;
+ nextAction = automatic_action_t.NO_ACTION;
+ finish = true;
+ break;
+
+ default:
+ throw new IllegalStateException("Unknown automatic action state.");
+ }
+
+ return finish;
+ }
+
+ @Override
+ public automatic_action_t getNextAction() {
+ switch(nextAction){
+ default:
+ case NO_ACTION:
+ return automatic_action_t.NO_ACTION;
+ case GO_BACKWARDS:
+ return automatic_action_t.GO_BACKWARDS;
+ case GO_FORWARD:
+ return automatic_action_t.GO_FORWARD;
+ case STOP:
+ return automatic_action_t.STOP;
+ case ROTATE_90:
+ return automatic_action_t.ROTATE_90;
+ case RECENTER:
+ return automatic_action_t.RECENTER;
+ }
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
similarity index 98%
rename from src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
index c5ac8af..8369159 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.entities;
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import java.util.LinkedList;
import java.util.List;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
-import ve.ucv.ciens.ccg.nxtar.components.BombComponent;
-import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t;
-import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
@@ -33,6 +29,8 @@ import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
+import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
+import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombComponent.bomb_type_t;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
similarity index 98%
rename from src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
index a77b4f4..aa82fb2 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
@@ -13,17 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.systems;
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
-import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
-import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.FadeEffectComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
-import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java
similarity index 96%
rename from src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java
index 5fd7862..61861ae 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/BombGameObjectTypeComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.components;
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import com.artemis.Component;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java
similarity index 92%
rename from src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java
index 82144ed..3950389 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/components/BombGamePlayerComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.components;
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+
+import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
public class BombGamePlayerComponent extends PlayerComponentBase {
public static final int MIN_LIVES = 1;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
similarity index 93%
rename from src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
index db2a7cc..d45a7d5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/BombGamePlayerSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.systems;
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-import ve.ucv.ciens.ccg.nxtar.components.BombGamePlayerComponent;
-import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.artemis.ComponentMapper;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
index 73b9354..3ad1abb 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
@@ -15,20 +15,20 @@
*/
package ve.ucv.ciens.ccg.nxtar.states;
+import ve.ucv.ciens.ccg.networkdata.MotorEvent;
+import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.automatic_action_t;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
+import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
+import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
-import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
-import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
-import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -37,6 +37,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
@@ -44,16 +45,24 @@ import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
+import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
public class AutomaticActionState extends BaseState{
- private static final String TAG = "IN_GAME_STATE";
+ private static final String TAG = "AUTOMATIC_STATE";
private static final String CLASS_NAME = AutomaticActionState.class.getSimpleName();
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
private static final float NEAR = 0.01f;
@@ -73,9 +82,9 @@ public class AutomaticActionState extends BaseState{
// Game related fields.
private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem;
- private ObjectRenderingSystem objectRenderingSystem;
- private RobotArmPositioningSystem robotArmPositioningSystem;
- private FadeEffectRenderingSystem fadeEffectRenderingSystem;
+ private boolean ignoreBackKey;
+ private boolean automaticActionEnabled;
+ private AutomaticActionPerformerBase automaticActionPerformer;
// Cameras.
private OrthographicCamera unitaryOrthographicCamera;
@@ -87,6 +96,22 @@ public class AutomaticActionState extends BaseState{
private Sprite renderableVideoFrame;
private Pixmap videoFrame;
+ // Gui elements.
+ private Texture startButtonEnabledTexture;
+ private Texture startButtonDisabledTexture;
+ private Texture startButtonPressedTexture;
+ private NinePatch startButtonEnabled9p;
+ private NinePatch startButtonDisabled9p;
+ private NinePatch startButtonPressed9p;
+ private BitmapFont font;
+ private TextButton startButton;
+ private Rectangle startButtonBBox;
+ private boolean startButtonPressed;
+ private Texture ouyaOButtonTexture;
+ private Sprite ouyaOButton;
+ private boolean oButtonPressed;
+ private boolean aButtonPressed;
+
// Button touch helper fields.
private boolean[] buttonsTouched;
private int[] buttonPointers;
@@ -94,17 +119,23 @@ public class AutomaticActionState extends BaseState{
// Monitors.
private VideoFrameMonitor frameMonitor;
- // private MotorEventQueue queue;
- // private SensorReportThread sensorThread;
+ private MotorEventQueue queue;
+ private SensorReportThread sensorThread;
- public AutomaticActionState(final NxtARCore core){
- this.core = core;
- frameMonitor = VideoFrameMonitor.getInstance();
- // queue = MotorEventQueue.getInstance();
- // sensorThread = SensorReportThread.getInstance();
+ public AutomaticActionState(final NxtARCore core) throws IllegalStateException, IllegalArgumentException{
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
- // Set up rendering fields;
- videoFrame = null;
+ this.core = core;
+ frameMonitor = VideoFrameMonitor.getInstance();
+ queue = MotorEventQueue.getInstance();
+ sensorThread = SensorReportThread.getInstance();
+ ignoreBackKey = false;
+ videoFrame = null;
+ aButtonPressed = false;
+ automaticActionEnabled = false;
+ startButtonPressed = false;
+ automaticActionPerformer = GameGlobals.getAutomaticActionPerformer();
// Set up the cameras.
pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
@@ -149,25 +180,15 @@ public class AutomaticActionState extends BaseState{
perspectiveCamera = null;
frameBufferSprite = null;
+ // Create the gui.
+ setUpButton();
+
// Set up the game world.
- gameWorld = GameSettings.getGameWorld();
+ gameWorld = GameGlobals.getGameWorld();
+ markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
- robotArmPositioningSystem = new RobotArmPositioningSystem();
- markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
- objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
- fadeEffectRenderingSystem = new FadeEffectRenderingSystem();
-
- gameWorld.setSystem(new MarkerPositioningSystem());
- gameWorld.setSystem(robotArmPositioningSystem, Ouya.runningOnOuya);
- gameWorld.setSystem(new GeometrySystem());
- gameWorld.setSystem(new AnimationSystem());
- gameWorld.setSystem(new CollisionDetectionSystem());
- gameWorld.setSystem(GameSettings.getGameLogicSystem());
- gameWorld.setSystem(markerRenderingSystem, true);
- gameWorld.setSystem(objectRenderingSystem, true);
- gameWorld.setSystem(fadeEffectRenderingSystem, true);
-
- gameWorld.initialize();
+ if(markerRenderingSystem == null)
+ throw new IllegalStateException(CLASS_NAME + ": Essential marker rendering system is null.");
}
/*;;;;;;;;;;;;;;;;;;;;;;
@@ -220,6 +241,9 @@ public class AutomaticActionState extends BaseState{
// If a valid frame was fetched.
if(data != null && data.outFrame != null){
+ if(automaticActionEnabled)
+ performAutomaticAction(data);
+
// Set the camera to the correct projection.
focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY();
@@ -308,11 +332,35 @@ public class AutomaticActionState extends BaseState{
videoFrameTexture.dispose();
}
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
+ core.batch.begin();{
+ startButton.draw(core.batch, 1.0f);
+ if(Ouya.runningOnOuya)
+ ouyaOButton.draw(core.batch);
+ }core.batch.end();
+
data = null;
}
@Override
public void dispose(){
+ SensorReportThread.freeInstance();
+
+ if(font != null)
+ font.dispose();
+
+ if(ouyaOButtonTexture != null)
+ ouyaOButtonTexture.dispose();
+
+ if(startButtonEnabledTexture != null)
+ startButtonEnabledTexture.dispose();
+
+ if(startButtonDisabledTexture != null)
+ startButtonDisabledTexture.dispose();
+
+ if(startButtonPressedTexture != null)
+ startButtonPressedTexture.dispose();
+
if(modelBatch != null)
modelBatch.dispose();
@@ -327,14 +375,8 @@ public class AutomaticActionState extends BaseState{
if(frameBuffer != null)
frameBuffer.dispose();
-
- fadeEffectRenderingSystem.dispose();
}
- /*;;;;;;;;;;;;;;;;;;
- ; HELPER METHODS ;
- ;;;;;;;;;;;;;;;;;;*/
-
@Override
public void onStateSet(){
stateActive = true;
@@ -351,6 +393,188 @@ public class AutomaticActionState extends BaseState{
Gdx.input.setCatchMenuKey(false);
}
+ /*;;;;;;;;;;;;;;;;;;
+ ; HELPER METHODS ;
+ ;;;;;;;;;;;;;;;;;;*/
+
+ private void setUpButton(){
+ TextButtonStyle textButtonStyle;
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+
+ // Create the start button background.
+ startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
+ startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
+ startButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
+ startButtonDisabled9p = new NinePatch(new TextureRegion(startButtonDisabledTexture, 0, 0, startButtonDisabledTexture.getWidth(), startButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
+ startButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
+ startButtonPressed9p = new NinePatch(new TextureRegion(startButtonPressedTexture, 0, 0, startButtonPressedTexture.getWidth(), startButtonPressedTexture.getHeight()), 49, 49, 45, 45);
+
+ // Create the start button font.
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+ font = fontGenerator.generateFont(fontParameters);
+ fontGenerator.dispose();
+
+ // Create the start button.
+ textButtonStyle = new TextButtonStyle();
+ textButtonStyle.font = font;
+ textButtonStyle.up = new NinePatchDrawable(startButtonEnabled9p);
+ textButtonStyle.checked = new NinePatchDrawable(startButtonPressed9p);
+ textButtonStyle.disabled = new NinePatchDrawable(startButtonDisabled9p);
+ textButtonStyle.fontColor = new Color(Color.BLACK);
+ textButtonStyle.downFontColor = new Color(Color.WHITE);
+ textButtonStyle.disabledFontColor = new Color(Color.BLACK);
+
+ startButton = new TextButton("Start automatic action", textButtonStyle);
+ startButton.setText("Start automatic action");
+ startButton.setDisabled(false);
+ startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
+ startButton.setPosition(-(startButton.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10);
+ startButtonBBox.setPosition(startButton.getX(), startButton.getY());
+
+ // Set OUYA's O button.
+ if(Ouya.runningOnOuya){
+ ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
+ ouyaOButton = new Sprite(ouyaOButtonTexture);
+ ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ oButtonPressed = false;
+ ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
+ }else{
+ ouyaOButtonTexture = null;
+ }
+ }
+
+ private void performAutomaticAction(MarkerData data){
+ MotorEvent event1 = null;
+ MotorEvent event2 = null;
+ automatic_action_t nextAction;
+
+ try{
+ if(!automaticActionPerformer.performAutomaticAction(sensorThread.getLightSensorReading(), data)){
+ nextAction = automaticActionPerformer.getNextAction();
+
+ switch(nextAction){
+ case GO_BACKWARDS:
+ event1 = new MotorEvent();
+ event2 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)-100);
+ event2.setMotor(motor_t.MOTOR_C);
+ event2.setPower((byte)-100);
+ break;
+
+ case GO_FORWARD:
+ event1 = new MotorEvent();
+ event2 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)100);
+ event2.setMotor(motor_t.MOTOR_C);
+ event2.setPower((byte)100);
+ break;
+
+ case STOP:
+ event1 = new MotorEvent();
+ event2 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)0);
+ event2.setMotor(motor_t.MOTOR_C);
+ event2.setPower((byte)0);
+ break;
+
+ case ROTATE_90:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.ROTATE_90);
+ event1.setPower((byte)100);
+ break;
+
+ case RECENTER:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.RECENTER);
+ event1.setPower((byte)100);
+ break;
+
+ case TURN_LEFT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)100);
+ break;
+
+ case TURN_RIGHT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_C);
+ event1.setPower((byte)100);
+ break;
+
+ case BACKWARDS_LEFT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_C);
+ event1.setPower((byte)-100);
+ break;
+
+ case BACKWARDS_RIGHT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)-100);
+ break;
+
+ case LOOK_RIGHT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_B);
+ event1.setPower((byte)25);
+ break;
+
+ case LOOK_LEFT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_B);
+ event1.setPower((byte)-25);
+ break;
+
+ case STOP_LOOKING:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_B);
+ event1.setPower((byte)0);
+ break;
+
+ case NO_ACTION:
+ default:
+ break;
+ }
+
+ if(event1 != null)
+ queue.addEvent(event1);
+ if(event2 != null)
+ queue.addEvent(event2);
+
+ }else{
+ // TODO: Go to summary screen.
+ startButton.setDisabled(false);
+ ignoreBackKey = false;
+ automaticActionEnabled = false;
+ core.nextState = game_states_t.MAIN_MENU;
+ }
+
+ }catch(IllegalArgumentException e){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Received IllegalArgumentException: ", e);
+
+ startButton.setDisabled(false);
+ ignoreBackKey = false;
+ automaticActionEnabled = false;
+ core.nextState = game_states_t.MAIN_MENU;
+
+ }catch(IllegalStateException e){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Received IllegalStateException: ", e);
+
+ startButton.setDisabled(false);
+ ignoreBackKey = false;
+ automaticActionEnabled = false;
+ core.nextState = game_states_t.MAIN_MENU;
+ }
+ }
+
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
; INPUT PROCESSOR METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@@ -361,6 +585,11 @@ public class AutomaticActionState extends BaseState{
win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
+
+ if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
+ startButtonPressed = true;
+ }
+
}
return false;
@@ -372,6 +601,13 @@ public class AutomaticActionState extends BaseState{
win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
+
+ if(!startButton.isDisabled() && startButtonPressed && startButtonBBox.contains(touchPointWorldCoords)){
+ startButton.setDisabled(true);
+ ignoreBackKey = true;
+ automaticActionEnabled = true;
+ }
+
}
return false;
@@ -383,6 +619,11 @@ public class AutomaticActionState extends BaseState{
win2world.set(screenX, screenY, 0.0f);
unitaryOrthographicCamera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
+
+ if(!startButton.isDisabled() && startButtonPressed && !startButtonBBox.contains(touchPointWorldCoords)){
+ startButtonPressed = false;
+ }
+
}
return false;
@@ -390,7 +631,7 @@ public class AutomaticActionState extends BaseState{
@Override
public boolean keyDown(int keycode){
- if(keycode == Input.Keys.BACK){
+ if(keycode == Input.Keys.BACK && !ignoreBackKey){
core.nextState = game_states_t.MAIN_MENU;
return true;
}
@@ -405,10 +646,11 @@ public class AutomaticActionState extends BaseState{
@Override
public boolean buttonDown(Controller controller, int buttonCode){
if(stateActive){
- Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
-
- if(buttonCode == Ouya.BUTTON_O){
-
+ if(buttonCode == Ouya.BUTTON_O && !startButton.isDisabled()){
+ oButtonPressed = true;
+ startButton.setChecked(true);
+ }else if(buttonCode == Ouya.BUTTON_A && !ignoreBackKey){
+ aButtonPressed = true;
}
return true;
@@ -420,9 +662,17 @@ public class AutomaticActionState extends BaseState{
@Override
public boolean buttonUp(Controller controller, int buttonCode){
if(stateActive){
- Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
-
- if(buttonCode == Ouya.BUTTON_O){ }
+ if(buttonCode == Ouya.BUTTON_O && oButtonPressed){
+ if(oButtonPressed){
+ oButtonPressed = false;
+ startButton.setChecked(false);
+ startButton.setDisabled(true);
+ ignoreBackKey = true;
+ automaticActionEnabled = true;
+ }
+ }else if(buttonCode == Ouya.BUTTON_A && aButtonPressed){
+ core.nextState = game_states_t.MAIN_MENU;
+ }
return true;
}else{
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 157028f..e02542e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -19,6 +19,7 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
@@ -32,7 +33,6 @@ import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
-import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -149,7 +149,10 @@ public class InGameState extends BaseState{
private VideoFrameMonitor frameMonitor;
private MotorEventQueue queue;
- public InGameState(final NxtARCore core) throws IllegalStateException{
+ public InGameState(final NxtARCore core) throws IllegalStateException, IllegalArgumentException{
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
+
this.core = core;
frameMonitor = VideoFrameMonitor.getInstance();
queue = MotorEventQueue.getInstance();
@@ -226,7 +229,7 @@ public class InGameState extends BaseState{
setUpButtons();
// Set up the game world.
- gameWorld = GameSettings.getGameWorld();
+ gameWorld = GameGlobals.getGameWorld();
robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class);
markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
@@ -1162,7 +1165,7 @@ public class InGameState extends BaseState{
if(!gamepadButtonPressed[3]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
- event.setPower((byte)-40);
+ event.setPower((byte)-25);
queue.addEvent(event);
}
@@ -1172,7 +1175,7 @@ public class InGameState extends BaseState{
if(!gamepadButtonPressed[2]){
event = new MotorEvent();
event.setMotor(motor_t.MOTOR_B);
- event.setPower((byte)40);
+ event.setPower((byte)25);
queue.addEvent(event);
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
index 60b6b5c..7e65221 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
@@ -45,7 +45,7 @@ public abstract class MainMenuStateBase extends BaseState{
private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName();
private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
- protected final int NUM_MENU_BUTTONS = 2;
+ protected final int NUM_MENU_BUTTONS = 3;
// Helper fields.
protected boolean clientConnected;
@@ -59,6 +59,8 @@ public abstract class MainMenuStateBase extends BaseState{
protected Rectangle startButtonBBox;
protected TextButton calibrationButton;
protected Rectangle calibrationButtonBBox;
+ protected TextButton autoButton;
+ protected Rectangle autoButtonBBox;
protected Sprite cameraCalibratedLedOn;
protected Sprite cameraCalibratedLedOff;
protected Sprite assetsLoadedLedOn;
@@ -86,6 +88,8 @@ public abstract class MainMenuStateBase extends BaseState{
protected int startButtonTouchPointer;
protected boolean calibrationButtonTouched;
protected int calibrationButtonTouchPointer;
+ protected boolean autoButtonTouched;
+ protected int autoButtonTouchPointer;
public MainMenuStateBase(){
TextureRegion region;
@@ -120,10 +124,12 @@ public abstract class MainMenuStateBase extends BaseState{
textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p);
textButtonStyle.checked = new NinePatchDrawable(menuButtonPressed9p);
textButtonStyle.disabled = new NinePatchDrawable(menuButtonDisabled9p);
- textButtonStyle.disabledFontColor = new Color(0, 0, 0, 1);
+ textButtonStyle.fontColor = new Color(Color.BLACK);
+ textButtonStyle.downFontColor = new Color(Color.WHITE);
+ textButtonStyle.disabledFontColor = new Color(Color.BLACK);
- startButton = new TextButton("Start server", textButtonStyle);
- startButton.setText("Start game");
+ startButton = new TextButton("Manual control", textButtonStyle);
+ startButton.setText("Manual control");
startButton.setDisabled(true);
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
@@ -133,6 +139,11 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButton.setDisabled(true);
calibrationButtonBBox = new Rectangle(0, 0, calibrationButton.getWidth(), calibrationButton.getHeight());
+ autoButton = new TextButton("Automatic action", textButtonStyle);
+ autoButton.setText("Automatic action");
+ autoButton.setDisabled(true);
+ autoButtonBBox = new Rectangle(0, 0, autoButton.getWidth(), autoButton.getHeight());
+
// Create the connection leds.
ledOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
ledOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
@@ -177,6 +188,8 @@ public abstract class MainMenuStateBase extends BaseState{
startButtonTouchPointer = -1;
calibrationButtonTouched = false;
calibrationButtonTouchPointer = -1;
+ autoButtonTouched = false;
+ autoButtonTouchPointer = -1;
clientConnected = false;
cameraCalibrated = false;
@@ -233,16 +246,17 @@ public abstract class MainMenuStateBase extends BaseState{
public void onCameraCalibrated(){
cameraCalibrated = true;
- startGame();
+ enableGameButtons();
}
public void onAssetsLoaded(){
assetsLoaded = true;
- startGame();
+ enableGameButtons();
}
- private void startGame(){
+ private void enableGameButtons(){
startButton.setDisabled(!(cameraCalibrated && assetsLoaded));
+ autoButton.setDisabled(!(cameraCalibrated && assetsLoaded));
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -256,16 +270,21 @@ public abstract class MainMenuStateBase extends BaseState{
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
- if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && !calibrationButtonTouched){
+ if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && (!calibrationButtonTouched && !autoButtonTouched)){
startButton.setChecked(true);
startButtonTouched = true;
startButtonTouchPointer = pointer;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
- }else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && !startButtonTouched){
+ }else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && (!startButtonTouched && !autoButtonTouched)){
calibrationButton.setChecked(true);
calibrationButtonTouched = true;
calibrationButtonTouchPointer = pointer;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button pressed.");
+ }else if(!autoButton.isDisabled() && autoButtonBBox.contains(touchPointWorldCoords) && (!startButtonTouched && !calibrationButtonTouched)){
+ autoButton.setChecked(true);
+ autoButtonTouched = true;
+ autoButtonTouchPointer = pointer;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Auto button pressed.");
}
return true;
@@ -290,6 +309,12 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButtonTouchPointer = -1;
core.nextState = game_states_t.CALIBRATION;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button released.");
+ }else if(!autoButton.isDisabled() && autoButtonBBox.contains(touchPointWorldCoords) && autoButtonTouched){
+ autoButton.setChecked(false);
+ autoButtonTouched = false;
+ autoButtonTouchPointer = -1;
+ core.nextState = game_states_t.AUTOMATIC_ACTION;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Auto button released.");
}
return true;
@@ -309,6 +334,11 @@ public abstract class MainMenuStateBase extends BaseState{
calibrationButtonTouched = false;
calibrationButton.setChecked(false);
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
+ }else if(!autoButton.isDisabled() && autoButtonTouched && pointer == autoButtonTouchPointer && !autoButtonBBox.contains(touchPointWorldCoords)){
+ autoButtonTouchPointer = -1;
+ autoButtonTouched = false;
+ autoButton.setChecked(false);
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Auto button released.");
}
return true;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
index 00e829c..5809214 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
@@ -46,9 +46,11 @@ public class OuyaMainMenuState extends MainMenuStateBase{
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
+ autoButton.setPosition(-(autoButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10);
+ autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY());
//Set leds.
- ledYPos = (-(Utils.getScreenHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
+ ledYPos = -(Utils.getScreenHeight() / 2) + 10;
cameraCalibratedLedOn.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f);
cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
@@ -88,12 +90,15 @@ public class OuyaMainMenuState extends MainMenuStateBase{
// Render buttons.
startButton.draw(core.batch, 1.0f);
calibrationButton.draw(core.batch, 1.0f);
+ autoButton.draw(core.batch, 1.0f);
// Render O button.
if(oButtonSelection == 0){
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
}else if(oButtonSelection == 1){
ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2));
+ }else if(oButtonSelection == 2){
+ ouyaOButton.setPosition(autoButton.getX() - ouyaOButton.getWidth() - 20, autoButton.getY() + (ouyaOButton.getHeight() / 2));
}
ouyaOButton.draw(core.batch);
@@ -132,6 +137,13 @@ public class OuyaMainMenuState extends MainMenuStateBase{
oButtonPressed = true;
calibrationButton.setChecked(true);
}
+ }else if(oButtonSelection == 2){
+ if(!clientConnected){
+ core.toast("Can't launch automatic action. No client is connected.", true);
+ }else{
+ oButtonPressed = true;
+ autoButton.setChecked(true);
+ }
}
}else if(buttonCode == Ouya.BUTTON_DPAD_UP){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
@@ -162,6 +174,9 @@ public class OuyaMainMenuState extends MainMenuStateBase{
}else if(oButtonSelection == 1){
calibrationButton.setChecked(false);
core.nextState = game_states_t.CALIBRATION;
+ }else if(oButtonSelection == 2){
+ autoButton.setChecked(false);
+ core.nextState = game_states_t.AUTOMATIC_ACTION;
}
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
index 60e2f46..8fb8331 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
@@ -34,9 +34,11 @@ public class TabletMainMenuState extends MainMenuStateBase{
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
+ autoButton.setPosition(-(autoButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10);
+ autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY());
// Set leds.
- ledYPos = (-(Utils.getScreenHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
+ ledYPos = -(Utils.getScreenHeight() / 2) + 10;
cameraCalibratedLedOn.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f);
cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
@@ -69,6 +71,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
// Render buttons.
startButton.draw(core.batch, 1.0f);
calibrationButton.draw(core.batch, 1.0f);
+ autoButton.draw(core.batch, 1.0f);
}core.batch.end();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
index c273e6a..d1ecf82 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
@@ -17,7 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
-import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import com.artemis.Aspect;
import com.artemis.Entity;
@@ -42,7 +42,7 @@ public abstract class PlayerSystemBase extends EntityProcessingSystem {
protected final void finishGame(boolean victory){
// TODO: Switch to game over state.
// TODO: Set game over state parameters.
- GameSettings.getEntityCreator().resetAllEntities();
+ GameGlobals.getEntityCreator().resetAllEntities();
core.nextState = NxtARCore.game_states_t.MAIN_MENU;
}
From 77aec83dbb689a3e1bf92c579a30b58ef0409a57 Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 25 Jun 2014 16:09:59 -0430
Subject: [PATCH 27/34] Bomb game automatic action and summary ready.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 61 ++--
.../game/AutomaticActionPerformerBase.java | 10 +-
.../AutomaticActionSummaryOverlayBase.java | 33 ++
.../ucv/ciens/ccg/nxtar/game/GameGlobals.java | 78 ++++-
.../nxtar/game/ScenarioImplementation.java | 2 +
.../BombGameAutomaticActionPerformer.java | 174 +++++++--
...BombGameAutomaticActionSummaryOverlay.java | 127 +++++++
.../game/bombgame/BombGameEntityCreator.java | 58 ++-
....java => BombGameEntityTypeComponent.java} | 4 +-
.../game/bombgame/BombGameLogicSystem.java | 48 +--
.../game/bombgame/BombGamePlayerSystem.java | 4 +-
.../nxtar/states/AutomaticActionState.java | 179 +++++-----
.../states/AutomaticActionSummaryState.java | 330 ++++++++++++++++++
.../ciens/ccg/nxtar/states/InGameState.java | 10 +-
.../ccg/nxtar/states/MainMenuStateBase.java | 11 +-
.../ccg/nxtar/states/OuyaMainMenuState.java | 13 +-
.../ccg/nxtar/states/TabletMainMenuState.java | 9 +-
.../ccg/nxtar/utils/ProjectConstants.java | 2 +-
src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java | 4 +-
19 files changed, 926 insertions(+), 231 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java
rename src/ve/ucv/ciens/ccg/nxtar/game/bombgame/{BombGameObjectTypeComponent.java => BombGameEntityTypeComponent.java} (91%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index db77ca5..43d562c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -24,6 +24,7 @@ import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionState;
+import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionSummaryState;
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
@@ -75,7 +76,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Valid game states.
*/
public enum game_states_t {
- MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3);
+ MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3), SUMMARY(4);
private int value;
@@ -88,7 +89,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
public static int getNumStates(){
- return 4;
+ return 5;
}
};
@@ -256,25 +257,35 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
// Create the state objects.
states = new BaseState[game_states_t.getNumStates()];
- if(Ouya.runningOnOuya)
- states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
- else
- states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
try{
- states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
- }catch(IllegalStateException e){
- Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: " + e.getMessage());
- Gdx.app.exit();
- return;
- }
+ if(Ouya.runningOnOuya)
+ states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
+ else
+ states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
- states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
+ try{
+ states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
+ }catch(IllegalStateException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: ", e);
+ Gdx.app.exit();
+ return;
+ }
- try{
- states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this);
- }catch(IllegalStateException e){
- Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: " + e.getMessage());
+ states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
+
+ try{
+ states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this);
+ }catch(IllegalStateException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: ", e);
+ Gdx.app.exit();
+ return;
+ }
+
+ states[game_states_t.SUMMARY.getValue()] = new AutomaticActionSummaryState(this);
+
+ }catch(IllegalArgumentException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
Gdx.app.exit();
return;
}
@@ -285,8 +296,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
// Set up the overlay font.
- overlayX = -(Utils.getScreenWidth() / 2) + 10;
- overlayY = (Utils.getScreenHeight() / 2) - 10;
+ overlayX = -(Utils.getScreenWidthWithOverscan() / 2) + 10;
+ overlayY = (Utils.getScreenHeightWithOverscan() / 2) - 10;
font = new BitmapFont();
font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
@@ -428,21 +439,23 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
/**
- * Pause a currently running thread. Pausing an already paused thread is a
- * no op.
+ * Pauses the video streaming and the current state.
*/
public void pause(){
if(videoThread != null)
videoThread.pause();
+
+ states[currState.getValue()].pause();
}
/**
- * Resume a currently paused thread. Resuming an already resumed thread is a
- * no op.
+ * Resumes the video streaming and the current state.
*/
public void resume(){
if(videoThread != null)
videoThread.play();
+
+ states[currState.getValue()].resume();
}
/**
@@ -473,7 +486,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
batch.dispose();
font.dispose();
- GameGlobals.clearGameSettings();
+ GameGlobals.dispose();
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
index 13f12ed..cf60a8d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
@@ -18,6 +18,10 @@ package ve.ucv.ciens.ccg.nxtar.game;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
public abstract class AutomaticActionPerformerBase {
+ public abstract class AutomaticActionSummary{
+ public abstract void reset();
+ }
+
public enum automatic_action_t{
NO_ACTION,
GO_FORWARD,
@@ -34,6 +38,8 @@ public abstract class AutomaticActionPerformerBase {
STOP_LOOKING;
}
- public abstract boolean performAutomaticAction(int lightSensorReading, MarkerData markers);
- public abstract automatic_action_t getNextAction();
+ public abstract boolean performAutomaticAction(int lightSensorReading, MarkerData markers);
+ public abstract automatic_action_t getNextAction();
+ public abstract AutomaticActionSummary getSummary();
+ public abstract void reset();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java
new file mode 100644
index 0000000..949edf4
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 Miguel Angel Astor Romero
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ve.ucv.ciens.ccg.nxtar.game;
+
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.AutomaticActionSummary;
+
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.utils.Disposable;
+
+/**
+ * Base class for summary screens. Just renders a summary overlay.
+ */
+public abstract class AutomaticActionSummaryOverlayBase implements Disposable{
+ /**
+ * Renders the overlay.
+ *
+ * @param batch The {@link SpriteBatch} to use for rendering.
+ */
+ public abstract void render(SpriteBatch batch, AutomaticActionSummary summary);
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
index 5f5c3ff..96e57e1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
@@ -36,11 +36,12 @@ import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable;
public abstract class GameGlobals{
- private static EntityCreatorBase entityCreator = null;
- private static GameLogicSystemBase gameLogicSystem = null;
- private static World gameWorld = null;
- private static ModelBatch modelBatch = null;
- private static AutomaticActionPerformerBase automaticActionPerformer = null;
+ private static EntityCreatorBase entityCreator = null;
+ private static GameLogicSystemBase gameLogicSystem = null;
+ private static World gameWorld = null;
+ private static ModelBatch modelBatch = null;
+ private static AutomaticActionPerformerBase automaticActionPerformer = null;
+ private static AutomaticActionSummaryOverlayBase automaticActionSummaryOverlay = null;
public static void initGameSettings(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{
if(core == null)
@@ -49,12 +50,12 @@ public abstract class GameGlobals{
if(modelBatch == null)
modelBatch = new ModelBatch();
- if(getGameWorld() == null){
+ if(gameWorld == null){
gameWorld = new World();
gameWorld.setManager(new GroupManager());
}
- if(getEntityCreator() == null){
+ if(entityCreator == null){
try {
entityCreator = (EntityCreatorBase) ScenarioImplementation.entityCreatorClass.newInstance();
} catch (InstantiationException e) {
@@ -68,7 +69,7 @@ public abstract class GameGlobals{
entityCreator.setCore(core);
}
- if(getGameLogicSystem() == null){
+ if(gameLogicSystem == null){
try {
gameLogicSystem = (GameLogicSystemBase) ScenarioImplementation.gameLogicSystemClass.newInstance();
} catch (InstantiationException e) {
@@ -92,6 +93,18 @@ public abstract class GameGlobals{
}
}
+ if(automaticActionSummaryOverlay == null){
+ try {
+ automaticActionSummaryOverlay = (AutomaticActionSummaryOverlayBase) ScenarioImplementation.automaticActionSummaryScreen.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating automatic action performer.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing automatic action performer.");
+ throw e;
+ }
+ }
+
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
gameWorld.setSystem(new GeometrySystem());
@@ -106,8 +119,13 @@ public abstract class GameGlobals{
gameWorld.initialize();
}
- public static void clearGameSettings(){
- ImmutableBag systems = gameWorld.getSystems();
+ public static void dispose() throws IllegalStateException{
+ ImmutableBag systems;
+
+ if(entityCreator == null || gameWorld == null || gameLogicSystem == null || automaticActionPerformer == null || automaticActionSummaryOverlay == null)
+ throw new IllegalStateException("Calling dispose before init or after previous dispose.");
+
+ systems = gameWorld.getSystems();
for(int i = 0; i < systems.size(); i++){
if(systems.get(i) instanceof Disposable){
@@ -115,38 +133,64 @@ public abstract class GameGlobals{
}
}
+ automaticActionSummaryOverlay.dispose();
entityCreator.dispose();
- entityCreator = null;
- gameLogicSystem = null;
- gameWorld = null;
+
+ entityCreator = null;
+ gameLogicSystem = null;
+ gameWorld = null;
+ automaticActionPerformer = null;
+ automaticActionSummaryOverlay = null;
System.gc();
}
/**
* @return the entityCreator
*/
- public static EntityCreatorBase getEntityCreator() {
+ public static EntityCreatorBase getEntityCreator() throws IllegalStateException{
+ if(entityCreator == null)
+ throw new IllegalStateException("Calling getEntityCreator() before init.");
+
return entityCreator;
}
/**
* @return the gameLogicSystem
*/
- public static GameLogicSystemBase getGameLogicSystem() {
+ public static GameLogicSystemBase getGameLogicSystem() throws IllegalStateException{
+ if(gameLogicSystem == null)
+ throw new IllegalStateException("Calling getGameLogicSystem() before init.");
+
return gameLogicSystem;
}
/**
* @return the gameWorld
*/
- public static World getGameWorld() {
+ public static World getGameWorld() throws IllegalStateException{
+ if(gameWorld == null)
+ throw new IllegalStateException("Calling getGameWorld() before init.");
+
return gameWorld;
}
/**
* @return the automaticActionPerformer
*/
- public static AutomaticActionPerformerBase getAutomaticActionPerformer() {
+ public static AutomaticActionPerformerBase getAutomaticActionPerformer() throws IllegalStateException{
+ if(automaticActionPerformer == null)
+ throw new IllegalStateException("Calling getAutomaticActionPerformer() before init.");
+
return automaticActionPerformer;
}
+
+ /**
+ * @return the automaticActionSummaryScreen
+ */
+ public static AutomaticActionSummaryOverlayBase getAutomaticActionSummaryOverlay() throws IllegalStateException{
+ if(automaticActionSummaryOverlay == null)
+ throw new IllegalStateException("Calling getAutomaticActionSummaryOverlay() before init.");
+
+ return automaticActionSummaryOverlay;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
index 303bd50..1d8c0ac 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.game;
import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionPerformer;
+import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionSummaryOverlay;
import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameLogicSystem;
@@ -24,6 +25,7 @@ public final class ScenarioImplementation{
public static Class gameLogicSystemClass = BombGameLogicSystem.class;
public static Class entityCreatorClass = BombGameEntityCreator.class;
public static Class automaticActionPerformerClass = BombGameAutomaticActionPerformer.class;
+ public static Class automaticActionSummaryScreen = BombGameAutomaticActionSummaryOverlay.class;
private ScenarioImplementation(){}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
index 3e04729..7aa2128 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
@@ -18,58 +18,132 @@ package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import java.util.LinkedList;
import java.util.List;
-import com.badlogic.gdx.Gdx;
-
import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import com.artemis.Entity;
+import com.artemis.World;
+import com.artemis.managers.GroupManager;
+import com.artemis.utils.ImmutableBag;
+import com.badlogic.gdx.Gdx;
+
public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBase {
- private static final int GOAL_FLOOR_MIN_LUMINANCE = 85;
- private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 45;
+ private static final String TAG = "BOMB_GAME_AUTO_PERFORMER";
+ private static final String CLASS_NAME = BombGameAutomaticActionPerformer.class.getSimpleName();
+ private static final int GOAL_FLOOR_MIN_LUMINANCE = 75;
+ private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 45;
private enum action_state_t{
START, WALK_FORWARD, DETECT_MARKER, FINISHING, END;
}
- private automatic_action_t nextAction;
- private action_state_t state;
- private List detectedMarkers;
- private float then;
+ public class BombGameAutomaticActionSummary extends AutomaticActionSummary{
+ private int numCombinationBombs;
+ private int numInclinationBombs;
+ private int numWireBombs;
+
+ public BombGameAutomaticActionSummary(){
+ reset();
+ }
+
+ public int getNumCombinationBombs() {
+ return numCombinationBombs;
+ }
+
+ public int getNumInclinationBombs() {
+ return numInclinationBombs;
+ }
+
+ public int getNumWireBombs() {
+ return numWireBombs;
+ }
+
+ public void addCombinationBomb(){
+ numCombinationBombs++;
+ }
+
+ public void addInclinationBomb(){
+ numInclinationBombs++;
+ }
+
+ public void addWireBomb(){
+ numWireBombs++;
+ }
+
+ @Override
+ public void reset() {
+ this.numCombinationBombs = 0;
+ this.numInclinationBombs = 0;
+ this.numWireBombs = 0;
+ }
+ }
+
+ private automatic_action_t nextAction;
+ private action_state_t state;
+ private List detectedMarkers;
+ private float then;
+ private float now;
+ private GroupManager manager;
+ private BombGameAutomaticActionSummary summary;
public BombGameAutomaticActionPerformer(){
nextAction = automatic_action_t.NO_ACTION;
state = action_state_t.START;
detectedMarkers = new LinkedList();
then = 0.0f;
+ now = 0.0f;
+ manager = null;
+ summary = new BombGameAutomaticActionSummary();
}
@Override
public boolean performAutomaticAction(int lightSensorReading, MarkerData markers) throws IllegalStateException, IllegalArgumentException{
- boolean finish = false;
- int detectedCode = -1;
- float now, deltaT;
+ BombComponent bomb;
+ boolean finish = false;
+ boolean markerDetected = false;
+ int detectedCode = -1;
+ ImmutableBag entities = null;
+ float deltaT;
+ World world;
+
+ if(manager == null){
+ world = GameGlobals.getGameWorld();
+ if(world == null)
+ throw new IllegalStateException("World is null after getGameWorld().");
+
+ manager = world.getManager(GroupManager.class);
+ if(manager == null)
+ throw new IllegalStateException("World has no group managers.");
+ }
if(markers == null)
throw new IllegalArgumentException("Markers is null");
switch(state){
case START:
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is START.");
+ summary.reset();
nextAction = automatic_action_t.ROTATE_90;
state = action_state_t.WALK_FORWARD;
finish = false;
break;
case WALK_FORWARD:
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is WALK_FORWARD.");
if(lightSensorReading >= GOAL_FLOOR_MIN_LUMINANCE){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Found goal.");
nextAction = automatic_action_t.STOP;
- state = action_state_t.END;
+ state = action_state_t.FINISHING;
}else{
if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE && lightSensorReading < GOAL_FLOOR_MIN_LUMINANCE){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): There is a marker nearby.");
nextAction = automatic_action_t.STOP;
state = action_state_t.DETECT_MARKER;
then = Gdx.graphics.getDeltaTime();
}else{
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Walking.");
nextAction = automatic_action_t.GO_FORWARD;
}
}
@@ -77,35 +151,68 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
break;
case DETECT_MARKER:
- for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is DETECT_MARKER.");
+ for(int i = 0; !markerDetected && i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
// Check if this marker has not been detected already.
for(Integer code : detectedMarkers){
if(markers.markerCodes[i] == code){
- i = ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS;
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Marker already detected.");
+ markerDetected = true;
break;
}
}
// If the marker has not been detected before then examine it.
- if(i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS){
+ if(!markerDetected){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): New marker detected.");
detectedCode = markers.markerCodes[i];
- // TODO: If marker is a bomb then add it to the summary.
+ entities = manager.getEntities(Integer.toString(detectedCode));
+
+ for(int e = 0; entities != null && e < entities.size() && entities.get(e) != null; e++){
+ bomb = entities.get(e).getComponent(BombComponent.class);
+
+ if(bomb == null){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Entity has no bomb component. Skipping.");
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Adding bomb.");
+ switch(bomb.bombType){
+ case COMBINATION:
+ summary.addCombinationBomb();
+ break;
+ case INCLINATION:
+ summary.addInclinationBomb();
+ break;
+ case WIRES:
+ summary.addWireBomb();
+ break;
+ default:
+ throw new IllegalStateException("Unrecognized bomb type.");
+ }
+ break;
+ }
+ }
+
+ break;
}
}
- if(detectedCode == -1)
+ if(!markerDetected && detectedCode != -1)
detectedMarkers.add(detectedCode);
if(lightSensorReading < MARKER_NEARBY_FLOOR_MIN_LUMINANCE){
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Switching to WALK_FORWARD.");
state = action_state_t.WALK_FORWARD;
nextAction = automatic_action_t.STOP;
then = 0.0f;
+ now = 0.0f;
}else{
- now = Gdx.graphics.getDeltaTime();
- deltaT = now - then;
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Clearing MARKER_NEARBY_FLOOR.");
+ now += Gdx.graphics.getDeltaTime();
+ deltaT = now - then;
if(deltaT >= 2.0f){
nextAction = automatic_action_t.GO_FORWARD;
then = Gdx.graphics.getDeltaTime();
+ now = 0.0f;
}
}
@@ -114,16 +221,20 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
break;
case FINISHING:
- detectedMarkers.clear();
- state = action_state_t.END;
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is FINISHING.");
+ state = action_state_t.END;
nextAction = automatic_action_t.RECENTER;
- finish = false;
+ finish = false;
break;
case END:
- state = action_state_t.START;
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is END.");
nextAction = automatic_action_t.NO_ACTION;
- finish = true;
+ state = action_state_t.START;
+ finish = true;
+ now = 0.0f;
+ then = 0.0f;
+ detectedMarkers.clear();
break;
default:
@@ -151,4 +262,19 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
return automatic_action_t.RECENTER;
}
}
+
+ @Override
+ public AutomaticActionSummary getSummary() {
+ return (AutomaticActionSummary)summary;
+ }
+
+ @Override
+ public void reset() {
+ Gdx.app.log(TAG, CLASS_NAME + ".reset(): Reset requested.");
+ detectedMarkers.clear();
+ summary.reset();
+ state = action_state_t.START;
+ nextAction = automatic_action_t.NO_ACTION;
+ then = 0.0f;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java
new file mode 100644
index 0000000..440e649
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2014 Miguel Angel Astor Romero
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.AutomaticActionSummary;
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionSummaryOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionPerformer.BombGameAutomaticActionSummary;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
+
+public class BombGameAutomaticActionSummaryOverlay extends AutomaticActionSummaryOverlayBase{
+ private static final float CANNONICAL_SCREEN_WIDTH = 800.0f;
+
+ private Texture inclinationBombTexture;
+ private Texture combinationBombTexture;
+ private Texture wireBombTexture;
+ private BitmapFont font;
+ private BitmapFont titleFont;
+ private Sprite inclinationBomb;
+ private Sprite combinationBomb;
+ private Sprite wireBomb;
+ private float inclinationX;
+ private float combinationX;
+ private float wireX;
+ private float inclinationY;
+ private float combinationY;
+ private float wireY;
+ private float titleWidth;
+ private float titleHeight;
+
+ public BombGameAutomaticActionSummaryOverlay(){
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+
+ inclinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/incl_bomb.png"));
+ combinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/comb_bomb.png"));
+ wireBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/wire_bomb.png"));
+
+ inclinationBomb = new Sprite(inclinationBombTexture);
+ combinationBomb = new Sprite(combinationBombTexture);
+ wireBomb = new Sprite(wireBombTexture);
+
+ inclinationBomb.setSize(inclinationBomb.getWidth() * 0.5f, inclinationBomb.getHeight() * 0.5f);
+ combinationBomb.setSize(combinationBomb.getWidth() * 0.5f, combinationBomb.getHeight() * 0.5f);
+ wireBomb.setSize(wireBomb.getWidth() * 0.5f, wireBomb.getHeight() * 0.5f);
+
+ combinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - combinationBomb.getWidth(), -(combinationBomb.getHeight() / 2.0f));
+ inclinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - inclinationBomb.getWidth(), combinationBomb.getY() + combinationBomb.getHeight() + 10.0f);
+ wireBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - wireBomb.getWidth(), combinationBomb.getY() - wireBomb.getHeight() - 10.0f);
+
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+
+ font = fontGenerator.generateFont(fontParameters);
+ font.setColor(Color.YELLOW);
+
+ fontParameters.size = (int)(90.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ titleFont = fontGenerator.generateFont(fontParameters);
+
+ fontGenerator.dispose();
+
+ inclinationX = inclinationBomb.getX() + inclinationBomb.getWidth() + 15.0f;
+ combinationX = combinationBomb.getX() + combinationBomb.getWidth() + 15.0f;
+ wireX = wireBomb.getX() + wireBomb.getWidth() + 15.0f;
+
+ inclinationY = inclinationBomb.getY() + (inclinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
+ combinationY = combinationBomb.getY() + (combinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
+ wireY = wireBomb.getY() + (wireBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
+
+ titleWidth = titleFont.getBounds("Summary").width;
+ titleHeight = titleFont.getBounds("Summary").height;
+ }
+
+ @Override
+ public void dispose() {
+ inclinationBombTexture.dispose();
+ combinationBombTexture.dispose();
+ wireBombTexture.dispose();
+ font.dispose();
+ titleFont.dispose();
+ }
+
+ @Override
+ public void render(SpriteBatch batch, AutomaticActionSummary summary) throws ClassCastException{
+ BombGameAutomaticActionSummary bombGameSummary;
+
+ if(!(summary instanceof BombGameAutomaticActionSummary))
+ throw new ClassCastException("Summary is not a bomb game summary.");
+
+ bombGameSummary = (BombGameAutomaticActionSummary)summary;
+
+ inclinationBomb.draw(batch);
+ combinationBomb.draw(batch);
+ wireBomb.draw(batch);
+
+ font.draw(batch, String.format("Inclination bombs: %d", bombGameSummary.getNumInclinationBombs()), inclinationX, inclinationY);
+ font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY);
+ font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);
+
+ titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
index 8369159..fcfdd2a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
@@ -269,7 +269,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb;
- BombComponent bombComponent = new BombComponent(currentBombId, type);
// Create a bomb entity and add it's generic components.
bomb = world.createEntity();
@@ -277,54 +276,54 @@ public class BombGameEntityCreator extends EntityCreatorBase{
bomb.addComponent(new EnvironmentComponent(parameters.environment));
bomb.addComponent(new ShaderComponent(parameters.shader));
bomb.addComponent(new MarkerCodeComponent(parameters.markerCode));
- bomb.addComponent(bombComponent);
+ bomb.addComponent(new BombComponent(currentBombId, type));
bomb.addComponent(new VisibilityComponent());
// Add the collision and render models depending on the bomb type.
if(type == bomb_type_t.COMBINATION){
bomb.addComponent(new RenderModelComponent(combinationBombModel));
bomb.addComponent(new CollisionModelComponent(combinationBombCollisionModel));
- addBombCombinationButtons(parameters, bombComponent);
+ addBombCombinationButtons(parameters);
if(DEBUG_RENDER_BOMB_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(combinationBombCollisionModel, parameters, false);
}else if(type == bomb_type_t.INCLINATION){
bomb.addComponent(new RenderModelComponent(inclinationBombModel));
bomb.addComponent(new CollisionModelComponent(inclinationBombCollisionModel));
- addBombInclinationButton(parameters, bombComponent);
+ addBombInclinationButton(parameters);
if(DEBUG_RENDER_BOMB_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(inclinationBombCollisionModel, parameters, false);
}else if(type == bomb_type_t.WIRES){
bomb.addComponent(new RenderModelComponent(wiresBombModel));
bomb.addComponent(new CollisionModelComponent(wiresBombCollisionModel));
- addBombWires(parameters, bombComponent);
+ addBombWires(parameters);
if(DEBUG_RENDER_BOMB_COLLISION_MODELS)
addDebugCollisionModelRenderingEntity(wiresBombCollisionModel, parameters, false);
}else
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
- // Add the bomb and increase the id for the next one.
- //groupManager.add(bomb, CollisionDetectionSystem.COLLIDABLE_OBJECT);
+ // Add the bomb to the world and the respective marker group. Then increase the id for the next bomb.
+ groupManager.add(bomb, Integer.toString(parameters.markerCode));
bomb.addToWorld();
entities.add(bomb);
currentBombId++;
NUM_BOMBS++;
}
- private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){
+ private void addBombCombinationButtons(EntityParameters parameters){
Entity button1, button2, button3, button4;
- button1 = addBombParaphernalia(combinationButton1Model, combinationButton1CollisionModel, bomb, parameters);
- button2 = addBombParaphernalia(combinationButton2Model, combinationButton2CollisionModel, bomb, parameters);
- button3 = addBombParaphernalia(combinationButton3Model, combinationButton3CollisionModel, bomb, parameters);
- button4 = addBombParaphernalia(combinationButton4Model, combinationButton4CollisionModel, bomb, parameters);
+ button1 = addBombParaphernalia(combinationButton1Model, combinationButton1CollisionModel, parameters);
+ button2 = addBombParaphernalia(combinationButton2Model, combinationButton2CollisionModel, parameters);
+ button3 = addBombParaphernalia(combinationButton3Model, combinationButton3CollisionModel, parameters);
+ button4 = addBombParaphernalia(combinationButton4Model, combinationButton4CollisionModel, parameters);
- button1.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_1));
- button2.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_2));
- button3.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_3));
- button4.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.COM_BUTTON_4));
+ button1.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.COM_BUTTON_1));
+ button2.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.COM_BUTTON_2));
+ button3.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.COM_BUTTON_3));
+ button4.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.COM_BUTTON_4));
button1.addToWorld();
button2.addToWorld();
@@ -332,31 +331,31 @@ public class BombGameEntityCreator extends EntityCreatorBase{
button4.addToWorld();
}
- private void addBombInclinationButton(EntityParameters parameters, BombComponent bomb){
+ private void addBombInclinationButton(EntityParameters parameters){
Entity button;
- button = addBombParaphernalia(inclinationBombButtonModel, inclinationBombButtonCollisionModel, bomb, parameters);
- button.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BIG_BUTTON));
+ button = addBombParaphernalia(inclinationBombButtonModel, inclinationBombButtonCollisionModel, parameters);
+ button.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.BIG_BUTTON));
button.addToWorld();
}
- private void addBombWires(EntityParameters parameters, BombComponent bomb){
+ private void addBombWires(EntityParameters parameters){
Entity wire1, wire2, wire3;
- wire1 = addBombParaphernalia(wiresBombModelWire1, wiresBombCollisionModelWire1, bomb, parameters);
- wire2 = addBombParaphernalia(wiresBombModelWire2, wiresBombCollisionModelWire2, bomb, parameters);
- wire3 = addBombParaphernalia(wiresBombModelWire3, wiresBombCollisionModelWire3, bomb, parameters);
+ wire1 = addBombParaphernalia(wiresBombModelWire1, wiresBombCollisionModelWire1, parameters);
+ wire2 = addBombParaphernalia(wiresBombModelWire2, wiresBombCollisionModelWire2, parameters);
+ wire3 = addBombParaphernalia(wiresBombModelWire3, wiresBombCollisionModelWire3, parameters);
- wire1.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BOMB_WIRE_1));
- wire2.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BOMB_WIRE_2));
- wire3.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.BOMB_WIRE_3));
+ wire1.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.BOMB_WIRE_1));
+ wire2.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.BOMB_WIRE_2));
+ wire3.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.BOMB_WIRE_3));
wire1.addToWorld();
wire2.addToWorld();
wire3.addToWorld();
}
- private Entity addBombParaphernalia(Model renderModel, Model collisionModel, BombComponent bomb, EntityParameters parameters){
+ private Entity addBombParaphernalia(Model renderModel, Model collisionModel, EntityParameters parameters){
Entity thing;
thing = world.createEntity();
@@ -365,7 +364,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
thing.addComponent(new ShaderComponent(parameters.shader));
thing.addComponent(new RenderModelComponent(renderModel));
thing.addComponent(new CollisionModelComponent(collisionModel));
- thing.addComponent(new BombComponent(bomb));
thing.addComponent(new VisibilityComponent());
thing.addComponent(new MarkerCodeComponent(parameters.markerCode));
thing.addComponent(new CollisionDetectionComponent());
@@ -393,7 +391,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
- frame.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR_FRAME));
+ frame.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.DOOR_FRAME));
groupManager.add(frame, Integer.toString(parameters.markerCode));
frame.addToWorld();
@@ -409,7 +407,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
doorColInstance = door.getComponent(CollisionModelComponent.class).instance;
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation, doorColInstance));
door.addComponent(new CollisionDetectionComponent());
- door.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.DOOR));
+ door.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.DOOR));
groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
groupManager.add(door, Integer.toString(parameters.markerCode));
groupManager.add(door, DOORS_GROUP);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityTypeComponent.java
similarity index 91%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityTypeComponent.java
index 61861ae..b472122 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameObjectTypeComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityTypeComponent.java
@@ -17,7 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.game.bombgame;
import com.artemis.Component;
-public class BombGameObjectTypeComponent extends Component {
+public class BombGameEntityTypeComponent extends Component {
public static final int BOMB_WIRE_1 = 10;
public static final int BOMB_WIRE_2 = 11;
public static final int BOMB_WIRE_3 = 12;
@@ -32,7 +32,7 @@ public class BombGameObjectTypeComponent extends Component {
public int type;
- public BombGameObjectTypeComponent(int type){
+ public BombGameEntityTypeComponent(int type){
this.type = type;
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
index aa82fb2..b3fd37c 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
@@ -53,7 +53,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
}
- @Mapper ComponentMapper typeMapper;
+ @Mapper ComponentMapper typeMapper;
@Mapper ComponentMapper animationMapper;
@Mapper ComponentMapper visibilityMapper;
@Mapper ComponentMapper markerMapper;
@@ -61,20 +61,20 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
@Mapper ComponentMapper fadeMapper;
private MarkerCodeComponent tempMarker;
- private BombGameObjectTypeComponent tempType;
+ private BombGameEntityTypeComponent tempType;
private GroupManager manager;
private int then;
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
- super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
+ super(Aspect.getAspectForAll(BombGameEntityTypeComponent.class));
manager = null;
then = 0;
}
@Override
protected void process(Entity e){
- BombGameObjectTypeComponent typeComponent;
+ BombGameEntityTypeComponent typeComponent;
if(manager == null)
manager = world.getManager(GroupManager.class);
@@ -82,28 +82,28 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
typeComponent = typeMapper.get(e);
switch(typeComponent.type){
- case BombGameObjectTypeComponent.BOMB_WIRE_1:
- case BombGameObjectTypeComponent.BOMB_WIRE_2:
- case BombGameObjectTypeComponent.BOMB_WIRE_3:
+ case BombGameEntityTypeComponent.BOMB_WIRE_1:
+ case BombGameEntityTypeComponent.BOMB_WIRE_2:
+ case BombGameEntityTypeComponent.BOMB_WIRE_3:
processWireBomb(e);
break;
- case BombGameObjectTypeComponent.BIG_BUTTON:
+ case BombGameEntityTypeComponent.BIG_BUTTON:
processInclinationBomb(e);
break;
- case BombGameObjectTypeComponent.COM_BUTTON_1:
- case BombGameObjectTypeComponent.COM_BUTTON_2:
- case BombGameObjectTypeComponent.COM_BUTTON_3:
- case BombGameObjectTypeComponent.COM_BUTTON_4:
+ case BombGameEntityTypeComponent.COM_BUTTON_1:
+ case BombGameEntityTypeComponent.COM_BUTTON_2:
+ case BombGameEntityTypeComponent.COM_BUTTON_3:
+ case BombGameEntityTypeComponent.COM_BUTTON_4:
processCombinationBomb(e);
break;
- case BombGameObjectTypeComponent.DOOR:
+ case BombGameEntityTypeComponent.DOOR:
processDoor(e);
break;
- case BombGameObjectTypeComponent.FADE_EFFECT:
+ case BombGameEntityTypeComponent.FADE_EFFECT:
processFade(e);
break;
@@ -120,7 +120,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
private void processWireBomb(Entity b){
CollisionDetectionComponent collision;
MarkerCodeComponent marker;
- BombGameObjectTypeComponent wireType;
+ BombGameEntityTypeComponent wireType;
// Get this wire's parameters.
collision = collisionMapper.getSafe(b);
@@ -140,7 +140,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld();
- if(wireType.type != BombGameObjectTypeComponent.BOMB_WIRE_1){
+ if(wireType.type != BombGameEntityTypeComponent.BOMB_WIRE_1){
Gdx.app.log(TAG, CLASS_NAME + ".processWireBomb(): Wire bomb exploded.");
createFadeOutEffect();
reducePlayerLivesByOne();
@@ -163,7 +163,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
combination_button_state_t state;
CollisionDetectionComponent collision;
MarkerCodeComponent marker;
- BombGameObjectTypeComponent buttonType;
+ BombGameEntityTypeComponent buttonType;
// Get this wire's parameters.
collision = collisionMapper.getSafe(b);
@@ -360,10 +360,10 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
// Enable collisions with the corresponding door frame entity. Disable collisions with other related entities.
if(tempMarker != null) tempMarker.enabled = false;
if(tempType != null){
- if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME && tempType.type != BombGameObjectTypeComponent.DOOR){
+ if(tempType.type != BombGameEntityTypeComponent.DOOR_FRAME && tempType.type != BombGameEntityTypeComponent.DOOR){
manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
manager.remove(related.get(i), Integer.toString(markerCode));
- }else if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
+ }else if(tempType.type != BombGameEntityTypeComponent.DOOR_FRAME){
manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}
}
@@ -373,7 +373,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
/**
* Checks if a combination bomb is being disabled in the correct sequence.
*
- * @param buttonType A number between {@link BombGameObjectTypeComponent.COM_BUTTON_1} and {@link BombGameObjectTypeComponent.COM_BUTTON_4}.
+ * @param buttonType A number between {@link BombGameEntityTypeComponent.COM_BUTTON_1} and {@link BombGameEntityTypeComponent.COM_BUTTON_4}.
* @param markerCode A marker code between [0, 1023], inclusive.
* @return The current state of the bomb.
* @throws IllegalArgumentException If marker code is not in range or if buttonType is not valid.
@@ -384,7 +384,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
int remainingButtons = 0;
ImmutableBag related;
- if(buttonType < BombGameObjectTypeComponent.COM_BUTTON_1 || buttonType > BombGameObjectTypeComponent.COM_BUTTON_4)
+ if(buttonType < BombGameEntityTypeComponent.COM_BUTTON_1 || buttonType > BombGameEntityTypeComponent.COM_BUTTON_4)
throw new IllegalArgumentException("Button is not a valid combination bomb button: " + Integer.toString(buttonType));
if(markerCode < 0 || markerCode > 1023)
@@ -398,7 +398,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
if(tempType == null) continue;
- if(tempType.type >= BombGameObjectTypeComponent.COM_BUTTON_1 && tempType.type <= BombGameObjectTypeComponent.COM_BUTTON_4){
+ if(tempType.type >= BombGameEntityTypeComponent.COM_BUTTON_1 && tempType.type <= BombGameEntityTypeComponent.COM_BUTTON_4){
if(tempType.type >= buttonType){
// If this remaining button is a correct one then skip it.
remainingButtons++;
@@ -427,7 +427,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
*/
private void createFadeOutEffect(){
Entity effect = world.createEntity();
- effect.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.FADE_EFFECT));
+ effect.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.FADE_EFFECT));
effect.addComponent(new FadeEffectComponent());
effect.addToWorld();
}
@@ -437,7 +437,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
*/
private void createFadeInEffect(){
Entity effect = world.createEntity();
- effect.addComponent(new BombGameObjectTypeComponent(BombGameObjectTypeComponent.FADE_EFFECT));
+ effect.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.FADE_EFFECT));
effect.addComponent(new FadeEffectComponent(true));
effect.addToWorld();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
index d45a7d5..b08a563 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
@@ -29,7 +29,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Disposable;
public class BombGamePlayerSystem extends PlayerSystemBase implements Disposable{
- private static final float HEART_Y_POS = (Utils.getScreenHeight() / 2) - 69;
+ private static final float HEART_Y_POS = (Utils.getScreenHeightWithOverscan() / 2) - 69;
@Mapper ComponentMapper playerMapper;
private SpriteBatch batch;
@@ -50,7 +50,7 @@ public class BombGamePlayerSystem extends PlayerSystemBase implements Disposable
BombGamePlayerComponent player = playerMapper.get(e);
// Render remaining lives.
- heartXPos = -(Utils.getScreenWidth() / 2) + 5;
+ heartXPos = -(Utils.getScreenWidthWithOverscan() / 2) + 5;
for(int i = 0; i < player.lives; ++i){
heart.setPosition(heartXPos, HEART_Y_POS);
heart.draw(batch);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
index 3ad1abb..cdfea66 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
@@ -85,6 +85,7 @@ public class AutomaticActionState extends BaseState{
private boolean ignoreBackKey;
private boolean automaticActionEnabled;
private AutomaticActionPerformerBase automaticActionPerformer;
+ private automatic_action_t previousAction;
// Cameras.
private OrthographicCamera unitaryOrthographicCamera;
@@ -136,6 +137,7 @@ public class AutomaticActionState extends BaseState{
automaticActionEnabled = false;
startButtonPressed = false;
automaticActionPerformer = GameGlobals.getAutomaticActionPerformer();
+ previousAction = automatic_action_t.NO_ACTION;
// Set up the cameras.
pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
@@ -306,11 +308,11 @@ public class AutomaticActionState extends BaseState{
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
}else{
float xSize = Gdx.graphics.getHeight() * (w / h);
- renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
+ renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
- frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
+ frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
}
@@ -342,6 +344,14 @@ public class AutomaticActionState extends BaseState{
data = null;
}
+ @Override
+ public void pause(){
+ automaticActionPerformer.reset();
+ startButton.setDisabled(false);
+ ignoreBackKey = false;
+ automaticActionEnabled = false;
+ }
+
@Override
public void dispose(){
SensorReportThread.freeInstance();
@@ -457,104 +467,109 @@ public class AutomaticActionState extends BaseState{
if(!automaticActionPerformer.performAutomaticAction(sensorThread.getLightSensorReading(), data)){
nextAction = automaticActionPerformer.getNextAction();
- switch(nextAction){
- case GO_BACKWARDS:
- event1 = new MotorEvent();
- event2 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_A);
- event1.setPower((byte)-100);
- event2.setMotor(motor_t.MOTOR_C);
- event2.setPower((byte)-100);
- break;
+ if(nextAction != previousAction){
+ switch(nextAction){
+ case GO_BACKWARDS:
+ event1 = new MotorEvent();
+ event2 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)-20);
+ event2.setMotor(motor_t.MOTOR_C);
+ event2.setPower((byte)-20);
+ break;
- case GO_FORWARD:
- event1 = new MotorEvent();
- event2 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_A);
- event1.setPower((byte)100);
- event2.setMotor(motor_t.MOTOR_C);
- event2.setPower((byte)100);
- break;
+ case GO_FORWARD:
+ event1 = new MotorEvent();
+ event2 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)20);
+ event2.setMotor(motor_t.MOTOR_C);
+ event2.setPower((byte)20);
+ break;
- case STOP:
- event1 = new MotorEvent();
- event2 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_A);
- event1.setPower((byte)0);
- event2.setMotor(motor_t.MOTOR_C);
- event2.setPower((byte)0);
- break;
+ case STOP:
+ event1 = new MotorEvent();
+ event2 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)0);
+ event2.setMotor(motor_t.MOTOR_C);
+ event2.setPower((byte)0);
+ break;
- case ROTATE_90:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.ROTATE_90);
- event1.setPower((byte)100);
- break;
+ case ROTATE_90:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.ROTATE_90);
+ event1.setPower((byte)20);
+ break;
- case RECENTER:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.RECENTER);
- event1.setPower((byte)100);
- break;
+ case RECENTER:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.RECENTER);
+ event1.setPower((byte)20);
+ break;
- case TURN_LEFT:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_A);
- event1.setPower((byte)100);
- break;
+ case TURN_LEFT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)20);
+ break;
- case TURN_RIGHT:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_C);
- event1.setPower((byte)100);
- break;
+ case TURN_RIGHT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_C);
+ event1.setPower((byte)20);
+ break;
- case BACKWARDS_LEFT:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_C);
- event1.setPower((byte)-100);
- break;
+ case BACKWARDS_LEFT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_C);
+ event1.setPower((byte)-20);
+ break;
- case BACKWARDS_RIGHT:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_A);
- event1.setPower((byte)-100);
- break;
+ case BACKWARDS_RIGHT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_A);
+ event1.setPower((byte)-20);
+ break;
- case LOOK_RIGHT:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_B);
- event1.setPower((byte)25);
- break;
+ case LOOK_RIGHT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_B);
+ event1.setPower((byte)25);
+ break;
- case LOOK_LEFT:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_B);
- event1.setPower((byte)-25);
- break;
+ case LOOK_LEFT:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_B);
+ event1.setPower((byte)-25);
+ break;
- case STOP_LOOKING:
- event1 = new MotorEvent();
- event1.setMotor(motor_t.MOTOR_B);
- event1.setPower((byte)0);
- break;
+ case STOP_LOOKING:
+ event1 = new MotorEvent();
+ event1.setMotor(motor_t.MOTOR_B);
+ event1.setPower((byte)0);
+ break;
- case NO_ACTION:
- default:
- break;
+ case NO_ACTION:
+ default:
+ break;
+ }
+
+ if(event1 != null)
+ queue.addEvent(event1);
+ if(event2 != null)
+ queue.addEvent(event2);
+
+ previousAction = nextAction;
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Skipping repeated action.");
}
- if(event1 != null)
- queue.addEvent(event1);
- if(event2 != null)
- queue.addEvent(event2);
-
}else{
- // TODO: Go to summary screen.
startButton.setDisabled(false);
ignoreBackKey = false;
automaticActionEnabled = false;
- core.nextState = game_states_t.MAIN_MENU;
+ core.nextState = game_states_t.SUMMARY;
}
}catch(IllegalArgumentException e){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
new file mode 100644
index 0000000..f5285b3
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
@@ -0,0 +1,330 @@
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionSummaryOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.controllers.Controller;
+import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.Texture.TextureFilter;
+import com.badlogic.gdx.graphics.Texture.TextureWrap;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
+import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
+import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
+
+public class AutomaticActionSummaryState extends BaseState{
+ private static final String TAG = "AUTO_SUMMARY";
+ private static final String CLASS_NAME = AutomaticActionSummaryState.class.getSimpleName();
+ private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
+
+ // Helper fields.
+ private float u_scaling[];
+ private float u_displacement;
+
+ // Buttons and other gui components.
+ private TextButton continueButton;
+ private Rectangle continueButtonBBox;
+ private Sprite background;
+ private Texture backgroundTexture;
+ private ShaderProgram backgroundShader;
+ private Texture ouyaOButtonTexture;
+ private Sprite ouyaOButton;
+ private boolean oButtonPressed;
+
+ // Graphic data for the start button.
+ private Texture buttonEnabledTexture;
+ private Texture buttonDisabledTexture;
+ private Texture buttonPressedTexture;
+ private NinePatch buttonEnabled9p;
+ private NinePatch buttonDisabled9p;
+ private NinePatch buttonPressed9p;
+ private BitmapFont font;
+
+ // Summary overlay related fields.
+ AutomaticActionPerformerBase automaticActionPerformer;
+ AutomaticActionSummaryOverlayBase summaryOverlay;
+
+ // Button touch helper fields.
+ private boolean continueButtonTouched;
+ private int continueButtonTouchPointer;
+
+ public AutomaticActionSummaryState(NxtARCore core) throws IllegalArgumentException{
+ TextButtonStyle textButtonStyle;
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
+
+ this.core = core;
+ this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ oButtonPressed = false;
+ automaticActionPerformer = GameGlobals.getAutomaticActionPerformer();
+ summaryOverlay = GameGlobals.getAutomaticActionSummaryOverlay();
+
+ // Create the start button background.
+ buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
+ buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
+ buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
+ buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
+
+ // Create the start button font.
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+ font = fontGenerator.generateFont(fontParameters);
+ fontGenerator.dispose();
+
+ // Create the contine button.
+ textButtonStyle = new TextButtonStyle();
+ textButtonStyle.font = font;
+ textButtonStyle.up = new NinePatchDrawable(buttonEnabled9p);
+ textButtonStyle.checked = new NinePatchDrawable(buttonPressed9p);
+ textButtonStyle.disabled = new NinePatchDrawable(buttonDisabled9p);
+ textButtonStyle.fontColor = new Color(Color.BLACK);
+ textButtonStyle.downFontColor = new Color(Color.WHITE);
+ textButtonStyle.disabledFontColor = new Color(Color.BLACK);
+
+ continueButton = new TextButton("Continue", textButtonStyle);
+ continueButton.setText("Continue");
+ continueButton.setPosition(-(continueButton.getWidth() / 2), -(Utils.getScreenHeightWithOverscan() / 2) + 10);
+ continueButtonBBox = new Rectangle(0, 0, continueButton.getWidth(), continueButton.getHeight());
+ continueButtonBBox.setPosition(continueButton.getX(), continueButton.getY());
+
+ // Set OUYA's O button.
+ if(Ouya.runningOnOuya){
+ ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
+ ouyaOButton = new Sprite(ouyaOButtonTexture);
+ ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ oButtonPressed = false;
+ }else{
+ ouyaOButtonTexture = null;
+ }
+
+ // Set up the background.
+ backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
+ backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
+ backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ background = new Sprite(backgroundTexture);
+ background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
+
+ backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + "_vert.glsl"), Gdx.files.internal(SHADER_PATH + "_frag.glsl"));
+ if(!backgroundShader.isCompiled()){
+ Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
+ Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
+ backgroundShader = null;
+ }
+
+ u_scaling = new float[2];
+ 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();
+ continueButtonTouched = false;
+ continueButtonTouchPointer = -1;
+ stateActive = false;
+ }
+
+ @Override
+ public void render(float delta){
+ Gdx.gl.glClearColor(1, 1, 1, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ core.batch.begin();{
+
+ // Render background.
+ core.batch.disableBlending();
+ drawBackground(core.batch);
+ core.batch.enableBlending();
+
+ summaryOverlay.render(core.batch, automaticActionPerformer.getSummary());
+
+ // Render buttons.
+ continueButton.draw(core.batch, 1.0f);
+ if(Ouya.runningOnOuya)
+ ouyaOButton.draw(core.batch);
+
+ }core.batch.end();
+ }
+
+ @Override
+ public void dispose(){
+ buttonEnabledTexture.dispose();
+ buttonDisabledTexture.dispose();
+ buttonPressedTexture.dispose();
+ if(ouyaOButtonTexture != null)
+ ouyaOButtonTexture.dispose();
+ backgroundTexture.dispose();
+ if(backgroundShader != null) backgroundShader.dispose();
+ font.dispose();
+ }
+
+ private void drawBackground(SpriteBatch batch){
+ 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
+ public void onStateSet(){
+ stateActive = true;
+ Gdx.input.setInputProcessor(this);
+ Gdx.input.setCatchBackKey(true);
+ Gdx.input.setCatchMenuKey(true);
+ }
+
+ @Override
+ public void onStateUnset(){
+ stateActive = false;
+ Gdx.input.setInputProcessor(null);
+ Gdx.input.setCatchBackKey(false);
+ Gdx.input.setCatchMenuKey(false);
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; INPUT LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean touchDown(int screenX, int screenY, int pointer, int button){
+ unprojectTouch(screenX, screenY);
+
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
+
+ if(!continueButton.isDisabled() && continueButtonBBox.contains(touchPointWorldCoords)){
+ continueButton.setChecked(true);
+ continueButtonTouched = true;
+ continueButtonTouchPointer = pointer;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean touchUp(int screenX, int screenY, int pointer, int button){
+ unprojectTouch(screenX, screenY);
+
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
+
+ if(!continueButton.isDisabled() && continueButtonBBox.contains(touchPointWorldCoords) && continueButtonTouched){
+ continueButton.setChecked(false);
+ continueButtonTouched = false;
+ continueButtonTouchPointer = -1;
+ core.nextState = game_states_t.MAIN_MENU;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean touchDragged(int screenX, int screenY, int pointer){
+ unprojectTouch(screenX, screenY);
+
+ if(!continueButton.isDisabled() && continueButtonTouched && pointer == continueButtonTouchPointer && !continueButtonBBox.contains(touchPointWorldCoords)){
+ continueButtonTouchPointer = -1;
+ continueButtonTouched = false;
+ continueButton.setChecked(false);
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean keyDown(int keycode){
+ if(keycode == Input.Keys.BACK){
+ core.nextState = game_states_t.MAIN_MENU;
+ return true;
+ }
+ return false;
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; CONTROLLER LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean buttonDown(Controller controller, int buttonCode){
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O && !continueButton.isDisabled()){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
+ oButtonPressed = true;
+ continueButton.setChecked(true);
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean buttonUp(Controller controller, int buttonCode){
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
+ if(oButtonPressed){
+ oButtonPressed = false;
+ continueButton.setChecked(false);
+ core.nextState = game_states_t.MAIN_MENU;
+ }
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index e02542e..e131b06 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -246,8 +246,8 @@ public class InGameState extends BaseState{
@Override
public void render(float delta){
- final float MIN_SLIDER_X = correctAngleLedOnSprite != null ? -(Utils.getScreenWidth() / 2) + 5 + correctAngleLedOnSprite.getWidth() : -(Utils.getScreenWidth() / 2) + 5;
- final float MAX_SLIDER_X = correctAngleLedOnSprite != null ? (Utils.getScreenWidth() / 2) - 5 - correctAngleLedOnSprite.getWidth(): (Utils.getScreenWidth() / 2) - 5;
+ final float MIN_SLIDER_X = correctAngleLedOnSprite != null ? -(Utils.getScreenWidthWithOverscan() / 2) + 5 + correctAngleLedOnSprite.getWidth() : -(Utils.getScreenWidthWithOverscan() / 2) + 5;
+ final float MAX_SLIDER_X = correctAngleLedOnSprite != null ? (Utils.getScreenWidthWithOverscan() / 2) - 5 - correctAngleLedOnSprite.getWidth(): (Utils.getScreenWidthWithOverscan() / 2) - 5;
int w, h;
float t, xSliderPos;
byte[] frame;
@@ -362,11 +362,11 @@ public class InGameState extends BaseState{
}else{
float xSize = Gdx.graphics.getHeight() * (w / h);
- renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
+ renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
- frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeight());
+ frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
}
@@ -595,7 +595,7 @@ public class InGameState extends BaseState{
orientationSliderTexture = new Texture(Gdx.files.internal("data/gfx/gui/slider_black.png"));
orientationSlider = new Sprite(orientationSliderTexture);
orientationSlider.setSize(orientationSlider.getWidth() * 0.25f, orientationSlider.getHeight() * 0.25f);
- orientationSlider.setPosition(-(orientationSlider.getWidth() / 2), (Utils.getScreenHeight() / 2) - orientationSlider.getHeight() - 5);
+ orientationSlider.setPosition(-(orientationSlider.getWidth() / 2), (Utils.getScreenHeightWithOverscan() / 2) - orientationSlider.getHeight() - 5);
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
index 7e65221..2b03546 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/MainMenuStateBase.java
@@ -65,8 +65,7 @@ public abstract class MainMenuStateBase extends BaseState{
protected Sprite cameraCalibratedLedOff;
protected Sprite assetsLoadedLedOn;
protected Sprite assetsLoadedLedOff;
-
- protected Sprite background;
+ protected Sprite background;
// Graphic data for the start button.
private Texture menuButtonEnabledTexture;
@@ -102,10 +101,8 @@ public abstract class MainMenuStateBase extends BaseState{
// Create the start button background.
menuButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
menuButtonEnabled9p = new NinePatch(new TextureRegion(menuButtonEnabledTexture, 0, 0, menuButtonEnabledTexture.getWidth(), menuButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
-
menuButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
menuButtonDisabled9p = new NinePatch(new TextureRegion(menuButtonDisabledTexture, 0, 0, menuButtonDisabledTexture.getWidth(), menuButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
-
menuButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
menuButtonPressed9p = new NinePatch(new TextureRegion(menuButtonPressedTexture, 0, 0, menuButtonPressedTexture.getWidth(), menuButtonPressedTexture.getHeight()), 49, 49, 45, 45);
@@ -118,7 +115,7 @@ public abstract class MainMenuStateBase extends BaseState{
font = fontGenerator.generateFont(fontParameters);
fontGenerator.dispose();
- // Create the start button.
+ // Create the buttons.
textButtonStyle = new TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p);
@@ -133,7 +130,6 @@ public abstract class MainMenuStateBase extends BaseState{
startButton.setDisabled(true);
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
- // Create the calibration button.
calibrationButton = new TextButton("Calibrate camera", textButtonStyle);
calibrationButton.setText("Calibrate camera");
calibrationButton.setDisabled(true);
@@ -150,13 +146,10 @@ public abstract class MainMenuStateBase extends BaseState{
region = new TextureRegion(ledOnTexture);
cameraCalibratedLedOn = new Sprite(region);
-
region = new TextureRegion(ledOffTexture);
cameraCalibratedLedOff = new Sprite(region);
-
region = new TextureRegion(ledOnTexture);
assetsLoadedLedOn = new Sprite(region);
-
region = new TextureRegion(ledOffTexture);
assetsLoadedLedOff = new Sprite(region);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
index 5809214..4390d7a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
@@ -36,9 +36,12 @@ public class OuyaMainMenuState extends MainMenuStateBase{
private int oButtonSelection;
private float ledYPos;
- public OuyaMainMenuState(final NxtARCore core){
+ public OuyaMainMenuState(final NxtARCore core) throws IllegalArgumentException{
super();
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
+
this.core = core;
// Set buttons.
@@ -50,7 +53,7 @@ public class OuyaMainMenuState extends MainMenuStateBase{
autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY());
//Set leds.
- ledYPos = -(Utils.getScreenHeight() / 2) + 10;
+ ledYPos = -(Utils.getScreenHeightWithOverscan() / 2) + 10;
cameraCalibratedLedOn.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f);
cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
@@ -111,9 +114,9 @@ public class OuyaMainMenuState extends MainMenuStateBase{
ouyaOButtonTexture.dispose();
}
- /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; BEGIN CONTROLLER LISTENER METHODS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; CONTROLLER LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean buttonDown(Controller controller, int buttonCode){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
index 8fb8331..763a1c1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/TabletMainMenuState.java
@@ -22,11 +22,16 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
public class TabletMainMenuState extends MainMenuStateBase{
+ private static final String CLASS_NAME = TabletMainMenuState.class.getSimpleName();
+
private float ledYPos;
- public TabletMainMenuState(final NxtARCore core){
+ public TabletMainMenuState(final NxtARCore core) throws IllegalArgumentException{
super();
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
+
this.core = core;
// Set buttons.
@@ -38,7 +43,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
autoButtonBBox.setPosition(autoButton.getX(), autoButton.getY());
// Set leds.
- ledYPos = -(Utils.getScreenHeight() / 2) + 10;
+ ledYPos = -(Utils.getScreenHeightWithOverscan() / 2) + 10;
cameraCalibratedLedOn.setSize(cameraCalibratedLedOn.getWidth() * 0.5f, cameraCalibratedLedOn.getHeight() * 0.5f);
cameraCalibratedLedOn.setPosition(-cameraCalibratedLedOn.getWidth() - 5, ledYPos);
cameraCalibratedLedOff.setSize(cameraCalibratedLedOff.getWidth() * 0.5f, cameraCalibratedLedOff.getHeight() * 0.5f);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
index dc13c2c..beda501 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
@@ -35,7 +35,7 @@ public abstract class ProjectConstants{
public static final float OVERSCAN;
public static final int MENU_BUTTON_FONT_SIZE;
- public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+ public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:";
public static final int MAXIMUM_NUMBER_OF_MARKERS = 5;
public static final int CALIBRATION_PATTERN_POINTS = 54;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
index 137fd52..677ab82 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
@@ -41,14 +41,14 @@ public abstract class Utils{
/**
* @return The width of the screen accounting for screen overscan.
*/
- public static int getScreenWidth(){
+ public static int getScreenWidthWithOverscan(){
return (int)(Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN);
}
/**
* @return The height of the screen accounting for screen overscan.
*/
- public static int getScreenHeight(){
+ public static int getScreenHeightWithOverscan(){
return (int)(Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
}
From 83e327545c2eedb9f961f50b5e7980373e8cbc45 Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 25 Jun 2014 16:28:27 -0430
Subject: [PATCH 28/34] Added enabling/disabling the collision detection
system.
---
.../nxtar/states/AutomaticActionState.java | 4 +++-
.../ciens/ccg/nxtar/states/InGameState.java | 2 ++
.../systems/CollisionDetectionSystem.java | 21 +++++++++++++++++--
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
index cdfea66..d08fa1b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
@@ -20,13 +20,14 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
-import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.automatic_action_t;
+import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
+import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -389,6 +390,7 @@ public class AutomaticActionState extends BaseState{
@Override
public void onStateSet(){
+ gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
stateActive = true;
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index e131b06..0f807fc 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -28,6 +28,7 @@ import ve.ucv.ciens.ccg.nxtar.input.UserInput;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
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.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
@@ -493,6 +494,7 @@ public class InGameState extends BaseState{
@Override
public void onStateSet(){
+ gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
stateActive = true;
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
index d1b24b2..600a061 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/CollisionDetectionSystem.java
@@ -40,12 +40,14 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
private GroupManager groupManager;
private BoundingBox colBB;
private BoundingBox targetBB;
+ private boolean collisionsEnabled;
@SuppressWarnings("unchecked")
public CollisionDetectionSystem(){
super(Aspect.getAspectForAll(CollisionModelComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
- colBB = new BoundingBox();
- targetBB = new BoundingBox();
+ colBB = new BoundingBox();
+ targetBB = new BoundingBox();
+ collisionsEnabled = true;
}
@Override
@@ -57,6 +59,9 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
CollisionDetectionComponent onCollisionTarget;
ImmutableBag collidables;
+ if(!collisionsEnabled)
+ return;
+
// Get this entity's known necessary components.
collision = collisionModelMapper.get(e);
onCollision = collisionDetectionMapper.get(e);
@@ -101,4 +106,16 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
}
}
}
+
+ public boolean isCollisionDetectionEnabled(){
+ return collisionsEnabled;
+ }
+
+ public void enableCollisions(){
+ this.collisionsEnabled = true;
+ }
+
+ public void disableCollisions(){
+ this.collisionsEnabled = false;
+ }
}
From 3288e3cb6b2bf31c86782d3e1a10f8e345ccadbe Mon Sep 17 00:00:00 2001
From: unknown
Date: Wed, 25 Jun 2014 16:43:01 -0430
Subject: [PATCH 29/34] Added some TODO's.
---
src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java | 6 ++++--
src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java | 1 +
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
index 96e57e1..d9a5adb 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
@@ -41,7 +41,7 @@ public abstract class GameGlobals{
private static World gameWorld = null;
private static ModelBatch modelBatch = null;
private static AutomaticActionPerformerBase automaticActionPerformer = null;
- private static AutomaticActionSummaryOverlayBase automaticActionSummaryOverlay = null;
+ private static AutomaticActionSummaryOverlayBase automaticActionSummaryOverlay = null;
public static void initGameSettings(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{
if(core == null)
@@ -104,7 +104,9 @@ public abstract class GameGlobals{
throw e;
}
}
-
+
+ // TODO: Create player processing system.
+
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
gameWorld.setSystem(new GeometrySystem());
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
index 1d8c0ac..047f193 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
@@ -26,6 +26,7 @@ public final class ScenarioImplementation{
public static Class entityCreatorClass = BombGameEntityCreator.class;
public static Class automaticActionPerformerClass = BombGameAutomaticActionPerformer.class;
public static Class automaticActionSummaryScreen = BombGameAutomaticActionSummaryOverlay.class;
+ // TODO: Add player processing system.
private ScenarioImplementation(){}
}
From 94c2bd6850c20e802b8b8abb096ae2e19aa5bb10 Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 26 Jun 2014 09:44:33 -0430
Subject: [PATCH 30/34] Finished implementing bomb game.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 43 +--
.../nxtar/game/ScenarioImplementation.java | 32 --
.../game/bombgame/BombGamePlayerSystem.java | 82 -----
.../AutomaticActionPerformerBase.java | 8 +-
.../ScenarioGlobals.java} | 90 +++--
.../scenarios/ScenarioImplementation.java | 35 ++
.../ccg/nxtar/scenarios/SummaryBase.java | 20 ++
.../SummaryOverlayBase.java} | 8 +-
.../bombgame/BombComponent.java | 2 +-
.../BombGameAutomaticActionPerformer.java | 15 +-
...BombGameAutomaticActionSummaryOverlay.java | 12 +-
.../bombgame/BombGameEntityCreator.java | 4 +-
.../bombgame/BombGameEntityTypeComponent.java | 2 +-
.../bombgame/BombGameLogicSystem.java | 32 +-
.../bombgame/BombGamePlayerComponent.java | 10 +-
.../bombgame/BombGamePlayerSystem.java | 118 +++++++
.../BombGameScenarioEndingOverlay.java | 101 ++++++
.../nxtar/states/AutomaticActionState.java | 12 +-
.../states/AutomaticActionSummaryState.java | 69 ++--
.../ciens/ccg/nxtar/states/InGameState.java | 20 +-
.../nxtar/states/ScenarioEndSummaryState.java | 329 ++++++++++++++++++
.../ccg/nxtar/systems/PlayerSystemBase.java | 29 +-
22 files changed, 810 insertions(+), 263 deletions(-)
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
delete mode 100644 src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/AutomaticActionPerformerBase.java (87%)
rename src/ve/ucv/ciens/ccg/nxtar/{game/GameGlobals.java => scenarios/ScenarioGlobals.java} (66%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryBase.java
rename src/ve/ucv/ciens/ccg/nxtar/{game/AutomaticActionSummaryOverlayBase.java => scenarios/SummaryOverlayBase.java} (75%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombComponent.java (96%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombGameAutomaticActionPerformer.java (95%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombGameAutomaticActionSummaryOverlay.java (91%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombGameEntityCreator.java (99%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombGameEntityTypeComponent.java (96%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombGameLogicSystem.java (94%)
rename src/ve/ucv/ciens/ccg/nxtar/{game => scenarios}/bombgame/BombGamePlayerComponent.java (90%)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerSystem.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index 43d562c..f4e05c7 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -15,7 +15,6 @@
*/
package ve.ucv.ciens.ccg.nxtar;
-import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver;
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
@@ -23,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread;
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionState;
import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionSummaryState;
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
@@ -30,6 +30,7 @@ import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
+import ve.ucv.ciens.ccg.nxtar.states.ScenarioEndSummaryState;
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -76,7 +77,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Valid game states.
*/
public enum game_states_t {
- MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3), SUMMARY(4);
+ MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3), AUTOMATIC_ACTION_SUMMARY(4), SCENARIO_END_SUMMARY(5);
private int value;
@@ -89,7 +90,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
public static int getNumStates(){
- return 5;
+ return 6;
}
};
@@ -233,18 +234,18 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
*/
public void create(){
try {
- GameGlobals.initGameSettings(this);
+ ScenarioGlobals.init(this);
} catch (IllegalArgumentException e) {
- Gdx.app.log(TAG, CLASS_NAME + ".create(): Illegal argument initializing globals: ", e);
- Gdx.app.exit();
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument initializing globals: ", e);
+ System.exit(1);
return;
} catch (InstantiationException e) {
- Gdx.app.log(TAG, CLASS_NAME + ".create(): Instantiation exception initializing globals: ", e);
- Gdx.app.exit();
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Instantiation exception initializing globals: ", e);
+ System.exit(1);
return;
} catch (IllegalAccessException e) {
- Gdx.app.log(TAG, CLASS_NAME + ".create(): Illegal access exception initializing globals: ", e);
- Gdx.app.exit();
+ Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal access exception initializing globals: ", e);
+ System.exit(1);
return;
}
@@ -268,7 +269,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
}catch(IllegalStateException e){
Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: ", e);
- Gdx.app.exit();
+ System.exit(1);
return;
}
@@ -278,15 +279,16 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this);
}catch(IllegalStateException e){
Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: ", e);
- Gdx.app.exit();
+ System.exit(1);
return;
}
- states[game_states_t.SUMMARY.getValue()] = new AutomaticActionSummaryState(this);
+ states[game_states_t.AUTOMATIC_ACTION_SUMMARY.getValue()] = new AutomaticActionSummaryState(this);
+ states[game_states_t.SCENARIO_END_SUMMARY.getValue()] = new ScenarioEndSummaryState(this);
}catch(IllegalArgumentException e){
Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
- Gdx.app.exit();
+ System.exit(1);
return;
}
@@ -342,11 +344,10 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
fadeTexture = new Texture(pixmap);
pixmap.dispose();
- alpha = new MutableFloat(0.0f);
+ alpha = new MutableFloat(0.0f);
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
- fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
-
- fading = false;
+ fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
+ fading = false;
// Set initial input handlers.
Gdx.input.setInputProcessor(states[currState.getValue()]);
@@ -368,8 +369,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
super.render();
// Load the assets.
- if(!GameGlobals.getEntityCreator().areEntitiesCreated())
- GameGlobals.getEntityCreator().updateAssetManager();
+ if(!ScenarioGlobals.getEntityCreator().areEntitiesCreated())
+ ScenarioGlobals.getEntityCreator().updateAssetManager();
// If the current state set a value for nextState then switch to that state.
if(nextState != null){
@@ -486,7 +487,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
batch.dispose();
font.dispose();
- GameGlobals.dispose();
+ ScenarioGlobals.dispose();
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
deleted file mode 100644
index 047f193..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/game/ScenarioImplementation.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2014 Miguel Angel Astor Romero
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ve.ucv.ciens.ccg.nxtar.game;
-
-import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionPerformer;
-import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionSummaryOverlay;
-import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameEntityCreator;
-import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameLogicSystem;
-
-@SuppressWarnings("rawtypes")
-public final class ScenarioImplementation{
- public static Class gameLogicSystemClass = BombGameLogicSystem.class;
- public static Class entityCreatorClass = BombGameEntityCreator.class;
- public static Class automaticActionPerformerClass = BombGameAutomaticActionPerformer.class;
- public static Class automaticActionSummaryScreen = BombGameAutomaticActionSummaryOverlay.class;
- // TODO: Add player processing system.
-
- private ScenarioImplementation(){}
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
deleted file mode 100644
index b08a563..0000000
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerSystem.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.game.bombgame;
-
-import ve.ucv.ciens.ccg.nxtar.NxtARCore;
-import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
-import ve.ucv.ciens.ccg.nxtar.utils.Utils;
-
-import com.artemis.ComponentMapper;
-import com.artemis.Entity;
-import com.artemis.annotations.Mapper;
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g2d.Sprite;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.utils.Disposable;
-
-public class BombGamePlayerSystem extends PlayerSystemBase implements Disposable{
- private static final float HEART_Y_POS = (Utils.getScreenHeightWithOverscan() / 2) - 69;
- @Mapper ComponentMapper playerMapper;
-
- private SpriteBatch batch;
- private Texture heartTexture;
- private Sprite heart;
-
- public BombGamePlayerSystem(NxtARCore core){
- super(BombGamePlayerComponent.class, core);
- batch = new SpriteBatch();
- heartTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_heart_1.png"));
- heart = new Sprite(heartTexture);
- heart.setSize(heart.getWidth() * 0.5f, heart.getHeight() * 0.5f);
- }
-
- @Override
- protected void process(Entity e) {
- float heartXPos;
- BombGamePlayerComponent player = playerMapper.get(e);
-
- // Render remaining lives.
- heartXPos = -(Utils.getScreenWidthWithOverscan() / 2) + 5;
- for(int i = 0; i < player.lives; ++i){
- heart.setPosition(heartXPos, HEART_Y_POS);
- heart.draw(batch);
- heartXPos += heart.getWidth() + 5;
- }
-
- // Check ending conditions.
- if(player.lives == 0){
- player.gameFinished = true;
- player.victory = false;
- }else if(player.disabledBombs == BombGameEntityCreator.NUM_BOMBS){
- player.gameFinished = true;
- player.victory = true;
- }
-
- // If met ending conditions then end the game.
- if(player.gameFinished)
- finishGame(player.victory);
- }
-
- @Override
- public void dispose() {
- if(batch != null)
- batch.dispose();
-
- if(heartTexture != null)
- heartTexture.dispose();
- }
-}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/AutomaticActionPerformerBase.java
similarity index 87%
rename from src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/AutomaticActionPerformerBase.java
index cf60a8d..95b279d 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionPerformerBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/AutomaticActionPerformerBase.java
@@ -13,15 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game;
+package ve.ucv.ciens.ccg.nxtar.scenarios;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
public abstract class AutomaticActionPerformerBase {
- public abstract class AutomaticActionSummary{
- public abstract void reset();
- }
-
public enum automatic_action_t{
NO_ACTION,
GO_FORWARD,
@@ -40,6 +36,6 @@ public abstract class AutomaticActionPerformerBase {
public abstract boolean performAutomaticAction(int lightSensorReading, MarkerData markers);
public abstract automatic_action_t getNextAction();
- public abstract AutomaticActionSummary getSummary();
+ public abstract SummaryBase getSummary();
public abstract void reset();
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
similarity index 66%
rename from src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
index d9a5adb..474ab02 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/GameGlobals.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game;
+package ve.ucv.ciens.ccg.nxtar.scenarios;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
@@ -25,6 +25,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
import com.artemis.EntitySystem;
@@ -35,15 +36,17 @@ import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable;
-public abstract class GameGlobals{
- private static EntityCreatorBase entityCreator = null;
- private static GameLogicSystemBase gameLogicSystem = null;
- private static World gameWorld = null;
- private static ModelBatch modelBatch = null;
- private static AutomaticActionPerformerBase automaticActionPerformer = null;
- private static AutomaticActionSummaryOverlayBase automaticActionSummaryOverlay = null;
+public abstract class ScenarioGlobals{
+ private static EntityCreatorBase entityCreator = null;
+ private static GameLogicSystemBase gameLogicSystem = null;
+ private static World gameWorld = null;
+ private static ModelBatch modelBatch = null;
+ private static AutomaticActionPerformerBase automaticActionPerformer = null;
+ private static SummaryOverlayBase automaticActionSummaryOverlay = null;
+ private static PlayerSystemBase playerSystem = null;
+ private static SummaryOverlayBase scenarioSummaryOverlay = null;
- public static void initGameSettings(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{
+ public static void init(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{
if(core == null)
throw new IllegalArgumentException("Core is null.");
@@ -95,17 +98,41 @@ public abstract class GameGlobals{
if(automaticActionSummaryOverlay == null){
try {
- automaticActionSummaryOverlay = (AutomaticActionSummaryOverlayBase) ScenarioImplementation.automaticActionSummaryScreen.newInstance();
+ automaticActionSummaryOverlay = (SummaryOverlayBase) ScenarioImplementation.automaticActionSummaryOverlay.newInstance();
} catch (InstantiationException e) {
- System.out.println("Error instantiating automatic action performer.");
+ System.out.println("Error instantiating automatic action summary overlay");
throw e;
} catch (IllegalAccessException e) {
- System.out.println("Error accessing automatic action performer.");
+ System.out.println("Error accessing automatic action summary overlay.");
throw e;
}
}
- // TODO: Create player processing system.
+ if(playerSystem == null){
+ try {
+ playerSystem = (PlayerSystemBase) ScenarioImplementation.playerSystemClass.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating player system.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing player system.");
+ throw e;
+ }
+ }
+
+ if(scenarioSummaryOverlay == null){
+ try {
+ scenarioSummaryOverlay = (SummaryOverlayBase) ScenarioImplementation.scenarioSummaryOverlayClass.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating scenario summary overlay.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing scenario summary overlay.");
+ throw e;
+ }
+ }
+
+ playerSystem.setCore(core);
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
@@ -113,7 +140,7 @@ public abstract class GameGlobals{
gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem());
gameWorld.setSystem(gameLogicSystem);
- // TODO: Add player processing system.
+ gameWorld.setSystem(playerSystem, true);
gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true);
gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true);
gameWorld.setSystem(new FadeEffectRenderingSystem(), true);
@@ -135,6 +162,7 @@ public abstract class GameGlobals{
}
}
+ scenarioSummaryOverlay.dispose();
automaticActionSummaryOverlay.dispose();
entityCreator.dispose();
@@ -143,12 +171,12 @@ public abstract class GameGlobals{
gameWorld = null;
automaticActionPerformer = null;
automaticActionSummaryOverlay = null;
+ playerSystem = null;
+ scenarioSummaryOverlay = null;
+
System.gc();
}
- /**
- * @return the entityCreator
- */
public static EntityCreatorBase getEntityCreator() throws IllegalStateException{
if(entityCreator == null)
throw new IllegalStateException("Calling getEntityCreator() before init.");
@@ -156,9 +184,6 @@ public abstract class GameGlobals{
return entityCreator;
}
- /**
- * @return the gameLogicSystem
- */
public static GameLogicSystemBase getGameLogicSystem() throws IllegalStateException{
if(gameLogicSystem == null)
throw new IllegalStateException("Calling getGameLogicSystem() before init.");
@@ -166,9 +191,6 @@ public abstract class GameGlobals{
return gameLogicSystem;
}
- /**
- * @return the gameWorld
- */
public static World getGameWorld() throws IllegalStateException{
if(gameWorld == null)
throw new IllegalStateException("Calling getGameWorld() before init.");
@@ -176,9 +198,6 @@ public abstract class GameGlobals{
return gameWorld;
}
- /**
- * @return the automaticActionPerformer
- */
public static AutomaticActionPerformerBase getAutomaticActionPerformer() throws IllegalStateException{
if(automaticActionPerformer == null)
throw new IllegalStateException("Calling getAutomaticActionPerformer() before init.");
@@ -186,13 +205,24 @@ public abstract class GameGlobals{
return automaticActionPerformer;
}
- /**
- * @return the automaticActionSummaryScreen
- */
- public static AutomaticActionSummaryOverlayBase getAutomaticActionSummaryOverlay() throws IllegalStateException{
+ public static SummaryOverlayBase getAutomaticActionSummaryOverlay() throws IllegalStateException{
if(automaticActionSummaryOverlay == null)
throw new IllegalStateException("Calling getAutomaticActionSummaryOverlay() before init.");
return automaticActionSummaryOverlay;
}
+
+ public static PlayerSystemBase getPlayerSystem() throws IllegalStateException{
+ if(playerSystem == null)
+ throw new IllegalStateException("Calling getPlayerSystem() before init.");
+
+ return playerSystem;
+ }
+
+ public static SummaryOverlayBase getScenarioSummaryOverlay() throws IllegalStateException{
+ if(scenarioSummaryOverlay == null)
+ throw new IllegalStateException("Calling getScenarioSummaryOverlay() before init.");
+
+ return scenarioSummaryOverlay;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java
new file mode 100644
index 0000000..3d50517
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java
@@ -0,0 +1,35 @@
+/*
+ * 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.scenarios;
+
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionPerformer;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionSummaryOverlay;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameLogicSystem;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGamePlayerSystem;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameScenarioEndingOverlay;
+
+@SuppressWarnings("rawtypes")
+public final class ScenarioImplementation{
+ public static final Class gameLogicSystemClass = BombGameLogicSystem.class;
+ public static final Class entityCreatorClass = BombGameEntityCreator.class;
+ public static final Class automaticActionPerformerClass = BombGameAutomaticActionPerformer.class;
+ public static final Class automaticActionSummaryOverlay = BombGameAutomaticActionSummaryOverlay.class;
+ public static final Class playerSystemClass = BombGamePlayerSystem.class;
+ public static final Class scenarioSummaryOverlayClass = BombGameScenarioEndingOverlay.class;
+
+ private ScenarioImplementation(){}
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryBase.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryBase.java
new file mode 100644
index 0000000..53a5874
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryBase.java
@@ -0,0 +1,20 @@
+/*
+ * 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.scenarios;
+
+public abstract class SummaryBase{
+ public abstract void reset();
+}
\ No newline at end of file
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryOverlayBase.java
similarity index 75%
rename from src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryOverlayBase.java
index 949edf4..08f9da5 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/AutomaticActionSummaryOverlayBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/SummaryOverlayBase.java
@@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game;
-
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.AutomaticActionSummary;
+package ve.ucv.ciens.ccg.nxtar.scenarios;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Disposable;
@@ -23,11 +21,11 @@ import com.badlogic.gdx.utils.Disposable;
/**
* Base class for summary screens. Just renders a summary overlay.
*/
-public abstract class AutomaticActionSummaryOverlayBase implements Disposable{
+public abstract class SummaryOverlayBase implements Disposable{
/**
* Renders the overlay.
*
* @param batch The {@link SpriteBatch} to use for rendering.
*/
- public abstract void render(SpriteBatch batch, AutomaticActionSummary summary);
+ public abstract void render(SpriteBatch batch, SummaryBase summary);
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombComponent.java
similarity index 96%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombComponent.java
index 4ffd0a3..5f75e50 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombComponent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
import com.artemis.Component;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionPerformer.java
similarity index 95%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionPerformer.java
index 7aa2128..e9d98ba 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionPerformer.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionPerformer.java
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
import java.util.LinkedList;
import java.util.List;
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
-import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
+import ve.ucv.ciens.ccg.nxtar.scenarios.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryBase;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import com.artemis.Entity;
@@ -39,7 +40,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
START, WALK_FORWARD, DETECT_MARKER, FINISHING, END;
}
- public class BombGameAutomaticActionSummary extends AutomaticActionSummary{
+ public class BombGameAutomaticActionSummary extends SummaryBase{
private int numCombinationBombs;
private int numInclinationBombs;
private int numWireBombs;
@@ -109,7 +110,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
World world;
if(manager == null){
- world = GameGlobals.getGameWorld();
+ world = ScenarioGlobals.getGameWorld();
if(world == null)
throw new IllegalStateException("World is null after getGameWorld().");
@@ -264,8 +265,8 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
}
@Override
- public AutomaticActionSummary getSummary() {
- return (AutomaticActionSummary)summary;
+ public SummaryBase getSummary() {
+ return (SummaryBase)summary;
}
@Override
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java
similarity index 91%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java
index 440e649..f3ec640 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameAutomaticActionSummaryOverlay.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.AutomaticActionSummary;
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionSummaryOverlayBase;
-import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombGameAutomaticActionPerformer.BombGameAutomaticActionSummary;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionPerformer.BombGameAutomaticActionSummary;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -30,7 +30,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
-public class BombGameAutomaticActionSummaryOverlay extends AutomaticActionSummaryOverlayBase{
+public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
private static final float CANNONICAL_SCREEN_WIDTH = 800.0f;
private Texture inclinationBombTexture;
@@ -106,7 +106,7 @@ public class BombGameAutomaticActionSummaryOverlay extends AutomaticActionSummar
}
@Override
- public void render(SpriteBatch batch, AutomaticActionSummary summary) throws ClassCastException{
+ public void render(SpriteBatch batch, SummaryBase summary) throws ClassCastException{
BombGameAutomaticActionSummary bombGameSummary;
if(!(summary instanceof BombGameAutomaticActionSummary))
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameEntityCreator.java
similarity index 99%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameEntityCreator.java
index fcfdd2a..2e931ef 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityCreator.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameEntityCreator.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
import java.util.LinkedList;
import java.util.List;
@@ -30,8 +30,8 @@ import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
-import ve.ucv.ciens.ccg.nxtar.game.bombgame.BombComponent.bomb_type_t;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombComponent.bomb_type_t;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityTypeComponent.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameEntityTypeComponent.java
similarity index 96%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityTypeComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameEntityTypeComponent.java
index b472122..0b5aa6a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameEntityTypeComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameEntityTypeComponent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
import com.artemis.Component;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java
similarity index 94%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java
index b3fd37c..adfdfd1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
@@ -227,7 +227,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld();
- if(Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL){
+ if(!Utils.isDeviceRollValid() || (Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL)){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
createFadeOutEffect();
reducePlayerLivesByOne();
@@ -326,7 +326,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
players = manager.getEntities(PlayerComponentBase.PLAYER_GROUP);
if(players != null && players.size() > 0 && players.get(0) != null){
- player = players.get(0);
+ player = players.get(0);
playerComponent = player.getComponent(BombGamePlayerComponent.class);
if(playerComponent != null){
@@ -340,6 +340,30 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
}
+ /**
+ * Updates the player's disabled bombs count.
+ */
+ private void increasePlayerDisabledBombsByOne(){
+ Entity player;
+ BombGamePlayerComponent playerComponent;
+ ImmutableBag players;
+
+ players = manager.getEntities(PlayerComponentBase.PLAYER_GROUP);
+ if(players != null && players.size() > 0 && players.get(0) != null){
+ player = players.get(0);
+ playerComponent = player.getComponent(BombGamePlayerComponent.class);
+
+ if(playerComponent != null){
+ playerComponent.disabledBombs += 1;
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".reducePlayerLivesByOne(): Players is missing required components.");
+ }
+
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + ".reducePlayerLivesByOne(): No players found.");
+ }
+ }
+
/**
* Disables all entities associated with the corresponding marker code.
*
@@ -368,6 +392,8 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
}
}
}
+
+ increasePlayerDisabledBombsByOne();
}
/**
diff --git a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerComponent.java
similarity index 90%
rename from src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java
rename to src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerComponent.java
index 3950389..af4f958 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/game/bombgame/BombGamePlayerComponent.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerComponent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ve.ucv.ciens.ccg.nxtar.game.bombgame;
+package ve.ucv.ciens.ccg.nxtar.scenarios.bombgame;
import ve.ucv.ciens.ccg.nxtar.components.PlayerComponentBase;
@@ -21,9 +21,9 @@ 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 int startingLives;
+ public int lives;
+ public int disabledBombs;
public BombGamePlayerComponent(int lives) throws IllegalArgumentException{
super();
@@ -38,7 +38,7 @@ public class BombGamePlayerComponent extends PlayerComponentBase {
public BombGamePlayerComponent(){
this(3);
}
-
+
@Override
public void reset(){
super.reset();
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerSystem.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerSystem.java
new file mode 100644
index 0000000..3c9f028
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGamePlayerSystem.java
@@ -0,0 +1,118 @@
+/*
+ * 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.scenarios.bombgame;
+
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryBase;
+import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.artemis.ComponentMapper;
+import com.artemis.Entity;
+import com.artemis.annotations.Mapper;
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+
+public class BombGamePlayerSystem extends PlayerSystemBase{
+ public final class BombGamePlayerSummary extends SummaryBase{
+ public int livesLeft;
+ public int disabledBombs;
+ public int detonatedBombs;
+ public boolean victory;
+
+ public BombGamePlayerSummary(){
+ reset();
+ }
+
+ @Override
+ public void reset() {
+ this.livesLeft = 0;
+ this.disabledBombs = 0;
+ this.detonatedBombs = 0;
+ this.victory = false;
+ }
+ }
+
+ @Mapper ComponentMapper playerMapper;
+
+ private SpriteBatch batch;
+ private Texture heartTexture;
+ private Sprite heart;
+ private OrthographicCamera camera;
+ private BombGamePlayerSummary summary;
+ private float heartYPos;
+
+ public BombGamePlayerSystem(){
+ super(BombGamePlayerComponent.class);
+ camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ batch = new SpriteBatch();
+ heartTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/Anonymous_heart_1.png"));
+ summary = new BombGamePlayerSummary();
+ heart = new Sprite(heartTexture);
+ heart.setSize(heart.getWidth() * 0.25f, heart.getHeight() * 0.25f);
+ heartYPos = (Utils.getScreenHeightWithOverscan() / 2) - heart.getHeight() - 64 - 5;
+ }
+
+ @Override
+ protected void process(Entity e){
+ float heartXPos;
+ BombGamePlayerComponent player = playerMapper.get(e);
+
+ // Render remaining lives.
+ batch.setProjectionMatrix(camera.combined);
+ batch.begin();{
+ heartXPos = -(Utils.getScreenWidthWithOverscan() / 2) + 5;
+ for(int i = 0; i < player.lives; ++i){
+ heart.setPosition(heartXPos, heartYPos);
+ heart.draw(batch);
+ heartXPos += heart.getWidth() + 5;
+ }
+ }batch.end();
+
+ // Check ending conditions.
+ 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){
+ summary.victory = player.victory;
+ summary.livesLeft = player.lives;
+ summary.disabledBombs = BombGameEntityCreator.NUM_BOMBS - (player.startingLives - player.lives);
+ summary.detonatedBombs = player.startingLives - player.lives;
+ finishGame(player.victory);
+ }
+ }
+
+ @Override
+ public void dispose() {
+ if(batch != null)
+ batch.dispose();
+
+ if(heartTexture != null)
+ heartTexture.dispose();
+ }
+
+ @Override
+ public SummaryBase getPlayerSummary() {
+ return summary;
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java
new file mode 100644
index 0000000..fc6df52
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java
@@ -0,0 +1,101 @@
+/*
+ * 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.scenarios.bombgame;
+
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGamePlayerSystem.BombGamePlayerSummary;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
+
+public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
+ private static final float CANNONICAL_SCREEN_WIDTH = 800.0f;
+
+ private BitmapFont font;
+ private BitmapFont titleFont;
+ private float textX;
+ private float baseTextY;
+ private TextBounds titleBounds;
+
+ public BombGameScenarioEndingOverlay(){
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+
+ font = fontGenerator.generateFont(fontParameters);
+ font.setColor(Color.YELLOW);
+
+ fontParameters.size = (int)(90.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ titleFont = fontGenerator.generateFont(fontParameters);
+
+ fontGenerator.dispose();
+
+ textX = -(Utils.getScreenWidthWithOverscan() / 7.0f);
+ baseTextY = -(font.getCapHeight() / 2.0f);
+ }
+
+ @Override
+ public void dispose(){
+ font.dispose();
+ titleFont.dispose();
+ }
+
+ @Override
+ public void render(SpriteBatch batch, SummaryBase summary) throws ClassCastException{
+ BombGamePlayerSummary bombGamePlayerSummary;
+ String title;
+ String text;
+
+ // Get the player's summary.
+ if(!(summary instanceof BombGamePlayerSummary))
+ throw new ClassCastException("Summary is not a bomb game summary.");
+ bombGamePlayerSummary = (BombGamePlayerSummary)summary;
+
+ // Render the summary.
+ text = String.format("Lives left: %d", bombGamePlayerSummary.livesLeft);
+ textX = -(font.getBounds(text).width / 2);
+ font.draw(batch, text, textX, baseTextY + font.getCapHeight() + 15);
+
+ text = String.format("Bombs defused: %d", bombGamePlayerSummary.disabledBombs);
+ textX = -(font.getBounds(text).width / 2);
+ font.draw(batch, text, textX, baseTextY);
+
+ text = String.format("Bombs detonated: %d", bombGamePlayerSummary.detonatedBombs);
+ textX = -(font.getBounds(text).width / 2);
+ font.draw(batch, text, textX, baseTextY - font.getCapHeight() - 15);
+
+ // Render the title.
+ if(bombGamePlayerSummary.victory)
+ title = "Victory!";
+ else
+ title = "Game Over";
+ titleBounds = titleFont.getBounds(title);
+ titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10);
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
index d08fa1b..7a8a24e 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionState.java
@@ -19,14 +19,14 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase;
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionPerformerBase.automatic_action_t;
-import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
+import ve.ucv.ciens.ccg.nxtar.scenarios.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.AutomaticActionPerformerBase.automatic_action_t;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
@@ -137,7 +137,7 @@ public class AutomaticActionState extends BaseState{
aButtonPressed = false;
automaticActionEnabled = false;
startButtonPressed = false;
- automaticActionPerformer = GameGlobals.getAutomaticActionPerformer();
+ automaticActionPerformer = ScenarioGlobals.getAutomaticActionPerformer();
previousAction = automatic_action_t.NO_ACTION;
// Set up the cameras.
@@ -187,7 +187,7 @@ public class AutomaticActionState extends BaseState{
setUpButton();
// Set up the game world.
- gameWorld = GameGlobals.getGameWorld();
+ gameWorld = ScenarioGlobals.getGameWorld();
markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
if(markerRenderingSystem == null)
@@ -571,7 +571,7 @@ public class AutomaticActionState extends BaseState{
startButton.setDisabled(false);
ignoreBackKey = false;
automaticActionEnabled = false;
- core.nextState = game_states_t.SUMMARY;
+ core.nextState = game_states_t.AUTOMATIC_ACTION_SUMMARY;
}
}catch(IllegalArgumentException e){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
index f5285b3..79c9cd9 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
@@ -17,9 +17,9 @@ 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.game.AutomaticActionPerformerBase;
-import ve.ucv.ciens.ccg.nxtar.game.AutomaticActionSummaryOverlayBase;
-import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.AutomaticActionPerformerBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryOverlayBase;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -71,14 +71,11 @@ public class AutomaticActionSummaryState extends BaseState{
private Texture buttonEnabledTexture;
private Texture buttonDisabledTexture;
private Texture buttonPressedTexture;
- private NinePatch buttonEnabled9p;
- private NinePatch buttonDisabled9p;
- private NinePatch buttonPressed9p;
private BitmapFont font;
// Summary overlay related fields.
- AutomaticActionPerformerBase automaticActionPerformer;
- AutomaticActionSummaryOverlayBase summaryOverlay;
+ AutomaticActionPerformerBase automaticActionPerformer;
+ SummaryOverlayBase summaryOverlay;
// Button touch helper fields.
private boolean continueButtonTouched;
@@ -88,6 +85,9 @@ public class AutomaticActionSummaryState extends BaseState{
TextButtonStyle textButtonStyle;
FreeTypeFontGenerator fontGenerator;
FreeTypeFontParameter fontParameters;
+ NinePatch buttonEnabled9p;
+ NinePatch buttonDisabled9p;
+ NinePatch buttonPressed9p;
if(core == null)
throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
@@ -95,34 +95,34 @@ public class AutomaticActionSummaryState extends BaseState{
this.core = core;
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
oButtonPressed = false;
- automaticActionPerformer = GameGlobals.getAutomaticActionPerformer();
- summaryOverlay = GameGlobals.getAutomaticActionSummaryOverlay();
+ automaticActionPerformer = ScenarioGlobals.getAutomaticActionPerformer();
+ summaryOverlay = ScenarioGlobals.getAutomaticActionSummaryOverlay();
// Create the start button background.
- buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
- buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
+ buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
buttonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
- buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
- buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
- buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
+ buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
+ buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
// Create the start button font.
- fontParameters = new FreeTypeFontParameter();
+ fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
- fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
- fontParameters.flip = false;
- fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
- font = fontGenerator.generateFont(fontParameters);
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+ font = fontGenerator.generateFont(fontParameters);
fontGenerator.dispose();
// Create the contine button.
- textButtonStyle = new TextButtonStyle();
- textButtonStyle.font = font;
- textButtonStyle.up = new NinePatchDrawable(buttonEnabled9p);
- textButtonStyle.checked = new NinePatchDrawable(buttonPressed9p);
- textButtonStyle.disabled = new NinePatchDrawable(buttonDisabled9p);
- textButtonStyle.fontColor = new Color(Color.BLACK);
- textButtonStyle.downFontColor = new Color(Color.WHITE);
+ textButtonStyle = new TextButtonStyle();
+ textButtonStyle.font = font;
+ textButtonStyle.up = new NinePatchDrawable(buttonEnabled9p);
+ textButtonStyle.checked = new NinePatchDrawable(buttonPressed9p);
+ textButtonStyle.disabled = new NinePatchDrawable(buttonDisabled9p);
+ textButtonStyle.fontColor = new Color(Color.BLACK);
+ textButtonStyle.downFontColor = new Color(Color.WHITE);
textButtonStyle.disabledFontColor = new Color(Color.BLACK);
continueButton = new TextButton("Continue", textButtonStyle);
@@ -156,17 +156,16 @@ public class AutomaticActionSummaryState extends BaseState{
backgroundShader = null;
}
- u_scaling = new float[2];
- 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 = new float[2];
+ 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();
- continueButtonTouched = false;
+ win2world = new Vector3(0.0f, 0.0f, 0.0f);
+ touchPointWorldCoords = new Vector2();
+ continueButtonTouched = false;
continueButtonTouchPointer = -1;
- stateActive = false;
+ stateActive = false;
}
@Override
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 0f807fc..798c1b4 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -19,7 +19,6 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
-import ve.ucv.ciens.ccg.nxtar.game.GameGlobals;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
@@ -28,11 +27,13 @@ import ve.ucv.ciens.ccg.nxtar.input.UserInput;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
+import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
@@ -99,6 +100,7 @@ public class InGameState extends BaseState{
private ObjectRenderingSystem objectRenderingSystem;
private RobotArmPositioningSystem robotArmPositioningSystem;
private FadeEffectRenderingSystem fadeEffectRenderingSystem;
+ private PlayerSystemBase playerSystem;
private robot_control_mode_t controlMode;
// Cameras.
@@ -215,13 +217,13 @@ public class InGameState extends BaseState{
backgroundShader = null;
}
- uScaling = new float[2];
+ uScaling = new float[2];
uScaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
// Set up the 3D rendering.
- modelBatch = new ModelBatch();
- frameBuffer = null;
+ modelBatch = new ModelBatch();
+ frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = null;
@@ -230,12 +232,13 @@ public class InGameState extends BaseState{
setUpButtons();
// Set up the game world.
- gameWorld = GameGlobals.getGameWorld();
+ gameWorld = ScenarioGlobals.getGameWorld();
robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class);
markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class);
objectRenderingSystem = gameWorld.getSystem(ObjectRenderingSystem.class);
fadeEffectRenderingSystem = gameWorld.getSystem(FadeEffectRenderingSystem.class);
+ playerSystem = ScenarioGlobals.getPlayerSystem();
if(robotArmPositioningSystem == null || markerRenderingSystem == null || objectRenderingSystem == null || fadeEffectRenderingSystem == null)
throw new IllegalStateException("One or more essential systems are null.");
@@ -303,6 +306,11 @@ public class InGameState extends BaseState{
perspectiveCamera.update(perspectiveCamera.projection);
// Update the game state.
+ if(controlMode == robot_control_mode_t.ARM_CONTROL)
+ gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
+ else
+ gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
+
gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
gameWorld.process();
@@ -436,6 +444,7 @@ public class InGameState extends BaseState{
}
fadeEffectRenderingSystem.process();
+ playerSystem.process();
data = null;
}
@@ -494,7 +503,6 @@ public class InGameState extends BaseState{
@Override
public void onStateSet(){
- gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
stateActive = true;
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true);
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java b/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
new file mode 100644
index 0000000..ced6867
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
@@ -0,0 +1,329 @@
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.controllers.Controller;
+import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.Texture.TextureFilter;
+import com.badlogic.gdx.graphics.Texture.TextureWrap;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
+import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
+import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
+
+public class ScenarioEndSummaryState extends BaseState {
+ private static final String TAG = "AUTO_SUMMARY";
+ private static final String CLASS_NAME = AutomaticActionSummaryState.class.getSimpleName();
+ private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
+
+ // Helper fields.
+ private float u_scaling[];
+ private float u_displacement;
+
+ // Buttons and other gui components.
+ private TextButton continueButton;
+ private Rectangle continueButtonBBox;
+ private Sprite background;
+ private Texture backgroundTexture;
+ private ShaderProgram backgroundShader;
+ private Texture ouyaOButtonTexture;
+ private Sprite ouyaOButton;
+ private boolean oButtonPressed;
+
+ // Graphic data for the start button.
+ private Texture buttonEnabledTexture;
+ private Texture buttonDisabledTexture;
+ private Texture buttonPressedTexture;
+ private BitmapFont font;
+
+ // Summary overlay related fields.
+ PlayerSystemBase playerSystem;
+ SummaryOverlayBase summaryOverlay;
+
+ // Button touch helper fields.
+ private boolean continueButtonTouched;
+ private int continueButtonTouchPointer;
+
+ public ScenarioEndSummaryState(NxtARCore core) throws IllegalArgumentException{
+ TextButtonStyle textButtonStyle;
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+ NinePatch buttonEnabled9p;
+ NinePatch buttonDisabled9p;
+ NinePatch buttonPressed9p;
+
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
+
+ this.core = core;
+ this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ oButtonPressed = false;
+ playerSystem = ScenarioGlobals.getPlayerSystem();
+ summaryOverlay = ScenarioGlobals.getScenarioSummaryOverlay();
+
+ // Create the start button background.
+ buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
+ buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
+ buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
+ buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
+
+ // Create the start button font.
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+ font = fontGenerator.generateFont(fontParameters);
+ fontGenerator.dispose();
+
+ // Create the contine button.
+ textButtonStyle = new TextButtonStyle();
+ textButtonStyle.font = font;
+ textButtonStyle.up = new NinePatchDrawable(buttonEnabled9p);
+ textButtonStyle.checked = new NinePatchDrawable(buttonPressed9p);
+ textButtonStyle.disabled = new NinePatchDrawable(buttonDisabled9p);
+ textButtonStyle.fontColor = new Color(Color.BLACK);
+ textButtonStyle.downFontColor = new Color(Color.WHITE);
+ textButtonStyle.disabledFontColor = new Color(Color.BLACK);
+
+ continueButton = new TextButton("Continue", textButtonStyle);
+ continueButton.setText("Continue");
+ continueButton.setPosition(-(continueButton.getWidth() / 2), -(Utils.getScreenHeightWithOverscan() / 2) + 10);
+ continueButtonBBox = new Rectangle(0, 0, continueButton.getWidth(), continueButton.getHeight());
+ continueButtonBBox.setPosition(continueButton.getX(), continueButton.getY());
+
+ // Set OUYA's O button.
+ if(Ouya.runningOnOuya){
+ ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
+ ouyaOButton = new Sprite(ouyaOButtonTexture);
+ ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ oButtonPressed = false;
+ }else{
+ ouyaOButtonTexture = null;
+ }
+
+ // Set up the background.
+ backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
+ backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
+ backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ background = new Sprite(backgroundTexture);
+ background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
+
+ backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + "_vert.glsl"), Gdx.files.internal(SHADER_PATH + "_frag.glsl"));
+ if(!backgroundShader.isCompiled()){
+ Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
+ Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
+ backgroundShader = null;
+ }
+
+ u_scaling = new float[2];
+ 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();
+ continueButtonTouched = false;
+ continueButtonTouchPointer = -1;
+ stateActive = false;
+ }
+
+ @Override
+ public void render(float delta){
+ Gdx.gl.glClearColor(1, 1, 1, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ core.batch.begin();{
+
+ // Render background.
+ core.batch.disableBlending();
+ drawBackground(core.batch);
+ core.batch.enableBlending();
+
+ summaryOverlay.render(core.batch, playerSystem.getPlayerSummary());
+
+ // Render buttons.
+ continueButton.draw(core.batch, 1.0f);
+ if(Ouya.runningOnOuya)
+ ouyaOButton.draw(core.batch);
+
+ }core.batch.end();
+ }
+
+ @Override
+ public void dispose(){
+ buttonEnabledTexture.dispose();
+ buttonDisabledTexture.dispose();
+ buttonPressedTexture.dispose();
+ if(ouyaOButtonTexture != null)
+ ouyaOButtonTexture.dispose();
+ backgroundTexture.dispose();
+ if(backgroundShader != null) backgroundShader.dispose();
+ font.dispose();
+ }
+
+ private void drawBackground(SpriteBatch batch){
+ 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
+ public void onStateSet(){
+ stateActive = true;
+ Gdx.input.setInputProcessor(this);
+ Gdx.input.setCatchBackKey(true);
+ Gdx.input.setCatchMenuKey(true);
+ }
+
+ @Override
+ public void onStateUnset(){
+ stateActive = false;
+ Gdx.input.setInputProcessor(null);
+ Gdx.input.setCatchBackKey(false);
+ Gdx.input.setCatchMenuKey(false);
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; INPUT LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean touchDown(int screenX, int screenY, int pointer, int button){
+ unprojectTouch(screenX, screenY);
+
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
+
+ if(!continueButton.isDisabled() && continueButtonBBox.contains(touchPointWorldCoords)){
+ continueButton.setChecked(true);
+ continueButtonTouched = true;
+ continueButtonTouchPointer = pointer;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean touchUp(int screenX, int screenY, int pointer, int button){
+ unprojectTouch(screenX, screenY);
+
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
+
+ if(!continueButton.isDisabled() && continueButtonBBox.contains(touchPointWorldCoords) && continueButtonTouched){
+ continueButton.setChecked(false);
+ continueButtonTouched = false;
+ continueButtonTouchPointer = -1;
+ core.nextState = game_states_t.MAIN_MENU;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean touchDragged(int screenX, int screenY, int pointer){
+ unprojectTouch(screenX, screenY);
+
+ if(!continueButton.isDisabled() && continueButtonTouched && pointer == continueButtonTouchPointer && !continueButtonBBox.contains(touchPointWorldCoords)){
+ continueButtonTouchPointer = -1;
+ continueButtonTouched = false;
+ continueButton.setChecked(false);
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean keyDown(int keycode){
+ if(keycode == Input.Keys.BACK){
+ core.nextState = game_states_t.MAIN_MENU;
+ return true;
+ }
+ return false;
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; CONTROLLER LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean buttonDown(Controller controller, int buttonCode){
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O && !continueButton.isDisabled()){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
+ oButtonPressed = true;
+ continueButton.setChecked(true);
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean buttonUp(Controller controller, int buttonCode){
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
+ if(oButtonPressed){
+ oButtonPressed = false;
+ continueButton.setChecked(false);
+ core.nextState = game_states_t.MAIN_MENU;
+ }
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
index d1ecf82..a3e6caf 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/PlayerSystemBase.java
@@ -17,36 +17,35 @@ 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.game.GameGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
+import ve.ucv.ciens.ccg.nxtar.scenarios.SummaryBase;
import com.artemis.Aspect;
-import com.artemis.Entity;
import com.artemis.systems.EntityProcessingSystem;
+import com.badlogic.gdx.utils.Disposable;
-public abstract class PlayerSystemBase extends EntityProcessingSystem {
+public abstract class PlayerSystemBase extends EntityProcessingSystem implements Disposable{
protected NxtARCore core;
@SuppressWarnings("unchecked")
- public PlayerSystemBase(Class extends PlayerComponentBase> component, NxtARCore core){
+ public PlayerSystemBase(Class extends PlayerComponentBase> component){
super(Aspect.getAspectForAll(component));
+ }
- if(component == null)
- throw new IllegalArgumentException("Component is null.");
+ public abstract SummaryBase getPlayerSummary();
+ public final void setCore(NxtARCore core) throws IllegalArgumentException{
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.
- GameGlobals.getEntityCreator().resetAllEntities();
- core.nextState = NxtARCore.game_states_t.MAIN_MENU;
+ protected final void finishGame(boolean victory) throws IllegalStateException{
+ if(core == null)
+ throw new IllegalStateException("Core is null.");
+
+ ScenarioGlobals.getEntityCreator().resetAllEntities();
+ core.nextState = NxtARCore.game_states_t.SCENARIO_END_SUMMARY;
}
-
- @Override
- protected abstract void process(Entity e);
-
}
From 5a8391aa28df8315b5bff7e4dfa9478050e7608b Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 26 Jun 2014 11:53:55 -0430
Subject: [PATCH 31/34] Updated the README file.
---
README.md | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 1d5ec59..a591f42 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,27 @@
-NxtAR-core
-==========
+NxtAR: A generic software architecture for Augmented Reality based mobile robot control.
+========================================================================================
-Modulo 2 de mi trabajo especial de grado.
+Core module
+-----------
+
+### Abstract ###
+
+NxtAR is a generic software architecture for the development of Augmented Reality games
+and applications centered around mobile robot control. This is a reference implementation
+with support for [LEGO Mindstorms NXT][1] mobile robots.
+
+### Module description ###
+
+The core module comprises all the operating system independent classes that implemente the
+base architecture and the different scenarios for the application. This implementation is
+designed and built around the [LibGDX][2] and the [Artemis Entity-System Framework][3] libraries.
+
+Currently there is one scenario titled *Bomb Game*.
+
+### Module installation and usage. ###
+
+The core module cannot be used directly. It is intended to be compiled with a LibGDX backend module.
+
+ [1]: http://www.lego.com/en-us/mindstorms/?domainredir=mindstorms.lego.com
+ [2]: http://libgdx.badlogicgames.com/
+ [3]: http://gamadu.com/artemis/
From 81d8a81b7e59ad9b8c5a17ef3db9d6f6ddccf2f9 Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 26 Jun 2014 12:51:01 -0430
Subject: [PATCH 32/34] Added instructions screen support.
---
src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 30 +-
.../ccg/nxtar/scenarios/HintsOverlayBase.java | 31 ++
.../ccg/nxtar/scenarios/ScenarioGlobals.java | 22 ++
.../scenarios/ScenarioImplementation.java | 2 +
.../bombgame/BombGameInstructionsOverlay.java | 120 +++++++
.../bombgame/BombGameLogicSystem.java | 12 +-
.../ciens/ccg/nxtar/states/InGameState.java | 46 ++-
.../ccg/nxtar/states/InstructionsState.java | 326 ++++++++++++++++++
.../nxtar/states/ScenarioEndSummaryState.java | 4 +-
.../systems/RobotArmPositioningSystem.java | 11 +-
.../ccg/nxtar/utils/ProjectConstants.java | 4 +-
src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java | 13 +-
12 files changed, 586 insertions(+), 35 deletions(-)
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/scenarios/HintsOverlayBase.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java
create mode 100644 src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java
diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
index f4e05c7..526ed65 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java
@@ -28,6 +28,7 @@ import ve.ucv.ciens.ccg.nxtar.states.AutomaticActionSummaryState;
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
+import ve.ucv.ciens.ccg.nxtar.states.InstructionsState;
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
import ve.ucv.ciens.ccg.nxtar.states.ScenarioEndSummaryState;
@@ -77,7 +78,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
* Valid game states.
*/
public enum game_states_t {
- MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3), AUTOMATIC_ACTION_SUMMARY(4), SCENARIO_END_SUMMARY(5);
+ MAIN_MENU(0), IN_GAME(1), CALIBRATION(2), AUTOMATIC_ACTION(3), AUTOMATIC_ACTION_SUMMARY(4), SCENARIO_END_SUMMARY(5), HINTS(6);
private int value;
@@ -90,7 +91,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
public static int getNumStates(){
- return 6;
+ return 7;
}
};
@@ -285,6 +286,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
states[game_states_t.AUTOMATIC_ACTION_SUMMARY.getValue()] = new AutomaticActionSummaryState(this);
states[game_states_t.SCENARIO_END_SUMMARY.getValue()] = new ScenarioEndSummaryState(this);
+ states[game_states_t.HINTS.getValue()] = new InstructionsState(this);
}catch(IllegalArgumentException e){
Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
@@ -426,17 +428,19 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
// Render the debug overlay.
- batch.setProjectionMatrix(pixelPerfectCamera.combined);
- batch.begin();{
- // Draw the FPS overlay.
- font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
- font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
- 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();
+ if(ProjectConstants.DEBUG){
+ batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ batch.begin();{
+ // Draw the FPS overlay.
+ font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
+ font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
+ 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();
+ }
}
/**
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/HintsOverlayBase.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/HintsOverlayBase.java
new file mode 100644
index 0000000..2a7d685
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/HintsOverlayBase.java
@@ -0,0 +1,31 @@
+/*
+ * 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.scenarios;
+
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.utils.Disposable;
+
+/**
+ * Base class for hint screens.
+ */
+public abstract class HintsOverlayBase implements Disposable{
+ /**
+ * Renders the overlay.
+ *
+ * @param batch The {@link SpriteBatch} to use for rendering.
+ */
+ public abstract void render(SpriteBatch batch);
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
index 474ab02..6670a38 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
@@ -45,6 +45,7 @@ public abstract class ScenarioGlobals{
private static SummaryOverlayBase automaticActionSummaryOverlay = null;
private static PlayerSystemBase playerSystem = null;
private static SummaryOverlayBase scenarioSummaryOverlay = null;
+ private static HintsOverlayBase hintsOverlay = null;
public static void init(NxtARCore core) throws IllegalArgumentException, InstantiationException, IllegalAccessException{
if(core == null)
@@ -132,6 +133,18 @@ public abstract class ScenarioGlobals{
}
}
+ if(hintsOverlay == null){
+ try {
+ hintsOverlay = (HintsOverlayBase) ScenarioImplementation.hintsOverlayClass.newInstance();
+ } catch (InstantiationException e) {
+ System.out.println("Error instantiating hints overlay.");
+ throw e;
+ } catch (IllegalAccessException e) {
+ System.out.println("Error accessing hints overlay.");
+ throw e;
+ }
+ }
+
playerSystem.setCore(core);
gameWorld.setSystem(new MarkerPositioningSystem());
@@ -165,6 +178,7 @@ public abstract class ScenarioGlobals{
scenarioSummaryOverlay.dispose();
automaticActionSummaryOverlay.dispose();
entityCreator.dispose();
+ hintsOverlay.dispose();
entityCreator = null;
gameLogicSystem = null;
@@ -173,6 +187,7 @@ public abstract class ScenarioGlobals{
automaticActionSummaryOverlay = null;
playerSystem = null;
scenarioSummaryOverlay = null;
+ hintsOverlay = null;
System.gc();
}
@@ -225,4 +240,11 @@ public abstract class ScenarioGlobals{
return scenarioSummaryOverlay;
}
+
+ public static HintsOverlayBase getHintsOverlay() throws IllegalStateException{
+ if(hintsOverlay == null)
+ throw new IllegalStateException("Calling getHintsOverlay() before init.");
+
+ return hintsOverlay;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java
index 3d50517..62edff3 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioImplementation.java
@@ -18,6 +18,7 @@ package ve.ucv.ciens.ccg.nxtar.scenarios;
import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionPerformer;
import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionSummaryOverlay;
import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator;
+import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameInstructionsOverlay;
import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameLogicSystem;
import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGamePlayerSystem;
import ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameScenarioEndingOverlay;
@@ -30,6 +31,7 @@ public final class ScenarioImplementation{
public static final Class automaticActionSummaryOverlay = BombGameAutomaticActionSummaryOverlay.class;
public static final Class playerSystemClass = BombGamePlayerSystem.class;
public static final Class scenarioSummaryOverlayClass = BombGameScenarioEndingOverlay.class;
+ public static final Class hintsOverlayClass = BombGameInstructionsOverlay.class;
private ScenarioImplementation(){}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java
new file mode 100644
index 0000000..52a705c
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java
@@ -0,0 +1,120 @@
+/*
+ * 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.scenarios.bombgame;
+
+import ve.ucv.ciens.ccg.nxtar.scenarios.HintsOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
+
+public class BombGameInstructionsOverlay extends HintsOverlayBase {
+ private static final float CANNONICAL_SCREEN_WIDTH = 800.0f;
+
+ private Texture inclinationBombTexture;
+ private Texture combinationBombTexture;
+ private Texture wireBombTexture;
+ private BitmapFont font;
+ private BitmapFont titleFont;
+ private Sprite inclinationBomb;
+ private Sprite combinationBomb;
+ private Sprite wireBomb;
+ private float inclinationX;
+ private float combinationX;
+ private float wireX;
+ private float inclinationY;
+ private float combinationY;
+ private float wireY;
+ private float titleWidth;
+ private float titleHeight;
+
+ public BombGameInstructionsOverlay(){
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+
+ inclinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/incl_bomb.png"));
+ combinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/comb_bomb.png"));
+ wireBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/wire_bomb.png"));
+
+ inclinationBomb = new Sprite(inclinationBombTexture);
+ combinationBomb = new Sprite(combinationBombTexture);
+ wireBomb = new Sprite(wireBombTexture);
+
+ inclinationBomb.setSize(inclinationBomb.getWidth() * 0.5f, inclinationBomb.getHeight() * 0.5f);
+ combinationBomb.setSize(combinationBomb.getWidth() * 0.5f, combinationBomb.getHeight() * 0.5f);
+ wireBomb.setSize(wireBomb.getWidth() * 0.5f, wireBomb.getHeight() * 0.5f);
+
+ combinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - combinationBomb.getWidth(), -(combinationBomb.getHeight() / 2.0f));
+ inclinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - inclinationBomb.getWidth(), combinationBomb.getY() + combinationBomb.getHeight() + 10.0f);
+ wireBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - wireBomb.getWidth(), combinationBomb.getY() - wireBomb.getHeight() - 10.0f);
+
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+
+ font = fontGenerator.generateFont(fontParameters);
+ font.setColor(Color.YELLOW);
+
+ fontParameters.size = (int)(90.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ titleFont = fontGenerator.generateFont(fontParameters);
+
+ fontGenerator.dispose();
+
+ inclinationX = inclinationBomb.getX() + inclinationBomb.getWidth() + 15.0f;
+ combinationX = combinationBomb.getX() + combinationBomb.getWidth() + 15.0f;
+ wireX = wireBomb.getX() + wireBomb.getWidth() + 15.0f;
+
+ inclinationY = inclinationBomb.getY() + (inclinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
+ combinationY = combinationBomb.getY() + (combinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
+ wireY = wireBomb.getY() + (wireBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
+
+ titleWidth = titleFont.getBounds("Instructions").width;
+ titleHeight = titleFont.getBounds("Instructions").height;
+ }
+
+ @Override
+ public void dispose() {
+ inclinationBombTexture.dispose();
+ combinationBombTexture.dispose();
+ wireBombTexture.dispose();
+ font.dispose();
+ titleFont.dispose();
+ }
+
+ @Override
+ public void render(SpriteBatch batch){
+ String inclText = Utils.deviceHasOrientationSensors() ? "Balance your device" : "Always defuses.";
+
+ inclinationBomb.draw(batch);
+ combinationBomb.draw(batch);
+ wireBomb.draw(batch);
+
+ font.draw(batch, inclText, inclinationX, inclinationY);
+ font.draw(batch, "Blue, red, gray and green", combinationX, combinationY);
+ font.draw(batch, "Cut the blue wire.", wireX, wireY);
+
+ titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java
index adfdfd1..dfeb62b 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameLogicSystem.java
@@ -227,10 +227,12 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld();
- if(!Utils.isDeviceRollValid() || (Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL)){
- Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
- createFadeOutEffect();
- reducePlayerLivesByOne();
+ if(Utils.deviceHasOrientationSensors()){
+ if(!Utils.isDeviceRollValid() || (Utils.isDeviceRollValid() && Math.abs(Gdx.input.getRoll()) > ProjectConstants.MAX_ABS_ROLL)){
+ Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb exploded.");
+ createFadeOutEffect();
+ reducePlayerLivesByOne();
+ }
}
// Disable all related entities.
@@ -363,7 +365,7 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
Gdx.app.log(TAG, CLASS_NAME + ".reducePlayerLivesByOne(): No players found.");
}
}
-
+
/**
* Disables all entities associated with the corresponding marker code.
*
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 798c1b4..2cdae95 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -124,6 +124,7 @@ public class InGameState extends BaseState{
private Texture correctAngleLedOnTexture;
private Texture correctAngleLedOffTexture;
private Texture orientationSliderTexture;
+ private Texture hintButtonTexture;
// Gui renderable sprites.
private Sprite motorAButton;
@@ -142,6 +143,7 @@ public class InGameState extends BaseState{
private Sprite correctAngleLedOnSprite;
private Sprite correctAngleLedOffSprite;
private Sprite orientationSlider;
+ private Sprite hintButton;
// Button touch helper fields.
private boolean[] buttonsTouched;
@@ -231,6 +233,16 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya)
setUpButtons();
+ // Set up the hint button.
+ // Set up the correct angle leds.
+ hintButtonTexture = new Texture(Gdx.files.internal("data/gfx/gui/help.png"));
+ hintButton = new Sprite(hintButtonTexture);
+ hintButton.setSize(hintButton.getWidth() * (Ouya.runningOnOuya ? 0.5f : 0.25f), hintButton.getHeight() * (Ouya.runningOnOuya ? 0.5f : 0.25f));
+ if(!Ouya.runningOnOuya)
+ hintButton.setPosition(-(Gdx.graphics.getWidth() / 2) + 5, (Gdx.graphics.getHeight() / 2) - hintButton.getHeight() - 5);
+ else
+ hintButton.setPosition(-(Utils.getScreenWidthWithOverscan() / 2) + 5, -hintButton.getHeight() / 2);
+
// Set up the game world.
gameWorld = ScenarioGlobals.getGameWorld();
@@ -443,6 +455,11 @@ public class InGameState extends BaseState{
}core.batch.end();
}
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
+ core.batch.begin();{
+ hintButton.draw(core.batch);
+ }core.batch.end();
+
fadeEffectRenderingSystem.process();
playerSystem.process();
@@ -484,6 +501,9 @@ public class InGameState extends BaseState{
if(orientationSliderTexture != null)
orientationSliderTexture.dispose();
+ if(hintButtonTexture != null)
+ hintButtonTexture.dispose();
+
if(backgroundShader != null)
backgroundShader.dispose();
@@ -744,17 +764,20 @@ public class InGameState extends BaseState{
buttonPointers[7] = pointer;
controlMode = controlMode.getValue() == robot_control_mode_t.WHEEL_CONTROL.getValue() ? robot_control_mode_t.ARM_CONTROL : robot_control_mode_t.WHEEL_CONTROL;
+ }else if(hintButton.getBoundingRectangle().contains(touchPointWorldCoords)){
+ core.nextState = game_states_t.HINTS;
}else{
+ if(controlMode == robot_control_mode_t.ARM_CONTROL){
+ touchPointWorldCoords.set(win2world.x, win2world.y);
- touchPointWorldCoords.set(win2world.x, win2world.y);
+ if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
+ Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer.");
+ input = new TouchUserInput();
+ robotArmPositioningSystem.setUserInput(input);
- if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
- Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer.");
- input = new TouchUserInput();
- robotArmPositioningSystem.setUserInput(input);
-
- }else{
- Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point outside framebuffer.");
+ }else{
+ Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point outside framebuffer.");
+ }
}
}
@@ -1060,6 +1083,9 @@ public class InGameState extends BaseState{
if(keycode == Input.Keys.BACK){
core.nextState = game_states_t.MAIN_MENU;
return true;
+ }else if(keycode == Input.Keys.F1){
+ core.nextState = game_states_t.HINTS;
+ return true;
}
switch(keycode){
@@ -1223,7 +1249,9 @@ public class InGameState extends BaseState{
robotArmPositioningSystem.setUserInput(userInput);
robotArmPositioningSystem.process();
- }else if(buttonCode == Ouya.BUTTON_A){
+ }else if(buttonCode == Ouya.BUTTON_U){
+ core.nextState = game_states_t.HINTS;
+ }else if(buttonCode == Ouya.BUTTON_A || buttonCode == Ouya.BUTTON_MENU){
core.nextState = game_states_t.MAIN_MENU;
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java
new file mode 100644
index 0000000..639f99f
--- /dev/null
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java
@@ -0,0 +1,326 @@
+/*
+ * 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.states;
+
+import ve.ucv.ciens.ccg.nxtar.NxtARCore;
+import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
+import ve.ucv.ciens.ccg.nxtar.scenarios.HintsOverlayBase;
+import ve.ucv.ciens.ccg.nxtar.scenarios.ScenarioGlobals;
+import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
+import ve.ucv.ciens.ccg.nxtar.utils.Utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.controllers.Controller;
+import com.badlogic.gdx.controllers.mappings.Ouya;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.Texture.TextureFilter;
+import com.badlogic.gdx.graphics.Texture.TextureWrap;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
+import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
+import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
+
+public class InstructionsState extends BaseState {
+ private static final String TAG = "HINTS_STATE";
+ private static final String CLASS_NAME = InstructionsState.class.getSimpleName();
+ private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
+
+ // Helper fields.
+ private float u_scaling[];
+ private float u_displacement;
+
+ // Buttons and other gui components.
+ private TextButton continueButton;
+ private Rectangle continueButtonBBox;
+ private Sprite background;
+ private Texture backgroundTexture;
+ private ShaderProgram backgroundShader;
+ private Texture ouyaOButtonTexture;
+ private Sprite ouyaOButton;
+ private boolean oButtonPressed;
+
+ // Graphic data for the start button.
+ private Texture buttonEnabledTexture;
+ private Texture buttonDisabledTexture;
+ private Texture buttonPressedTexture;
+ private BitmapFont font;
+
+ // Overlay related fields.
+ HintsOverlayBase hintsOverlay;
+
+ // Button touch helper fields.
+ private boolean continueButtonTouched;
+ private int continueButtonTouchPointer;
+
+ public InstructionsState(NxtARCore core) throws IllegalArgumentException{
+ TextButtonStyle textButtonStyle;
+ FreeTypeFontGenerator fontGenerator;
+ FreeTypeFontParameter fontParameters;
+ NinePatch buttonEnabled9p;
+ NinePatch buttonDisabled9p;
+ NinePatch buttonPressed9p;
+
+ if(core == null)
+ throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
+
+ this.core = core;
+ this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ oButtonPressed = false;
+ hintsOverlay = ScenarioGlobals.getHintsOverlay();
+
+ // Create the start button background.
+ buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
+ buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
+ buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
+ buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
+ buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
+
+ // Create the start button font.
+ fontParameters = new FreeTypeFontParameter();
+ fontParameters.characters = ProjectConstants.FONT_CHARS;
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
+ fontParameters.flip = false;
+ fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
+ font = fontGenerator.generateFont(fontParameters);
+ fontGenerator.dispose();
+
+ // Create the contine button.
+ textButtonStyle = new TextButtonStyle();
+ textButtonStyle.font = font;
+ textButtonStyle.up = new NinePatchDrawable(buttonEnabled9p);
+ textButtonStyle.checked = new NinePatchDrawable(buttonPressed9p);
+ textButtonStyle.disabled = new NinePatchDrawable(buttonDisabled9p);
+ textButtonStyle.fontColor = new Color(Color.BLACK);
+ textButtonStyle.downFontColor = new Color(Color.WHITE);
+ textButtonStyle.disabledFontColor = new Color(Color.BLACK);
+
+ continueButton = new TextButton("Continue", textButtonStyle);
+ continueButton.setText("Continue");
+ continueButton.setPosition(-(continueButton.getWidth() / 2), -(Utils.getScreenHeightWithOverscan() / 2) + 10);
+ continueButtonBBox = new Rectangle(0, 0, continueButton.getWidth(), continueButton.getHeight());
+ continueButtonBBox.setPosition(continueButton.getX(), continueButton.getY());
+
+ // Set OUYA's O button.
+ if(Ouya.runningOnOuya){
+ ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
+ ouyaOButton = new Sprite(ouyaOButtonTexture);
+ ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ oButtonPressed = false;
+ }else{
+ ouyaOButtonTexture = null;
+ }
+
+ // Set up the background.
+ backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
+ backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
+ backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ background = new Sprite(backgroundTexture);
+ background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
+
+ backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + "_vert.glsl"), Gdx.files.internal(SHADER_PATH + "_frag.glsl"));
+ if(!backgroundShader.isCompiled()){
+ Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
+ Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
+ backgroundShader = null;
+ }
+
+ u_scaling = new float[2];
+ 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();
+ continueButtonTouched = false;
+ continueButtonTouchPointer = -1;
+ stateActive = false;
+ }
+
+ @Override
+ public void render(float delta){
+ Gdx.gl.glClearColor(1, 1, 1, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
+ core.batch.begin();{
+
+ // Render background.
+ core.batch.disableBlending();
+ drawBackground(core.batch);
+ core.batch.enableBlending();
+
+ hintsOverlay.render(core.batch);
+
+ // Render buttons.
+ continueButton.draw(core.batch, 1.0f);
+ if(Ouya.runningOnOuya)
+ ouyaOButton.draw(core.batch);
+
+ }core.batch.end();
+ }
+
+ @Override
+ public void dispose(){
+ buttonEnabledTexture.dispose();
+ buttonDisabledTexture.dispose();
+ buttonPressedTexture.dispose();
+ if(ouyaOButtonTexture != null)
+ ouyaOButtonTexture.dispose();
+ backgroundTexture.dispose();
+ if(backgroundShader != null) backgroundShader.dispose();
+ font.dispose();
+ }
+
+ private void drawBackground(SpriteBatch batch){
+ 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
+ public void onStateSet(){
+ stateActive = true;
+ Gdx.input.setInputProcessor(this);
+ Gdx.input.setCatchBackKey(true);
+ Gdx.input.setCatchMenuKey(true);
+ }
+
+ @Override
+ public void onStateUnset(){
+ stateActive = false;
+ Gdx.input.setInputProcessor(null);
+ Gdx.input.setCatchBackKey(false);
+ Gdx.input.setCatchMenuKey(false);
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; INPUT LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean touchDown(int screenX, int screenY, int pointer, int button){
+ unprojectTouch(screenX, screenY);
+
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
+
+ if(!continueButton.isDisabled() && continueButtonBBox.contains(touchPointWorldCoords)){
+ continueButton.setChecked(true);
+ continueButtonTouched = true;
+ continueButtonTouchPointer = pointer;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean touchUp(int screenX, int screenY, int pointer, int button){
+ unprojectTouch(screenX, screenY);
+
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
+ Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
+
+ if(!continueButton.isDisabled() && continueButtonBBox.contains(touchPointWorldCoords) && continueButtonTouched){
+ continueButton.setChecked(false);
+ continueButtonTouched = false;
+ continueButtonTouchPointer = -1;
+ core.nextState = game_states_t.IN_GAME;
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean touchDragged(int screenX, int screenY, int pointer){
+ unprojectTouch(screenX, screenY);
+
+ if(!continueButton.isDisabled() && continueButtonTouched && pointer == continueButtonTouchPointer && !continueButtonBBox.contains(touchPointWorldCoords)){
+ continueButtonTouchPointer = -1;
+ continueButtonTouched = false;
+ continueButton.setChecked(false);
+ Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean keyDown(int keycode){
+ if(keycode == Input.Keys.BACK){
+ core.nextState = game_states_t.IN_GAME;
+ return true;
+ }
+ return false;
+ }
+
+ /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; CONTROLLER LISTENER METHODS ;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
+
+ @Override
+ public boolean buttonDown(Controller controller, int buttonCode){
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O && !continueButton.isDisabled()){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
+ oButtonPressed = true;
+ continueButton.setChecked(true);
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean buttonUp(Controller controller, int buttonCode){
+ if(stateActive){
+ if(buttonCode == Ouya.BUTTON_O){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
+ if(oButtonPressed){
+ oButtonPressed = false;
+ continueButton.setChecked(false);
+ core.nextState = game_states_t.IN_GAME;
+ }
+ }
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java b/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
index ced6867..f94d916 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
@@ -49,8 +49,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
public class ScenarioEndSummaryState extends BaseState {
- private static final String TAG = "AUTO_SUMMARY";
- private static final String CLASS_NAME = AutomaticActionSummaryState.class.getSimpleName();
+ private static final String TAG = "SCENARIO_SUMMARY";
+ private static final String CLASS_NAME = ScenarioEndSummaryState.class.getSimpleName();
private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
// Helper fields.
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index fc59807..a1ff564 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -31,6 +31,7 @@ import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.math.Vector3;
public class RobotArmPositioningSystem extends EntityProcessingSystem {
@@ -82,6 +83,8 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
}else autoMove(geometry, auto, collision);
+ input = null;
+
}else if(input instanceof GamepadUserInput){
tempGP = (GamepadUserInput) input;
@@ -89,12 +92,16 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
if(!tempGP.oButton){
geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
+ if(Math.abs(tempGP.axisLeftX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisLeftY) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisRightX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisRightY) < Ouya.STICK_DEADZONE)
+ input = null;
}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;
+
+ input = null;
}
}else autoMove(geometry, auto, collision);
@@ -116,11 +123,11 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
}
}else autoMove(geometry, auto, collision);
+ input = null;
+
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
}
-
- input = null;
}
private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
index beda501..c8e8470 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/ProjectConstants.java
@@ -28,14 +28,14 @@ public abstract class ProjectConstants{
public static final int EXIT_SUCCESS = 0;
public static final int EXIT_FAILURE = 1;
- public static final boolean DEBUG = true;
+ public static final boolean DEBUG = false;
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 OVERSCAN;
public static final int MENU_BUTTON_FONT_SIZE;
- public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:";
+ public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:,";
public static final int MAXIMUM_NUMBER_OF_MARKERS = 5;
public static final int CALIBRATION_PATTERN_POINTS = 54;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
index 677ab82..68f6bac 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
@@ -52,16 +52,25 @@ public abstract class Utils{
return (int)(Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
}
+ /**
+ * Checks if the running device posseses and accelerometer and compass.
+ *
+ * @return True when the device supports both sensors. False otherwise.
+ */
+ public static boolean deviceHasOrientationSensors(){
+ return Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Gdx.input.isPeripheralAvailable(Peripheral.Compass);
+ }
+
/**
* Checks if the device's orientation is available and wihtin some arbitrary ranges.
*
* @return True if the device can detect it's orientation and it's within range. False otherwise.
*/
public static boolean isDeviceRollValid(){
- boolean rollValid = Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) && Gdx.input.isPeripheralAvailable(Peripheral.Compass);
+ boolean rollValid = false;
float azimuth, pitch;
- if(rollValid){
+ if(deviceHasOrientationSensors()){
azimuth = Gdx.input.getAzimuth();
pitch = Gdx.input.getPitch();
From a9285a684fe4389d6432b679267b4079fb3de762 Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 26 Jun 2014 13:01:39 -0430
Subject: [PATCH 33/34] Fixed a bug with the orientation calculation.
---
src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
index 68f6bac..dbd0686 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/utils/Utils.java
@@ -67,7 +67,7 @@ public abstract class Utils{
* @return True if the device can detect it's orientation and it's within range. False otherwise.
*/
public static boolean isDeviceRollValid(){
- boolean rollValid = false;
+ boolean rollValid = true;
float azimuth, pitch;
if(deviceHasOrientationSensors()){
@@ -79,7 +79,8 @@ public abstract class Utils{
if(rollValid && (azimuth < MIN_AZIMUTH || azimuth > MAX_AZIMUTH))
rollValid = false;
- }
+ }else
+ rollValid = false;
return rollValid;
}
From 53ae001e59702dae693f2a4fa4209889259f8307 Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 26 Jun 2014 18:25:28 -0430
Subject: [PATCH 34/34] Assorted fixes for OUYA.
---
.../ccg/nxtar/scenarios/ScenarioGlobals.java | 3 +-
...BombGameAutomaticActionSummaryOverlay.java | 11 +-
.../bombgame/BombGameInstructionsOverlay.java | 11 +-
.../BombGameScenarioEndingOverlay.java | 12 +-
.../states/AutomaticActionSummaryState.java | 1 +
.../ciens/ccg/nxtar/states/InGameState.java | 177 +++++++++---------
.../ccg/nxtar/states/InstructionsState.java | 1 +
.../ccg/nxtar/states/OuyaMainMenuState.java | 21 ++-
.../nxtar/states/ScenarioEndSummaryState.java | 1 +
.../systems/RobotArmPositioningSystem.java | 26 ++-
10 files changed, 159 insertions(+), 105 deletions(-)
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
index 6670a38..864df04 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java
@@ -32,7 +32,6 @@ import com.artemis.EntitySystem;
import com.artemis.World;
import com.artemis.managers.GroupManager;
import com.artemis.utils.ImmutableBag;
-import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable;
@@ -148,7 +147,7 @@ public abstract class ScenarioGlobals{
playerSystem.setCore(core);
gameWorld.setSystem(new MarkerPositioningSystem());
- gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
+ gameWorld.setSystem(new RobotArmPositioningSystem());
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem());
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java
index f3ec640..f1b3749 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameAutomaticActionSummaryOverlay.java
@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
@@ -72,7 +73,10 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
- fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ if(!Ouya.runningOnOuya)
+ fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ else
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -122,6 +126,9 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY);
font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);
- titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
+ if(!Ouya.runningOnOuya)
+ titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
+ else
+ titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java
index 52a705c..7b6c219 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameInstructionsOverlay.java
@@ -20,6 +20,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
@@ -70,7 +71,10 @@ public class BombGameInstructionsOverlay extends HintsOverlayBase {
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
- fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ if(!Ouya.runningOnOuya)
+ fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ else
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -115,6 +119,9 @@ public class BombGameInstructionsOverlay extends HintsOverlayBase {
font.draw(batch, "Blue, red, gray and green", combinationX, combinationY);
font.draw(batch, "Cut the blue wire.", wireX, wireY);
- titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
+ if(!Ouya.runningOnOuya)
+ titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
+ else
+ titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java
index fc6df52..97c6c82 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/bombgame/BombGameScenarioEndingOverlay.java
@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
@@ -44,7 +45,10 @@ public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
- fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ if(!Ouya.runningOnOuya)
+ fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
+ else
+ fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -96,6 +100,10 @@ public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
else
title = "Game Over";
titleBounds = titleFont.getBounds(title);
- titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10);
+
+ if(!Ouya.runningOnOuya)
+ titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10);
+ else
+ titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
index 79c9cd9..c4473d1 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/AutomaticActionSummaryState.java
@@ -136,6 +136,7 @@ public class AutomaticActionSummaryState extends BaseState{
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false;
}else{
ouyaOButtonTexture = null;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
index 2cdae95..66a73cf 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java
@@ -57,6 +57,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.utils.GdxRuntimeException;
public class InGameState extends BaseState{
private static final String TAG = "IN_GAME_STATE";
@@ -309,104 +310,108 @@ public class InGameState extends BaseState{
// If a valid frame was fetched.
if(data != null && data.outFrame != null){
- // Set the camera to the correct projection.
- focalPointX = core.cvProc.getFocalPointX();
- focalPointY = core.cvProc.getFocalPointY();
- cameraCenterX = core.cvProc.getCameraCenterX();
- cameraCenterY = core.cvProc.getCameraCenterY();
- perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
- perspectiveCamera.update(perspectiveCamera.projection);
+ try{
+ // Set the camera to the correct projection.
+ focalPointX = core.cvProc.getFocalPointX();
+ focalPointY = core.cvProc.getFocalPointY();
+ cameraCenterX = core.cvProc.getCameraCenterX();
+ cameraCenterY = core.cvProc.getCameraCenterY();
+ perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
+ perspectiveCamera.update(perspectiveCamera.projection);
- // Update the game state.
- if(controlMode == robot_control_mode_t.ARM_CONTROL)
- gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
- else
- gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
+ // Update the game state.
+ if(controlMode == robot_control_mode_t.ARM_CONTROL || Ouya.runningOnOuya)
+ gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
+ else
+ gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
- gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
- gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
- gameWorld.process();
+ gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
+ gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
+ gameWorld.process();
- // Decode the video frame.
- videoFrame = new Pixmap(data.outFrame, 0, w * h);
- videoFrameTexture = new Texture(videoFrame);
- videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
- videoFrame.dispose();
+ // Decode the video frame.
+ videoFrame = new Pixmap(data.outFrame, 0, w * h);
+ videoFrameTexture = new Texture(videoFrame);
+ videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ videoFrame.dispose();
- // Convert the decoded frame into a renderable texture.
- region = new TextureRegion(videoFrameTexture, 0, 0, w, h);
- if(renderableVideoFrame == null)
- renderableVideoFrame = new Sprite(region);
- else
- renderableVideoFrame.setRegion(region);
- renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2, renderableVideoFrame.getHeight() / 2);
- renderableVideoFrame.setPosition(0, 0);
+ // Convert the decoded frame into a renderable texture.
+ region = new TextureRegion(videoFrameTexture, 0, 0, w, h);
+ if(renderableVideoFrame == null)
+ renderableVideoFrame = new Sprite(region);
+ else
+ renderableVideoFrame.setRegion(region);
+ renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2, renderableVideoFrame.getHeight() / 2);
+ renderableVideoFrame.setPosition(0, 0);
- // Set the 3D frame buffer for rendering.
- frameBuffer.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);
+ // Set the 3D frame buffer for rendering.
+ frameBuffer.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.
- markerRenderingSystem.begin(perspectiveCamera);
- markerRenderingSystem.process();
- markerRenderingSystem.end();
+ // Call rendering systems.
+ 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();
+ if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
+ objectRenderingSystem.begin(perspectiveCamera);
+ objectRenderingSystem.process();
+ objectRenderingSystem.end();
+ }
+ }frameBuffer.end();
+
+ // Set the frame buffer object texture to a renderable sprite.
+ region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
+ region.flip(false, true);
+ if(frameBufferSprite == null)
+ frameBufferSprite = new Sprite(region);
+ else
+ frameBufferSprite.setRegion(region);
+ frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
+ frameBufferSprite.setPosition(0, 0);
+
+ // Set the position and orientation of the renderable video frame and the frame buffer.
+ if(!Ouya.runningOnOuya){
+ renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
+ renderableVideoFrame.rotate90(true);
+ renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, 0.5f - renderableVideoFrame.getHeight());
+
+ frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth() );
+ frameBufferSprite.rotate90(true);
+ frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
+
+ }else{
+ float xSize = Gdx.graphics.getHeight() * (w / h);
+ renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
+ renderableVideoFrame.rotate90(true);
+ renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
+
+ frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
+ frameBufferSprite.rotate90(true);
+ frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
}
- }frameBuffer.end();
- // Set the frame buffer object texture to a renderable sprite.
- region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
- region.flip(false, true);
- if(frameBufferSprite == null)
- frameBufferSprite = new Sprite(region);
- else
- frameBufferSprite.setRegion(region);
- frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
- frameBufferSprite.setPosition(0, 0);
+ // Set the correct camera for the device.
+ if(!Ouya.runningOnOuya){
+ core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
+ }else{
+ core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
+ }
- // Set the position and orientation of the renderable video frame and the frame buffer.
- if(!Ouya.runningOnOuya){
- renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
- renderableVideoFrame.rotate90(true);
- renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, 0.5f - renderableVideoFrame.getHeight());
+ // Render the video frame and the frame buffer.
+ core.batch.begin();{
+ renderableVideoFrame.draw(core.batch);
+ frameBufferSprite.draw(core.batch);
+ }core.batch.end();
- frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth() );
- frameBufferSprite.rotate90(true);
- frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
-
- }else{
- float xSize = Gdx.graphics.getHeight() * (w / h);
- renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
- renderableVideoFrame.rotate90(true);
- renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
-
- frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
- frameBufferSprite.rotate90(true);
- frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
+ // Clear the video frame from memory.
+ videoFrameTexture.dispose();
+ }catch(GdxRuntimeException e){
+ Gdx.app.error(TAG, CLASS_NAME + ".render(): Runtime exception caught: ", e);
}
-
- // Set the correct camera for the device.
- if(!Ouya.runningOnOuya){
- core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
- }else{
- core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
- }
-
- // Render the video frame and the frame buffer.
- core.batch.begin();{
- renderableVideoFrame.draw(core.batch);
- frameBufferSprite.draw(core.batch);
- }core.batch.end();
-
- // Clear the video frame from memory.
- videoFrameTexture.dispose();
}
// Render the interface buttons.
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java
index 639f99f..e647165 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/InstructionsState.java
@@ -133,6 +133,7 @@ public class InstructionsState extends BaseState {
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false;
}else{
ouyaOButtonTexture = null;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
index 4390d7a..3611e84 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/OuyaMainMenuState.java
@@ -150,10 +150,10 @@ public class OuyaMainMenuState extends MainMenuStateBase{
}
}else if(buttonCode == Ouya.BUTTON_DPAD_UP){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
- oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
+ oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
}else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
- oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
+ oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
}
return true;
@@ -189,4 +189,21 @@ public class OuyaMainMenuState extends MainMenuStateBase{
return false;
}
}
+
+ @Override
+ public boolean axisMoved(Controller controller, int axisCode, float value){
+ if(Math.abs(value) > 0.99f){
+ if(axisCode == Ouya.AXIS_LEFT_Y && value < 0.0f){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
+ oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
+ }else if(axisCode == Ouya.AXIS_LEFT_Y && value >= 0.0f){
+ Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
+ oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java b/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
index f94d916..51b5336 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/states/ScenarioEndSummaryState.java
@@ -136,6 +136,7 @@ public class ScenarioEndSummaryState extends BaseState {
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
+ ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false;
}else{
ouyaOButtonTexture = null;
diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
index a1ff564..daab97a 100644
--- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
+++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java
@@ -82,9 +82,7 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
}else autoMove(geometry, auto, collision);
-
input = null;
-
}else if(input instanceof GamepadUserInput){
tempGP = (GamepadUserInput) input;
@@ -92,18 +90,22 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
if(!tempGP.oButton){
geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
- if(Math.abs(tempGP.axisLeftX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisLeftY) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisRightX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisRightY) < Ouya.STICK_DEADZONE)
+ if(Math.abs(tempGP.axisLeftX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisLeftY) < Ouya.STICK_DEADZONE)
input = null;
+ else
+ input = (UserInput)tempGP;
}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;
-
input = null;
}
- }else autoMove(geometry, auto, collision);
+ }else{
+ autoMove(geometry, auto, collision);
+ input = null;
+ }
}else if(input instanceof KeyboardUserInput){
tempKey = (KeyboardUserInput) input;
@@ -114,20 +116,26 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
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;
+ if(!tempKey.keyUp && !tempKey.keyUp && !tempKey.keyUp && !tempKey.keyUp)
+ input = null;
+ else
+ input = (UserInput)tempKey;
}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;
+ input = null;
}
- }else autoMove(geometry, auto, collision);
-
- input = null;
-
+ }else{
+ autoMove(geometry, auto, collision);
+ input = null;
+ }
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
}
+
}
private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){