Broke everything down into packages and fixed resolution issues
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<TextureAtlas.AtlasRegion> animation;
|
||||
|
||||
Player(int x, int y) {
|
||||
public Player(int x, int y) {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.spriteName = "man";
|
||||
@@ -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);
|
||||
|
||||
@@ -7,4 +7,6 @@ public interface Restrictions {
|
||||
int MOVEMENT_SPEED = 16;
|
||||
int KEY_DELAY = 20;
|
||||
int CHUNK_SIZE = 16;
|
||||
int SUPER_CHUNK_SIZE = 3;
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mygdx.game;
|
||||
package com.mygdx.game.World;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mygdx.game;
|
||||
package com.mygdx.game.World;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import net.dermetfan.utils.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
56
core/src/com/mygdx/game/World/WorldRenderer.java
Normal file
56
core/src/com/mygdx/game/World/WorldRenderer.java
Normal file
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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<CHUNK_SIZE; x++) {
|
||||
for(int y = 0; y<CHUNK_SIZE; y++) {
|
||||
try {
|
||||
batch.draw(chunkloading.getChunk(0,0).getBlock(x,y).getTexture(), (x * TILE_SIZE), (y * TILE_SIZE));
|
||||
} catch (Exception e){}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void dispose(){
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user