Changed the movement back to tile-by-tile movement, we'll figure out a way to toggle between the two modes later on.

This commit is contained in:
2020-04-10 10:18:19 -06:00
parent cb9d3a4107
commit 890f38b6b4
3 changed files with 58 additions and 40 deletions

View File

@@ -13,78 +13,86 @@ 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;
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)));
}

View File

@@ -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{
@@ -25,7 +26,16 @@ public class Chunks{
public static void placeBlock(int x, int y, String name){
Triple<Integer, Integer, Integer> triple = new Triple<>(x, y, 1);
Chunks.blocks.replace(triple, Chunks.blocks.get(triple), new Block(name));
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<Integer, Integer, Integer> 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<Triple<Integer, Integer,Integer>, 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){

View File

@@ -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;