Added processing for the remaining bombs.

This commit is contained in:
2014-06-16 16:57:47 -04:30
parent fd197211b5
commit 29c4bea104
4 changed files with 180 additions and 48 deletions

View File

@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent; import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader; import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem;
import com.artemis.Entity; import com.artemis.Entity;
@@ -53,6 +54,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false; private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false; private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
public static final String DOORS_GROUP = "DOORS"; public static final String DOORS_GROUP = "DOORS";
public static final Vector3 ROBOT_ARM_START_POINT = new Vector3(0.0f, 0.0f, -1.0f);
public static final int DOOR_OPEN_ANIMATION = 1;
public static final int DOOR_CLOSE_ANIMATION = 1;
private class EntityParameters{ private class EntityParameters{
public Environment environment; public Environment environment;
@@ -184,7 +188,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
addBomb(parameters, bomb_type_t.WIRES); addBomb(parameters, bomb_type_t.WIRES);
// Add doors. // Add doors.
parameters.nextAnimation = -1; parameters.nextAnimation = AnimationSystem.NO_ANIMATION;
parameters.loopAnimation = false; parameters.loopAnimation = false;
parameters.markerCode = 89; parameters.markerCode = 89;
@@ -233,7 +237,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){ private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity(); Entity robotArm = world.createEntity();
robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -1.0f), new Matrix3(), new Vector3(1, 1, 1))); robotArm.addComponent(new GeometryComponent(new Vector3(ROBOT_ARM_START_POINT), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment)); robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader)); robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel)); robotArm.addComponent(new RenderModelComponent(robotArmModel));

View File

