summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9e390d2)
raw | patch | inline | side by side (parent: 9e390d2)
author | fredboy <fredboy@protonmail.com> | |
Sun, 21 Apr 2024 14:03:09 +0000 (21:03 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Sun, 21 Apr 2024 14:03:09 +0000 (21:03 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index e5b08381fbd10d0ad9285c4805dfe3a5bea00179..e1257d518fce877884bde4e669a5b089918e2037 100644 (file)
private float mTouchDownX;
private float mTouchDownY;
private long mTouchDownTime;
-
- private int mCurX;
- private int mCurY;
+
private int mCreativeScroll;
- private int mBlockDamage;
@Inject
public GameInput(MainConfig mainConfig,
} else {
switch (keycode) {
case Input.Keys.A:
- mCurX--;
+ mPlayer.cursorX--;
break;
case Input.Keys.D:
- mCurX++;
+ mPlayer.cursorX++;
break;
case Input.Keys.W:
- mCurY--;
+ mPlayer.cursorY--;
break;
case Input.Keys.S:
- mCurY++;
+ mPlayer.cursorY++;
break;
}
- mBlockDamage = 0;
+ mPlayer.blockDamage = 0;
}
}
}
private void checkCursorBounds() {
- if (mCurY < 0) {
- mCurY = 0;
- } else if (mCurY >= mGameWorld.getHeight()) {
- mCurY = mGameWorld.getHeight() - 1;
+ if (mPlayer.cursorY < 0) {
+ mPlayer.cursorY = 0;
+ } else if (mPlayer.cursorY >= mGameWorld.getHeight()) {
+ mPlayer.cursorY = mGameWorld.getHeight() - 1;
}
if (mControlMode == ControlMode.CURSOR) {
- if (mCurX * 16 + 8 < mPlayer.getX() + mPlayer.getWidth() / 2) {
+ if (mPlayer.cursorX * 16 + 8 < mPlayer.getX() + mPlayer.getWidth() / 2) {
mPlayer.setDir(Mob.Direction.LEFT);
} else {
mPlayer.setDir(Mob.Direction.RIGHT);
}
public void moveCursor(GameRenderer gameRenderer) {
- int pastX = mCurX;
- int pastY = mCurY;
+ int pastX = mPlayer.cursorX;
+ int pastY = mPlayer.cursorY;
if (mControlMode == ControlMode.WALK && mMainConfig.isTouch()) {
- mCurX = mPlayer.getMapX() + (mPlayer.looksLeft() ? -1 : 1);
- mCurY = mPlayer.getUpperMapY();
- for (int i = 0; i < 2 && isNotAutoselectable(mCurX, mCurY); i++) {
- mCurY++;
+ mPlayer.cursorX = mPlayer.getMapX() + (mPlayer.looksLeft() ? -1 : 1);
+ mPlayer.cursorY = mPlayer.getUpperMapY();
+ for (int i = 0; i < 2 && isNotAutoselectable(mPlayer.cursorX, mPlayer.cursorY); i++) {
+ mPlayer.cursorY++;
}
- if (isNotAutoselectable(mCurX, mCurY)) {
- mCurX += mPlayer.looksLeft() ? 1 : -1;
+ if (isNotAutoselectable(mPlayer.cursorX, mPlayer.cursorY)) {
+ mPlayer.cursorX += mPlayer.looksLeft() ? 1 : -1;
}
} else if (!mMainConfig.isTouch()) {
final int tmpX = (int) (Gdx.input.getX() * (mMainConfig.getWidth() /
Gdx.graphics.getWidth()) + gameRenderer.getCamX());
- mCurX = tmpX / 16;
+ mPlayer.cursorX = tmpX / 16;
final int tmpY = (int) (Gdx.input.getY() * (mMainConfig.getHeight() /
Gdx.graphics.getHeight()) + gameRenderer.getCamY());
- mCurY = tmpY / 16;
+ mPlayer.cursorY = tmpY / 16;
if (tmpX < 0) {
- mCurX--;
+ mPlayer.cursorX--;
}
final double a = tmpX - mPlayer.x;
mPlayer.headRotation = (float) Math.atan(b / a) * MathUtils.radDeg;
}
- if (pastX != mCurX || pastY != mCurY) {
- mBlockDamage = 0;
+ if (pastX != mPlayer.cursorX || pastY != mPlayer.cursorY) {
+ mPlayer.blockDamage = 0;
}
checkCursorBounds();
if (mMainConfig.checkGameUiWindow(GameUiWindow.NONE)) {
mPlayer.startHitting();
- if ((mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.getForeMap(mCurX, mCurY).getHp() >= 0) ||
- (!mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.hasBackAt(mCurX, mCurY) &&
- mGameWorld.getBackMap(mCurX, mCurY).getHp() >= 0)) {
+ if ((mGameWorld.hasForeAt(mPlayer.cursorX, mPlayer.cursorY) && mGameWorld.getForeMap(mPlayer.cursorX, mPlayer.cursorY).getHp() >= 0) ||
+ (!mGameWorld.hasForeAt(mPlayer.cursorX, mPlayer.cursorY) && mGameWorld.hasBackAt(mPlayer.cursorX, mPlayer.cursorY) &&
+ mGameWorld.getBackMap(mPlayer.cursorX, mPlayer.cursorY).getHp() >= 0)) {
if (mPlayer.gameMode == 0) {
- mBlockDamage++;
- if (mGameWorld.hasForeAt(mCurX, mCurY)) {
- if (mBlockDamage >= mGameWorld.getForeMap(mCurX, mCurY).getHp()) {
- mGameWorld.destroyForeMap(mCurX, mCurY);
- mBlockDamage = 0;
+ if (mGameWorld.hasForeAt(mPlayer.cursorX, mPlayer.cursorY)) {
+ if (mPlayer.blockDamage >= mGameWorld.getForeMap(mPlayer.cursorX, mPlayer.cursorY).getHp()) {
+ mGameWorld.destroyForeMap(mPlayer.cursorX, mPlayer.cursorY);
+ mPlayer.blockDamage = 0;
}
- } else if (mGameWorld.hasBackAt(mCurX, mCurY)) {
- if (mBlockDamage >= mGameWorld.getBackMap(mCurX, mCurY).getHp()) {
- mGameWorld.destroyBackMap(mCurX, mCurY);
- mBlockDamage = 0;
+ } else if (mGameWorld.hasBackAt(mPlayer.cursorX, mPlayer.cursorY)) {
+ if (mPlayer.blockDamage >= mGameWorld.getBackMap(mPlayer.cursorX, mPlayer.cursorY).getHp()) {
+ mGameWorld.destroyBackMap(mPlayer.cursorX, mPlayer.cursorY);
+ mPlayer.blockDamage = 0;
}
}
} else {
- if (mGameWorld.hasForeAt(mCurX, mCurY)) {
- mGameWorld.placeToForeground(mCurX, mCurY, mGameItemsHolder.getFallbackBlock());
- } else if (mGameWorld.hasBackAt(mCurX, mCurY)) {
- mGameWorld.placeToBackground(mCurX, mCurY, mGameItemsHolder.getFallbackBlock());
+ if (mGameWorld.hasForeAt(mPlayer.cursorX, mPlayer.cursorY)) {
+ mGameWorld.placeToForeground(mPlayer.cursorX, mPlayer.cursorY, mGameItemsHolder.getFallbackBlock());
+ } else if (mGameWorld.hasBackAt(mPlayer.cursorX, mPlayer.cursorY)) {
+ mGameWorld.placeToBackground(mPlayer.cursorX, mPlayer.cursorY, mGameItemsHolder.getFallbackBlock());
}
mTouchedDown = false;
}
private void holdMB() {
if (mTouchDownBtn == Input.Buttons.RIGHT) {
- useItem(mCurX, mCurY, mPlayer.inventory[mPlayer.slot].getItem(), true);
+ useItem(mPlayer.cursorX, mPlayer.cursorY, mPlayer.inventory[mPlayer.slot].getItem(), true);
mTouchedDown = false;
} else {
if (insideHotbar(mTouchDownX, mTouchDownY)) {
break;
case Input.Keys.G:
- final Mob pig = new Pig(mCurX * 16, mCurY * 16);
+ final Mob pig = new Pig(mPlayer.cursorX * 16, mPlayer.cursorY * 16);
pig.attachToController(mMobsController);
break;
screenX < mMainConfig.getWidth() / 2 + (float) hotbar.getRegionWidth() / 2) {
mPlayer.slot = (int) ((screenX - (mMainConfig.getWidth() / 2 - hotbar.getRegionWidth() / 2)) / 20);
} else if (button == Input.Buttons.RIGHT) {
- useItem(mCurX, mCurY,
+ useItem(mPlayer.cursorX, mPlayer.cursorY,
mPlayer.inventory[mPlayer.slot].getItem(), false);
} else if (button == Input.Buttons.LEFT) {
- mBlockDamage = 0;
+ mPlayer.stopHitting();
+ mPlayer.blockDamage = 0;
}
}
mTouchedDown = false;
return mKeyDown;
}
- public int getBlockDamage() {
- return mBlockDamage;
- }
-
- public int getCurX() {
- return mCurX;
- }
-
- public int getCurY() {
- return mCurY;
- }
-
public int getCreativeScroll() {
return mCreativeScroll;
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 9edffe4a9f3c41e128b1cfb30ee5e2561a6db5f1..a0c8c378ef3c35e6006e99dab47b192fb669d75c 100644 (file)
}
playerPhy(player, delta);
+ player.ai(mGameWorld, mGameItemsHolder, delta);
if (player.isDead()) {
player.respawn(mGameWorld, mGameItemsHolder);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/debug/DebugInfoStringsProvider.kt b/core/src/ru/deadsoftware/cavedroid/game/debug/DebugInfoStringsProvider.kt
index 678a91f7456cabacc8d63ebcf53096b8801c543e..3a0ef06610c8434ae377b4b5a07fd98ad0a24ebc 100644 (file)
package ru.deadsoftware.cavedroid.game.debug
import com.badlogic.gdx.Gdx
-import ru.deadsoftware.cavedroid.game.GameInput
import ru.deadsoftware.cavedroid.game.GameScope
import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.objects.DropController
@GameScope
class DebugInfoStringsProvider @Inject constructor(
private val mobsController: MobsController,
- private val gameInput: GameInput,
private val dropController: DropController,
private val gameWorld: GameWorld
) {
"FPS: ${Gdx.graphics.framesPerSecond}",
"X: ${player.mapX}",
"Y: ${player.upperMapY}",
- "CurX: ${gameInput.curX}",
- "CurY: ${gameInput.curY}",
+ "CurX: ${player.cursorX}",
+ "CurY: ${player.cursorY}",
"Velocity: ${player.velocity}",
"Swim: ${player.swim}",
"Mobs: ${mobsController.mobs.size}",
"Drops: ${dropController.size}",
- "Block: ${gameWorld.getForeMap(gameInput.curX, gameInput.curY).params.key}",
+ "Block: ${gameWorld.getForeMap(player.cursorX, player.cursorY).params.key}",
"Hand: ${player.inventory[player.slot].item.params.key}",
- "Game mode: ${player.gameMode}"
+ "Game mode: ${player.gameMode}",
+ "Block damage: ${player.blockDamage}"
)
}
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 9972617b5364156afb13e4b35736be8c56251868..216db6abbf0f3d6b435fe4ce5c0ef57f2af7b93b 100644 (file)
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavedroid.game.GameItemsHolder;
+import ru.deadsoftware.cavedroid.game.model.block.Block;
import ru.deadsoftware.cavedroid.game.model.item.InventoryItem;
import ru.deadsoftware.cavedroid.game.model.item.Item;
import ru.deadsoftware.cavedroid.game.objects.Drop;
public boolean swim;
public float headRotation = 0f;
+ public float blockDamage = 0f;
+ public int cursorX = 0;
+ public int cursorY = 0;
+
public Player(GameItemsHolder gameItemsHolder) {
super(0, 0, 4, 30, randomDir(), Type.MOB, MAX_HEALTH);
inventory = new InventoryItem[9];
@Override
public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
+ if (gameMode == 1) {
+ return;
+ }
+
+ final Block foregroundBlock = gameWorld.getForeMap(cursorX, cursorY);
+ final Block backgroundBlock = gameWorld.getBackMap(cursorX, cursorY);
+
+ final boolean canHitBlock = !foregroundBlock.isNone() && foregroundBlock.getParams().getHitPoints() >= 0
+ || !backgroundBlock.isNone() && backgroundBlock.getParams().getHitPoints() >= 0;
+
+ if (hitting && canHitBlock) {
+ blockDamage += 60f * delta;
+ } else {
+ blockDamage = 0f;
+ }
}
@Override
}
public void stopHitting() {
+ blockDamage = 0f;
hitting = false;
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/BackgroundBlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/BackgroundBlocksRenderer.kt
index 515ad796f62c8cfa866804f614d0b6d74f834aa9..aae4f9891e26212224ec020b8be8ce67f910faf8 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Rectangle
-import ru.deadsoftware.cavedroid.game.GameInput
import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.utils.forEachBlockInArea
import javax.inject.Inject
@GameScope
class BackgroundBlocksRenderer @Inject constructor(
gameWorld: GameWorld,
- gameInput: GameInput
-) : BlocksRenderer(gameWorld, gameInput) {
+ mobsController: MobsController
+) : BlocksRenderer(gameWorld, mobsController) {
override val renderLayer get() = RENDER_LAYER
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt
index 65d9e0ade81636d8855f1c509b51ae13a889f08f..ae243a374ea182a7dce46be95e041661ada6f76f 100644 (file)
import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Rectangle
import ru.deadsoftware.cavedroid.game.GameInput
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.model.block.Block
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.Assets
abstract class BlocksRenderer(
protected val gameWorld: GameWorld,
- protected val gameInput: GameInput,
+ protected val mobsController: MobsController,
) : IGameRenderer {
protected abstract val background: Boolean
}
protected fun drawBlockDamage(spriteBatch: SpriteBatch, viewport: Rectangle) {
- val blockDamage = gameInput.blockDamage
- if (blockDamage <= 0) {
- return
- }
+ val player = mobsController.player
+ val blockDamage = player.blockDamage.takeIf { it > 0f } ?: return
+ val cursorX = player.cursorX
+ val cursorY = player.cursorY
val block = if (background) {
- gameWorld.getBackMap(gameInput.curX, gameInput.curY)
+ gameWorld.getBackMap(cursorX, cursorY)
} else {
- gameWorld.getForeMap(gameInput.curX, gameInput.curY)
+ gameWorld.getForeMap(cursorX, cursorY)
}
val index = (MAX_BLOCK_DAMAGE_INDEX.toFloat() * (blockDamage.toFloat() / block.params.hitPoints.toFloat()))
.let(MathUtils::floor)
val texture = blockDamageTexture(index) ?: return
- if (gameWorld.hasForeAt(gameInput.curX, gameInput.curY) != background) {
- spriteBatch.draw(texture, gameInput.curX.px - viewport.x, gameInput.curY.px - viewport.y)
+ if (gameWorld.hasForeAt(cursorX, cursorY) != background) {
+ spriteBatch.draw(texture, cursorX.px - viewport.x, cursorY.px - viewport.y)
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/ForegroundBlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/ForegroundBlocksRenderer.kt
index 30736958f36f3f31ec1e8941a11fc4f11e85b25a..ef8be714220b88ce94b849893be3883cc9d14a31 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Rectangle
-import ru.deadsoftware.cavedroid.game.GameInput
import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.utils.forEachBlockInArea
import javax.inject.Inject
@GameScope
class ForegroundBlocksRenderer @Inject constructor(
gameWorld: GameWorld,
- gameInput: GameInput
-) : BlocksRenderer(gameWorld, gameInput) {
+ mobsController: MobsController
+) : BlocksRenderer(gameWorld, mobsController) {
override val renderLayer get() = RENDER_LAYER
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt
index 911df5a301749aefd61ed385d9f1f456037cf7f3..cea623a40d0194f6e87d13570ab9cfc75229278f 100644 (file)
private val halfHeartTexture get() = requireNotNull(Assets.textureRegions[HALF_HEART_KEY])
private fun drawCursor(spriteBatch: SpriteBatch, viewport: Rectangle) {
- if (gameWorld.hasForeAt(gameInput.curX, gameInput.curY) ||
- gameWorld.hasBackAt(gameInput.curX, gameInput.curY) ||
+ val cursorX = mobsController.player.cursorX
+ val cursorY = mobsController.player.cursorY
+
+ if (gameWorld.hasForeAt(cursorX, cursorY) ||
+ gameWorld.hasBackAt(cursorX, cursorY) ||
gameInput.controlMode == ControlMode.CURSOR
) {
- spriteBatch.draw(cursorTexture, gameInput.curX.px - viewport.x, gameInput.curY.px - viewport.y)
+ spriteBatch.draw(cursorTexture, cursorX.px - viewport.x, cursorY.px - viewport.y)
}
}