diff --git a/core/assets/badlogic.jpg b/core/assets/badlogic.jpg deleted file mode 100644 index 4390da6..0000000 Binary files a/core/assets/badlogic.jpg and /dev/null differ diff --git a/core/assets/grass.png b/core/assets/grass.png new file mode 100644 index 0000000..f1b5151 Binary files /dev/null and b/core/assets/grass.png differ diff --git a/core/src/com/mygdx/game/Block.java b/core/src/com/mygdx/game/Block.java index 8c749bd..5dc72c5 100644 --- a/core/src/com/mygdx/game/Block.java +++ b/core/src/com/mygdx/game/Block.java @@ -1,56 +1,17 @@ package com.mygdx.game; -import com.badlogic.gdx.graphics.Color; - public class Block { - int x,y,width,height; - Color color; + private String material; - public Block(int tempX, int tempY,int tempWidth, int tempHeight, Color tempColor) { - x = tempX; - y = tempY; - color = tempColor; - width = tempWidth; - height = tempHeight; + public Block(String tempMaterial) { + material = tempMaterial; } - public int getX() { - return x; + public String getMaterial() { + return material; } - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public Color getColor() { - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public int getWidth() { - return width; - } - - public void setWidth(int width) { - this.width = width; - } - - public int getHeight() { - return height; - } - - public void setHeight(int height) { - this.height = height; + public void setMaterial(String material) { + this.material = material; } } diff --git a/core/src/com/mygdx/game/Main.java b/core/src/com/mygdx/game/Main.java new file mode 100644 index 0000000..16dd0ae --- /dev/null +++ b/core/src/com/mygdx/game/Main.java @@ -0,0 +1,45 @@ +package com.mygdx.game; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import javafx.util.Pair; + +import java.util.HashMap; + +public class Main extends ApplicationAdapter { + private SpriteBatch batch; + private WorldRenderer worldRenderer; + + @Override + public void create () { + batch = new SpriteBatch(); + + World world = new World(); + + Player player = new Player(0, 0); + + worldRenderer = new WorldRenderer(world, player); + } + + @Override + public void render () { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + batch.begin(); + worldRenderer.render(batch); + batch.end(); + } + + @Override + public void dispose () { + worldRenderer.dispose(); + batch.dispose(); + } +} diff --git a/core/src/com/mygdx/game/MyGdxGame.java b/core/src/com/mygdx/game/MyGdxGame.java deleted file mode 100644 index 3812959..0000000 --- a/core/src/com/mygdx/game/MyGdxGame.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.mygdx.game; - -import com.badlogic.gdx.ApplicationAdapter; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; - -public class MyGdxGame extends ApplicationAdapter { - SpriteBatch batch; - Texture img; - World world; - WorldRenderer worldRenderer; - - @Override - public void create () { - Block[] blocks = new Block[4]; - blocks[0] = new Block(0,0, 6,1,new Color(0,1,0,1)); - blocks[1] = new Block(1,0, 1,1,new Color(0,1,0,1)); - blocks[2] = new Block(2,0, 1,1,new Color(0,1,0,1)); - blocks[3] = new Block(3,0, 1,1,new Color(0,1,0,1)); - world = new World(blocks); - } - - @Override - public void render () { - Gdx.gl.glClearColor(0, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - worldRenderer = new WorldRenderer(world.getBlocks()); - worldRenderer.render(); - } - - @Override - public void dispose () { - batch.dispose(); - img.dispose(); - } -} diff --git a/core/src/com/mygdx/game/Player.java b/core/src/com/mygdx/game/Player.java new file mode 100644 index 0000000..cdfaef8 --- /dev/null +++ b/core/src/com/mygdx/game/Player.java @@ -0,0 +1,28 @@ +package com.mygdx.game; + +import javafx.util.Pair; + +public class Player { + private int x,y = 0; + + public Player(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } +} diff --git a/core/src/com/mygdx/game/World.java b/core/src/com/mygdx/game/World.java index e881c11..1c1515f 100644 --- a/core/src/com/mygdx/game/World.java +++ b/core/src/com/mygdx/game/World.java @@ -1,17 +1,36 @@ package com.mygdx.game; -public class World { - Block[] blocks; +import javafx.util.Pair; - public World(Block[] blocks) { +import java.util.HashMap; +import java.util.Map; + +public class World { + Map,Block> blocks; + + public World(HashMap, Block> blocks) { this.blocks = blocks; } - public Block[] getBlocks() { + public World() { + this.blocks = new HashMap<>(); + fillWorld(); + } + + public Map, Block> getBlocks() { return blocks; } - public void setBlocks(Block[] blocks) { - this.blocks = blocks; + public void addTile(int x, int y, Block block){ + this.blocks.put(new Pair<>(x,y),block); } + + public void fillWorld(){ + this.addTile(1,1,new Block("grass")); + this.addTile(1,2,new Block("grass")); + this.addTile(1,3,new Block("grass")); + this.addTile(-1,-2,new Block("grass")); + + } + } diff --git a/core/src/com/mygdx/game/WorldRenderer.java b/core/src/com/mygdx/game/WorldRenderer.java index 71eb26e..ad008ca 100644 --- a/core/src/com/mygdx/game/WorldRenderer.java +++ b/core/src/com/mygdx/game/WorldRenderer.java @@ -1,34 +1,60 @@ package com.mygdx.game; import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import javafx.util.Pair; + +import java.util.HashMap; +import java.util.Map; public class WorldRenderer { + private Texture texture; private OrthographicCamera cam; private World world; - private ShapeRenderer debugRenderer = new ShapeRenderer(); + private Player player; - public WorldRenderer(World world) { - this.cam = new OrthographicCamera(10,7); - this.cam.position.set(5,3.5f,0); - this.cam.update(); + + public WorldRenderer(World world, Player player) { + this.player = player; this.world = world; + + texture = new Texture("core/assets/grass.png"); + + cam = new OrthographicCamera(10, 7); + cam.position.set(this.player.getX(), this.player.getY(),0); } - public WorldRenderer(Block[] blocks) { - this.cam = new OrthographicCamera(10,7); - this.cam.position.set(5,3.5f,0); - this.cam.update(); - this.world = new World(blocks); + public WorldRenderer(OrthographicCamera cam, World world, Player player) { + this.cam = cam; + this.world = world; + this.player = player; + + texture = new Texture("core/assets/grass.png"); + cam.zoom = 1; + + cam = new OrthographicCamera(10, 7); + cam.position.set(player.getX(), player.getY(),0); } - public void render(){ - debugRenderer.setProjectionMatrix(cam.combined); - debugRenderer.begin(ShapeRenderer.ShapeType.Filled); - for (Block block : world.getBlocks()) { - debugRenderer.setColor(block.getColor()); - debugRenderer.rect(block.getX()+0.5f, block.getY()+0.5f, block.getWidth(), block.getHeight()); + public void render(Batch batch){ + cam.position.x = player.getX(); + cam.position.y = player.getY(); + drawWorld(batch, player); + cam.update(); + } + + private void drawWorld(Batch batch,Player player) { + for(int x = player.getX()-10; x