mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Merge a3064ef8d622343fade86854bcb786c678057e44 into 6fc583d6f034e16e2d70448a0ba215610ea38b73
This commit is contained in:
commit
faf61d8f38
@ -44,6 +44,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
|||||||
private int energy;
|
private int energy;
|
||||||
private int maxEnergy;
|
private int maxEnergy;
|
||||||
|
|
||||||
|
private int jumpDistance;
|
||||||
|
|
||||||
private static final float SOLAR_PANEL_MULTIPLIER = 1;
|
private static final float SOLAR_PANEL_MULTIPLIER = 1;
|
||||||
private static final int CONSOLE_BUFFER_MAX_SIZE = 40;
|
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 (currentAction == Action.WALKING) {
|
||||||
if (spendEnergy(100)) {
|
if (spendEnergy(100)) {
|
||||||
if (!incrementLocation()) {
|
if (!incrementLocation(1)) {
|
||||||
//Couldn't walk
|
//Couldn't walk
|
||||||
currentAction = Action.IDLE;
|
currentAction = Action.IDLE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentAction = Action.IDLE;
|
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;
|
return heldItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setJumpDistance(int jumpDistance) {
|
||||||
|
this.jumpDistance = jumpDistance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyboardBuffer(ArrayList<Integer> kbBuffer) {
|
public void setKeyboardBuffer(ArrayList<Integer> kbBuffer) {
|
||||||
keyboardBuffer = kbBuffer;
|
keyboardBuffer = kbBuffer;
|
||||||
|
@ -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 = 1;
|
||||||
private static final int LEGS_SET_DIR_AND_WALK = 2;
|
private static final int LEGS_SET_DIR_AND_WALK = 2;
|
||||||
|
private static final int LEGS_JUMP = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hardware ID (Should be unique)
|
* Hardware ID (Should be unique)
|
||||||
@ -72,6 +73,15 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
|
|||||||
cubot.setCurrentAction(Action.WALKING);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
|||||||
LogManager.LOGGER.severe("FIXME: moveTo:NonPlayerCharacter, Direction is null");
|
LogManager.LOGGER.severe("FIXME: moveTo:NonPlayerCharacter, Direction is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (incrementLocation()) {
|
if (incrementLocation(1)) {
|
||||||
lastAction = Action.WALKING;
|
lastAction = Action.WALKING;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
|||||||
getWorld().getX(), getWorld().getY() - 1) <= MAX_FACTORY_DISTANCE) {
|
getWorld().getX(), getWorld().getY() - 1) <= MAX_FACTORY_DISTANCE) {
|
||||||
if (!moveTo(8, 0, 0)) {
|
if (!moveTo(8, 0, 0)) {
|
||||||
setDirection(Direction.NORTH);
|
setDirection(Direction.NORTH);
|
||||||
incrementLocation();
|
incrementLocation(1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -143,7 +143,7 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
|||||||
getWorld().getX() + 1, getWorld().getY()) <= MAX_FACTORY_DISTANCE) {
|
getWorld().getX() + 1, getWorld().getY()) <= MAX_FACTORY_DISTANCE) {
|
||||||
if (!moveTo(15, 7, 0)) {
|
if (!moveTo(15, 7, 0)) {
|
||||||
setDirection(Direction.EAST);
|
setDirection(Direction.EAST);
|
||||||
incrementLocation();
|
incrementLocation(1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -154,7 +154,7 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
|||||||
getWorld().getX(), getWorld().getY() + 1) <= MAX_FACTORY_DISTANCE) {
|
getWorld().getX(), getWorld().getY() + 1) <= MAX_FACTORY_DISTANCE) {
|
||||||
if (!moveTo(8, 15, 0)) {
|
if (!moveTo(8, 15, 0)) {
|
||||||
setDirection(Direction.SOUTH);
|
setDirection(Direction.SOUTH);
|
||||||
incrementLocation();
|
incrementLocation(1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -165,7 +165,7 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
|||||||
getWorld().getX() - 1, getWorld().getY()) <= MAX_FACTORY_DISTANCE) {
|
getWorld().getX() - 1, getWorld().getY()) <= MAX_FACTORY_DISTANCE) {
|
||||||
if (!moveTo(0, 7, 0)) {
|
if (!moveTo(0, 7, 0)) {
|
||||||
setDirection(Direction.WEST);
|
setDirection(Direction.WEST);
|
||||||
incrementLocation();
|
incrementLocation(1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,7 @@ public enum Action {
|
|||||||
WALKING,
|
WALKING,
|
||||||
WITHDRAWING,
|
WITHDRAWING,
|
||||||
DEPOSITING,
|
DEPOSITING,
|
||||||
LISTENING
|
LISTENING,
|
||||||
|
JUMPING
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,24 +49,24 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
|||||||
* Increment the location of the game object by 1 tile
|
* Increment the location of the game object by 1 tile
|
||||||
* Collision checks happen here
|
* Collision checks happen here
|
||||||
*/
|
*/
|
||||||
public boolean incrementLocation() {
|
public boolean incrementLocation(int distance) {
|
||||||
|
|
||||||
int newX = 0, newY = 0;
|
int newX = 0, newY = 0;
|
||||||
|
|
||||||
if (direction == Direction.NORTH) {
|
if (direction == Direction.NORTH) {
|
||||||
newX = x;
|
newX = x;
|
||||||
newY = (y - 1);
|
newY = (y - distance);
|
||||||
|
|
||||||
} else if (direction == Direction.EAST) {
|
} else if (direction == Direction.EAST) {
|
||||||
newX = (x + 1);
|
newX = (x + distance);
|
||||||
newY = y;
|
newY = y;
|
||||||
|
|
||||||
} else if (direction == Direction.SOUTH) {
|
} else if (direction == Direction.SOUTH) {
|
||||||
newX = x;
|
newX = x;
|
||||||
newY = (y + 1);
|
newY = (y + distance);
|
||||||
|
|
||||||
} else if (direction == Direction.WEST) {
|
} else if (direction == Direction.WEST) {
|
||||||
newX = (x - 1);
|
newX = (x - distance);
|
||||||
newY = y;
|
newY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,13 +84,17 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (leftWorld != null) {
|
if (leftWorld != null) {
|
||||||
|
if(!leftWorld.isTileBlocked(World.WORLD_SIZE+newX, newY)) {
|
||||||
world.getGameObjects().remove(this);
|
world.getGameObjects().remove(this);
|
||||||
world.decUpdatable();
|
world.decUpdatable();
|
||||||
leftWorld.getGameObjects().add(this);
|
leftWorld.getGameObjects().add(this);
|
||||||
leftWorld.incUpdatable();
|
leftWorld.incUpdatable();
|
||||||
setWorld(leftWorld);
|
setWorld(leftWorld);
|
||||||
|
|
||||||
x = World.WORLD_SIZE - 1;
|
x = World.WORLD_SIZE + newX;
|
||||||
|
} else if (distance > 1) {
|
||||||
|
return incrementLocation(distance-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (newX >= World.WORLD_SIZE) {
|
} else if (newX >= World.WORLD_SIZE) {
|
||||||
//Move object to adjacent World (right)
|
//Move object to adjacent World (right)
|
||||||
@ -103,13 +107,17 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rightWorld != null) {
|
if (rightWorld != null) {
|
||||||
|
if(!rightWorld.isTileBlocked(newX-World.WORLD_SIZE, y)) {
|
||||||
world.getGameObjects().remove(this);
|
world.getGameObjects().remove(this);
|
||||||
world.decUpdatable();
|
world.decUpdatable();
|
||||||
rightWorld.getGameObjects().add(this);
|
rightWorld.getGameObjects().add(this);
|
||||||
rightWorld.incUpdatable();
|
rightWorld.incUpdatable();
|
||||||
setWorld(rightWorld);
|
setWorld(rightWorld);
|
||||||
|
|
||||||
x = 0;
|
x = newX - World.WORLD_SIZE;
|
||||||
|
} else if (distance > 1) {
|
||||||
|
return incrementLocation(distance-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (newY < 0) {
|
} else if (newY < 0) {
|
||||||
//Move object to adjacent World (up)
|
//Move object to adjacent World (up)
|
||||||
@ -123,13 +131,17 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (upWorld != null) {
|
if (upWorld != null) {
|
||||||
|
if (!upWorld.isTileBlocked(x, World.WORLD_SIZE+newY)) {
|
||||||
world.getGameObjects().remove(this);
|
world.getGameObjects().remove(this);
|
||||||
world.decUpdatable();
|
world.decUpdatable();
|
||||||
upWorld.getGameObjects().add(this);
|
upWorld.getGameObjects().add(this);
|
||||||
upWorld.incUpdatable();
|
upWorld.incUpdatable();
|
||||||
setWorld(upWorld);
|
setWorld(upWorld);
|
||||||
|
|
||||||
y = World.WORLD_SIZE - 1;
|
y = World.WORLD_SIZE + newY;
|
||||||
|
} else if (distance > 1) {
|
||||||
|
return incrementLocation(distance-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (newY >= World.WORLD_SIZE) {
|
} else if (newY >= World.WORLD_SIZE) {
|
||||||
//Move object to adjacent World (down)
|
//Move object to adjacent World (down)
|
||||||
@ -143,13 +155,17 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
|||||||
|
|
||||||
|
|
||||||
if (downWorld != null) {
|
if (downWorld != null) {
|
||||||
|
if (!downWorld.isTileBlocked(x,newY-World.WORLD_SIZE)) {
|
||||||
world.getGameObjects().remove(this);
|
world.getGameObjects().remove(this);
|
||||||
world.decUpdatable();
|
world.decUpdatable();
|
||||||
downWorld.getGameObjects().add(this);
|
downWorld.getGameObjects().add(this);
|
||||||
downWorld.incUpdatable();
|
downWorld.incUpdatable();
|
||||||
setWorld(downWorld);
|
setWorld(downWorld);
|
||||||
|
|
||||||
y = 0;
|
y = newY - World.WORLD_SIZE;
|
||||||
|
} else if (distance > 1) {
|
||||||
|
return incrementLocation(distance-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Check collision
|
//Check collision
|
||||||
@ -157,7 +173,9 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
|||||||
//Tile is passable
|
//Tile is passable
|
||||||
x = newX;
|
x = newX;
|
||||||
y = newY;
|
y = newY;
|
||||||
} else {
|
} else if (distance > 1) {
|
||||||
|
return incrementLocation(distance-1);
|
||||||
|
}else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user