@@ -26,6 +26,8 @@ import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
public class AnimationSystem extends EntityProcessingSystem { public class AnimationSystem extends EntityProcessingSystem {
public static final int NO_ANIMATION = -1;
@Mapper ComponentMapper<AnimationComponent> animationMapper; @Mapper ComponentMapper<AnimationComponent> animationMapper;
@Mapper ComponentMapper<VisibilityComponent> visibilityMapper; @Mapper ComponentMapper<VisibilityComponent> visibilityMapper;

View File

@@ -42,10 +42,12 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
private MarkerCodeComponent tempMarker; private MarkerCodeComponent tempMarker;
private BombGameObjectTypeComponent tempType; private BombGameObjectTypeComponent tempType;
private GroupManager manager;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public BombGameLogicSystem(){ public BombGameLogicSystem(){
super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class)); super(Aspect.getAspectForAll(BombGameObjectTypeComponent.class));
manager = world.getManager(GroupManager.class);
} }
@Override @Override
@@ -56,75 +58,171 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
switch(typeComponent.type){ switch(typeComponent.type){
case BombGameObjectTypeComponent.BOMB_WIRE_1: case BombGameObjectTypeComponent.BOMB_WIRE_1:
break;
case BombGameObjectTypeComponent.BOMB_WIRE_2: case BombGameObjectTypeComponent.BOMB_WIRE_2:
break;
case BombGameObjectTypeComponent.BOMB_WIRE_3: case BombGameObjectTypeComponent.BOMB_WIRE_3:
processWireBomb(e);
break; break;
case BombGameObjectTypeComponent.BIG_BUTTON: case BombGameObjectTypeComponent.BIG_BUTTON:
processInclinationBomb(e); processInclinationBomb(e);
break; break;
case BombGameObjectTypeComponent.COM_BUTTON_1: case BombGameObjectTypeComponent.COM_BUTTON_1:
break;
case BombGameObjectTypeComponent.COM_BUTTON_2: case BombGameObjectTypeComponent.COM_BUTTON_2:
break;
case BombGameObjectTypeComponent.COM_BUTTON_3: case BombGameObjectTypeComponent.COM_BUTTON_3:
break;
case BombGameObjectTypeComponent.COM_BUTTON_4: case BombGameObjectTypeComponent.COM_BUTTON_4:
processCombinationBomb(e);
break; break;
case BombGameObjectTypeComponent.DOOR: case BombGameObjectTypeComponent.DOOR:
processDoor(e); processDoor(e);
break; break;
case BombGameObjectTypeComponent.DOOR_FRAME:
break;
default: default:
Gdx.app.debug(TAG, CLASS_NAME + ".process(): Unrecognized object type.");
break; break;
} }
} }
private void processInclinationBomb(Entity b){ /**
CollisionDetectionComponent collision = collisionMapper.getSafe(b); * <p>Checks if the current player interaction disables a wire based bomb.</p>
MarkerCodeComponent marker = markerMapper.getSafe(b); *
GroupManager manager = world.getManager(GroupManager.class); * @param b An Artemis {@link Entity} that possibly represents any of a Wire Bomb's wires.
*/
private void processWireBomb(Entity b){
int relatedWires = 0;
CollisionDetectionComponent collision;
MarkerCodeComponent marker;
BombGameObjectTypeComponent wireType;
ImmutableBag<Entity> related; ImmutableBag<Entity> related;
// Get this wire's parameters.
collision = collisionMapper.getSafe(b);
marker = markerMapper.getSafe(b);
wireType = typeMapper.getSafe(b);
// if any of the parameters is missing then skip.
if(marker == null || collision == null || wireType == null){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Wire bomb is missing some components.");
return;
}
// If this bomb is still enabled and it's door is already open then process it.
if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld();
related = manager.getEntities(Integer.toString(marker.code));
// Check the state of the other wires associated with this bomb.
for(int i = 0; i < related.size(); i++){
tempType = typeMapper.getSafe(related.get(i));
if(tempType == null) continue;
if(tempType.type >= BombGameObjectTypeComponent.BOMB_WIRE_1 && tempType.type <= BombGameObjectTypeComponent.BOMB_WIRE_3){
if(tempType.type != wireType.type){
relatedWires++;
}
}
}
if(relatedWires == 0)
disableBomb(marker.code);
}
}
/**
* <p>Checks if the current player interaction disables a combination bomb.</p>
*
* @param b An Artemis {@link Entity} that possibly represents any of a Combination Bomb's buttons.
*/
private void processCombinationBomb(Entity b){
int relatedButtons = 0;
CollisionDetectionComponent collision;
MarkerCodeComponent marker;
BombGameObjectTypeComponent buttonType;
ImmutableBag<Entity> related;
// Get this wire's parameters.
collision = collisionMapper.getSafe(b);
marker = markerMapper.getSafe(b);
buttonType = typeMapper.getSafe(b);
// if any of the parameters is missing then skip.
if(marker == null || collision == null || buttonType == null){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Wire bomb is missing some components.");
return;
}
// If this bomb is still enabled and it's door is already open then process it.
if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld();
related = manager.getEntities(Integer.toString(marker.code));
// Check the state of the other wires associated with this bomb.
for(int i = 0; i < related.size(); i++){
tempType = typeMapper.getSafe(related.get(i));
if(tempType == null) continue;
if(tempType.type >= BombGameObjectTypeComponent.COM_BUTTON_1 && tempType.type <= BombGameObjectTypeComponent.COM_BUTTON_4){
if(tempType.type != buttonType.type){
relatedButtons++;
}
}
}
if(relatedButtons == 0)
disableBomb(marker.code);
}
}
/**
* <p>Checks if the current player interaction disables an inclination bomb.</p>
*
* @param b An Artemis {@link Entity} that possibly represents an Inclination Bomb's big button.
*/
private void processInclinationBomb(Entity b){
// Get the components of the big button.
CollisionDetectionComponent collision = collisionMapper.getSafe(b);
MarkerCodeComponent marker = markerMapper.getSafe(b);
// If any of the components is missing, skip this entity.
if(marker == null || collision == null ){ if(marker == null || collision == null ){
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb is missing some components."); Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb is missing some components.");
return; return;
} }
if(isDoorOpen(marker.code, manager) && marker.enabled && collision.colliding){ // If this bomb is still enabled and it's door is already open then process it.
if(marker.enabled && isDoorOpen(marker.code, manager) && collision.colliding){
// Disable the bomb and remove it from collision detection.
marker.enabled = false; marker.enabled = false;
manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP); manager.remove(b, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
manager.remove(b, Integer.toString(marker.code));
b.deleteFromWorld();
// Disable all related entities. // Disable all related entities.
related = manager.getEntities(Integer.toString(marker.code)); disableBomb(marker.code);
for(int i = 0; i < related.size(); i++){
tempMarker = markerMapper.getSafe(related.get(i));
tempType = typeMapper.getSafe(related.get(i));
// Enable collisions with the door frame. Disable collisions with other related objects. Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Inclination bomb disabled.");
if(tempMarker != null) tempMarker.enabled = false;
if(tempType != null){
if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}else{
manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}
}
}
Gdx.app.log(TAG, CLASS_NAME + ".processInclinationBomb(): Disabling inclination bomb.");
} }
} }
/**
* <p>Set's the animation for a door depending on it's collision and marker state.</p>
*
* @param d An Artemis {@link Entity} possibly representing a door.
*/
private void processDoor(Entity d){ private void processDoor(Entity d){
// Get the components of the door.
CollisionDetectionComponent collision = collisionMapper.getSafe(d); CollisionDetectionComponent collision = collisionMapper.getSafe(d);
AnimationComponent animation = animationMapper.getSafe(d); AnimationComponent animation = animationMapper.getSafe(d);
VisibilityComponent visibility = visibilityMapper.getSafe(d); VisibilityComponent visibility = visibilityMapper.getSafe(d);
MarkerCodeComponent marker = markerMapper.getSafe(d); MarkerCodeComponent marker = markerMapper.getSafe(d);
// If any of the components is missing, skip this entity.
if(marker == null || collision == null || animation == null || visibility == null){ if(marker == null || collision == null || animation == null || visibility == null){
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Door is missing some components."); Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Door is missing some components.");
return; return;
@@ -133,15 +231,18 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
if(visibility.visible){ if(visibility.visible){
if(marker.enabled){ if(marker.enabled){
if(collision.colliding){ if(collision.colliding){
animation.next = 1; // If the door is visible and enabled and the player is colliding with it then set
// it's opening animation;
animation.next = BombGameEntityCreator.DOOR_OPEN_ANIMATION;
animation.loop = false; animation.loop = false;
collision.colliding = false; collision.colliding = false;
world.getManager(GroupManager.class).remove(d, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP); world.getManager(GroupManager.class).remove(d, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Opening door."); Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Opening door.");
} }
}else{ }else{
// If the door is disabled and open, then set it's closing animation.
if(animation.current != 0){ if(animation.current != 0){
animation.next = 0; animation.next = BombGameEntityCreator.DOOR_CLOSE_ANIMATION;
animation.loop = false; animation.loop = false;
Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Closing door."); Gdx.app.log(TAG, CLASS_NAME + ".processDoor(): Closing door.");
} }
@@ -149,18 +250,27 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
} }
} }
/**
* <p>Checks if a door is either open or closed depending on the completeness of it's animation.</p>
*
* @param markerCode The code of the door to check. Must be between 0 and 1023.
* @param manager An Artemis {@link GroupManager} to use to get all related entities.
* @return true if the opening animation of the door has finished playing.
*/
private boolean isDoorOpen(int markerCode, GroupManager manager){ private boolean isDoorOpen(int markerCode, GroupManager manager){
AnimationComponent animation; AnimationComponent animation;
boolean doorOpen = false; boolean doorOpen = false;
ImmutableBag<Entity> doors = manager.getEntities(BombGameEntityCreator.DOORS_GROUP); ImmutableBag<Entity> doors = manager.getEntities(BombGameEntityCreator.DOORS_GROUP);
// For every door.
for(int i = 0; i < doors.size(); i++){ for(int i = 0; i < doors.size(); i++){
tempMarker = markerMapper.getSafe(doors.get(i)); tempMarker = markerMapper.getSafe(doors.get(i));
animation = animationMapper.getSafe(doors.get(i)); animation = animationMapper.getSafe(doors.get(i));
if(animation == null || tempMarker == null) return false; if(animation == null || tempMarker == null) return false;
if(tempMarker.code == markerCode && animation.current == 1 && animation.controller.current.loopCount == 0){ // If this is the door we are looking for and it's opening animation is finished then this door is open.
if(tempMarker.code == markerCode && animation.current == BombGameEntityCreator.DOOR_OPEN_ANIMATION && animation.controller.current.loopCount == 0){
doorOpen = true; doorOpen = true;
break; break;
} }
@@ -168,4 +278,31 @@ public class BombGameLogicSystem extends GameLogicSystemBase {
return doorOpen; return doorOpen;
} }
/**
* <p>Disables all entities associated with the corresponding marker code.</p>
*
* @param markerCode
*/
private void disableBomb(int markerCode){
ImmutableBag<Entity> related = manager.getEntities(Integer.toString(markerCode));
// Disable every entity sharing this marker code except for the corresponding door frame.
for(int i = 0; i < related.size(); i++){
tempMarker = markerMapper.getSafe(related.get(i));
tempType = typeMapper.getSafe(related.get(i));
// Enable collisions with the corresponding door frame entity. Disable collisions with other related entities.
if(tempMarker != null) tempMarker.enabled = false;
if(tempType != null){
if(tempType.type != BombGameObjectTypeComponent.DOOR_FRAME){
manager.remove(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
manager.remove(related.get(i), Integer.toString(markerCode));
related.get(i).deleteFromWorld();
}else{
manager.add(related.get(i), CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP);
}
}
}
}
} }

View File

@@ -19,6 +19,7 @@ import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent; import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent; import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput; import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput; import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput; import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
@@ -38,7 +39,6 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName(); private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
private static final float INTERPOLATION_STEP = 0.05f; private static final float INTERPOLATION_STEP = 0.05f;
private static final float STEP_SIZE = 0.05f; private static final float STEP_SIZE = 0.05f;
private static final Vector3 END_POINT = new Vector3(0.0f, 0.0f, -0.5f);
private static final float MAX_Z = -4.5f; private static final float MAX_Z = -4.5f;
@Mapper ComponentMapper<GeometryComponent> geometryMapper; @Mapper ComponentMapper<GeometryComponent> geometryMapper;
@@ -89,12 +89,11 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
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;
geometry.position.z += tempGP.axisRightY * STEP_SIZE; geometry.position.z += tempGP.axisRightY * STEP_SIZE;
//clampPosition(geometry);
}else{ }else{
auto.moving = true; auto.moving = true;
auto.forward = false; auto.forward = false;
auto.startPoint.set(geometry.position); auto.startPoint.set(geometry.position);
auto.endPoint.set(END_POINT); auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
} }
}else if(input instanceof KeyboardUserInput){ }else if(input instanceof KeyboardUserInput){
@@ -107,12 +106,11 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f; geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f; geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f;
geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f; geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f;
//clampPosition(geometry);
}else{ }else{
auto.moving = true; auto.moving = true;
auto.forward = false; auto.forward = false;
auto.startPoint.set(geometry.position); auto.startPoint.set(geometry.position);
auto.endPoint.set(END_POINT); auto.endPoint.set(BombGameEntityCreator.ROBOT_ARM_START_POINT);
} }
}else }else
@@ -154,13 +152,4 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
}else return; }else return;
} }
// private void clampPosition(GeometryComponent geometry){
// geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
// geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
// geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
// geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
// geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
// geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
// }
} }