diff --git a/core/src/com/mygdx/game/InputController.java b/core/src/com/mygdx/game/Character/InputController.java similarity index 96% rename from core/src/com/mygdx/game/InputController.java rename to core/src/com/mygdx/game/Character/InputController.java index dc1b002..0fa73b5 100644 --- a/core/src/com/mygdx/game/InputController.java +++ b/core/src/com/mygdx/game/Character/InputController.java @@ -1,10 +1,11 @@ -package com.mygdx.game; +package com.mygdx.game.Character; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.mygdx.game.Restrictions; public class InputController implements Restrictions { diff --git a/core/src/com/mygdx/game/Mouse.java b/core/src/com/mygdx/game/Character/Mouse.java similarity index 95% rename from core/src/com/mygdx/game/Mouse.java rename to core/src/com/mygdx/game/Character/Mouse.java index f9fa7b7..4a64b32 100644 --- a/core/src/com/mygdx/game/Mouse.java +++ b/core/src/com/mygdx/game/Character/Mouse.java @@ -1,10 +1,11 @@ -package com.mygdx.game; +package com.mygdx.game.Character; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector3; +import com.mygdx.game.Restrictions; import static java.lang.Math.round; diff --git a/core/src/com/mygdx/game/Player.java b/core/src/com/mygdx/game/Character/Player.java similarity index 94% rename from core/src/com/mygdx/game/Player.java rename to core/src/com/mygdx/game/Character/Player.java index abf0e3c..8ab5510 100644 --- a/core/src/com/mygdx/game/Player.java +++ b/core/src/com/mygdx/game/Character/Player.java @@ -1,9 +1,10 @@ -package com.mygdx.game; +package com.mygdx.game.Character; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; +import com.mygdx.game.Restrictions; public class Player implements Restrictions { private int x,y = 0; @@ -11,7 +12,7 @@ public class Player implements Restrictions { private TextureAtlas textureAtlas; private Animation animation; - Player(int x, int y) { + public Player(int x, int y) { this.x = 0; this.y = 0; this.spriteName = "man"; diff --git a/core/src/com/mygdx/game/Main.java b/core/src/com/mygdx/game/Main.java index 5370726..807287f 100644 --- a/core/src/com/mygdx/game/Main.java +++ b/core/src/com/mygdx/game/Main.java @@ -2,10 +2,14 @@ package com.mygdx.game; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL30; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.mygdx.game.Character.Mouse; +import com.mygdx.game.Character.Player; +import com.mygdx.game.UI.GUI; +import com.mygdx.game.World.Chunkloading; +import com.mygdx.game.World.WorldRenderer; import static com.mygdx.game.Restrictions.*; @@ -19,6 +23,10 @@ public class Main extends ApplicationAdapter { @Override public void create () { Chunkloading chunkloading = new Chunkloading(); + chunkloading.create(); + + Gdx.graphics.setWindowedMode(1024,576); + Player player = new Player(0, 0); mouse = new Mouse(player); cam = new OrthographicCamera(VIEWPORT_WIDTH,VIEWPORT_HEIGHT); @@ -31,7 +39,7 @@ public class Main extends ApplicationAdapter { @Override public void render () { - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); batch.begin(); worldRenderer.render(batch); gui.render(batch); diff --git a/core/src/com/mygdx/game/Restrictions.java b/core/src/com/mygdx/game/Restrictions.java index a29ce4b..d93e3ad 100644 --- a/core/src/com/mygdx/game/Restrictions.java +++ b/core/src/com/mygdx/game/Restrictions.java @@ -7,4 +7,6 @@ public interface Restrictions { int MOVEMENT_SPEED = 16; int KEY_DELAY = 20; int CHUNK_SIZE = 16; + int SUPER_CHUNK_SIZE = 3; + } diff --git a/core/src/com/mygdx/game/GUI.java b/core/src/com/mygdx/game/UI/GUI.java similarity index 87% rename from core/src/com/mygdx/game/GUI.java rename to core/src/com/mygdx/game/UI/GUI.java index cff7127..5f77f61 100644 --- a/core/src/com/mygdx/game/GUI.java +++ b/core/src/com/mygdx/game/UI/GUI.java @@ -1,10 +1,9 @@ -package com.mygdx.game; +package com.mygdx.game.UI; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.math.Vector3; +import com.mygdx.game.Character.Mouse; public class GUI { private BitmapFont font = new BitmapFont(); diff --git a/core/src/com/mygdx/game/Block.java b/core/src/com/mygdx/game/World/Block.java similarity index 95% rename from core/src/com/mygdx/game/Block.java rename to core/src/com/mygdx/game/World/Block.java index e93c798..39a038b 100644 --- a/core/src/com/mygdx/game/Block.java +++ b/core/src/com/mygdx/game/World/Block.java @@ -1,4 +1,4 @@ -package com.mygdx.game; +package com.mygdx.game.World; import com.badlogic.gdx.graphics.Texture; diff --git a/core/src/com/mygdx/game/Chunk.java b/core/src/com/mygdx/game/World/Chunk.java similarity index 77% rename from core/src/com/mygdx/game/Chunk.java rename to core/src/com/mygdx/game/World/Chunk.java index bb6dc5e..67ab792 100644 --- a/core/src/com/mygdx/game/Chunk.java +++ b/core/src/com/mygdx/game/World/Chunk.java @@ -1,12 +1,11 @@ -package com.mygdx.game; +package com.mygdx.game.World; -import com.badlogic.gdx.graphics.Texture; import net.dermetfan.utils.Pair; import java.util.HashMap; public class Chunk { - private HashMap,Block> blocks = new HashMap<>(); + private HashMap,Block> blocks= new HashMap<>(); public HashMap, Block> getBlocks() { return blocks; diff --git a/core/src/com/mygdx/game/Chunkloading.java b/core/src/com/mygdx/game/World/Chunkloading.java similarity index 78% rename from core/src/com/mygdx/game/Chunkloading.java rename to core/src/com/mygdx/game/World/Chunkloading.java index eb4260a..3534501 100644 --- a/core/src/com/mygdx/game/Chunkloading.java +++ b/core/src/com/mygdx/game/World/Chunkloading.java @@ -1,6 +1,7 @@ -package com.mygdx.game; +package com.mygdx.game.World; +import com.mygdx.game.Restrictions; import net.dermetfan.utils.Pair; import java.util.HashMap; @@ -33,7 +34,12 @@ public class Chunkloading implements Restrictions { } } - public void render(){ - populateChunk(0,0); + public void create(){ + for(int x = 0; x!=SUPER_CHUNK_SIZE; x++){ + for(int y = 0; y!=SUPER_CHUNK_SIZE; y++){ + populateChunk(x,y); + + } + } } } diff --git a/core/src/com/mygdx/game/World/WorldRenderer.java b/core/src/com/mygdx/game/World/WorldRenderer.java new file mode 100644 index 0000000..ebc8e0e --- /dev/null +++ b/core/src/com/mygdx/game/World/WorldRenderer.java @@ -0,0 +1,56 @@ +package com.mygdx.game.World; + +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.mygdx.game.Character.InputController; +import com.mygdx.game.Character.Mouse; +import com.mygdx.game.Character.Player; +import com.mygdx.game.Restrictions; + +public class WorldRenderer implements Restrictions { + private Mouse mouse; + private OrthographicCamera cam; + private Player player; + private InputController inputController; + private Chunkloading chunkloading; + + public WorldRenderer(Chunkloading chunkloading, Player player, Mouse mouse, OrthographicCamera cam) { + this.player = player; + this.chunkloading = chunkloading; + this.mouse = mouse; + this.cam = cam; + inputController = new InputController(this.cam, this.player); + } + + private void drawWorld(Batch batch) { + for (int i = 0; i != SUPER_CHUNK_SIZE; i++) { + for (int j = 0; j != SUPER_CHUNK_SIZE; j++) { + drawChunk(batch, i, j); + } + } + } + + private void drawChunk(Batch batch, int i, int j) { + for (int x = 0; x < CHUNK_SIZE; x++) { + for (int y = 0; y < CHUNK_SIZE; y++) { + try { + batch.draw(chunkloading.getChunk(i, j).getBlock(x+i*CHUNK_SIZE,y+j*CHUNK_SIZE).getTexture(), (x * TILE_SIZE), (y * TILE_SIZE)); + } catch (Exception ignored) { + } + } + } + } + + public void render(SpriteBatch batch) { + drawWorld(batch); + inputController.handleInput(); + batch.setProjectionMatrix(cam.combined); + cam.update(); + mouse.render(batch, cam); + player.render(batch); + } + + public void dispose() { + } +} diff --git a/core/src/com/mygdx/game/WorldRenderer.java b/core/src/com/mygdx/game/WorldRenderer.java deleted file mode 100644 index 0015190..0000000 --- a/core/src/com/mygdx/game/WorldRenderer.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.mygdx.game; - -import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; - -public class WorldRenderer implements Restrictions { - private Mouse mouse; - private OrthographicCamera cam; - private Player player; - private InputController inputController; - private Chunkloading chunkloading; - - public WorldRenderer(Chunkloading chunkloading, Player player, Mouse mouse, OrthographicCamera cam) { - this.player = player; - this.chunkloading = chunkloading; - this.mouse = mouse; - this.cam = cam; - inputController = new InputController(this.cam,this.player); - } - - public void render(SpriteBatch batch){ - chunkloading.render(); - drawWorld(batch,player); - inputController.handleInput(); - batch.setProjectionMatrix(cam.combined); - cam.update(); - mouse.render(batch,cam); - player.render(batch); - } - - - private void drawWorld(Batch batch,Player player) { - for(int x = 0; x