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 component, NxtARCore core){ + public PlayerSystemBase(Class 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); - }