Functional payload factories

This commit is contained in:
Anuken
2020-05-23 11:53:49 -04:00
parent 39b0051b73
commit d8ee862125
18 changed files with 83 additions and 33 deletions

View File

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

View File

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