summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ca4dfc9)
raw | patch | inline | side by side (parent: ca4dfc9)
author | fredboy <fredboy@protonmail.com> | |
Thu, 9 May 2024 11:45:59 +0000 (18:45 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Thu, 9 May 2024 11:45:59 +0000 (18:45 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index a2354f0c8f9ea68edd6d9b6242c1bda9f18a245f..eee83c747ab915f41570455f4add9854d70877db 100644 (file)
int blY = (int) (mob.getY() + mob.getHeight() - 8);
Block block = mGameWorld.getForeMap(blX / 16, blY / 16);
- if (checkColl(new Rectangle(blX, mob.getY() - 18, mob.getWidth(), mob.getHeight()))) {
+ if (checkColl(new Rectangle(blX, mob.getY() - 18, mob.getWidth(), mob.getHeight())) != null) {
return false;
}
(mob.getY() + mob.getHeight()) - block.getRectangle(blX / 16, blY / 16).y > 8);
}
- private boolean checkColl(Rectangle rect) {
+ /**
+ * @return colliding rect or null if no collision
+ */
+ @CheckForNull
+ private Rectangle checkColl(Rectangle rect) {
int minX = (int) ((rect.x + rect.width / 2) / 16) - 4;
int minY = (int) ((rect.y + rect.height / 2) / 16) - 4;
int maxX = (int) ((rect.x + rect.width / 2) / 16) + 4;
}
block = mGameWorld.getForeMap(x, y);
if (block.hasCollision()) {
- if (Intersector.overlaps(rect, block.getRectangle(x, y))) {
- return true;
+ final Rectangle blockRect = block.getRectangle(x, y);
+ if (Intersector.overlaps(rect, blockRect)) {
+ return blockRect;
}
}
}
}
- return false;
+ return null;
}
private Block getBlock(Rectangle rect) {
drop.x += dropVelocity.x * delta;
drop.y += dropVelocity.y * delta;
- if (checkColl(drop)) {
+ if (checkColl(drop) != null) {
dropVelocity.setZero();
do {
drop.y--;
- } while (checkColl(drop));
+ } while (checkColl(drop) != null);
}
if (playerMagnetTarget != null) {
}
private void mobXColl(Mob mob) {
- if (checkColl(mob)) {
- if (mob.canJump() && !mob.isFlyMode()) {
- mob.y -= 8;
+ if (mob.getVelocity().x == 0f) {
+ return;
+ }
+
+ @CheckForNull Rectangle collidingRect = checkColl(mob);
+
+ if (collidingRect != null) {
+ if (mob.canJump() && !mob.isFlyMode() && collidingRect.y >= mob.y + mob.height - 8) {
+ mob.y = collidingRect.y - mob.height;
+ return;
}
- if (checkColl(mob)) {
- if (mob.canJump() && !mob.isFlyMode()) {
- mob.y += 8;
- }
+ collidingRect = checkColl(mob);
+ if (collidingRect != null) {
int d = 0;
if (mob.getVelocity().x < 0) {
d = -1;
}
- mob.x = MathUtils.round(mob.getX());
-
- while (checkColl(mob)) {
- mob.x += d;
+ if (d < 0) {
+ mob.x = collidingRect.x - mob.width;
+ } else {
+ mob.x = collidingRect.x + collidingRect.width;
}
+// mob.x = MathUtils.round(mob.getX());
+// while (checkColl(mob) != null) {
+// mob.x += d;
+// }
+
if (mob.canJump()) {
mob.changeDir();
}
}
private void mobYColl(Mob mob) {
- if (checkColl(mob)) {
+ @CheckForNull final Rectangle collidingRect = checkColl(mob);
+ if (collidingRect != null) {
int d = -1;
if (mob.getVelocity().y < 0) {
}
}
- mob.y = MathUtils.round(mob.getY());
-
- while (checkColl(mob)) {
- mob.y += d;
+ if (d < 0) {
+ mob.y = collidingRect.y - mob.height;
+ } else {
+ mob.y = collidingRect.y + collidingRect.height;
}
+
+// mob.y = MathUtils.round(mob.getY());
+//
+// while (checkColl(mob)) {
+// mob.y += d;
+// }
+
mob.getVelocity().y = 0;
} else {
mob.y += 1;
- mob.setCanJump(checkColl(mob));
+ mob.setCanJump(checkColl(mob) != null);
mob.y -= 1;
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index 302b70586d3b55e0be012b3a380485d8b167848f..36f6c75aadbe64eb4de8115db837ba7de59a8d35 100644 (file)
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ObjectMap;
+import com.badlogic.gdx.utils.TimeUtils;
import ru.deadsoftware.cavedroid.MainConfig;
import ru.deadsoftware.cavedroid.game.input.IGameInputHandler;
import ru.deadsoftware.cavedroid.game.input.Joystick;
private final TouchButton mouseLeftTouchButton, mouseRightTouchButton;
+ private final Vector2 mCamCenterToPlayer = new Vector2();
+
+ private float mTouchDownX, mTouchDownY;
+ private long mCameraDelayMs = 0L;
+
@Inject
GameRenderer(MainConfig mainConfig,
MobsController mobsController,
Gdx.gl.glClearColor(0f, .6f, .6f, 1f);
}
- private float mTouchDownX, mTouchDownY;
-
private void updateDynamicCameraPosition(float delta) {
Player player = mMobsController.getPlayer();
float plTargetX = player.getX() + player.getWidth() / 2;
float plTargetY = player.getY() + player.getHeight() / 2;
+ float camCenterX = getCamX() + getWidth() / 2;
+ float camCenterY = getCamY() + getHeight() / 2;
+
float camTargetX, camTargetY;
if (player.controlMode == Player.ControlMode.WALK) {
camTargetY = MeasureUnitsUtilsKt.getPx(player.cursorY) + MeasureUnitsUtilsKt.getPx(1) / 2;
}
- float camCenterX = getCamX() + getWidth() / 2;
- float camCenterY = getCamY() + getHeight() / 2;
-
Vector2 moveVector = new Vector2(camTargetX - camCenterX, camTargetY - camCenterY);
+ if (player.controlMode == Player.ControlMode.WALK && player.getVelocity().isZero()) {
+ mCameraDelayMs = TimeUtils.millis();
+ mCamCenterToPlayer.x = plTargetX - camCenterX;
+ mCamCenterToPlayer.y = plTargetY - camCenterY;
+ }
+
+ if (TimeUtils.timeSinceMillis(mCameraDelayMs) < 500L && !player.getVelocity().isZero()) {
+ updateStaticCameraPosition(plTargetX - mCamCenterToPlayer.x,
+ camCenterY + moveVector.y * delta * 2);
+ return;
+ }
+
float camX = getCamX();
float camY = getCamY();
float worldWidth = MeasureUnitsUtilsKt.getPx(mGameWorld.getWidth()) - getWidth() / 2;
setCamPos(camX, camY);
}
+ private void updateStaticCameraPosition(float targetX, float targetY) {
+ setCamPos(targetX - getWidth() / 2, targetY - getHeight() / 2);
+ }
+
private void updateStaticCameraPosition() {
Player player = mMobsController.getPlayer();
- setCamPos(player.getX() + player.getWidth() / 2 - getWidth() / 2,
- player.getY() + player.getHeight() / 2 - getHeight() / 2);
+ updateStaticCameraPosition(player.getX() + player.getWidth() / 2,
+ player.getY() + player.getHeight() / 2);
}
private void updateCameraPosition(float delta) {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCraftingInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCraftingInventoryItemMouseInputHandler.kt
index b3fb22394abadc8f151cda3cfc03f5854d570ef7..1b4838a65e63c45ce3d0aa755ea951b1d036fad7 100644 (file)
window.craftResult = gameItemsHolder.craftItem(window.craftingItems
.map { it?.item ?: gameItemsHolder.fallbackItem })
}
- } else if (action.actionKey.touchUp) {
- window.selectedItem?.let { selectedItem ->
- dropController.addDrop(
- /* x = */ mobsController.player.x + (32f * mobsController.player.direction.basis),
- /* y = */ mobsController.player.y,
- /* item = */ selectedItem.item,
- /* count = */ selectedItem.amount,
- )
- window.selectedItem = null
- }
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt
index d5858ac0d70822b6f1aa2a317669273c75f4e203..91ec3111998f2f7400ffb3576ec4b48843a3d9b0 100644 (file)
window.craftResult = gameItemsHolder.craftItem(window.craftingItems
.map { it?.item ?: gameItemsHolder.fallbackItem })
}
- } else if (action.actionKey.touchUp) {
- window.selectedItem?.let { selectedItem ->
- dropController.addDrop(
- /* x = */ mobsController.player.x + (32f * mobsController.player.direction.basis),
- /* y = */ mobsController.player.y,
- /* item = */ selectedItem.item,
- /* count = */ selectedItem.amount,
- )
- window.selectedItem = null
- }
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/touch/JoystickInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/touch/JoystickInputHandler.kt
index d4fb451ee761a1033aafeb6f661fe918afb76bf9..1c020a5c189bd982493cd21b46f49c6687b62224 100644 (file)
set(value) {
if (!value) {
resetVelocity()
- if (TimeUtils.timeSinceMillis(activateTimeMs) < 100L &&
+ if (TimeUtils.timeSinceMillis(activateTimeMs) < 200L &&
mobsController.player.controlMode != Player.ControlMode.CURSOR) {
mobsController.player.jump()
}
private fun handleCursor() {
val joystick = mainConfig.joystick ?: return
- if (TimeUtils.timeSinceMillis(cursorTimeoutMs) < 200L) {
+ if (TimeUtils.timeSinceMillis(cursorTimeoutMs) < 150L) {
return
}
+ val pastCursorX = mobsController.player.cursorX
+ val pastCursorY = mobsController.player.cursorY
+
if (Math.abs(joystick.activeX - joystick.centerX) >= Joystick.RADIUS / 2) {
mobsController.player.cursorX += if (joystick.activeX > joystick.centerX) 1 else -1
cursorTimeoutMs = TimeUtils.millis()
}
mobsController.player.checkCursorBounds(gameWorld)
+
+ if (mobsController.player.cursorX != pastCursorX || mobsController.player.cursorY != pastCursorY) {
+ mobsController.player.blockDamage = 0f
+ }
}
private fun handleDragged() {
val joystick = mainConfig.joystick ?: return
val joyVector = joystick.getVelocityVector()
+ if (mobsController.player.isFlyMode) {
+ joyVector.scl(2f);
+ }
+
mobsController.player.velocity.x = joyVector.x
mobsController.player.setDir(
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt
index 36827c36bd997bdfea07808f98412d403a4e9f14..d99a90ec60e8762c5e6b0c16f4fdfeccb02b361c 100644 (file)
tooltipManager.showHotbarTooltip(activeItem.item.params.name)
}
- val activeItem get() = items[activeSlot]
+ val activeItem get() = _items[activeSlot]
fun initItems(gameItemsHolder: GameItemsHolder, tooltipManager: TooltipManager) {
this.tooltipManager = tooltipManager
fallbackItem = gameItemsHolder.fallbackItem.toInventoryItem()
- items.forEach { item ->
+ _items.forEach { item ->
item.init(gameItemsHolder)
}
}
private fun getItemPickSlot(item: Item): Int {
- for (i in items.indices) {
- val inventoryItem = items[i]
+ for (i in _items.indices) {
+ val inventoryItem = _items[i]
if (item == inventoryItem.item && inventoryItem.canBeAdded()) {
return i
}
+ }
+
+ for (i in _items.indices) {
+ val inventoryItem = _items[i]
if (inventoryItem.item.isNone()) {
return i
fun pickDrop(drop: Drop) {
val slot = getItemPickSlot(drop.item).takeIf { it >= 0 } ?: return
- val inventoryItem = items[slot]
+ val inventoryItem = _items[slot]
if (inventoryItem.item == drop.item) {
inventoryItem.add(drop.amount)
diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
index 8c31da7f22aaae2eb0b17678cb787f7ad1eb1fdf..686f1c946c81f55fb90ef5d4578538a6d85e3c2f 100644 (file)
private final Block[][] mForeMap;
private final Block[][] mBackMap;
- private final WorldGeneratorConfig mWorldConfig = WorldGeneratorConfig.Companion.getDefault();
+ private final WorldGeneratorConfig mWorldConfig = WorldGeneratorConfig.Companion.getDefault();
@Inject
public GameWorld(DropController dropController,
private Block getMap(int x, int y, int layer) {
Block map = mGameItemsHolder.getFallbackBlock();
- try {
- x = transformX(x);
- map = (layer == 0) ? mForeMap[x][y] : mBackMap[x][y];
- } catch (ArrayIndexOutOfBoundsException ignored) {
+
+ if (y < 0 || y >= getHeight()) {
+ return map;
+ }
+
+ x = transformX(x);
+
+ if (x < 0 || x >= getWidth()) {
+ return map;
}
+
+ map = (layer == 0) ? mForeMap[x][y] : mBackMap[x][y];
+
return map;
}
private void setMap(int x, int y, int layer, Block value) {
- try {
- x = transformX(x);
- if (layer == 0) {
- mForeMap[x][y] = value;
- } else {
- mBackMap[x][y] = value;
- }
- } catch (ArrayIndexOutOfBoundsException ignored) {
+ if (y < 0 || y >= getHeight()) {
+ return;
+ }
+
+ x = transformX(x);
+
+ if (x < 0 || x >= getWidth()) {
+ return;
+ }
+
+ if (layer == 0) {
+ mForeMap[x][y] = value;
+ } else {
+ mBackMap[x][y] = value;
}
}
private boolean shouldDrop(Block block) {
final Item item = mMobsController.getPlayer().inventory.getActiveItem().getItem();
- int toolLevel = item.isTool() ? ((Item.Tool)item).getLevel() : 0;
+ int toolLevel = item.isTool() ? ((Item.Tool) item).getLevel() : 0;
if (item.isTool() && block.getParams().getToolType() != item.getClass()) {
toolLevel = 0;
}