Broke everything down into packages and fixed resolution issues

This commit is contained in:
2020-03-29 14:03:08 -06:00
parent 53b367cc0f
commit 6d98bc5996
11 changed files with 89 additions and 60 deletions

View File

@@ -1,10 +1,11 @@
package com.mygdx.game; package com.mygdx.game.Character;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.mygdx.game.Restrictions;
public class InputController implements Restrictions { public class InputController implements Restrictions {

View File

@@ -1,10 +1,11 @@
package com.mygdx.game; package com.mygdx.game.Character;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.mygdx.game.Restrictions;
import static java.lang.Math.round; import static java.lang.Math.round;

View File

@@ -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.Animation;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.mygdx.game.Restrictions;
public class Player implements Restrictions { public class Player implements Restrictions {
private int x,y = 0; private int x,y = 0;
@@ -11,7 +12,7 @@ public class Player implements Restrictions {
private TextureAtlas textureAtlas; private TextureAtlas textureAtlas;
private Animation<TextureAtlas.AtlasRegion> animation; private Animation<TextureAtlas.AtlasRegion> animation;
Player(int x, int y) { public Player(int x, int y) {
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;
this.spriteName = "man"; this.spriteName = "man";

View File

@@ -2,10 +2,14 @@ package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.GL30; import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 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.*; import static com.mygdx.game.Restrictions.*;
@@ -19,6 +23,10 @@ public class Main extends ApplicationAdapter {
@Override @Override
public void create () { public void create () {
Chunkloading chunkloading = new Chunkloading(); Chunkloading chunkloading = new Chunkloading();
chunkloading.create();
Gdx.graphics.setWindowedMode(1024,576);
Player player = new Player(0, 0); Player player = new Player(0, 0);
mouse = new Mouse(player); mouse = new Mouse(player);
cam = new OrthographicCamera(VIEWPORT_WIDTH,VIEWPORT_HEIGHT); cam = new OrthographicCamera(VIEWPORT_WIDTH,VIEWPORT_HEIGHT);
@@ -31,7 +39,7 @@ public class Main extends ApplicationAdapter {
@Override @Override
public void render () { public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
batch.begin(); batch.begin();
worldRenderer.render(batch); worldRenderer.render(batch);
gui.render(batch); gui.render(batch);

View File

@@ -7,4 +7,6 @@ public interface Restrictions {
int MOVEMENT_SPEED = 16; int MOVEMENT_SPEED = 16;
int KEY_DELAY = 20; int KEY_DELAY = 20;
int CHUNK_SIZE = 16; int CHUNK_SIZE = 16;
int SUPER_CHUNK_SIZE = 3;
} }

View File

@@ -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.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3; import com.mygdx.game.Character.Mouse;
public class GUI { public class GUI {
private BitmapFont font = new BitmapFont(); private BitmapFont font = new BitmapFont();

View File

@@ -1,4 +1,4 @@
package com.mygdx.game; package com.mygdx.game.World;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;

View File

@@ -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 net.dermetfan.utils.Pair;
import java.util.HashMap; import java.util.HashMap;
public class Chunk { public class Chunk {
private HashMap<Pair<Integer,Integer>,Block> blocks = new HashMap<>(); private HashMap<Pair<Integer,Integer>,Block> blocks= new HashMap<>();
public HashMap<Pair<Integer, Integer>, Block> getBlocks() { public HashMap<Pair<Integer, Integer>, Block> getBlocks() {
return blocks; return blocks;

View File

@@ -1,6 +1,7 @@
package com.mygdx.game; package com.mygdx.game.World;
import com.mygdx.game.Restrictions;
import net.dermetfan.utils.Pair; import net.dermetfan.utils.Pair;
import java.util.HashMap; import java.util.HashMap;
@@ -33,7 +34,12 @@ public class Chunkloading implements Restrictions {
} }
} }
public void render(){ public void create(){
populateChunk(0,0); for(int x = 0; x!=SUPER_CHUNK_SIZE; x++){
for(int y = 0; y!=SUPER_CHUNK_SIZE; y++){
populateChunk(x,y);
}
}
} }
} }

View 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() {
}
}

View File

@@ -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(){
}
}