mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-25 10:25:42 +07:00
Sector darkness boundaries
This commit is contained in:
parent
48c04bda8c
commit
65800a51c6
@ -96,7 +96,7 @@ public class UnitTypes implements ContentList{
|
||||
flying = true;
|
||||
drag = 0.05f;
|
||||
mass = 2f;
|
||||
speed = 3f;
|
||||
speed = 4f;
|
||||
rotateSpeed = 12f;
|
||||
accel = 0.3f;
|
||||
range = 70f;
|
||||
|
@ -7,6 +7,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
@ -196,7 +197,7 @@ public class World{
|
||||
|
||||
public void loadSector(Sector sector){
|
||||
state.rules.sector = sector;
|
||||
int size = (int)(sector.rect.radius * 2500);
|
||||
int size = (int)(sector.rect.radius * 3200);
|
||||
|
||||
loadGenerator(size, size, tiles -> {
|
||||
TileGen gen = new TileGen();
|
||||
@ -352,6 +353,48 @@ public class World{
|
||||
}
|
||||
}
|
||||
|
||||
public float getDarkness(int x, int y){
|
||||
int edgeBlend = 2;
|
||||
|
||||
float dark = 0;
|
||||
int edgeDst = Math.min(x, Math.min(y, Math.min(Math.abs(x - (world.width() - 1)), Math.abs(y - (world.height() - 1)))));
|
||||
if(edgeDst <= edgeBlend){
|
||||
dark = Math.max((edgeBlend - edgeDst) * (4f / edgeBlend), dark);
|
||||
}
|
||||
|
||||
//TODO tweak noise and radius
|
||||
if(world.isCampaign()){
|
||||
int circleBlend = 14;
|
||||
//quantized angle
|
||||
float offset = getSector().rect.rotation + 90;
|
||||
float angle = Angles.angle(x, y, world.width()/2, world.height()/2) + offset;
|
||||
//polygon sides, depends on sector
|
||||
int sides = getSector().tile.corners.length;
|
||||
float step = 360f / sides;
|
||||
//prev and next angles of poly
|
||||
float prev = Mathf.round(angle, step);
|
||||
float next = prev + step;
|
||||
//raw line length to be translated
|
||||
float length = world.width()/2f;
|
||||
float rawDst = Intersector.distanceLinePoint(Tmp.v1.trns(prev, length), Tmp.v2.trns(next, length), Tmp.v3.set(x - world.width()/2, y - world.height()/2).rotate(offset)) / Mathf.sqrt3 - 1;
|
||||
|
||||
//noise
|
||||
rawDst += Noise.nnoise(x, y, 11f, 7f) + Noise.nnoise(x, y, 22f, 15f);
|
||||
|
||||
int circleDst = (int)(rawDst - (world.width() / 2 - circleBlend));
|
||||
if(circleDst > 0){
|
||||
dark = Math.max(circleDst / 0.8f, dark);
|
||||
}
|
||||
}
|
||||
|
||||
Tile tile = world.rawTile(x, y);
|
||||
if(tile.block().solid && tile.block().fillsTile && !tile.block().synthetic()){
|
||||
dark = Math.max(dark, tile.rotation());
|
||||
}
|
||||
|
||||
return dark;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Prepares' a tile array by:<br>
|
||||
* - setting up multiblocks<br>
|
||||
|
@ -8,7 +8,6 @@ import arc.graphics.gl.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.Teams.*;
|
||||
@ -77,7 +76,7 @@ public class BlockRenderer implements Disposable{
|
||||
for(int y = 0; y < world.height(); y++){
|
||||
Tile tile = world.rawTile(x, y);
|
||||
|
||||
float darkness = getDarkness(x, y);
|
||||
float darkness = world.getDarkness(x, y);
|
||||
|
||||
if(darkness > 0){
|
||||
Draw.color(0f, 0f, 0f, Math.min((darkness + 0.5f) / 4f, 1f));
|
||||
@ -105,33 +104,6 @@ public class BlockRenderer implements Disposable{
|
||||
});
|
||||
}
|
||||
|
||||
public float getDarkness(int x, int y){
|
||||
int edgeBlend = 2;
|
||||
|
||||
float dark = 0;
|
||||
int edgeDst = Math.min(x, Math.min(y, Math.min(Math.abs(x - (world.width() - 1)), Math.abs(y - (world.height() - 1)))));
|
||||
if(edgeDst <= edgeBlend){
|
||||
dark = Math.max((edgeBlend - edgeDst) * (4f / edgeBlend), dark);
|
||||
}
|
||||
|
||||
//TODO tweak noise and radius
|
||||
if(world.isCampaign()){
|
||||
int circleBlend = 14;
|
||||
float rawDst = Mathf.dst(x, y, world.width() / 2, world.height() / 2) + Noise.nnoise(x, y, 7f, 7f) + Noise.nnoise(x, y, 20f, 15f);
|
||||
int circleDst = (int)(rawDst - (world.width() / 2 - circleBlend));
|
||||
if(circleDst > 0){
|
||||
dark = Math.max(circleDst / 1.6f, dark);
|
||||
}
|
||||
}
|
||||
|
||||
Tile tile = world.rawTile(x, y);
|
||||
if(tile.block().solid && tile.block().fillsTile && !tile.block().synthetic()){
|
||||
dark = Math.max(dark, tile.rotation());
|
||||
}
|
||||
|
||||
return dark;
|
||||
}
|
||||
|
||||
public void drawFog(){
|
||||
float ww = world.width() * tilesize, wh = world.height() * tilesize;
|
||||
float x = camera.position.x + tilesize / 2f, y = camera.position.y + tilesize / 2f;
|
||||
|
@ -162,7 +162,7 @@ public class MinimapRenderer implements Disposable{
|
||||
return bc;
|
||||
}
|
||||
Color color = Tmp.c1.set(MapIO.colorFor(tile.floor(), tile.block(), tile.overlay(), tile.team()));
|
||||
color.mul(1f - Mathf.clamp(renderer.blocks.getDarkness(tile.x, tile.y) / 4f));
|
||||
color.mul(1f - Mathf.clamp(world.getDarkness(tile.x, tile.y) / 4f));
|
||||
|
||||
return color.rgba();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import static mindustry.Vars.*;
|
||||
public class PlanetRenderer implements PlanetGenerator{
|
||||
private final Color outlineColor = Pal.accent.cpy().a(0.7f);
|
||||
private final float camLength = 4f, outlineRad = 1.15f;
|
||||
private final boolean drawRect = false;
|
||||
private final boolean drawRect = true;
|
||||
|
||||
private final PlanetMesh[] outlines = new PlanetMesh[10];
|
||||
private final Camera3D cam = new Camera3D();
|
||||
@ -64,15 +64,18 @@ public class PlanetRenderer implements PlanetGenerator{
|
||||
rect.right.scl(outlineRad);
|
||||
rect.top.scl(outlineRad);
|
||||
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(0, 0));
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(1, 0));
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(1, 1));
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(0, 1));
|
||||
batch.flush(cam.combined(), Gl.lineLoop);
|
||||
batch.color(Color.red);
|
||||
batch.vertex(rect.center);
|
||||
batch.color(Color.red);
|
||||
batch.vertex(sector.tile.corners[0].v);
|
||||
|
||||
batch.color(Color.green);
|
||||
batch.vertex(rect.center);
|
||||
batch.color(Color.green);
|
||||
batch.vertex(rect.top.cpy().add(rect.center));
|
||||
batch.flush(cam.combined(), Gl.lines);
|
||||
|
||||
//Log.info((int)(sector.tile.corners[0].v.cpy().sub(rect.center).angle(rect.top)));
|
||||
|
||||
rect.center.scl(1f / outlineRad);
|
||||
rect.right.scl(1f / outlineRad);
|
||||
|
@ -118,7 +118,7 @@ public class TestPlanetGenerator implements PlanetGenerator{
|
||||
}
|
||||
|
||||
tiles.each((x, y) -> tiles.get(x, y).setBlock(!read.get(x, y) ? Blocks.air : tiles.get(x, y).floor().wall));
|
||||
distort(0.01f, 8f);
|
||||
distort(0.009f, 12f);
|
||||
|
||||
tiles.get(tiles.width /2, tiles.height /2).setBlock(Blocks.coreShard, Team.sharded);
|
||||
}
|
||||
|
@ -58,22 +58,28 @@ public class Sector{
|
||||
Plane plane = new Plane();
|
||||
plane.set(corners[0], corners[2], corners[4]);
|
||||
|
||||
Vec3 planeTop = plane.project(center.cpy().add(0f, 1f, 0f)).sub(center).setLength(radius).add(center);
|
||||
Vec3 planeRight = plane.project(center.cpy().rotate(Vec3.Y, -4f)).sub(center).setLength(radius).add(center);
|
||||
//relative vectors
|
||||
Vec3 planeTop = plane.project(center.cpy().add(0f, 1f, 0f)).sub(center).setLength(radius);
|
||||
Vec3 planeRight = plane.project(center.cpy().rotate(Vec3.Y, -4f)).sub(center).setLength(radius);
|
||||
|
||||
return new SectorRect(radius, center, planeTop.sub(center), planeRight.sub(center));
|
||||
//get angle from first corner to top vector
|
||||
Vec3 first = corners[1].cpy().sub(center); //first vector relative to center
|
||||
float angle = first.angle(planeTop);
|
||||
|
||||
return new SectorRect(radius, center, planeTop, planeRight, angle);
|
||||
}
|
||||
|
||||
public static class SectorRect{
|
||||
public final Vec3 center, top, right;
|
||||
public final Vec3 result = new Vec3();
|
||||
public final float radius;
|
||||
public final float radius, rotation;
|
||||
|
||||
public SectorRect(float radius, Vec3 center, Vec3 top, Vec3 right){
|
||||
public SectorRect(float radius, Vec3 center, Vec3 top, Vec3 right, float rotation){
|
||||
this.center = center;
|
||||
this.top = top;
|
||||
this.right = right;
|
||||
this.radius = radius;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
/** Project a coordinate into 3D space.
|
||||
|
@ -82,8 +82,8 @@ public class Build{
|
||||
return false;
|
||||
}
|
||||
|
||||
//campaign circle check
|
||||
if(world.isCampaign() && !Mathf.within(x, y, world.width()/2, world.height()/2, world.width()/2 - 8)){
|
||||
//ca check
|
||||
if(world.getDarkness(x, y) >= 3){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user