Added jump/warp movement, animation needs changing

This commit is contained in:
Jaggernaut555
2017-12-31 18:03:07 -08:00
parent b21e33601e
commit b9d66dc30f
5 changed files with 78 additions and 37 deletions

View File

@@ -40,6 +40,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;
@@ -59,13 +61,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 * 200)) {
if (!incrementLocation(jumpDistance)) {
//Couldn't jump
currentAction = Action.IDLE;
}
} else {
currentAction = Action.IDLE;
}
}
/*
@@ -136,6 +147,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

@@ -16,6 +16,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)
@@ -67,6 +68,12 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
cubot.setCurrentAction(Action.WALKING);
}
} else if (a == LEGS_JUMP) {
// jump up to 3 spaces, each space costs 200
if (b < 4 && cubot.getMaxEnergy() >= b * 200) {
cubot.setJumpDistance(b);
cubot.setCurrentAction(Action.JUMPING);
}
}
}