summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6bb7e1d)
raw | patch | inline | side by side (parent: 6bb7e1d)
author | fredboy <fredboy@protonmail.com> | |
Sun, 19 May 2024 14:21:30 +0000 (21:21 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Sun, 19 May 2024 14:21:30 +0000 (21:21 +0700) |
12 files changed:
index 245ebb04c8b169875bbab55d0ff5c7e9e4a44ee8..349daf3f752dfb4a5caeb70f9a8c2c6dbd6e1589 100644 (file)
"tint": "#EDBFB4",
"action_key": "use_spawn_egg_pig",
"origin_x": 0.5
+ },
+ "porkchop_raw": {
+ "name": "Raw Porkchop",
+ "type": "food",
+ "texture": "porkchop_raw",
+ "heal": 3,
+ "smelt_product": "porkchop_cooked"
+ },
+ "porkchop_cooked": {
+ "name": "Raw Porkchop",
+ "type": "food",
+ "texture": "porkchop_cooked",
+ "heal": 8
}
}
}
diff --git a/android/assets/pp/textures/items/porkchop_cooked.png b/android/assets/pp/textures/items/porkchop_cooked.png
new file mode 100644 (file)
index 0000000..dbd02c5
Binary files /dev/null and b/android/assets/pp/textures/items/porkchop_cooked.png differ
index 0000000..dbd02c5
Binary files /dev/null and b/android/assets/pp/textures/items/porkchop_cooked.png differ
diff --git a/android/assets/pp/textures/items/porkchop_raw.png b/android/assets/pp/textures/items/porkchop_raw.png
new file mode 100644 (file)
index 0000000..6c83dd0
Binary files /dev/null and b/android/assets/pp/textures/items/porkchop_raw.png differ
index 0000000..6c83dd0
Binary files /dev/null and b/android/assets/pp/textures/items/porkchop_raw.png differ
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index cb5b37e35a5d5a0c157c225cfac938e4154dbdfc..cece8e2c625ebe9e8823f9a5b347f063e5485e4b 100644 (file)
import ru.deadsoftware.cavedroid.game.mobs.MobsController;
import ru.deadsoftware.cavedroid.game.mobs.player.Player;
import ru.deadsoftware.cavedroid.game.model.block.Block;
+import ru.deadsoftware.cavedroid.game.model.item.InventoryItem;
import ru.deadsoftware.cavedroid.game.objects.drop.Drop;
import ru.deadsoftware.cavedroid.game.objects.drop.DropController;
import ru.deadsoftware.cavedroid.game.world.GameWorld;
mob.ai(mGameWorld, mGameItemsHolder, mMobsController, delta);
mobPhy(mob, delta);
if (mob.isDead()) {
+ for (InventoryItem invItem : mob.getDrop(mGameItemsHolder)) {
+ mDropController.addDrop(mob.x, mob.y, invItem);
+ }
+
it.remove();
}
}
playerPhy(player, delta);
player.ai(mGameWorld, mGameItemsHolder, mMobsController, delta);
if (player.isDead()) {
+ for (InventoryItem invItem : player.inventory.getItems()) {
+ mDropController.addDrop(player.x, player.y, invItem);
+ }
+ player.inventory.clear();
player.respawn(mGameWorld, mGameItemsHolder);
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/UseItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/UseItemMouseInputHandler.kt
index 541bba71243e63ababb76f794f5960e1b7a29b09..7405faf0c5eae97f812199b8ec46599506f822ef 100644 (file)
import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindMouseInputHandler
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.utils.Timer
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
import ru.deadsoftware.cavedroid.game.GameScope
import ru.deadsoftware.cavedroid.game.GameUiWindow
import ru.deadsoftware.cavedroid.game.actions.placeToBackgroundAction
private val useBlockActionMap: Map<String, @JvmSuppressWildcards IUseBlockAction>,
private val gameWindowsManager: GameWindowsManager,
private val gameWorld: GameWorld,
+ private val gameItemsHolder: GameItemsHolder,
) : IMouseInputHandler {
private var buttonHoldTask: Timer.Task? = null
} else if (item is Item.Usable) {
useItemActionMap[item.useActionKey]?.perform(item, player.cursorX, player.cursorY)
?: Gdx.app.error(TAG, "use item action ${item.useActionKey} not found");
+ } else if (item is Item.Food && player.health < player.maxHealth) {
+ player.heal(item.heal)
+ player.decreaseCurrentItemCount(gameItemsHolder)
} else {
tryUseBlock()
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 04fa1bbe91f8b88ca6879094dbf343f5dbbef068..e4ca679cb43c5a68430d521889459c1958e6c439 100644 (file)
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Timer;
import ru.deadsoftware.cavedroid.game.GameItemsHolder;
+import ru.deadsoftware.cavedroid.game.model.item.InventoryItem;
+import ru.deadsoftware.cavedroid.game.model.item.Item;
import ru.deadsoftware.cavedroid.game.world.GameWorld;
import javax.annotation.CheckForNull;
import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
/**
* Mob class.
/**
* Set's mob's dead variable to true and nothing else. It doesn't delete the
*/
- public final void kill() {
+ public void kill() {
mDead = true;
}
return mHealth;
}
+ public final int getMaxHealth() {
+ return mMaxHealth;
+ }
+
public final void attachToController(MobsController controller) {
controller.addMob(this);
}
return isTakingDamage() ? DAMAGE_TINT_COLOR : Color.WHITE;
}
+ public List<InventoryItem> getDrop(GameItemsHolder gameItemsHolder) {
+ return Collections.emptyList();
+ }
+
public abstract void draw(SpriteBatch spriteBatch, float x, float y, float delta);
public abstract void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, MobsController mobsController, float delta);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/PeacefulMob.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/PeacefulMob.kt
--- /dev/null
@@ -0,0 +1,20 @@
+package ru.deadsoftware.cavedroid.game.mobs
+
+import com.badlogic.gdx.math.MathUtils
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+
+abstract class PeacefulMob(x: Float, y: Float, width: Float, height: Float, direction: Direction, maxHealth: Int, )
+ : Mob(x, y, width, height, direction, Type.MOB, maxHealth) {
+
+ override fun ai(world: GameWorld, gameItemsHolder: GameItemsHolder, mobsController: MobsController, delta: Float) {
+ if (MathUtils.randomBoolean(delta)) {
+ if (velocity.x != 0f) {
+ velocity.x = 0f
+ } else {
+ changeDir()
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.kt
index 68c457ee05887ee81521ac93bffe0740e8e84688..b3d647d328aae2fd0a65f89f66b92ff3c5b0e832 100644 (file)
package ru.deadsoftware.cavedroid.game.mobs
import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2
import ru.deadsoftware.cavedroid.game.GameItemsHolder
-import ru.deadsoftware.cavedroid.game.world.GameWorld
+import ru.deadsoftware.cavedroid.game.model.item.InventoryItem
import ru.deadsoftware.cavedroid.misc.utils.drawSprite
import ru.deadsoftware.cavedroid.misc.utils.mobs.MobSprites.Pig.getBackgroundLeg
import ru.deadsoftware.cavedroid.misc.utils.mobs.MobSprites.Pig.getBody
import ru.deadsoftware.cavedroid.misc.utils.mobs.MobSprites.Pig.getLegsRelativeY
import ru.deadsoftware.cavedroid.misc.utils.mobs.MobSprites.Pig.getRightLegRelativeX
-class Pig(x: Float, y: Float) : Mob(x, y, WIDTH, HEIGHT, randomDir(), Type.MOB, MAX_HEALTH) {
+class Pig(x: Float, y: Float) : PeacefulMob(x, y, WIDTH, HEIGHT, randomDir(), MAX_HEALTH) {
override fun getSpeed(): Float {
return SPEED
}
}
- override fun ai(world: GameWorld, gameItemsHolder: GameItemsHolder, mobsController: MobsController, delta: Float) {
- if (MathUtils.randomBoolean(delta)) {
- if (velocity.x != 0f) {
- velocity.x = 0f
- } else {
- changeDir()
- }
- }
+ override fun getDrop(gameItemsHolder: GameItemsHolder): List<InventoryItem> {
+ return listOf(gameItemsHolder.getItem("porkchop_raw").toInventoryItem())
}
override fun draw(spriteBatch: SpriteBatch, x: Float, y: Float, delta: Float) {
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 3012d6675a3346bed978a5183b342120d31ab0b9..43f298c876e9702fb5e675e5b429602b22fbf13d 100644 (file)
fun decreaseCurrentItemAmount(count: Int = 1) {
decreaseItemAmount(activeSlot, count)
}
+
+ fun clear() {
+ for (i in _items.indices) {
+ _items[i] = fallbackItem
+ }
+ }
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt b/core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt
index 373db466baf14f54fb86b352be00acbb8353f3e6..a276b7100decd2174e87cd88bb0f9231f7030b9e 100644 (file)
@SerialName("tint") val tint: String? = null,
@SerialName("burning_time") val burningTime: Long? = null,
@SerialName("smelt_product") val smeltProduct: String? = null,
+ @SerialName("heal") val heal: Int? = null,
)
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt
index bf2a55cd6a9d164870c6d4ebb8339310a0bece86..9b2c62de4794111b4edab8bb332af7a0a99f5809 100644 (file)
return this is Usable
}
+ fun isFood(): Boolean {
+ contract { returns(true) implies (this@Item is Food) }
+ return this is Food
+ }
+
@JvmOverloads
fun toInventoryItem(amount: Int = 1): InventoryItem {
return InventoryItem(this, amount)
override val level: Int,
) : Tool()
+ data class Food(
+ override val params: CommonItemParams,
+ override val sprite: Sprite,
+ val heal: Int,
+ ) : Item()
+
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt
index a0949a05d2c082c427cb6ccec26524c6a87a047c..a1a6f0c68d0cb2357eebc5262fa2acb9c1b6f777 100644 (file)
"shears" -> Shears(params, requireNotNull(loadSprite(dto)), dto.mobDamageMultiplier, dto.blockDamageMultiplier, requireNotNull(dto.toolLevel))
"block" -> Block(params, requireNotNull(block))
"slab" -> Slab(params, requireNotNull(slabTopBlock), requireNotNull(slabBottomBlock))
+ "food" -> Food(params, requireNotNull(loadSprite(dto)), requireNotNull(dto.heal))
"none" -> None(params)
else -> throw IllegalArgumentException("Unknown item type ${dto.type}")
}