Added incomplete procedural map generator

This commit is contained in:
Anuken 2018-06-20 16:16:59 -04:00
parent 2884e4b847
commit 23d621e9c7
10 changed files with 96 additions and 15 deletions

View File

@ -96,6 +96,7 @@ public class Blocks extends BlockList implements ContentList{
}};
stone = new Floor("stone") {{
hasOres = true;
drops = new ItemStack(Items.stone, 1);
blends = block -> block != this && !(block instanceof Ore);
}};

View File

@ -151,7 +151,7 @@ public class Control extends Module{
hiscore = false;
ui.hudfrag.fadeRespawn(false);
saves.resetSave();
});
Events.on(WaveEvent.class, () -> {
@ -260,7 +260,6 @@ public class Control extends Module{
public void playMap(Map map){
ui.loadfrag.show();
saves.resetSave();
Timers.run(5f, () -> {
threads.run(() -> {

View File

@ -298,14 +298,16 @@ public class Renderer extends RendererModule{
.lerp(tmpVector2.set(lastx, lasty), alpha);
s.setRotation(Mathf.slerp(s.lastPosition().z, lastrot, alpha));
s.set(tmpVector1.x, tmpVector1.y);
s.setX(tmpVector1.x);
s.setY(tmpVector1.y);
}
}
drawer.accept(t);
if(threads.doInterpolate() && threads.isEnabled()) {
t.set(lastx, lasty);
t.setX(lastx);
t.setY(lasty);
if (t instanceof SolidTrait) {
((SolidTrait) t).setRotation(lastrot);

View File

@ -220,7 +220,7 @@ public class FloorRenderer {
Timers.mark();
int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize;
int chunksx = Mathf.ceil((float)world.width() / chunksize), chunksy = Mathf.ceil((float)world.height() / chunksize);
cache = new Chunk[chunksx][chunksy];
cbatch = new CacheBatch(world.width()*world.height()*4*4);

View File

@ -1,6 +1,7 @@
package io.anuke.mindustry.graphics;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
@ -34,6 +35,7 @@ public class MinimapRenderer implements Disposable{
private TextureRegion region;
private Rectangle rect = new Rectangle();
private Rectangle clipRect = new Rectangle();
private Color tmpColor = new Color();
private int zoom = 4;
public MinimapRenderer(){
@ -138,6 +140,11 @@ public class MinimapRenderer implements Disposable{
private int colorFor(Tile tile){
int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getColor(tile.block());
if(color == 0) color = ColorMapper.getColor(tile.floor());
if(tile.cliffs != 0){
tmpColor.set(color);
tmpColor.mul(1.5f, 1.5f, 1.5f, 1f);
color = Color.rgba8888(tmpColor);
}
return color;
}

View File

@ -35,6 +35,7 @@ public class MapIO {
data.position(0, 0);
TileDataMarker marker = data.newDataMarker();
Color color = new Color();
for(int y = 0; y < data.height(); y ++){
for(int x = 0; x < data.width(); x ++){
@ -43,7 +44,14 @@ public class MapIO {
Block wall = Block.getByID(marker.wall);
int wallc = ColorMapper.getColor(wall);
if(wallc == 0 && (wall.update || wall.solid || wall.breakable)) wallc = Color.rgba8888(Team.values()[marker.team].color);
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, wallc == 0 ? ColorMapper.getColor(floor) : wallc);
wallc = wallc == 0 ? ColorMapper.getColor(floor) : wallc;
if(marker.elevation > 0){
float scaling = 1f + marker.elevation/8f;
color.set(wallc);
color.mul(scaling, scaling, scaling, 1f);
wallc = Color.rgba8888(color);
}
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, wallc);
}
}

View File

@ -1,11 +1,20 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.io.Map;
import io.anuke.mindustry.io.MapMeta;
import io.anuke.mindustry.io.MapTileData;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.WorldGenerator;
import io.anuke.mindustry.world.mapgen.ProcGen;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityPhysics;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.layout.Stack;
@ -99,7 +108,6 @@ public class LevelDialog extends FloatingDialog{
ImageButton image = new ImageButton(new TextureRegion(map.texture), "togglemap");
image.row();
image.add(inset).width(images+6);
//TODO custom map delete button
image.clicked(() -> {
hide();
@ -112,10 +120,41 @@ public class LevelDialog extends FloatingDialog{
maps.add(stack).width(170).top().pad(4f);
maps.marginRight(26);
i ++;
}
maps.addImageButton("icon-editor", 16*4, () -> {
hide();
ProcGen gen = new ProcGen();
MapTileData data = gen.generate(null);
Map map = new Map("generated-map", new MapMeta(0, new ObjectMap<>(), data.width(), data.height(), null), true, () -> null);
ui.loadfrag.show();
Timers.run(5f, () -> {
threads.run(() -> {
logic.reset();
world.beginMapLoad();
world.setMap(map);
int width = map.meta.width, height = map.meta.height;
Tile[][] tiles = world.createTiles(data.width(), data.height());
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
WorldGenerator.generate(tiles, data, true, 0);
world.endMapLoad();
logic.play();
Gdx.app.postRunnable(ui.loadfrag::hide);
});
});
}).size(170, 154f + 73).pad(4f);
content().add(pane).uniformX();
}

View File

@ -343,8 +343,4 @@ public class HudFragment implements Fragment{
l.setTouchable(!paused ? Touchable.enabled : Touchable.disabled);
});
}
public void fadeRespawn(boolean in){
//respawntable.addAction(Actions.color(in ? new Color(0, 0, 0, 0.3f) : Color.CLEAR, 0.3f));
}
}

View File

@ -58,7 +58,7 @@ public class Floor extends Block{
/**liquids that drop from this block, used for pumps*/
public Liquid liquidDrop = null;
/**Whether ores generate on this block.*/
public boolean hasOres = true;
public boolean hasOres = false;
/**whether this block can be drowned in*/
public boolean isLiquid;

View File

@ -1,20 +1,49 @@
package io.anuke.mindustry.world.mapgen;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.io.MapTileData;
import io.anuke.mindustry.io.MapTileData.DataPosition;
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
import io.anuke.ucore.noise.RidgedPerlin;
import io.anuke.ucore.noise.Simplex;
import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Mathf;
public class ProcGen {
public RidgedPerlin rid = new RidgedPerlin(1, 1);
public Simplex sim = new Simplex();
public MapTileData generate(GenProperties props){
sim.setSeed(Mathf.random(9999));
rid = new RidgedPerlin(Mathf.random(9999), 1);
MapTileData data = new MapTileData(300, 300);
TileDataMarker marker = data.newDataMarker();
for (int x = 0; x < data.width(); x++) {
for (int y = 0; y < data.height(); y++) {
marker.floor = (byte)Blocks.stone.id;
double r = rid.getValue(x, y, 1/70f);
double elevation = sim.octaveNoise2D(3, 0.6, 1f/50, x, y) * 3 - 1 - r*2;
if(r > 0.0){
marker.floor = (byte)Blocks.water.id;
elevation = 0;
if(r > 0.055){
marker.floor = (byte)Blocks.deepwater.id;
}
}
marker.elevation = (byte)Math.max(elevation, 0);
data.write(marker);
}
}
return null;
data.write(data.width()/2, data.height()/2, DataPosition.wall, (byte)StorageBlocks.core.id);
data.write(data.width()/2, data.height()/2, DataPosition.rotationTeam, Bits.packByte((byte)0, (byte)Team.blue.ordinal()));
return data;
}
}