diff --git a/core/src/main/java/Collector/Character/InputController.java b/core/src/main/java/Collector/Character/InputController.java index 5e4853a..0d45753 100644 --- a/core/src/main/java/Collector/Character/InputController.java +++ b/core/src/main/java/Collector/Character/InputController.java @@ -20,7 +20,6 @@ public class InputController implements Restrictions { public InputController(Player player) { this.player = player; animations = new HashMap<>(); - /* animations.put("Up", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "Up"))); animations.put("UpRight", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "UpRight"))); animations.put("UpLeft", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "UpLeft"))); @@ -29,21 +28,16 @@ public class InputController implements Restrictions { animations.put("DownLeft", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "DownLeft"))); animations.put("Left", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "Left"))); animations.put("Right", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "Right"))); - - */ } public void handleInput() { i++; - if (Gdx.input.isKeyPressed(Input.Keys.Q)) { cam.zoom += 5; } if (Gdx.input.isKeyPressed(Input.Keys.E)) { cam.zoom -= 5; } - - if ((Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) || Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT) )&& i > KEY_DELAY) { Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); cam.unproject(mousePos); @@ -61,28 +55,28 @@ public class InputController implements Restrictions { if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("UpLeft")); + player.setAnimation(animations.get("UpLeft")); Player.addX(-MOVEMENT_SPEED); Player.addY(MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED, MOVEMENT_SPEED); } else if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("UpRight")); + player.setAnimation(animations.get("UpRight")); Player.addX(MOVEMENT_SPEED); Player.addY(MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED, MOVEMENT_SPEED); } else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("DownLeft")); + player.setAnimation(animations.get("DownLeft")); Player.addX(-MOVEMENT_SPEED); Player.addY(-MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED, -MOVEMENT_SPEED); } else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("DownRight")); + player.setAnimation(animations.get("DownRight")); Player.addX(MOVEMENT_SPEED); Player.addY(-MOVEMENT_SPEED); @@ -90,25 +84,25 @@ public class InputController implements Restrictions { } else if (Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("Left")); + player.setAnimation(animations.get("Left")); Player.addX(-MOVEMENT_SPEED); cam.translate(-MOVEMENT_SPEED, 0); } else if (Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("Right")); + player.setAnimation(animations.get("Right")); Player.addX(MOVEMENT_SPEED); cam.translate(MOVEMENT_SPEED, 0); } else if (Gdx.input.isKeyPressed(Input.Keys.S) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("Down")); + player.setAnimation(animations.get("Down")); Player.addY(-MOVEMENT_SPEED); cam.translate(0, -MOVEMENT_SPEED); } if (Gdx.input.isKeyPressed(Input.Keys.W) && i > KEY_DELAY) { i = 0; - //player.setAnimation(animations.get("Up")); + player.setAnimation(animations.get("Up")); Player.addY(MOVEMENT_SPEED); cam.translate(0, MOVEMENT_SPEED); } diff --git a/core/src/main/java/Collector/Character/Player.java b/core/src/main/java/Collector/Character/Player.java index a512045..dfffae2 100644 --- a/core/src/main/java/Collector/Character/Player.java +++ b/core/src/main/java/Collector/Character/Player.java @@ -1,6 +1,8 @@ package Collector.Character; +import Collector.Dimension.BlockMaterials; import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Sprite; @@ -13,21 +15,21 @@ public class Player implements Restrictions { public static int y; private final String spriteName; public TextureAtlas textureAtlas; - private Animation animation; + private static Animation animation; public static Sprite sprite; public Player(OrthographicCamera cam, int x, int y) { Player.x = x< keyFrames = textureAtlas.findRegions(spriteName + "_Down"); + textureAtlas = new TextureAtlas("man.atlas"); + Array keyFrames = textureAtlas.findRegions(spriteName + "_Down"); float frameDuration = 1 / 4f; - //animation = new Animation<>(frameDuration, keyFrames); + animation = new Animation<>(frameDuration, keyFrames); } public static int getX() { @@ -50,8 +52,7 @@ public class Player implements Restrictions { return spriteName; } - /* - public Animation getAnimation() { + public static Animation getAnimation() { return animation; } @@ -59,6 +60,4 @@ public class Player implements Restrictions { animation = animationTemp; } - */ - } diff --git a/core/src/main/java/Collector/Dimension/WorldRenderer.java b/core/src/main/java/Collector/Dimension/WorldRenderer.java index 8168349..bc2f81b 100644 --- a/core/src/main/java/Collector/Dimension/WorldRenderer.java +++ b/core/src/main/java/Collector/Dimension/WorldRenderer.java @@ -1,5 +1,8 @@ package Collector.Dimension; +import Collector.Character.Player; +import Collector.Main; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.github.czyzby.kiwi.util.tuple.immutable.Triple; @@ -7,7 +10,7 @@ import Collector.Character.InputController; import Collector.Character.Mouse; import Collector.Restrictions; -import static Collector.Main.cam; +import static Collector.Character.Player.getX; public class WorldRenderer implements Restrictions { private final Mouse mouse; @@ -30,12 +33,13 @@ public class WorldRenderer implements Restrictions { } } - public void render(SpriteBatch batch) { + public void render(SpriteBatch batch, float timeSinceLastUpdate) { inputController.handleInput(); drawWorld(batch,0); drawWorld(batch,1); - batch.setProjectionMatrix(cam.combined); - cam.update(); + batch.setProjectionMatrix(Main.cam.combined); + Main.cam.update(); + batch.draw(Player.getAnimation().getKeyFrame(timeSinceLastUpdate, true), Player.x, Player.y,TILE_SIZE,TILE_SIZE); mouse.render(batch); } } diff --git a/core/src/main/java/Collector/Main.java b/core/src/main/java/Collector/Main.java index b490198..79097fb 100644 --- a/core/src/main/java/Collector/Main.java +++ b/core/src/main/java/Collector/Main.java @@ -1,5 +1,6 @@ package Collector; +import Collector.Dimension.*; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL30; @@ -9,10 +10,6 @@ import com.badlogic.gdx.utils.viewport.FitViewport; import Collector.Character.InputController; import Collector.Character.Mouse; import Collector.Character.Player; -import Collector.Dimension.BlockMaterials; -import Collector.Dimension.Chunks; -import Collector.Dimension.World; -import Collector.Dimension.WorldRenderer; import Collector.UI.GUI; import static Collector.Restrictions.*; @@ -34,10 +31,10 @@ public class Main extends ApplicationAdapter { public void create () { Gdx.graphics.setWindowedMode(1024, 576); cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); - player = new Player(cam, 0, 0); fitViewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, cam); mouse = new Mouse(); gui = new GUI(fitViewport); + player = new Player(cam, 0, 0); inputController = new InputController(player); worldRenderer = new WorldRenderer(mouse, inputController); batch = new SpriteBatch(); @@ -45,8 +42,6 @@ public class Main extends ApplicationAdapter { BlockMaterials.create(); Chunks.create(); - - //Starting location of the player cam.translate(TILE_SIZE >> 1, TILE_SIZE >> 1); cam.zoom = 25f; } @@ -55,11 +50,10 @@ public class Main extends ApplicationAdapter { public void render () { Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); - timeSinceLastUpdate += Gdx.graphics.getDeltaTime(); //Accumulate delta time batch.begin(); if(timeSinceLastUpdate > 1/10f){ - worldRenderer.render(batch); + worldRenderer.render(batch,timeSinceLastUpdate); } delta += Gdx.graphics.getDeltaTime(); @@ -70,7 +64,6 @@ public class Main extends ApplicationAdapter { } gui.render(); - batch.draw(BlockMaterials.materials.get("wood").getTexture(), Player.x, Player.y,TILE_SIZE,TILE_SIZE); batch.end(); } diff --git a/lwjgl3/src/main/java/Collector/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/Collector/lwjgl3/Lwjgl3Launcher.java index a7c45a8..681d6d7 100644 --- a/lwjgl3/src/main/java/Collector/lwjgl3/Lwjgl3Launcher.java +++ b/lwjgl3/src/main/java/Collector/lwjgl3/Lwjgl3Launcher.java @@ -16,7 +16,7 @@ public class Lwjgl3Launcher { private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() { Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration(); - configuration.setTitle("Collevtor"); + configuration.setTitle("Collector"); configuration.setWindowedMode(640, 480); configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png"); return configuration;