diff --git a/core/assets/gdx-texturepacker/gdx-texturepacker.jar b/core/assets/gdx-texturepacker/gdx-texturepacker.jar new file mode 100755 index 0000000..8bf5922 Binary files /dev/null and b/core/assets/gdx-texturepacker/gdx-texturepacker.jar differ diff --git a/core/assets/gdx-texturepacker/icon.ico b/core/assets/gdx-texturepacker/icon.ico new file mode 100644 index 0000000..836bbfa Binary files /dev/null and b/core/assets/gdx-texturepacker/icon.ico differ diff --git a/core/assets/gdx-texturepacker/launcher.bat b/core/assets/gdx-texturepacker/launcher.bat new file mode 100644 index 0000000..97ffdb0 --- /dev/null +++ b/core/assets/gdx-texturepacker/launcher.bat @@ -0,0 +1,2 @@ +cd /d %~dp0 +start javaw -Xms64m -Xmx1024m -XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=30 -jar gdx-texturepacker.jar %* \ No newline at end of file diff --git a/core/assets/gdx-texturepacker/launcher.sh b/core/assets/gdx-texturepacker/launcher.sh new file mode 100755 index 0000000..8d94f08 --- /dev/null +++ b/core/assets/gdx-texturepacker/launcher.sh @@ -0,0 +1,3 @@ +SCRIPTDIR=$(dirname "$0") +cd $SCRIPTDIR +java -Xms64m -Xmx1024m -XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=30 -jar ./gdx-texturepacker.jar \ No newline at end of file diff --git a/core/assets/gdx-texturepacker/launcher_no_cmd.vbs b/core/assets/gdx-texturepacker/launcher_no_cmd.vbs new file mode 100644 index 0000000..7e20c5b --- /dev/null +++ b/core/assets/gdx-texturepacker/launcher_no_cmd.vbs @@ -0,0 +1,7 @@ +Set oShell = CreateObject ("Wscript.Shell") +Dim strArgs +strArgs = "cmd /c launcher.bat " +For Each arg In Wscript.Arguments + strArgs = strArgs + arg +Next +oShell.Run strArgs, 0, false \ No newline at end of file diff --git a/core/assets/gdx-texturepacker/readme.txt b/core/assets/gdx-texturepacker/readme.txt new file mode 100644 index 0000000..8d0a8d2 --- /dev/null +++ b/core/assets/gdx-texturepacker/readme.txt @@ -0,0 +1,27 @@ +Gdx Texture Packer GUI + +Simple utility to help you pack and manage texture atlases for LibGDX game framework. It's mostly just visual wrapper over LibGDX TexturePacker classes and offers more convenient way of using it. + +For further details visit GitHub project page: +https://github.com/crashinvaders/gdx-texture-packer-gui + +Requirements: +- Java 7 JRE (or higher) (can be donwnloaded here http://www.oracle.com/technetwork/java/javase/downloads/index.html) +- OpenGL support + +How to launch: +Application is packed into JAR executable file. To launch it, issue next command +java -jar gdx-texturepacker.jar + +MacOS and UNIX +You may execute launch.sh bash script to launch application + +Windows +launch.bat - starts application +launcher_no_cmd.vbs - does exactly what launch.bat does, but CMD window won't appear in that case + + +If you got any questions or would like to share some ideas, reach me out at anton@crashinvaders.com + +Hope you will enjoy it! +Anton Chekulaev \ No newline at end of file diff --git a/core/assets/gdx-texturepacker/readme_hotkeys.txt b/core/assets/gdx-texturepacker/readme_hotkeys.txt new file mode 100644 index 0000000..761d9cf --- /dev/null +++ b/core/assets/gdx-texturepacker/readme_hotkeys.txt @@ -0,0 +1,3 @@ +You can define/override you own keyboard shortcuts for some actions. +For the details look at the default hotkey configuration file. +https://github.com/crashinvaders/gdx-texture-packer-gui/blob/master/assets/hotkeys_default.txt \ No newline at end of file diff --git a/core/assets/grass.png b/core/assets/grass.png index 1ae9b3b..a554e52 100644 Binary files a/core/assets/grass.png and b/core/assets/grass.png differ diff --git a/core/assets/jungleGrass.png b/core/assets/jungleGrass.png new file mode 100644 index 0000000..ecff7a2 Binary files /dev/null and b/core/assets/jungleGrass.png differ diff --git a/core/assets/output/world.atlas b/core/assets/output/world.atlas new file mode 100644 index 0000000..95981ff --- /dev/null +++ b/core/assets/output/world.atlas @@ -0,0 +1,62 @@ + +world.png +size: 128,16 +format: RGBA8888 +filter: Nearest,Nearest +repeat: none +crosshair + rotate: false + xy: 48, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +grass + rotate: false + xy: 96, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +jungleGrass + rotate: false + xy: 112, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +sand + rotate: false + xy: 16, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +snow + rotate: false + xy: 0, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +stone + rotate: false + xy: 64, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +water + rotate: false + xy: 32, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 +wood + rotate: false + xy: 80, 0 + size: 16, 16 + orig: 16, 16 + offset: 0, 0 + index: -1 diff --git a/core/assets/output/world.png b/core/assets/output/world.png new file mode 100644 index 0000000..7782b94 Binary files /dev/null and b/core/assets/output/world.png differ diff --git a/core/src/com/mygdx/game/Character/InputController.java b/core/src/com/mygdx/game/Character/InputController.java index d2c4aed..1d807ad 100644 --- a/core/src/com/mygdx/game/Character/InputController.java +++ b/core/src/com/mygdx/game/Character/InputController.java @@ -2,20 +2,15 @@ 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.mygdx.game.Restrictions; +import static com.mygdx.game.Main.cam; + public class InputController implements Restrictions { - private OrthographicCamera cam; - private Player player; int i = 0; - public InputController(OrthographicCamera cam, Player player) { - this.cam = cam; - this.player = player; - } public void handleInput() { i++; @@ -30,29 +25,29 @@ public class InputController implements Restrictions { if (Gdx.input.isKeyPressed(Input.Keys.UP) && Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) { i = 0; directionAnimation("UpLeft"); - player.addX(-MOVEMENT_SPEED); - player.addY(MOVEMENT_SPEED); + Player.addX(-MOVEMENT_SPEED); + Player.addY(MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED,MOVEMENT_SPEED); } else if (Gdx.input.isKeyPressed(Input.Keys.UP)&& Gdx.input.isKeyPressed(Input.Keys.RIGHT) &&i > KEY_DELAY) { i = 0; directionAnimation("UpRight"); - player.addX(MOVEMENT_SPEED); - player.addY(MOVEMENT_SPEED); + Player.addX(MOVEMENT_SPEED); + Player.addY(MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED,MOVEMENT_SPEED); } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) { i = 0; directionAnimation("DownLeft"); - player.addX(-MOVEMENT_SPEED); - player.addY(-MOVEMENT_SPEED); + Player.addX(-MOVEMENT_SPEED); + Player.addY(-MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED,-MOVEMENT_SPEED); } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& Gdx.input.isKeyPressed(Input.Keys.RIGHT) && i > KEY_DELAY) { i = 0; directionAnimation("DownRight"); - player.addX(MOVEMENT_SPEED); - player.addY(-MOVEMENT_SPEED); + Player.addX(MOVEMENT_SPEED); + Player.addY(-MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED,-MOVEMENT_SPEED); } @@ -60,33 +55,34 @@ public class InputController implements Restrictions { else if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) { i = 0; directionAnimation("Left"); - player.addX(-MOVEMENT_SPEED); + Player.addX(-MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED,0); } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)&& i > KEY_DELAY) { i = 0; directionAnimation("Right"); - player.addX(MOVEMENT_SPEED); + Player.addX(MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED,0); } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& i > KEY_DELAY) { i = 0; directionAnimation("Down"); - player.addY(-MOVEMENT_SPEED); + Player.addY(-MOVEMENT_SPEED); cam.translate(0,-MOVEMENT_SPEED); } if (Gdx.input.isKeyPressed(Input.Keys.UP)&& i > KEY_DELAY) { i = 0; directionAnimation("Up"); - player.addY(MOVEMENT_SPEED); + Player.addY(MOVEMENT_SPEED); cam.translate(0,MOVEMENT_SPEED); } + cam.update(); } public void directionAnimation(String direction) { - player.setAnimation(new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + direction))); + Player.setAnimation(new Animation<>(1 / 4f, Player.textureAtlas.findRegions(Player.getSpriteName() + "_" + direction))); } } diff --git a/core/src/com/mygdx/game/Character/Mouse.java b/core/src/com/mygdx/game/Character/Mouse.java index 90eacbf..9b75805 100644 --- a/core/src/com/mygdx/game/Character/Mouse.java +++ b/core/src/com/mygdx/game/Character/Mouse.java @@ -7,45 +7,43 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector3; import com.mygdx.game.Restrictions; -import static java.lang.Math.round; +import static com.mygdx.game.Main.cam; public class Mouse implements Restrictions { - Player player; Texture crosshair = new Texture("core/assets/crosshair.png"); - public Mouse(Player player) { - this.player = player; - } - public void selectedTile(SpriteBatch batch, OrthographicCamera cam){ + public void selectedTile(SpriteBatch batch){ Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0); cam.unproject(mousePos); - batch.draw(crosshair, getSelectedX(mousePos), getSelectedY(mousePos)); + int x = getSelectedX(mousePos); + int y = getSelectedY(mousePos); + batch.draw(crosshair, x, y); } public int getSelectedX(Vector3 mousePos) { - return round((mousePos.x-8)/16)*16; + return ((int)(mousePos.x)>>4)<<4; } public int getSelectedY(Vector3 mousePos) { - return round((mousePos.y-8)/16)*16; + return ((int)(mousePos.y)>>4)<<4; } public int getTileX(OrthographicCamera cam){ Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0); cam.unproject(mousePos); - return (getSelectedX(mousePos) + player.getX()/2)/TILE_SIZE; + return (getSelectedX(mousePos) + Player.getX()>>1)/TILE_SIZE; } public int getTileY(OrthographicCamera cam){ Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0); cam.unproject(mousePos); - return (getSelectedY(mousePos) + player.getY()/2)/TILE_SIZE; + return (getSelectedY(mousePos) + Player.getY()>>1)/TILE_SIZE; } - public void render(SpriteBatch batch, OrthographicCamera cam) { - selectedTile(batch,cam); + public void render(SpriteBatch batch) { + selectedTile(batch); //System.out.println("X = " + getTileX(cam) + " Y = "+ getTileY(cam)); } } diff --git a/core/src/com/mygdx/game/Character/Player.java b/core/src/com/mygdx/game/Character/Player.java index 5fc48b1..a5538e3 100644 --- a/core/src/com/mygdx/game/Character/Player.java +++ b/core/src/com/mygdx/game/Character/Player.java @@ -1,72 +1,66 @@ package com.mygdx.game.Character; -import com.badlogic.gdx.graphics.OrthographicCamera; 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.Main; import com.mygdx.game.Restrictions; public class Player implements Restrictions { - private int x,y; - private String spriteName; - private TextureAtlas textureAtlas; - private Animation animation; - private OrthographicCamera cam; + private static int x,y; + private static String spriteName; + public static TextureAtlas textureAtlas; + private static Animation animation; - public Player(int x, int y, OrthographicCamera cam) { - this.cam = cam; - this.x = x*TILE_SIZE; - this.y = y*TILE_SIZE; + public static void create(int x, int y) { + Player.x = x< keyFrames = textureAtlas.findRegions(spriteName + "_Down"); float frameDuration = 1 / 4f; - this.animation = new Animation<>(frameDuration, keyFrames); + animation = new Animation<>(frameDuration, keyFrames); } - public static void teleport(Player player, int x, int y){ - player.x = x*TILE_SIZE; - player.y = y*TILE_SIZE; - player.cam.translate(x,y); + public static void teleport(int x, int y){ + Player.x = x< getAnimation() { + public static Animation getAnimation() { return animation; } - void setAnimation(Animation animation) { - this.animation = animation; + static void setAnimation(Animation animationTemp) { + animation = animationTemp; } + } diff --git a/core/src/com/mygdx/game/Dimension/Block.java b/core/src/com/mygdx/game/Dimension/Block.java index 2931303..84ce188 100644 --- a/core/src/com/mygdx/game/Dimension/Block.java +++ b/core/src/com/mygdx/game/Dimension/Block.java @@ -2,12 +2,12 @@ package com.mygdx.game.Dimension; public class Block { private String name; - private Boolean floor, wall, harvestable, breakable, passable; + private Boolean harvestable; + private Boolean breakable; + private Boolean passable; - public Block(String name, Boolean floor, Boolean wall, Boolean harvestable, Boolean breakable, Boolean passable) { + public Block(String name, Boolean harvestable, Boolean breakable, Boolean passable) { this.name = name; - this.floor = floor; - this.wall = wall; this.harvestable = harvestable; this.breakable = breakable; this.passable = passable; @@ -21,22 +21,6 @@ public class Block { this.name = name; } - public Boolean getFloor() { - return floor; - } - - public void setFloor(Boolean floor) { - this.floor = floor; - } - - public Boolean getWall() { - return wall; - } - - public void setWall(Boolean wall) { - this.wall = wall; - } - public Boolean getHarvestable() { return harvestable; } diff --git a/core/src/com/mygdx/game/Dimension/BlockMaterials.java b/core/src/com/mygdx/game/Dimension/BlockMaterials.java index ed22708..a593826 100644 --- a/core/src/com/mygdx/game/Dimension/BlockMaterials.java +++ b/core/src/com/mygdx/game/Dimension/BlockMaterials.java @@ -11,17 +11,17 @@ public class BlockMaterials { //Private so the singleton can't be instantiated private BlockMaterials() {} - public Texture getTexture(String material) { + public static Texture getTexture(String material) { return textures.get(material); } public static void create(){ - materials.put("grass",new Block("grass",true,false,true,true,true)); - materials.put("wood",new Block("wood",false,true,true,true,false)); - materials.put("water",new Block("water",true,false,false,false,false)); - materials.put("stone",new Block("stone",true,false,false,false,false)); - materials.put("snow",new Block("snow",true,false,false,false,false)); - materials.put("sand",new Block("sand",true,false,false,false,false)); + materials.put("grass",new Block("grass",true,false,true)); + materials.put("wood",new Block("wood",false,true,true)); + materials.put("water",new Block("water",true,false,false)); + materials.put("stone",new Block("stone",true,false,false)); + materials.put("snow",new Block("snow",true,false,false)); + materials.put("sand",new Block("sand",true,false,false)); textures.put("grass", new Texture("core/assets/grass.png")); textures.put("wood", new Texture("core/assets/wood.png")); diff --git a/core/src/com/mygdx/game/Dimension/Chunks.java b/core/src/com/mygdx/game/Dimension/Chunks.java index 4cc97d9..17224ad 100644 --- a/core/src/com/mygdx/game/Dimension/Chunks.java +++ b/core/src/com/mygdx/game/Dimension/Chunks.java @@ -1,28 +1,30 @@ //https://www.redblobgames.com/maps/terrain-from-noise/ package com.mygdx.game.Dimension; +import com.github.czyzby.kiwi.util.tuple.immutable.Triple; import com.mygdx.game.OpenSimplexNoise; -import net.dermetfan.utils.Pair; import java.util.HashMap; -import static com.mygdx.game.Restrictions.CHUNK_SIZE; +import static com.mygdx.game.Restrictions.*; public class Chunks { - public HashMap, Block> blocks = new HashMap<>(); + public static HashMap, Block> blocks = new HashMap<>(); private long seed = 1; public void generateChunk(int x, int y){ - int startX = x*CHUNK_SIZE; - int startY = y*CHUNK_SIZE; + int startX = x << CHUNK_SHIFT; + int startY = y << CHUNK_SHIFT; + int startZ = 0; int endX = startX + CHUNK_SIZE; int endY = startY + CHUNK_SIZE; + int endZ = startY + CHUNK_HEIGHT; //Going from start of selected chunk to end of selected chunk in x and y for (int i = startX; i != endX; i++){ for (int j = startY; j != endY; j++) { - blocks.put(new Pair<>(i, j), getTerrain(i,j)); + blocks.put(new Triple(i, j, 0), getTerrain(i, j)); } } } @@ -53,12 +55,12 @@ public class Chunks { elevation /= (0.17+0.42+0.16+0.00+0.00+0.03); elevation = Math.pow(elevation, 3.00); moisture = (1.00 * noise2( 1 * nx, 1 * ny) - + 0.75 * noise2( 2 * nx, 2 * ny) - + 0.33 * noise2( 4 * nx, 4 * ny) - + 0.33 * noise2( 8 * nx, 8 * ny) - + 0.33 * noise2(16 * nx, 16 * ny) - + 0.50 * noise2(32 * nx, 32 * ny)); - moisture /= (1.00+0.75+0.33+0.33+0.33+0.50); + + 0.00 * noise2( 2 * nx, 2 * ny) + + 1.00 * noise2( 4 * nx, 4 * ny) + + 0.00 * noise2( 8 * nx, 8 * ny) + + 0.00 * noise2(16 * nx, 16 * ny) + + 0.00 * noise2(32 * nx, 32 * ny)); + moisture /= (0.00+1.00+0.00+0.00+0.00+0.00); return getBiomeBlock(moisture, elevation); } @@ -68,18 +70,23 @@ public class Chunks { if (biome.equals("Tundra")) return BlockMaterials.materials.get("snow"); if (biome.equals("Taiga")) return BlockMaterials.materials.get("snow"); if (biome.equals("Snow")) return BlockMaterials.materials.get("snow"); + if (biome.equals("Grassland")) return BlockMaterials.materials.get("grass"); if (biome.equals("Shrubland")) return BlockMaterials.materials.get("grass"); if (biome.equals("TemperateDeciduousForest")) return BlockMaterials.materials.get("grass"); + if (biome.equals("TemperateRainForest")) return BlockMaterials.materials.get("grass"); if (biome.equals("TropicalSeasonalForest")) return BlockMaterials.materials.get("grass"); if (biome.equals("TropicalForest")) return BlockMaterials.materials.get("grass"); + if (biome.equals("TropicalRainForest")) return BlockMaterials.materials.get("grass"); + if (biome.equals("Beach")) return BlockMaterials.materials.get("sand"); if (biome.equals("Bare")) return BlockMaterials.materials.get("sand"); if (biome.equals("Scorched")) return BlockMaterials.materials.get("sand"); if (biome.equals("TemperateDesert")) return BlockMaterials.materials.get("sand"); if (biome.equals("SubtropicalDesert")) return BlockMaterials.materials.get("sand"); - else return BlockMaterials.materials.get("water"); + + return BlockMaterials.materials.get("water"); } @@ -113,8 +120,4 @@ public class Chunks { return "TropicalRainForest"; } - public HashMap, Block> getBlocks() { - return blocks; - } - } diff --git a/core/src/com/mygdx/game/Dimension/Superchunks.java b/core/src/com/mygdx/game/Dimension/Superchunks.java index 0aca159..b794eac 100644 --- a/core/src/com/mygdx/game/Dimension/Superchunks.java +++ b/core/src/com/mygdx/game/Dimension/Superchunks.java @@ -42,29 +42,29 @@ public class Superchunks { } - public static void loadChunks(Player player) { + public static void loadChunks() { int chunkY = 0; 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)); + 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() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); + else 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) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); } //Bottom-left - else if (0 >= player.getX() && 0 >= player.getY()) { - chunkY = ((player.getY() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); - chunkX = ((player.getX() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); + else if (0 >= Player.getX()) { + chunkY = ((Player.getY() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); + chunkX = ((Player.getX() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); } //Bottom-right - else if (0 < player.getX() && 0 > player.getY()) { - chunkY = ((player.getY() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); - chunkX = ((player.getX()) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); + else { + chunkY = ((Player.getY() - TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); + chunkX = ((Player.getX()) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)); } diff --git a/core/src/com/mygdx/game/Dimension/WorldRenderer.java b/core/src/com/mygdx/game/Dimension/WorldRenderer.java index 23fbb29..f4b0acb 100644 --- a/core/src/com/mygdx/game/Dimension/WorldRenderer.java +++ b/core/src/com/mygdx/game/Dimension/WorldRenderer.java @@ -1,56 +1,43 @@ package com.mygdx.game.Dimension; -import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.github.czyzby.kiwi.util.tuple.immutable.Triple; import com.mygdx.game.Character.InputController; import com.mygdx.game.Character.Mouse; -import com.mygdx.game.Character.Player; import com.mygdx.game.Restrictions; -import net.dermetfan.utils.Pair; -import java.util.HashMap; +import static com.mygdx.game.Main.cam; public class WorldRenderer implements Restrictions { private Mouse mouse; - private OrthographicCamera cam; - private Player player; private InputController inputController; - public WorldRenderer(Player player, Mouse mouse, OrthographicCamera cam) { - this.player = player; + public WorldRenderer(Mouse mouse) { this.mouse = mouse; - this.cam = cam; - inputController = new InputController(this.cam, this.player); + inputController = new InputController(); } public void drawWorld(Batch batch) { - for (Pair worldpair: Superchunks.loadedChunks.keySet()) { - Chunks chunks = Superchunks.loadedChunks.get(worldpair); - for (Pair chunkpair: chunks.blocks.keySet()) { + for (Triple chunkpair : Chunks.blocks.keySet()) { - HashMap, Block> blocks = chunks.getBlocks(); - Block chunkBlock = blocks.get(chunkpair); - String name = chunkBlock.getName(); + String name = Chunks.blocks.get(chunkpair).getName(); + int drawingLocationX = chunkpair.getFirst() << TILE_SHIFT; + int drawingLocationY = chunkpair.getSecond() << TILE_SHIFT; - int drawingLocationX = chunkpair.getKey() * TILE_SIZE; - int drawingLocationY = chunkpair.getValue()* TILE_SIZE; - - batch.draw(BlockMaterials.textures.get(name),drawingLocationX ,drawingLocationY); - } + batch.draw(BlockMaterials.getTexture(name), drawingLocationX, drawingLocationY); } } - public void render(SpriteBatch batch, float elapsedTime) { + public void render(SpriteBatch batch) { try { drawWorld(batch); - }catch (Exception e){} + }catch (Exception ignored){} inputController.handleInput(); batch.setProjectionMatrix(cam.combined); cam.update(); - mouse.render(batch, cam); - player.render(batch,elapsedTime); + mouse.render(batch); } public void dispose() { diff --git a/core/src/com/mygdx/game/Main.java b/core/src/com/mygdx/game/Main.java index 84fb398..3bc780a 100644 --- a/core/src/com/mygdx/game/Main.java +++ b/core/src/com/mygdx/game/Main.java @@ -22,26 +22,25 @@ public class Main extends ApplicationAdapter { public static float delta = 0; 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 - private Player player; + public static OrthographicCamera cam; @Override public void create () { Gdx.graphics.setWindowedMode(1024,576); - OrthographicCamera cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); + cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam); Superchunks.create(); //Starting location of the player - player = new Player(0, 0, cam); - - cam.translate((float) TILE_SIZE / 2, (float) TILE_SIZE / 2); + cam.translate(TILE_SIZE >> 1, TILE_SIZE >> 1); + Player.create(0,0); cam.zoom = 25f; - Mouse mouse = new Mouse(player); + Mouse mouse = new Mouse(); gui = new GUI(mouse,fitViewport); - worldRenderer = new WorldRenderer(player, mouse, cam); + worldRenderer = new WorldRenderer(mouse); batch = new SpriteBatch(); } @@ -50,16 +49,18 @@ public class Main extends ApplicationAdapter { Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); timeSinceLastUpdate += Gdx.graphics.getDeltaTime(); //Accumulate delta time + batch.begin(); + if(timeSinceLastUpdate > 1/10f){ + worldRenderer.render(batch); + } + Player.render(batch,timeSinceLastUpdate); delta +=Gdx.graphics.getDeltaTime(); if(delta > RENDER_TIME) { delta -= RENDER_TIME; - Superchunks.loadedChunks.clear(); - Superchunks.loadChunks(player); + Superchunks.loadChunks(); } - batch.begin(); - worldRenderer.render(batch,timeSinceLastUpdate); gui.render(batch); batch.end(); } @@ -70,6 +71,6 @@ public class Main extends ApplicationAdapter { worldRenderer.dispose(); gui.dispose(); batch.dispose(); - player.getTextureAtlas().dispose(); + Player.textureAtlas.dispose(); } } diff --git a/core/src/com/mygdx/game/Restrictions.java b/core/src/com/mygdx/game/Restrictions.java index 099c447..4bc3adb 100644 --- a/core/src/com/mygdx/game/Restrictions.java +++ b/core/src/com/mygdx/game/Restrictions.java @@ -1,13 +1,21 @@ package com.mygdx.game; public interface Restrictions { - int TILE_SIZE = 16; float VIEWPORT_HEIGHT = 9/2f; float VIEWPORT_WIDTH = 16/2f; - int MOVEMENT_SPEED = 16; + int MOVEMENT_SPEED = 2; int KEY_DELAY = 0; - int CHUNK_SIZE = 16; - int SUPER_CHUNK_SIZE = 3; + + int TILE_SIZE = 16; + int CHUNK_SIZE = 8; + int CHUNK_HEIGHT = 2; + int SUPER_CHUNK_SIZE = 1; + + int TILE_SHIFT = 4; + int CHUNK_SHIFT = 3; + int CHUNK_HEIGHT_SHIFT = 2; + int SUPER_CHUNK_SHIFT = 0; + int RENDER_DISTANCE = 2; - float RENDER_TIME = 4f; + float RENDER_TIME = 1f; }