mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-05 08:27:37 +07:00
Added basic ore generator
This commit is contained in:
parent
7889db43a8
commit
777bd60f88
@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.maps.generators.BasicGenerator;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Zone;
|
||||
|
||||
@ -10,7 +11,7 @@ public class Zones implements ContentList{
|
||||
@Override
|
||||
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)};
|
||||
}};
|
||||
}
|
||||
|
@ -1,13 +1,46 @@
|
||||
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);
|
||||
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
|
||||
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;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
|
||||
public abstract class RandomGenerator extends Generator{
|
||||
protected Block floor;
|
||||
@ -20,10 +20,11 @@ public abstract class RandomGenerator extends Generator{
|
||||
floor = Blocks.air;
|
||||
block = Blocks.air;
|
||||
generate(x, y);
|
||||
tiles[x][y].setFloor((Floor) floor);
|
||||
tiles[x][y].setBlock(block);
|
||||
tiles[x][y] = new Tile(x, y, floor.id, block.id);
|
||||
}
|
||||
}
|
||||
|
||||
tiles[width/2][height/2].setBlock(Blocks.core, Team.blue);
|
||||
}
|
||||
|
||||
/**Sets {@link #floor} and {@link #block} to the correct values as output.
|
||||
|
Loading…
Reference in New Issue
Block a user