From c217099d21a0703347236f2d83e4d20c266f9be1 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Wed, 25 Apr 2018 17:37:48 +0700 Subject: [PATCH] Add inventory scrolling --- .../ru/deadsoftware/cavecraft/CaveGame.java | 2 +- .../cavecraft/game/GameInput.java | 39 +++++++++++++------ .../deadsoftware/cavecraft/game/GameProc.java | 7 +++- .../cavecraft/game/GameRenderer.java | 15 ++++--- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/CaveGame.java b/core/src/ru/deadsoftware/cavecraft/CaveGame.java index 88fb850..d95c477 100644 --- a/core/src/ru/deadsoftware/cavecraft/CaveGame.java +++ b/core/src/ru/deadsoftware/cavecraft/CaveGame.java @@ -34,7 +34,7 @@ public class CaveGame extends Game { default: Gdx.app.exit(); } - Gdx.app.log("CaveGame", "Folder: "+GAME_FOLDER); + Gdx.app.log("CaveGame", GAME_FOLDER); Gdx.files.absolute(GAME_FOLDER).mkdirs(); setScreen(new GameScreen()); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index c0fc292..e177f40 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -2,10 +2,10 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Input; import com.badlogic.gdx.utils.TimeUtils; +import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.misc.AppState; import ru.deadsoftware.cavecraft.misc.Assets; -import ru.deadsoftware.cavecraft.CaveGame; public class GameInput { @@ -112,7 +112,7 @@ public class GameInput { screenY= 0 && item < Items.BLOCKS.size) { for (int i = 8; i > 0; i--) { gameProc.player.inventory[i] = gameProc.player.inventory[i - 1]; @@ -121,13 +121,12 @@ public class GameInput { } } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) { CaveGame.STATE = AppState.GAME_PLAY; - } else { - gameProc.touchDownX = screenX; - gameProc.touchDownY = screenY; - gameProc.touchDownTime = TimeUtils.millis(); - gameProc.isTouchDown = true; - gameProc.touchDownButton = button; } + gameProc.touchDownX = screenX; + gameProc.touchDownY = screenY; + gameProc.touchDownTime = TimeUtils.millis(); + gameProc.isTouchDown = true; + gameProc.touchDownButton = button; } public void touchUp(int screenX, int screenY, int button) { @@ -156,12 +155,30 @@ public class GameInput { } public void touchDragged(int screenX, int screenY) { + if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY-gameProc.touchDownY)>16) { + gameProc.creativeScroll+=(screenY-gameProc.touchDownY)/16; + gameProc.touchDownX = screenX; + gameProc.touchDownY = screenY; + if (gameProc.creativeScroll<0) gameProc.creativeScroll=0; + if (gameProc.creativeScroll>gameProc.maxCreativeScroll) + gameProc.creativeScroll=gameProc.maxCreativeScroll; + } } public void scrolled(int amount) { - gameProc.invSlot += amount; - if (gameProc.invSlot < 0) gameProc.invSlot = 8; - if (gameProc.invSlot > 8) gameProc.invSlot = 0; + switch (CaveGame.STATE) { + case GAME_PLAY: + gameProc.invSlot += amount; + if (gameProc.invSlot < 0) gameProc.invSlot = 8; + if (gameProc.invSlot > 8) gameProc.invSlot = 0; + break; + case GAME_CREATIVE_INV: + gameProc.creativeScroll+=amount; + if (gameProc.creativeScroll<0) gameProc.creativeScroll=0; + if (gameProc.creativeScroll>gameProc.maxCreativeScroll) + gameProc.creativeScroll=gameProc.maxCreativeScroll; + break; + } } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index ce88856..8f5dca2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -3,7 +3,8 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.utils.TimeUtils; -import ru.deadsoftware.cavecraft.*; +import ru.deadsoftware.cavecraft.CaveGame; +import ru.deadsoftware.cavecraft.GameScreen; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -28,6 +29,7 @@ public class GameProc implements Serializable{ public int cursorX, cursorY; public int invSlot; public int ctrlMode; + public int creativeScroll, maxCreativeScroll; public boolean isTouchDown, isKeyDown; public int touchDownX, touchDownY, keyDownCode; @@ -43,14 +45,15 @@ public class GameProc implements Serializable{ mobs.add(new Pig(i*256, 196*16)); } physics = new GamePhysics(this); - if (!CaveGame.TOUCH) ctrlMode = 1; if (CaveGame.TOUCH) { renderer = new GameRenderer(this,320, 320*((float)GameScreen.getHeight()/GameScreen.getWidth())); } else { + ctrlMode = 1; renderer = new GameRenderer(this,480, 480*((float)GameScreen.getHeight()/GameScreen.getWidth())); } + maxCreativeScroll = Items.BLOCKS.size/40; GameSaver.save(this); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 7f693c4..3ffc0ae 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -3,11 +3,11 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.math.Vector2; -import ru.deadsoftware.cavecraft.misc.Assets; import ru.deadsoftware.cavecraft.CaveGame; -import ru.deadsoftware.cavecraft.misc.Renderer; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; +import ru.deadsoftware.cavecraft.misc.Assets; +import ru.deadsoftware.cavecraft.misc.Renderer; public class GameRenderer extends Renderer { @@ -115,10 +115,13 @@ public class GameRenderer extends Renderer { float x = camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2; float y = camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2; spriteBatch.draw(Assets.creativeInv, x, y); - spriteBatch.draw(Assets.creativeScroll, x+156, y+18); - for (int i=1; i0 && i0) -- 2.29.2