Better spawn selection

This commit is contained in:
Anuken
2020-03-22 09:28:55 -04:00
parent 196a9dd77e
commit ad45bebbdc
7 changed files with 56 additions and 31 deletions

View File

@@ -97,7 +97,7 @@ public class WaveSpawner{
for(Tile tile : spawns){ for(Tile tile : spawns){
float angle = Angles.angle(tile.x, tile.y, world.width()/2, world.height()/2); float angle = Angles.angle(tile.x, tile.y, world.width()/2, world.height()/2);
float trns = (world.width() + world.height()) * tilesize; float trns = Math.max(world.width(), world.height()) * Mathf.sqrt2 * tilesize;
float spawnX = Mathf.clamp(world.width() * tilesize / 2f + Angles.trnsx(angle, trns), -margin, world.width() * tilesize + margin); float spawnX = Mathf.clamp(world.width() * tilesize / 2f + Angles.trnsx(angle, trns), -margin, world.width() * tilesize + margin);
float spawnY = Mathf.clamp(world.height() * tilesize / 2f + Angles.trnsy(angle, trns), -margin, world.height() * tilesize + margin); float spawnY = Mathf.clamp(world.height() * tilesize / 2f + Angles.trnsy(angle, trns), -margin, world.height() * tilesize + margin);
cons.get(spawnX, spawnY); cons.get(spawnX, spawnY);

View File

@@ -112,7 +112,8 @@ public class Blocks implements ContentList{
{ {
variants = 0; variants = 0;
} }
public void draw(){} @Override
public void drawBase(Tile tile){}
}; };
cliff = new Cliff("cliff"); cliff = new Cliff("cliff");

View File

@@ -42,12 +42,13 @@ public class Fx{
Tmp.v1.set(e.x, e.y).interpolate(Tmp.v2.set(to), e.fin(), Interpolation.pow3) Tmp.v1.set(e.x, e.y).interpolate(Tmp.v2.set(to), e.fin(), Interpolation.pow3)
.add(Tmp.v2.sub(e.x, e.y).nor().rotate90(1).scl(Mathf.randomSeedRange(e.id, 1f) * e.fslope() * 10f)); .add(Tmp.v2.sub(e.x, e.y).nor().rotate90(1).scl(Mathf.randomSeedRange(e.id, 1f) * e.fslope() * 10f));
float x = Tmp.v1.x, y = Tmp.v1.y; float x = Tmp.v1.x, y = Tmp.v1.y;
float size = Math.min(0.8f + e.rotation / 5f, 2);
stroke(e.fslope() * 2f, Pal.accent); stroke(e.fslope() * 2f * size, Pal.accent);
Lines.circle(x, y, e.fslope() * 2f); Lines.circle(x, y, e.fslope() * 2f * size);
color(e.color); color(e.color);
Fill.circle(x, y, e.fslope() * 1.5f); Fill.circle(x, y, e.fslope() * 1.5f * size);
}), }),
lightning = new Effect(10f, 500f, e -> { lightning = new Effect(10f, 500f, e -> {

View File

@@ -251,7 +251,7 @@ public class Control implements ApplicationListener, Loadable{
ui.planet.hide(); ui.planet.hide();
SaveSlot slot = sector.save; SaveSlot slot = sector.save;
//TODO comment for new sector states //TODO comment for new sector states
//slot = null; slot = null;
if(slot != null){ if(slot != null){
try{ try{
net.reset(); net.reset();

View File

@@ -69,26 +69,26 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
@Remote(called = Loc.server, unreliable = true) @Remote(called = Loc.server, unreliable = true)
public static void transferItemEffect(Item item, float x, float y, Itemsc to){ public static void transferItemEffect(Item item, float x, float y, Itemsc to){
if(to == null) return; if(to == null) return;
createItemTransfer(item, x, y, to, null); createItemTransfer(item, 1, x, y, to, null);
} }
@Remote(called = Loc.server, unreliable = true) @Remote(called = Loc.server, unreliable = true)
public static void transferItemToUnit(Item item, float x, float y, Itemsc to){ public static void transferItemToUnit(Item item, float x, float y, Itemsc to){
if(to == null) return; if(to == null) return;
createItemTransfer(item, x, y, to, () -> to.addItem(item)); createItemTransfer(item, 1, x, y, to, () -> to.addItem(item));
} }
@Remote(called = Loc.server, unreliable = true) @Remote(called = Loc.server, unreliable = true)
public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){ public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){
if(tile == null || tile.entity == null || tile.entity.items() == null) return; if(tile == null || tile.entity == null || tile.entity.items() == null) return;
for(int i = 0; i < Mathf.clamp(amount / 3, 1, 8); i++){ for(int i = 0; i < Mathf.clamp(amount / 3, 1, 8); i++){
Time.run(i * 3, () -> createItemTransfer(item, x, y, tile, () -> {})); Time.run(i * 3, () -> createItemTransfer(item, amount, x, y, tile, () -> {}));
} }
tile.entity.items().add(item, amount); tile.entity.items().add(item, amount);
} }
public static void createItemTransfer(Item item, float x, float y, Position to, Runnable done){ public static void createItemTransfer(Item item, int amount, float x, float y, Position to, Runnable done){
Fx.itemTransfer.at(x, y, 0, item.color, to); Fx.itemTransfer.at(x, y, amount, item.color, to);
if(done != null){ if(done != null){
Time.run(Fx.itemTransfer.lifetime, done); Time.run(Fx.itemTransfer.lifetime, done);
} }
@@ -137,21 +137,17 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
int accepted = tile.acceptStack(item, amount, player.unit()); int accepted = tile.acceptStack(item, amount, player.unit());
player.unit().stack().amount -= accepted; player.unit().stack().amount -= accepted;
int sent = Mathf.clamp(accepted / 4, 1, 8);
Block block = tile.block();
Core.app.post(() -> Events.fire(new DepositEvent(tile, player, item, accepted))); Core.app.post(() -> Events.fire(new DepositEvent(tile, player, item, accepted)));
for(int i = 0; i < sent; i++){ tile.getStackOffset(item, stackTrns);
tile.getStackOffset(item, stackTrns);
createItemTransfer(item, player.x() + Angles.trnsx(player.unit().rotation() + 180f, backTrns), player.y() + Angles.trnsy(player.unit().rotation() + 180f, backTrns), createItemTransfer(
new Vec2(tile.x() + stackTrns.x, tile.y() + stackTrns.y), () -> { item,
if(tile.block() != block || !tile.isValid() || tile.items() == null) return; amount,
player.x() + Angles.trnsx(player.unit().rotation() + 180f, backTrns), player.y() + Angles.trnsy(player.unit().rotation() + 180f, backTrns),
tile.handleStack(item, accepted, player.unit()); new Vec2(tile.x() + stackTrns.x, tile.y() + stackTrns.y),
}); () -> tile.handleStack(item, accepted, player.unit())
} );
} }
@Remote(targets = Loc.both, called = Loc.server, forward = true) @Remote(targets = Loc.both, called = Loc.server, forward = true)

View File

@@ -125,7 +125,7 @@ public class TestPlanetGenerator extends PlanetGenerator{
float constraint = 1.3f; float constraint = 1.3f;
float radius = width / 2f / Mathf.sqrt3; float radius = width / 2f / Mathf.sqrt3;
int rooms = rand.random(2, 5); int rooms = rand.random(2, 5)/* - 1*/;
Array<Room> array = new Array<>(); Array<Room> array = new Array<>();
for(int i = 0; i < rooms; i++){ for(int i = 0; i < rooms; i++){
@@ -137,12 +137,40 @@ public class TestPlanetGenerator extends PlanetGenerator{
array.add(new Room((int)rx, (int)ry, (int)rrad)); array.add(new Room((int)rx, (int)ry, (int)rrad));
} }
//check positions on the map to place the player spawn. this needs to be in the corner of the map
Room spawn = null;
int offset = rand.nextInt(360);
float length = width/2.55f - rand.random(13, 23);
int angleStep = 5;
int waterCheckRad = 5;
for(int i = 0; i < 360; i+= angleStep){
int angle = offset + i;
int cx = (int)(width/2 + Angles.trnsx(angle, length));
int cy = (int)(height/2 + Angles.trnsy(angle, length));
int waterTiles = 0;
//check for water presence
for(int rx = -waterCheckRad; rx <= waterCheckRad; rx++){
for(int ry = -waterCheckRad; ry <= waterCheckRad; ry++){
Tile tile = tiles.get(cx + rx, cy + ry);
if(tile == null || tile.floor().liquidDrop != null){
waterTiles ++;
}
}
}
if(waterTiles <= 4 || (i + angleStep >= 360)){
array.add(spawn = new Room(cx, cy, rand.random(8, 15)));
break;
}
}
for(Room room : array){ for(Room room : array){
erase(room.x, room.y, room.radius); erase(room.x, room.y, room.radius);
} }
int connections = rand.random(Math.max(rooms - 1, 1), rooms + 3); int connections = rand.random(Math.max(rooms - 1, 1), rooms + 3);
Room spawn = array.random(rand);
for(int i = 0; i < connections; i++){ for(int i = 0; i < connections; i++){
array.random(rand).connect(array.random(rand)); array.random(rand).connect(array.random(rand));
} }
@@ -158,11 +186,9 @@ public class TestPlanetGenerator extends PlanetGenerator{
ores(ores); ores(ores);
for(Room other : array){ Room target = spawn;
if(other != spawn){ Room furthest = array.max(r -> Mathf.dst(r.x, r.y, target.x, target.y));
// tiles.getn(other.x, other.y).setOverlay(Blocks.spawn); tiles.getn(furthest.x, furthest.y).setOverlay(Blocks.spawn);
}
}
trimDark(); trimDark();

View File

@@ -89,7 +89,8 @@ public class Planet extends UnlockableContent{
} }
} }
sectors.get(sectors.size/2).unlocked = true; //for now
sectors.each(s -> s.unlocked = true);
}else{ }else{
sectors = new Array<>(); sectors = new Array<>();
} }