Assorted fixes for OUYA.

This commit is contained in:
2014-06-26 18:25:28 -04:30
parent a9285a684f
commit 53ae001e59
10 changed files with 159 additions and 105 deletions

View File

@@ -32,7 +32,6 @@ import com.artemis.EntitySystem;
import com.artemis.World; import com.artemis.World;
import com.artemis.managers.GroupManager; import com.artemis.managers.GroupManager;
import com.artemis.utils.ImmutableBag; import com.artemis.utils.ImmutableBag;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.g3d.ModelBatch; import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
@@ -148,7 +147,7 @@ public abstract class ScenarioGlobals{
playerSystem.setCore(core); playerSystem.setCore(core);
gameWorld.setSystem(new MarkerPositioningSystem()); gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya); gameWorld.setSystem(new RobotArmPositioningSystem());
gameWorld.setSystem(new GeometrySystem()); gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem()); gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem()); gameWorld.setSystem(new CollisionDetectionSystem());

View File

@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
@@ -72,7 +73,10 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
fontParameters = new FreeTypeFontParameter(); fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS; fontParameters.characters = ProjectConstants.FONT_CHARS;
if(!Ouya.runningOnOuya)
fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH)); 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; fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf")); 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("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY);
font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY); font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10); titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
else
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
} }
} }

View File

@@ -20,6 +20,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
@@ -70,7 +71,10 @@ public class BombGameInstructionsOverlay extends HintsOverlayBase {
fontParameters = new FreeTypeFontParameter(); fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS; fontParameters.characters = ProjectConstants.FONT_CHARS;
if(!Ouya.runningOnOuya)
fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH)); 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; fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf")); 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, "Blue, red, gray and green", combinationX, combinationY);
font.draw(batch, "Cut the blue wire.", wireX, wireY); font.draw(batch, "Cut the blue wire.", wireX, wireY);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10); titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
else
titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
} }
} }

View File

@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils; import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
@@ -44,7 +45,10 @@ public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
fontParameters = new FreeTypeFontParameter(); fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS; fontParameters.characters = ProjectConstants.FONT_CHARS;
if(!Ouya.runningOnOuya)
fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH)); fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
else
fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false; fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf")); fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -96,6 +100,10 @@ public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
else else
title = "Game Over"; title = "Game Over";
titleBounds = titleFont.getBounds(title); titleBounds = titleFont.getBounds(title);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10); 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);
} }
} }

View File

@@ -136,6 +136,7 @@ public class AutomaticActionSummaryState extends BaseState{
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png"); ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture); ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f); ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false; oButtonPressed = false;
}else{ }else{
ouyaOButtonTexture = null; ouyaOButtonTexture = null;

View File

@@ -57,6 +57,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
public class InGameState extends BaseState{ public class InGameState extends BaseState{
private static final String TAG = "IN_GAME_STATE"; private static final String TAG = "IN_GAME_STATE";
@@ -309,6 +310,7 @@ public class InGameState extends BaseState{
// If a valid frame was fetched. // If a valid frame was fetched.
if(data != null && data.outFrame != null){ if(data != null && data.outFrame != null){
try{
// Set the camera to the correct projection. // Set the camera to the correct projection.
focalPointX = core.cvProc.getFocalPointX(); focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY(); focalPointY = core.cvProc.getFocalPointY();
@@ -318,7 +320,7 @@ public class InGameState extends BaseState{
perspectiveCamera.update(perspectiveCamera.projection); perspectiveCamera.update(perspectiveCamera.projection);
// Update the game state. // Update the game state.
if(controlMode == robot_control_mode_t.ARM_CONTROL) if(controlMode == robot_control_mode_t.ARM_CONTROL || Ouya.runningOnOuya)
gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions(); gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
else else
gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions(); gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
@@ -407,6 +409,9 @@ public class InGameState extends BaseState{
// Clear the video frame from memory. // Clear the video frame from memory.
videoFrameTexture.dispose(); videoFrameTexture.dispose();
}catch(GdxRuntimeException e){
Gdx.app.error(TAG, CLASS_NAME + ".render(): Runtime exception caught: ", e);
}
} }
// Render the interface buttons. // Render the interface buttons.

View File

@@ -133,6 +133,7 @@ public class InstructionsState extends BaseState {
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png"); ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture); ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f); ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false; oButtonPressed = false;
}else{ }else{
ouyaOButtonTexture = null; ouyaOButtonTexture = null;

View File

@@ -150,10 +150,10 @@ public class OuyaMainMenuState extends MainMenuStateBase{
} }
}else if(buttonCode == Ouya.BUTTON_DPAD_UP){ }else if(buttonCode == Ouya.BUTTON_DPAD_UP){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed."); Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1; oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
}else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){ }else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed."); 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; return true;
@@ -189,4 +189,21 @@ public class OuyaMainMenuState extends MainMenuStateBase{
return false; 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;
}
} }

View File

@@ -136,6 +136,7 @@ public class ScenarioEndSummaryState extends BaseState {
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png"); ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture); ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f); ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false; oButtonPressed = false;
}else{ }else{
ouyaOButtonTexture = null; ouyaOButtonTexture = null;

View File

@@ -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)); 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 autoMove(geometry, auto, collision);
input = null; input = null;
}else if(input instanceof GamepadUserInput){ }else if(input instanceof GamepadUserInput){
tempGP = (GamepadUserInput) input; tempGP = (GamepadUserInput) input;
@@ -92,18 +90,22 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
if(!tempGP.oButton){ if(!tempGP.oButton){
geometry.position.x += -tempGP.axisLeftY * STEP_SIZE; geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
geometry.position.y += tempGP.axisLeftX * 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; input = null;
else
input = (UserInput)tempGP;
}else{ }else{
endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z); endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
auto.startPoint.set(geometry.position); auto.startPoint.set(geometry.position);
auto.endPoint.set(endPoint); auto.endPoint.set(endPoint);
auto.moving = true; auto.moving = true;
auto.forward = true; auto.forward = true;
input = null; input = null;
} }
}else autoMove(geometry, auto, collision); }else{
autoMove(geometry, auto, collision);
input = null;
}
}else if(input instanceof KeyboardUserInput){ }else if(input instanceof KeyboardUserInput){
tempKey = (KeyboardUserInput) input; tempKey = (KeyboardUserInput) input;
@@ -114,20 +116,26 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
geometry.position.x -= tempKey.keyDown ? 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.keyLeft ? STEP_SIZE : 0.0f;
geometry.position.y += tempKey.keyRight ? 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{ }else{
endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z); endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
auto.startPoint.set(geometry.position); auto.startPoint.set(geometry.position);
auto.endPoint.set(endPoint); auto.endPoint.set(endPoint);
auto.moving = true; auto.moving = true;
auto.forward = true; auto.forward = true;
}
}else autoMove(geometry, auto, collision);
input = null; input = null;
}
}else{
autoMove(geometry, auto, collision);
input = null;
}
}else }else
throw new ClassCastException("Input is not a valid UserInput instance."); throw new ClassCastException("Input is not a valid UserInput instance.");
} }
} }
private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){ private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){