Added basic ore generator
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.content;
|
package io.anuke.mindustry.content;
|
||||||
|
|
||||||
import io.anuke.mindustry.game.ContentList;
|
import io.anuke.mindustry.game.ContentList;
|
||||||
|
import io.anuke.mindustry.maps.generators.BasicGenerator;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Zone;
|
import io.anuke.mindustry.type.Zone;
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ public class Zones implements ContentList{
|
|||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
|
|
||||||
wasteland = new Zone("wasteland"){{
|
wasteland = new Zone("wasteland", new BasicGenerator(256, 256, Items.lead, Items.copper)){{
|
||||||
deployCost = new ItemStack[]{new ItemStack(Items.copper, 2)};
|
deployCost = new ItemStack[]{new ItemStack(Items.copper, 2)};
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,46 @@
|
|||||||
package io.anuke.mindustry.maps.generators;
|
package io.anuke.mindustry.maps.generators;
|
||||||
|
|
||||||
public class BasicGenerator extends RandomGenerator{
|
import io.anuke.arc.collection.Array;
|
||||||
|
import io.anuke.arc.math.Mathf;
|
||||||
|
import io.anuke.arc.util.noise.Simplex;
|
||||||
|
import io.anuke.mindustry.content.Blocks;
|
||||||
|
import io.anuke.mindustry.type.Item;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.blocks.Floor;
|
||||||
|
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||||
|
|
||||||
public BasicGenerator(int width, int height){
|
public class BasicGenerator extends RandomGenerator{
|
||||||
|
private Array<Item> ores;
|
||||||
|
private Simplex sim = new Simplex();
|
||||||
|
private Simplex sim2 = new Simplex();
|
||||||
|
|
||||||
|
public BasicGenerator(int width, int height, Item... ores){
|
||||||
super(width, height);
|
super(width, height);
|
||||||
|
this.ores = Array.with(ores);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generate(Tile[][] tiles){
|
||||||
|
int seed = Mathf.random(99999999);
|
||||||
|
sim.setSeed(seed);
|
||||||
|
sim2.setSeed(seed + 1);
|
||||||
|
super.generate(tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generate(int x, int y){
|
public void generate(int x, int y){
|
||||||
|
floor = Blocks.stone;
|
||||||
|
|
||||||
|
if(ores != null && ((Floor) floor).hasOres){
|
||||||
|
int offsetX = x - 4, offsetY = y + 23;
|
||||||
|
for(int i = ores.size - 1; i >= 0; i--){
|
||||||
|
Item entry = ores.get(i);
|
||||||
|
if(Math.abs(0.5f - sim.octaveNoise2D(2, 0.7, 1f / (50 + i * 2), offsetX, offsetY)) > 0.23f &&
|
||||||
|
Math.abs(0.5f - sim2.octaveNoise2D(1, 1, 1f / (40 + i * 4), offsetX, offsetY)) > 0.32f){
|
||||||
|
floor = OreBlock.get(floor, entry);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package io.anuke.mindustry.maps.generators;
|
package io.anuke.mindustry.maps.generators;
|
||||||
|
|
||||||
import io.anuke.mindustry.content.Blocks;
|
import io.anuke.mindustry.content.Blocks;
|
||||||
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.Floor;
|
|
||||||
|
|
||||||
public abstract class RandomGenerator extends Generator{
|
public abstract class RandomGenerator extends Generator{
|
||||||
protected Block floor;
|
protected Block floor;
|
||||||
@@ -20,10 +20,11 @@ public abstract class RandomGenerator extends Generator{
|
|||||||
floor = Blocks.air;
|
floor = Blocks.air;
|
||||||
block = Blocks.air;
|
block = Blocks.air;
|
||||||
generate(x, y);
|
generate(x, y);
|
||||||
tiles[x][y].setFloor((Floor) floor);
|
tiles[x][y] = new Tile(x, y, floor.id, block.id);
|
||||||
tiles[x][y].setBlock(block);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tiles[width/2][height/2].setBlock(Blocks.core, Team.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Sets {@link #floor} and {@link #block} to the correct values as output.
|
/**Sets {@link #floor} and {@link #block} to the correct values as output.
|
||||||
|
|||||||
Reference in New Issue
Block a user