Functional payload factories
This commit is contained in:
@@ -27,6 +27,10 @@ abstract class PosComp implements Position{
|
||||
set(this.x + x, this.y + y);
|
||||
}
|
||||
|
||||
void trns(Position pos){
|
||||
trns(pos.getX(), pos.getY());
|
||||
}
|
||||
|
||||
int tileX(){
|
||||
return Vars.world.toTile(x);
|
||||
}
|
||||
|
||||
@@ -197,6 +197,11 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
||||
return tile.absoluteRelativeTo(cx, cy);
|
||||
}
|
||||
|
||||
public @Nullable Tile frontLarge(){
|
||||
int trns = block.size/2 + 1;
|
||||
return tile.getNearby(Geometry.d4(rotation()).x * trns, Geometry.d4(rotation()).y * trns);
|
||||
}
|
||||
|
||||
public @Nullable Tilec front(){
|
||||
return nearby((rotation() + 4) % 4);
|
||||
}
|
||||
@@ -217,6 +222,10 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
||||
return tile.pos();
|
||||
}
|
||||
|
||||
public float rotdeg(){
|
||||
return tile.rotation() * 90;
|
||||
}
|
||||
|
||||
public int rotation(){
|
||||
return tile.rotation();
|
||||
}
|
||||
@@ -345,13 +354,30 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries dumping a payload.
|
||||
* Tries moving a payload forwards.
|
||||
* @param todump payload to dump.
|
||||
* @return whether the payload was moved successfully
|
||||
*/
|
||||
public boolean movePayload(@NonNull Payload todump){
|
||||
int trns = block.size/2 + 1;
|
||||
Tile next = tile.getNearby(Geometry.d4(rotation()).x * trns, Geometry.d4(rotation()).y * trns);
|
||||
|
||||
if(next != null && next.entity != null && next.entity.team() == team() && next.entity.acceptPayload(this, todump)){
|
||||
next.entity.handlePayload(this, todump);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries dumping a payload to any adjacent block.
|
||||
* @param todump payload to dump.
|
||||
* @return whether the payload was moved successfully
|
||||
*/
|
||||
public boolean dumpPayload(@NonNull Payload todump){
|
||||
Array<Tilec> proximity = proximity();
|
||||
int dump = rotation();
|
||||
|
||||
if(proximity.size == 0) return false;
|
||||
|
||||
Reference in New Issue
Block a user