This commit is contained in:
Jaggernaut555
2018-01-09 13:08:30 +00:00
committed by GitHub
5 changed files with 81 additions and 37 deletions

View File

@@ -44,6 +44,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
private int energy;
private int maxEnergy;
private int jumpDistance;
private static final float SOLAR_PANEL_MULTIPLIER = 1;
private static final int CONSOLE_BUFFER_MAX_SIZE = 40;
@@ -63,13 +65,22 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
if (currentAction == Action.WALKING) {
if (spendEnergy(100)) {
if (!incrementLocation()) {
if (!incrementLocation(1)) {
//Couldn't walk
currentAction = Action.IDLE;
}
} else {
currentAction = Action.IDLE;
}
} else if (currentAction == Action.JUMPING) {
if (spendEnergy(jumpDistance * 300)) {
if (!incrementLocation(jumpDistance)) {
//Couldn't jump
currentAction = Action.IDLE;
}
} else {
currentAction = Action.IDLE;
}
}
/*
@@ -165,6 +176,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
return heldItem;
}
public void setJumpDistance(int jumpDistance) {
this.jumpDistance = jumpDistance;
}
@Override
public void setKeyboardBuffer(ArrayList<Integer> kbBuffer) {
keyboardBuffer = kbBuffer;

View File

@@ -18,6 +18,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
private static final int LEGS_SET_DIR = 1;
private static final int LEGS_SET_DIR_AND_WALK = 2;
private static final int LEGS_JUMP = 3;
/**
* Hardware ID (Should be unique)
@@ -72,6 +73,15 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
cubot.setCurrentAction(Action.WALKING);
}
}
} else if (a == LEGS_JUMP) {
// jump up to 3 spaces, each space costs 300
if (b < 4 && cubot.getMaxEnergy() >= b * 300) {
cubot.setJumpDistance(b);
cubot.setCurrentAction(Action.JUMPING);
status.setErrorFlag(false);
} else {
status.setErrorFlag(true);
}
}
}