From 6e30e6b56b40261d5bf1b04a16d36565a06bc872 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Jun 2014 12:03:17 -0430 Subject: [PATCH] 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(); }