Added a chunkloading system but not a unloading system
This commit is contained in:
@@ -53,7 +53,8 @@ project(":desktop") {
|
|||||||
api "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
|
api "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
|
||||||
api "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
|
api "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
|
||||||
api "de.tomgrill.gdxdialogs:gdx-dialogs-desktop:1.2.5"
|
api "de.tomgrill.gdxdialogs:gdx-dialogs-desktop:1.2.5"
|
||||||
|
compile "org.mini2Dx:universal-tween-engine:6.3.3"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class InputController implements Restrictions {
|
|||||||
i = 0;
|
i = 0;
|
||||||
directionAnimation("Up");
|
directionAnimation("Up");
|
||||||
player.addY(MOVEMENT_SPEED);
|
player.addY(MOVEMENT_SPEED);
|
||||||
//Tween.to(player,Tween.)
|
|
||||||
cam.translate(0,MOVEMENT_SPEED);
|
cam.translate(0,MOVEMENT_SPEED);
|
||||||
}
|
}
|
||||||
cam.update();
|
cam.update();
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import net.dermetfan.utils.Pair;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static com.mygdx.game.Restrictions.CHUNK_SIZE;
|
import static com.mygdx.game.Restrictions.*;
|
||||||
import static com.mygdx.game.Restrictions.SUPER_CHUNK_SIZE;
|
|
||||||
|
|
||||||
public class Superchunks {
|
public class Superchunks {
|
||||||
public static HashMap<Pair<Integer,Integer>, Chunks> overworld = new HashMap<>();
|
public static HashMap<Pair<Integer,Integer>, Chunks> overworld = new HashMap<>();
|
||||||
@@ -14,8 +13,8 @@ public class Superchunks {
|
|||||||
private Superchunks() {}
|
private Superchunks() {}
|
||||||
|
|
||||||
public static void generateSuperchunk(int x, int y) {
|
public static void generateSuperchunk(int x, int y) {
|
||||||
int startX = x*SUPER_CHUNK_SIZE;
|
int startX = x * SUPER_CHUNK_SIZE;
|
||||||
int startY = y*SUPER_CHUNK_SIZE;
|
int startY = y * SUPER_CHUNK_SIZE;
|
||||||
int endX = startX + SUPER_CHUNK_SIZE;
|
int endX = startX + SUPER_CHUNK_SIZE;
|
||||||
int endY = startY + SUPER_CHUNK_SIZE;
|
int endY = startY + SUPER_CHUNK_SIZE;
|
||||||
|
|
||||||
@@ -29,11 +28,37 @@ public class Superchunks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateWithPlayer(Player player){
|
|
||||||
for (int i = -1+player.getX()/CHUNK_SIZE*SUPER_CHUNK_SIZE; i < 1+player.getX()/CHUNK_SIZE*SUPER_CHUNK_SIZE; i++) {
|
public static void loadChunks(Player player) {
|
||||||
for (int j = -1+player.getY()/CHUNK_SIZE*SUPER_CHUNK_SIZE; j < 1+player.getY()/CHUNK_SIZE*SUPER_CHUNK_SIZE; j++) {
|
int chunkY = 0;
|
||||||
generateSuperchunk(i,j);
|
int chunkX = 0;
|
||||||
|
//Top-right
|
||||||
|
if(0<=player.getX() && 0<=player.getY()) {
|
||||||
|
chunkY = (player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
chunkX = (player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
}
|
||||||
|
//Top-left
|
||||||
|
else if(0>player.getX() && 0<player.getY()){
|
||||||
|
chunkY = (player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
chunkX = ((player.getX()-48*CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
}
|
||||||
|
//Bottom-left
|
||||||
|
else if(0>=player.getX() && 0>=player.getY()){
|
||||||
|
chunkY = ((player.getY()-48*CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
chunkX = ((player.getX()-48*CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
}
|
||||||
|
//Bottom-right
|
||||||
|
else if(0<player.getX() && 0>player.getY()){
|
||||||
|
chunkY = ((player.getY()-48*CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
chunkX = ((player.getX()) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE; i++) {
|
||||||
|
for (int j = -RENDER_DISTANCE; j < RENDER_DISTANCE; j++) {
|
||||||
|
generateSuperchunk(chunkX+i,chunkY+j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class Main extends ApplicationAdapter {
|
|||||||
private FitViewport fitViewport;
|
private FitViewport fitViewport;
|
||||||
float physicsUpdateSpeed = 1/60f; //how often you want to do a physics-update, in this case every 1/60th of a sec
|
float physicsUpdateSpeed = 1/60f; //how often you want to do a physics-update, in this case every 1/60th of a sec
|
||||||
float timeSinceLastUpdate = 0f; //accumulator
|
float timeSinceLastUpdate = 0f; //accumulator
|
||||||
|
private float chunkSeconds;
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,7 +32,7 @@ public class Main extends ApplicationAdapter {
|
|||||||
fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam);
|
fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam);
|
||||||
|
|
||||||
//Starting location of the player
|
//Starting location of the player
|
||||||
Player player = new Player(0, 0, cam);
|
player = new Player(0, 0, cam);
|
||||||
|
|
||||||
cam.translate((float) TILE_SIZE / 2, (float) TILE_SIZE / 2);
|
cam.translate((float) TILE_SIZE / 2, (float) TILE_SIZE / 2);
|
||||||
cam.zoom = 25f;
|
cam.zoom = 25f;
|
||||||
@@ -38,9 +40,6 @@ public class Main extends ApplicationAdapter {
|
|||||||
Mouse mouse = new Mouse(player);
|
Mouse mouse = new Mouse(player);
|
||||||
gui = new GUI(mouse,fitViewport);
|
gui = new GUI(mouse,fitViewport);
|
||||||
|
|
||||||
Superchunks.generateWithPlayer(player);
|
|
||||||
|
|
||||||
|
|
||||||
worldRenderer = new WorldRenderer(player, mouse, cam);
|
worldRenderer = new WorldRenderer(player, mouse, cam);
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
}
|
}
|
||||||
@@ -51,6 +50,11 @@ public class Main extends ApplicationAdapter {
|
|||||||
|
|
||||||
fixedStep();
|
fixedStep();
|
||||||
|
|
||||||
|
chunkSeconds +=Gdx.graphics.getRawDeltaTime();
|
||||||
|
if(chunkSeconds > RENDER_TIME){
|
||||||
|
chunkSeconds -= RENDER_TIME;
|
||||||
|
Superchunks.loadChunks(player);
|
||||||
|
}
|
||||||
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
worldRenderer.render(batch);
|
worldRenderer.render(batch);
|
||||||
@@ -58,6 +62,7 @@ public class Main extends ApplicationAdapter {
|
|||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void fixedStep() {
|
public void fixedStep() {
|
||||||
timeSinceLastUpdate = Gdx.graphics.getDeltaTime(); //Accumulate delta time
|
timeSinceLastUpdate = Gdx.graphics.getDeltaTime(); //Accumulate delta time
|
||||||
while(timeSinceLastUpdate >= physicsUpdateSpeed){ //If the accumulated delta-time is greater than, do a physics update - this can happen multiple times in a single frame, depending on fps/lag/physicsUpdateSpeed
|
while(timeSinceLastUpdate >= physicsUpdateSpeed){ //If the accumulated delta-time is greater than, do a physics update - this can happen multiple times in a single frame, depending on fps/lag/physicsUpdateSpeed
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ public interface Restrictions {
|
|||||||
float VIEWPORT_HEIGHT = 9/2f;
|
float VIEWPORT_HEIGHT = 9/2f;
|
||||||
float VIEWPORT_WIDTH = 16/2f;
|
float VIEWPORT_WIDTH = 16/2f;
|
||||||
int MOVEMENT_SPEED = 16;
|
int MOVEMENT_SPEED = 16;
|
||||||
int KEY_DELAY = 10;
|
int KEY_DELAY = 1;
|
||||||
int CHUNK_SIZE = 16;
|
int CHUNK_SIZE = 16;
|
||||||
int SUPER_CHUNK_SIZE = 3;
|
int SUPER_CHUNK_SIZE = 3;
|
||||||
int RENDER_DISTANCE = 3;
|
int RENDER_DISTANCE = 3;
|
||||||
|
int RENDER_TIME = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user