Basic map shading

This commit is contained in:
Anuken 2019-01-16 20:37:43 -05:00
parent 4344af1f02
commit 6d50a747e3
12 changed files with 66 additions and 23 deletions

View File

@ -238,7 +238,7 @@ error.mapnotfound = Map file not found!
error.io = Network I/O error.
error.any = Unknown network error.
zone.wasteland.name = Wasteland
zone.groundZero.name = Ground Zero
settings.language = Language
settings.reset = Reset to Defaults

Binary file not shown.

Binary file not shown.

View File

@ -88,14 +88,7 @@ public class Blocks implements ContentList{
blockpart = new BlockPart();
spawn = new Block("spawn"){
public void drawShadow(Tile tile){}
public void draw(Tile tile){
Draw.color(Color.SCARLET);
Lines.circle(tile.worldx(), tile.worldy(), 4f +Mathf.absin(Time.time(), 6f, 6f));
Draw.color();
}
};
//Registers build blocks from size 1-6

View File

@ -2,17 +2,17 @@ package io.anuke.mindustry.content;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.game.Rules;
import io.anuke.mindustry.maps.generators.BasicGenerator;
import io.anuke.mindustry.maps.generators.MapGenerator;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Zone;
public class Zones implements ContentList{
public Zone wasteland;
public Zone groundZero;
@Override
public void load(){
wasteland = new Zone("wasteland", new BasicGenerator(256, 256, Items.copper)){{
groundZero = new Zone("groundZero", new MapGenerator("groundZero")){{
deployCost = ItemStack.with(Items.copper, 100);
startingItems = ItemStack.with(Items.copper, 50);
alwaysUnlocked = true;

View File

@ -6,6 +6,8 @@ import io.anuke.arc.Events;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.IntArray;
import io.anuke.arc.entities.EntityQuery;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Structs;
@ -409,6 +411,47 @@ public class World implements ApplicationListener{
* Usually used before placing structures on a tile array.*/
public void prepareTiles(Tile[][] tiles){
byte[][] dark = new byte[tiles.length][tiles[0].length];
byte[][] writeBuffer = new byte[tiles.length][tiles[0].length];
byte darkIterations = 4;
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
Tile tile = tiles[x][y];
if(tile.block().solid && !tile.block().update){
dark[x][y] = darkIterations;
}
}
}
for(int i = 0; i < darkIterations; i++){
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
boolean min = false;
for(Point2 point : Geometry.d4){
int newX = x + point.x, newY = y + point.y;
if(Structs.inBounds(newX, newY, tiles) && dark[newX][newY] < dark[x][y]){
min = true;
break;
}
}
writeBuffer[x][y] = (byte)Math.max(0, dark[x][y] - Mathf.num(min));
}
}
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
dark[x][y] = writeBuffer[x][y];
}
}
}
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
tiles[x][y].setRotation(dark[x][y]);
}
}
//find multiblocks
IntArray multiblocks = new IntArray();

View File

@ -99,9 +99,6 @@ public class MapEditor{
}
public void draw(int x, int y, Block drawBlock){
if(x < 0 || y < 0 || x >= map.width() || y >= map.height()){
return;
}
byte writeID = drawBlock.id;
byte partID = Blocks.blockpart.id;

View File

@ -63,14 +63,7 @@ public class Maps implements Disposable{
FileHandle file = Core.files.internal("maps/" + name + "." + mapExtension);
try(DataInputStream ds = new DataInputStream(file.read())) {
MapMeta meta = MapIO.readMapMeta(ds);
Map map = new Map(name, meta, false, file::read);
if (!headless){
map.texture = new Texture(MapIO.generatePixmap(MapIO.readTileData(ds, meta, true)));
}
return map;
return new Map(name, MapIO.readMapMeta(ds), false, file::read);
}catch(IOException e){
throw new RuntimeException(e);
}

View File

@ -12,5 +12,9 @@ public abstract class Generator{
public Generator(){}
public void init(){
}
public abstract void generate(Tile[][] tiles);
}

View File

@ -10,9 +10,15 @@ import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.world;
public class MapGenerator extends Generator{
private final Map map;
private Map map;
private String mapName;
public MapGenerator(String mapName){
this.mapName = mapName;
}
@Override
public void init(){
map = world.maps.loadInternalMap(mapName);
width = map.meta.width;
height = map.meta.height;

View File

@ -21,6 +21,11 @@ public class Zone extends UnlockableContent{
this.generator = generator;
}
@Override
public void init(){
generator.init();
}
@Override
public boolean alwaysUnlocked(){
return alwaysUnlocked;

View File

@ -19,11 +19,13 @@ public class Rock extends Block{
@Override
public void draw(Tile tile){
Draw.colorl(1f - tile.getRotation() / 4f);
if(variants > 0){
Draw.rect(regions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, regions.length - 1))], tile.worldx(), tile.worldy());
}else{
Draw.rect(region, tile.worldx(), tile.worldy());
}
Draw.color();
}
@Override