Finished optimizations for now
This commit is contained in:
@@ -10,10 +10,14 @@ import com.mygdx.game.Restrictions;
|
||||
import static com.mygdx.game.Main.cam;
|
||||
|
||||
public class Mouse implements Restrictions {
|
||||
Texture crosshair = new Texture("core/assets/crosshair.png");
|
||||
Texture crosshair;
|
||||
|
||||
public void selectedTile(SpriteBatch batch){
|
||||
Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0);
|
||||
public Mouse() {
|
||||
this.crosshair = new Texture("core/assets/crosshair.png");
|
||||
}
|
||||
|
||||
public void selectedTile(SpriteBatch batch) {
|
||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
cam.unproject(mousePos);
|
||||
int x = getSelectedX(mousePos);
|
||||
int y = getSelectedY(mousePos);
|
||||
|
||||
@@ -8,16 +8,13 @@ import com.badlogic.gdx.utils.Array;
|
||||
import com.mygdx.game.Main;
|
||||
import com.mygdx.game.Restrictions;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Player implements Restrictions {
|
||||
private static int x;
|
||||
private static int y;
|
||||
private OrthographicCamera cam;
|
||||
private String spriteName;
|
||||
private final String spriteName;
|
||||
public TextureAtlas textureAtlas;
|
||||
private Animation<TextureAtlas.AtlasRegion> animation;
|
||||
private HashMap<String, Animation> animations = new HashMap<>();
|
||||
|
||||
public Player(OrthographicCamera cam, int x, int y) {
|
||||
Player.x = x<<TILE_SHIFT;
|
||||
|
||||
@@ -7,24 +7,25 @@ import com.mygdx.game.OpenSimplexNoise;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.mygdx.game.Dimension.BlockMaterials.*;
|
||||
import static com.mygdx.game.Dimension.BlockMaterials.materials;
|
||||
import static com.mygdx.game.Restrictions.*;
|
||||
|
||||
public class Chunks{
|
||||
OpenSimplexNoise gen1 = new OpenSimplexNoise(SEED+1);
|
||||
OpenSimplexNoise gen2 = new OpenSimplexNoise(SEED);
|
||||
public class Chunks {
|
||||
public static HashMap<Triple<Integer, Integer, Integer>, Block> blocks = new HashMap<>();
|
||||
public static HashMap<Pair<Integer, Integer>, Block> buildings = new HashMap<>();
|
||||
public static OpenSimplexNoise gen1 = new OpenSimplexNoise(SEED + 1);
|
||||
public static OpenSimplexNoise gen2 = new OpenSimplexNoise(SEED);
|
||||
|
||||
|
||||
public static void create(){
|
||||
public static void create() {
|
||||
int i = 10;
|
||||
setBlock(3+i,2,"wall");
|
||||
setBlock(4+i,2,"wall");
|
||||
setBlock(3+i,3,"roof");
|
||||
setBlock(4+i,3,"roof");
|
||||
setBlock(3 + i, 2, "wall");
|
||||
setBlock(4 + i, 2, "wall");
|
||||
setBlock(3 + i, 3, "roof");
|
||||
setBlock(4 + i, 3, "roof");
|
||||
}
|
||||
|
||||
public static void setBlock(int x, int y, String name){
|
||||
buildings.put(new Pair<>(x,y),new Block(name));
|
||||
public static void setBlock(int x, int y, String name) {
|
||||
buildings.put(new Pair<>(x, y), materials.get(name));
|
||||
}
|
||||
|
||||
public static void placeBlock(int x, int y, String name){
|
||||
@@ -41,20 +42,16 @@ public class Chunks{
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<Triple<Integer, Integer,Integer>, Block> blocks = new HashMap<>();
|
||||
|
||||
public static HashMap<Pair<Integer,Integer>, Block> buildings = new HashMap<>();
|
||||
|
||||
public void ungenerateChunk(int x, int y) {
|
||||
public static void ungenerateChunk(int x, int y) {
|
||||
int startX = x << CHUNK_SHIFT;
|
||||
int startY = y << CHUNK_SHIFT;
|
||||
int endX = startX + CHUNK_SIZE;
|
||||
int endY = startY + CHUNK_SIZE;
|
||||
|
||||
//Going from start of selected chunk to end of selected chunk in x and y
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int i = startX; i != endX; i++) {
|
||||
for (int j = startY; j != endY; j++) {
|
||||
blocks.remove(new Triple<>(i, j,0), getTerrain(i, j));
|
||||
blocks.remove(new Triple<>(i, j, 0), getTerrain(i, j));
|
||||
}
|
||||
}
|
||||
//Second Layer
|
||||
@@ -66,14 +63,14 @@ public class Chunks{
|
||||
}
|
||||
}
|
||||
|
||||
public void generateChunk(int x, int y){
|
||||
public static void generateChunk(int x, int y) {
|
||||
int startX = x << CHUNK_SHIFT;
|
||||
int startY = y << CHUNK_SHIFT;
|
||||
int endX = startX + CHUNK_SIZE;
|
||||
int endY = startY + CHUNK_SIZE;
|
||||
|
||||
//Going from start of selected chunk to end of selected chunk in x and y
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int i = startX; i != endX; i++) {
|
||||
for (int j = startY; j != endY; j++) {
|
||||
blocks.put(new Triple<>(i, j, 0), getTerrain(i, j));
|
||||
}
|
||||
@@ -88,27 +85,27 @@ public class Chunks{
|
||||
}
|
||||
}
|
||||
|
||||
public Block getBuildings(int x, int y) {
|
||||
return buildings.getOrDefault(new Pair<>(x,y),new Block("air"));
|
||||
public static Block getBuildings(int x, int y) {
|
||||
return buildings.getOrDefault(new Pair<>(x, y), new Block("air"));
|
||||
}
|
||||
|
||||
public double noise1(double nx, double ny) {
|
||||
return gen1.eval(nx, ny)/2 + 0.5;
|
||||
public static double noise1(double nx, double ny) {
|
||||
return gen1.eval(nx, ny) / 2 + 0.5;
|
||||
}
|
||||
|
||||
public double noise2(double nx, double ny) {
|
||||
return gen2.eval(nx, ny)/2 + 0.5;
|
||||
public static double noise2(double nx, double ny) {
|
||||
return gen2.eval(nx, ny) / 2 + 0.5;
|
||||
}
|
||||
|
||||
public Block getTerrain(int x, int y) {
|
||||
double moisture, elevation,nx,ny;
|
||||
public static Block getTerrain(int x, int y) {
|
||||
double moisture, elevation, nx, ny;
|
||||
double scale = 0.01;
|
||||
nx = x * scale;
|
||||
ny = y * scale;
|
||||
elevation = (0.17 * noise1( 1 * nx, 1 * ny)
|
||||
+ 0.42 * noise1( 2 * nx, 2 * ny)
|
||||
+ 0.16 * noise1( 4 * nx, 4 * ny)
|
||||
+ 0.00 * noise1( 8 * nx, 8 * ny)
|
||||
elevation = (0.17 * noise1(1 * nx, 1 * ny)
|
||||
+ 0.42 * noise1(2 * nx, 2 * ny)
|
||||
+ 0.16 * noise1(4 * nx, 4 * ny)
|
||||
+ 0.00 * noise1(8 * nx, 8 * ny)
|
||||
+ 0.00 * noise1(16 * nx, 16 * ny)
|
||||
+ 0.03 * noise1(32 * nx, 32 * ny));
|
||||
elevation /= (0.17+0.42+0.16+0.00+0.00+0.03);
|
||||
@@ -124,8 +121,8 @@ public class Chunks{
|
||||
return getBiomeBlock(moisture, elevation);
|
||||
}
|
||||
|
||||
public Block getBiomeBlock(double moisture, double elevation) {
|
||||
String biome = getBiome(moisture,elevation);
|
||||
public static Block getBiomeBlock(double moisture, double elevation) {
|
||||
String biome = getBiome(moisture, elevation);
|
||||
if (biome.equals("Tundra")) return materials.get("snow");
|
||||
if (biome.equals("Taiga")) return materials.get("snow");
|
||||
if (biome.equals("Snow")) return materials.get("snow");
|
||||
@@ -148,7 +145,7 @@ public class Chunks{
|
||||
return materials.get("water");
|
||||
}
|
||||
|
||||
public String getBiome(double moisture,double elevation){
|
||||
public static String getBiome(double moisture, double elevation) {
|
||||
if (elevation < 0.1) return "Ocean";
|
||||
if (elevation < 0.12) return "Beach";
|
||||
|
||||
|
||||
@@ -6,16 +6,14 @@ import static com.mygdx.game.Restrictions.*;
|
||||
|
||||
public class World {
|
||||
public static void generateWorld(int x, int y) {
|
||||
Chunks chunks = new Chunks();
|
||||
if (chunks.isEmpty(x, y)) {
|
||||
chunks.generateChunk(x, y);
|
||||
if (Chunks.isEmpty(x, y)) {
|
||||
Chunks.generateChunk(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ungenerateWorld(int x, int y) {
|
||||
Chunks chunks = new Chunks();
|
||||
if (!chunks.isEmpty(x, y)) {
|
||||
chunks.ungenerateChunk(x, y);
|
||||
if (!Chunks.isEmpty(x, y)) {
|
||||
Chunks.ungenerateChunk(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,21 @@ import com.mygdx.game.Character.Mouse;
|
||||
import com.mygdx.game.Restrictions;
|
||||
|
||||
public class GUI implements Restrictions {
|
||||
private Stage stage;
|
||||
private Label label;
|
||||
private Mouse mouse;
|
||||
private BitmapFont font = new BitmapFont();
|
||||
private FitViewport fitViewport;
|
||||
private final Stage stage;
|
||||
private final Label label;
|
||||
private final Mouse mouse;
|
||||
private final BitmapFont font;
|
||||
private final FitViewport fitViewport;
|
||||
|
||||
public GUI(Mouse mouse, FitViewport fitViewport) {
|
||||
font = new BitmapFont();
|
||||
stage = new Stage(fitViewport);
|
||||
label = new Label("Start", new Label.LabelStyle(font, new Color(Color.WHITE)));
|
||||
|
||||
this.mouse = mouse;
|
||||
this.fitViewport = fitViewport;
|
||||
|
||||
stage = new Stage(fitViewport);
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
label = new Label("Hello",new Label.LabelStyle(font,new Color(Color.WHITE)));
|
||||
stage.addActor(label);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user