Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -59,13 +61,22 @@ public void update() {

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;
}
}

/*
Expand Down Expand Up @@ -136,6 +147,10 @@ public int getHeldItem() {
return heldItem;
}

public void setJumpDistance(int jumpDistance) {
this.jumpDistance = jumpDistance;
}

@Override
public void setKeyboardBuffer(ArrayList<Integer> kbBuffer) {
keyboardBuffer = kbBuffer;
Expand Down
10 changes: 10 additions & 0 deletions Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -67,6 +68,15 @@ public void handleInterrupt(Status status) {

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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ boolean moveTo(int x, int y, int range) {
LogManager.LOGGER.severe("FIXME: moveTo:NonPlayerCharacter, Direction is null");
}

if (incrementLocation()) {
if (incrementLocation(1)) {
lastAction = Action.WALKING;
return true;
}
Expand All @@ -113,7 +113,7 @@ boolean gotoWorld(Direction direction) {
getWorld().getX(), getWorld().getY() - 1) <= MAX_FACTORY_DISTANCE) {
if (!moveTo(8, 0, 0)) {
setDirection(Direction.NORTH);
incrementLocation();
incrementLocation(1);
}
return true;
} else {
Expand All @@ -125,7 +125,7 @@ boolean gotoWorld(Direction direction) {
getWorld().getX() + 1, getWorld().getY()) <= MAX_FACTORY_DISTANCE) {
if (!moveTo(15, 7, 0)) {
setDirection(Direction.EAST);
incrementLocation();
incrementLocation(1);
}
return true;
} else {
Expand All @@ -136,7 +136,7 @@ boolean gotoWorld(Direction direction) {
getWorld().getX(), getWorld().getY() + 1) <= MAX_FACTORY_DISTANCE) {
if (!moveTo(8, 15, 0)) {
setDirection(Direction.SOUTH);
incrementLocation();
incrementLocation(1);
}
return true;
} else {
Expand All @@ -147,7 +147,7 @@ boolean gotoWorld(Direction direction) {
getWorld().getX() - 1, getWorld().getY()) <= MAX_FACTORY_DISTANCE) {
if (!moveTo(0, 7, 0)) {
setDirection(Direction.WEST);
incrementLocation();
incrementLocation(1);
}
return true;
} else {
Expand Down
3 changes: 2 additions & 1 deletion Server/src/main/java/net/simon987/server/game/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum Action {
WALKING,
WITHDRAWING,
DEPOSITING,
LISTENING
LISTENING,
JUMPING

}
86 changes: 52 additions & 34 deletions Server/src/main/java/net/simon987/server/game/GameObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ public abstract class GameObject implements JSONSerialisable {
* Increment the location of the game object by 1 tile
* Collision checks happen here
*/
public boolean incrementLocation() {
public boolean incrementLocation(int distance) {

int newX = 0, newY = 0;

if (direction == Direction.NORTH) {
newX = x;
newY = (y - 1);
newY = (y - distance);

} else if (direction == Direction.EAST) {
newX = (x + 1);
newX = (x + distance);
newY = y;

} else if (direction == Direction.SOUTH) {
newX = x;
newY = (y + 1);
newY = (y + distance);

} else if (direction == Direction.WEST) {
newX = (x - 1);
newX = (x - distance);
newY = y;
}

Expand All @@ -81,13 +81,17 @@ public boolean incrementLocation() {
}

if (leftWorld != null) {
world.getGameObjects().remove(this);
world.decUpdatable();
leftWorld.getGameObjects().add(this);
leftWorld.incUpdatable();
setWorld(leftWorld);

x = World.WORLD_SIZE - 1;
if(!leftWorld.isTileBlocked(World.WORLD_SIZE+newX, newY)) {
world.getGameObjects().remove(this);
world.decUpdatable();
leftWorld.getGameObjects().add(this);
leftWorld.incUpdatable();
setWorld(leftWorld);

x = World.WORLD_SIZE + newX;
} else if (distance > 1) {
return incrementLocation(distance-1);
}
}
} else if (newX >= World.WORLD_SIZE) {
//Move object to adjacent World (right)
Expand All @@ -100,13 +104,17 @@ public boolean incrementLocation() {
}

if (rightWorld != null) {
world.getGameObjects().remove(this);
world.decUpdatable();
rightWorld.getGameObjects().add(this);
rightWorld.incUpdatable();
setWorld(rightWorld);

x = 0;
if(!rightWorld.isTileBlocked(newX-World.WORLD_SIZE, y)) {
world.getGameObjects().remove(this);
world.decUpdatable();
rightWorld.getGameObjects().add(this);
rightWorld.incUpdatable();
setWorld(rightWorld);

x = newX - World.WORLD_SIZE;
} else if (distance > 1) {
return incrementLocation(distance-1);
}
}
} else if (newY < 0) {
//Move object to adjacent World (up)
Expand All @@ -120,13 +128,17 @@ public boolean incrementLocation() {
}

if (upWorld != null) {
world.getGameObjects().remove(this);
world.decUpdatable();
upWorld.getGameObjects().add(this);
upWorld.incUpdatable();
setWorld(upWorld);

y = World.WORLD_SIZE - 1;
if (!upWorld.isTileBlocked(x, World.WORLD_SIZE+newY)) {
world.getGameObjects().remove(this);
world.decUpdatable();
upWorld.getGameObjects().add(this);
upWorld.incUpdatable();
setWorld(upWorld);

y = World.WORLD_SIZE + newY;
} else if (distance > 1) {
return incrementLocation(distance-1);
}
}
} else if (newY >= World.WORLD_SIZE) {
//Move object to adjacent World (down)
Expand All @@ -140,21 +152,27 @@ public boolean incrementLocation() {


if (downWorld != null) {
world.getGameObjects().remove(this);
world.decUpdatable();
downWorld.getGameObjects().add(this);
downWorld.incUpdatable();
setWorld(downWorld);

y = 0;
if (!downWorld.isTileBlocked(x,newY-World.WORLD_SIZE)) {
world.getGameObjects().remove(this);
world.decUpdatable();
downWorld.getGameObjects().add(this);
downWorld.incUpdatable();
setWorld(downWorld);

y = newY - World.WORLD_SIZE;
} else if (distance > 1) {
return incrementLocation(distance-1);
}
}
}
//Check collision
else if (!world.isTileBlocked(newX, newY)) {
//Tile is passable
x = newX;
y = newY;
} else {
} else if (distance > 1) {
return incrementLocation(distance-1);
}else {
return false;
}

Expand Down