From b62c3a39c63a5a558352627026c6019ff6110071 Mon Sep 17 00:00:00 2001 From: fredboy Date: Fri, 19 Apr 2024 19:52:33 +0700 Subject: [PATCH] Add crippled survival --- android/assets/json/menu_new_game_buttons.json | 3 +-- core/src/ru/deadsoftware/cavedroid/CaveGame.java | 4 ++-- core/src/ru/deadsoftware/cavedroid/game/GameProc.java | 11 ++++++++++- .../ru/deadsoftware/cavedroid/game/GameRenderer.java | 7 +++++++ .../ru/deadsoftware/cavedroid/game/GameScreen.java | 4 +++- .../ru/deadsoftware/cavedroid/game/mobs/Player.java | 3 +-- core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java | 2 +- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/android/assets/json/menu_new_game_buttons.json b/android/assets/json/menu_new_game_buttons.json index c61adc3..ca4c404 100644 --- a/android/assets/json/menu_new_game_buttons.json +++ b/android/assets/json/menu_new_game_buttons.json @@ -3,8 +3,7 @@ "label": "Creative" }, "survival": { - "label": "Survival", - "type": 0 + "label": "Survival" }, "back": { "label": "Back" diff --git a/core/src/ru/deadsoftware/cavedroid/CaveGame.java b/core/src/ru/deadsoftware/cavedroid/CaveGame.java index 53d4310..4fa6b0e 100644 --- a/core/src/ru/deadsoftware/cavedroid/CaveGame.java +++ b/core/src/ru/deadsoftware/cavedroid/CaveGame.java @@ -54,9 +54,9 @@ public class CaveGame extends Game { mMainConfig.setAssetsPackPath(mAssetsPackPath); } - public void newGame() { + public void newGame(int gameMode) { GameScreen gameScreen = mMainComponent.getGameScreen(); - gameScreen.newGame(); + gameScreen.newGame(gameMode); setScreen(gameScreen); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java index d5a1a95..f063f7a 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java @@ -1,6 +1,7 @@ package ru.deadsoftware.cavedroid.game; import com.badlogic.gdx.utils.Disposable; +import ru.deadsoftware.cavedroid.game.mobs.MobsController; import ru.deadsoftware.cavedroid.game.world.GameWorld; import javax.inject.Inject; @@ -14,16 +15,24 @@ public class GameProc implements Disposable { private final GamePhysics mGamePhysics; private final GameInput mGameInput; private final GameRenderer mGameRenderer; + private final MobsController mMobsController; @Inject public GameProc(GameWorld gameWorld, GamePhysics gamePhysics, GameInput gameInput, - GameRenderer gameRenderer) { + GameRenderer gameRenderer, + MobsController mobsController + ) { mGameWorld = gameWorld; mGamePhysics = gamePhysics; mGameInput = gameInput; mGameRenderer = gameRenderer; + mMobsController = mobsController; + } + + public void setPlayerGameMode(int gameMode) { + mMobsController.getPlayer().gameMode = gameMode; } public void update(float delta) { diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java index b555f6b..09878f5 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java @@ -32,6 +32,8 @@ import static ru.deadsoftware.cavedroid.misc.Assets.*; @GameScope public class GameRenderer extends Renderer { + private static final String TAG = "GameRenderer"; + private final MainConfig mMainConfig; private final GameInput mGameInput; private final GameWorld mGameWorld; @@ -67,6 +69,11 @@ public class GameRenderer extends Renderer { if (mGameInput.getBlockDamage() > 0) { int index = 10 * mGameInput.getBlockDamage() / GameItems.getBlock(bl).getHp(); String key = "break_" + index; + + if (index > 10 || index < 0) { + return; + } + spriter.draw(textureRegions.get(key), mGameInput.getCurX() * 16 - getCamX(), mGameInput.getCurY() * 16 - getCamY()); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java b/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java index 4a7d613..e2c83bc 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java @@ -23,7 +23,7 @@ public class GameScreen implements Screen { mMainConfig = mainConfig; } - public void newGame() { + public void newGame(int gameMode) { if (mGameProc != null) { mGameProc.dispose(); } @@ -34,6 +34,8 @@ public class GameScreen implements Screen { mGameProc = gameComponent.getGameProc(); mGameInputProcessor = gameComponent.getGameInputProcessor(); + mGameProc.setPlayerGameMode(gameMode); + Gdx.input.setInputProcessor(gameComponent.getGameInputProcessor()); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java index ebdd9c0..34232f7 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java @@ -26,13 +26,12 @@ public class Player extends Mob { public final int[] inventory; public int slot; - public final int gameMode; + public int gameMode; public boolean swim; public float headRotation = 0f; public Player() { super(0, 0, 4, 30, randomDir(), Type.MOB, MAX_HEALTH); - this.gameMode = 1; inventory = new int[9]; swim = false; } diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java index 2b64520..6accb57 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java @@ -19,7 +19,7 @@ public class MenuProc extends Renderer { public class Input { private void startNewGame(int gameMode) { - mMainConfig.getCaveGame().newGame(); + mMainConfig.getCaveGame().newGame(gameMode); } public void newGameClicked() { -- 2.29.2