diff --git a/core/src/com/mygdx/game/Character/InputController.java b/core/src/com/mygdx/game/Character/InputController.java index 66ca8b7..15b6fb0 100644 --- a/core/src/com/mygdx/game/Character/InputController.java +++ b/core/src/com/mygdx/game/Character/InputController.java @@ -9,82 +9,90 @@ import com.mygdx.game.Restrictions; import static com.mygdx.game.Main.cam; -public class InputController implements Restrictions { +public class InputController implements Restrictions { int i = 0; - public void handleInput() { i++; - if (Gdx.input.isKeyPressed(Input.Keys.A)) { + if (Gdx.input.isKeyPressed(Input.Keys.Q)) { cam.zoom += 5; } - if (Gdx.input.isKeyPressed(Input.Keys.Q)) { + if (Gdx.input.isKeyPressed(Input.Keys.E)) { cam.zoom -= 5; } - if (Gdx.input.isTouched()) { - Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); - cam.unproject(mousePos); - int x = Mouse.getSelectedX(mousePos) >> TILE_SHIFT; - int y = Mouse.getSelectedY(mousePos) >> TILE_SHIFT; + Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); + cam.unproject(mousePos); + int x = Mouse.getSelectedX(mousePos) >> TILE_SHIFT; + int y = Mouse.getSelectedY(mousePos) >> TILE_SHIFT; + + if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && i > KEY_DELAY) { + i = 0; Chunks.placeBlock(x,y,"wood"); } - - if (Gdx.input.isKeyPressed(Input.Keys.UP) && Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) { + if (Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT) && i > KEY_DELAY) { + i = 0; + Chunks.removeBlock(x,y); + } + if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) { i = 0; directionAnimation("UpLeft"); 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) { + } + else if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) { i = 0; directionAnimation("UpRight"); 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) { + } + else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) { i = 0; directionAnimation("DownLeft"); 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) { + } + else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) { i = 0; directionAnimation("DownRight"); Player.addX(MOVEMENT_SPEED); Player.addY(-MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED, -MOVEMENT_SPEED); - } else if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) { + } + else if (Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) { i = 0; directionAnimation("Left"); Player.addX(-MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED, 0); - } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) && i > KEY_DELAY) { + } + else if (Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) { i = 0; directionAnimation("Right"); Player.addX(MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED, 0); - } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN) && i > KEY_DELAY) { + } + else if (Gdx.input.isKeyPressed(Input.Keys.S) && i > KEY_DELAY) { i = 0; directionAnimation("Down"); Player.addY(-MOVEMENT_SPEED); cam.translate(0, -MOVEMENT_SPEED); } - if (Gdx.input.isKeyPressed(Input.Keys.UP) && i > KEY_DELAY) { + if (Gdx.input.isKeyPressed(Input.Keys.W) && i > KEY_DELAY) { i = 0; directionAnimation("Up"); Player.addY(MOVEMENT_SPEED); cam.translate(0, MOVEMENT_SPEED); } - cam.update(); } - public void directionAnimation(String direction) { Player.setAnimation(new Animation<>(1 / 4f, Player.textureAtlas.findRegions(Player.getSpriteName() + "_" + direction))); } diff --git a/core/src/com/mygdx/game/Dimension/Chunks.java b/core/src/com/mygdx/game/Dimension/Chunks.java index 319adfe..c6d3c01 100644 --- a/core/src/com/mygdx/game/Dimension/Chunks.java +++ b/core/src/com/mygdx/game/Dimension/Chunks.java @@ -7,6 +7,7 @@ import com.mygdx.game.OpenSimplexNoise; import java.util.HashMap; +import static com.mygdx.game.Dimension.BlockMaterials.*; import static com.mygdx.game.Restrictions.*; public class Chunks{ @@ -24,8 +25,17 @@ public class Chunks{ } public static void placeBlock(int x, int y, String name){ - Triple triple = new Triple<>(x, y,1); - Chunks.blocks.replace(triple, Chunks.blocks.get(triple), new Block(name)); + Triple triple = new Triple<>(x, y, 1); + if(Chunks.blocks.get(triple).getName().equals("air")) { + Chunks.blocks.replace(triple, Chunks.blocks.get(triple), materials.get(name)); + } + } + + public static void removeBlock(int x, int y){ + Triple triple = new Triple<>(x, y, 1); + if(!Chunks.blocks.get(triple).getName().equals("air")) { + Chunks.blocks.replace(triple, Chunks.blocks.get(triple), materials.get("air")); + } } public static HashMap, Block> blocks = new HashMap<>(); @@ -117,26 +127,26 @@ public class Chunks{ public Block getBiomeBlock(double moisture, double elevation) { String biome = getBiome(moisture,elevation); - 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("Tundra")) return materials.get("snow"); + if (biome.equals("Taiga")) return materials.get("snow"); + if (biome.equals("Snow")) return 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("Grassland")) return materials.get("grass"); + if (biome.equals("Shrubland")) return materials.get("grass"); + if (biome.equals("TemperateDeciduousForest")) return 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("TemperateRainForest")) return materials.get("grass"); + if (biome.equals("TropicalSeasonalForest")) return materials.get("grass"); + if (biome.equals("TropicalForest")) return materials.get("grass"); + if (biome.equals("TropicalRainForest")) return 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"); + if (biome.equals("Beach")) return materials.get("sand"); + if (biome.equals("Bare")) return materials.get("sand"); + if (biome.equals("Scorched")) return materials.get("sand"); + if (biome.equals("TemperateDesert")) return materials.get("sand"); + if (biome.equals("SubtropicalDesert")) return materials.get("sand"); - return BlockMaterials.materials.get("water"); + return materials.get("water"); } public String getBiome(double moisture,double elevation){ diff --git a/core/src/com/mygdx/game/Restrictions.java b/core/src/com/mygdx/game/Restrictions.java index 31e7c78..789ea15 100644 --- a/core/src/com/mygdx/game/Restrictions.java +++ b/core/src/com/mygdx/game/Restrictions.java @@ -6,8 +6,8 @@ public interface Restrictions { float VIEWPORT_HEIGHT = 9/2f; float VIEWPORT_WIDTH = 16/2f; - int MOVEMENT_SPEED = 2; - int KEY_DELAY = 0; + int MOVEMENT_SPEED = 16; + int KEY_DELAY = 1; int TILE_SIZE = 16; int CHUNK_SIZE = 8;