Changed the Bomb Game automatic action behaviour.

This commit is contained in:
2014-07-01 10:13:15 -04:30
parent 238f62d4d3
commit 15c41d1229
3 changed files with 36 additions and 14 deletions

View File

@@ -33,8 +33,7 @@ import com.badlogic.gdx.Gdx;
public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBase { public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBase {
private static final String TAG = "BOMB_GAME_AUTO_PERFORMER"; private static final String TAG = "BOMB_GAME_AUTO_PERFORMER";
private static final String CLASS_NAME = BombGameAutomaticActionPerformer.class.getSimpleName(); private static final String CLASS_NAME = BombGameAutomaticActionPerformer.class.getSimpleName();
private static final int GOAL_FLOOR_MIN_LUMINANCE = 75; private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 50;
private static final int MARKER_NEARBY_FLOOR_MIN_LUMINANCE = 45;
private enum action_state_t{ private enum action_state_t{
START, WALK_FORWARD, DETECT_MARKER, FINISHING, END; START, WALK_FORWARD, DETECT_MARKER, FINISHING, END;
@@ -44,6 +43,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
private int numCombinationBombs; private int numCombinationBombs;
private int numInclinationBombs; private int numInclinationBombs;
private int numWireBombs; private int numWireBombs;
private int totalBombs;
public BombGameAutomaticActionSummary(){ public BombGameAutomaticActionSummary(){
reset(); reset();
@@ -63,14 +63,21 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
public void addCombinationBomb(){ public void addCombinationBomb(){
numCombinationBombs++; numCombinationBombs++;
totalBombs++;
} }
public void addInclinationBomb(){ public void addInclinationBomb(){
numInclinationBombs++; numInclinationBombs++;
totalBombs++;
} }
public void addWireBomb(){ public void addWireBomb(){
numWireBombs++; numWireBombs++;
totalBombs++;
}
public int getBombsSeen(){
return totalBombs;
} }
@Override @Override
@@ -78,6 +85,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
this.numCombinationBombs = 0; this.numCombinationBombs = 0;
this.numInclinationBombs = 0; this.numInclinationBombs = 0;
this.numWireBombs = 0; this.numWireBombs = 0;
this.totalBombs = 0;
} }
} }
@@ -86,6 +94,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
private List<Integer> detectedMarkers; private List<Integer> detectedMarkers;
private float then; private float then;
private float now; private float now;
private int stops;
private GroupManager manager; private GroupManager manager;
private BombGameAutomaticActionSummary summary; private BombGameAutomaticActionSummary summary;
@@ -103,7 +112,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
public boolean performAutomaticAction(int lightSensorReading, MarkerData markers) throws IllegalStateException, IllegalArgumentException{ public boolean performAutomaticAction(int lightSensorReading, MarkerData markers) throws IllegalStateException, IllegalArgumentException{
BombComponent bomb; BombComponent bomb;
boolean finish = false; boolean finish = false;
boolean markerDetected = false; boolean markerAlreadyDetected = false;
int detectedCode = -1; int detectedCode = -1;
ImmutableBag<Entity> entities = null; ImmutableBag<Entity> entities = null;
float deltaT; float deltaT;
@@ -125,7 +134,8 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
switch(state){ switch(state){
case START: case START:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is START."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is START.");
summary.reset(); // Reset everything, then look to the left and start moving forward.
this.reset();
nextAction = automatic_action_t.ROTATE_90; nextAction = automatic_action_t.ROTATE_90;
state = action_state_t.WALK_FORWARD; state = action_state_t.WALK_FORWARD;
finish = false; finish = false;
@@ -133,17 +143,22 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case WALK_FORWARD: case WALK_FORWARD:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is WALK_FORWARD."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is WALK_FORWARD.");
if(lightSensorReading >= GOAL_FLOOR_MIN_LUMINANCE){ // Check if all stops have been found.
if(stops >= BombGameEntityCreator.NUM_BOMBS){
// If all stops have been found then stop the robot and finish the automatic action.
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Found goal."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Found goal.");
nextAction = automatic_action_t.STOP; nextAction = automatic_action_t.STOP;
state = action_state_t.FINISHING; state = action_state_t.FINISHING;
}else{ }else{
if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE && lightSensorReading < GOAL_FLOOR_MIN_LUMINANCE){ // If there are stops to be found yet then check if the light sensor found a stop.
if(lightSensorReading >= MARKER_NEARBY_FLOOR_MIN_LUMINANCE){
// If a stop have been found then check if there is a marker nearby.
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): There is a marker nearby."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): There is a marker nearby.");
nextAction = automatic_action_t.STOP; nextAction = automatic_action_t.STOP;
state = action_state_t.DETECT_MARKER; state = action_state_t.DETECT_MARKER;
then = Gdx.graphics.getDeltaTime(); then = Gdx.graphics.getDeltaTime();
}else{ }else{
// If the light sensor didn't find a stop the keep moving.
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Walking."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Walking.");
nextAction = automatic_action_t.GO_FORWARD; nextAction = automatic_action_t.GO_FORWARD;
} }
@@ -153,18 +168,18 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case DETECT_MARKER: case DETECT_MARKER:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is DETECT_MARKER."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is DETECT_MARKER.");
for(int i = 0; !markerDetected && i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){ for(int i = 0; !markerAlreadyDetected && i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
// Check if this marker has not been detected already. // Check if this marker has not been detected already.
for(Integer code : detectedMarkers){ for(Integer code : detectedMarkers){
if(markers.markerCodes[i] == code){ if(markers.markerCodes[i] == code){
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Marker already detected."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Marker already detected.");
markerDetected = true; markerAlreadyDetected = true;
break; break;
} }
} }
// If the marker has not been detected before then examine it. // If the marker has not been detected before then examine it.
if(!markerDetected){ if(!markerAlreadyDetected){
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): New marker detected."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): New marker detected.");
detectedCode = markers.markerCodes[i]; detectedCode = markers.markerCodes[i];
entities = manager.getEntities(Integer.toString(detectedCode)); entities = manager.getEntities(Integer.toString(detectedCode));
@@ -197,17 +212,21 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
} }
} }
if(!markerDetected && detectedCode != -1) // If found a marker and it has not been detected before then add it to the detected markers list.
if(!markerAlreadyDetected && detectedCode != -1)
detectedMarkers.add(detectedCode); detectedMarkers.add(detectedCode);
if(lightSensorReading < MARKER_NEARBY_FLOOR_MIN_LUMINANCE){ if(lightSensorReading < MARKER_NEARBY_FLOOR_MIN_LUMINANCE){
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Switching to WALK_FORWARD."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Switching to WALK_FORWARD.");
// If cleared the stop mark on the floor then start moving is search for the next mark.
state = action_state_t.WALK_FORWARD; state = action_state_t.WALK_FORWARD;
nextAction = automatic_action_t.STOP; nextAction = automatic_action_t.STOP;
then = 0.0f; then = 0.0f;
now = 0.0f; now = 0.0f;
stops++;
}else{ }else{
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Clearing MARKER_NEARBY_FLOOR."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): Clearing MARKER_NEARBY_FLOOR.");
// Wait for two seconds to make sure the marker can be correctly detected.
now += Gdx.graphics.getDeltaTime(); now += Gdx.graphics.getDeltaTime();
deltaT = now - then; deltaT = now - then;
if(deltaT >= 2.0f){ if(deltaT >= 2.0f){
@@ -223,6 +242,7 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case FINISHING: case FINISHING:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is FINISHING."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is FINISHING.");
// Recenter the camera.
state = action_state_t.END; state = action_state_t.END;
nextAction = automatic_action_t.RECENTER; nextAction = automatic_action_t.RECENTER;
finish = false; finish = false;
@@ -230,12 +250,10 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
case END: case END:
Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is END."); Gdx.app.log(TAG, CLASS_NAME + ".performAutomaticAction(): State is END.");
// Finish the automatic action.
nextAction = automatic_action_t.NO_ACTION; nextAction = automatic_action_t.NO_ACTION;
state = action_state_t.START; state = action_state_t.START;
finish = true; finish = true;
now = 0.0f;
then = 0.0f;
detectedMarkers.clear();
break; break;
default: default:
@@ -277,5 +295,6 @@ public class BombGameAutomaticActionPerformer extends AutomaticActionPerformerBa
state = action_state_t.START; state = action_state_t.START;
nextAction = automatic_action_t.NO_ACTION; nextAction = automatic_action_t.NO_ACTION;
then = 0.0f; then = 0.0f;
stops = 0;
} }
} }

View File

@@ -126,6 +126,9 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY); font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY);
font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY); font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);
font.draw(batch, "Bombs found: " + bombGameSummary.getBombsSeen(), wireX, inclinationY + inclinationBomb.getHeight() + font.getCapHeight() + 20.0f);
font.draw(batch, "Bombs expected: " + BombGameEntityCreator.NUM_BOMBS, wireX, inclinationY + inclinationBomb.getHeight() + 10.0f);
if(!Ouya.runningOnOuya) if(!Ouya.runningOnOuya)
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10); titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
else else

View File

@@ -98,7 +98,7 @@ public class InGameState extends BaseState{
// Game related fields. // Game related fields.
private World gameWorld; private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem; private MarkerRenderingSystem markerRenderingSystem;
private RobotArmRenderingSystem robotArmRenderingSystem; private RobotArmRenderingSystem robotArmRenderingSystem;
private RobotArmPositioningSystem robotArmPositioningSystem; private RobotArmPositioningSystem robotArmPositioningSystem;
private FadeEffectRenderingSystem fadeEffectRenderingSystem; private FadeEffectRenderingSystem fadeEffectRenderingSystem;
private PlayerSystemBase playerSystem; private PlayerSystemBase playerSystem;