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