From c66f5cbb5486db833cb54ea2f1676d0bbdb51201 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 14 Feb 2024 03:54:14 +0900 Subject: [PATCH] throwable cherry bomb (no explosion yet) --- assets/mods/basegame/crafting/items.json | 10 +++ assets/mods/basegame/items/itemid.csv | 2 + assets/mods/basegame/items/items.tga | 2 +- assets/mods/basegame/locales/en/items.json | 1 + assets/mods/basegame/locales/koKR/items.json | 1 + .../spriteanimation/SingleImageSprite.kt | 76 +++++++++++++++++++ src/net/torvald/terrarum/Terrarum.kt | 12 ++- src/net/torvald/terrarum/gameactors/Actor.kt | 5 +- .../gameactors/ActorMovingPlatform.kt | 2 +- .../terrarum/gameactors/ActorWithBody.kt | 4 +- .../terrarum/gameactors/BlockMarkerActor.kt | 2 +- .../terrarum/gameactors/PhysProperties.kt | 40 +++++----- .../torvald/terrarum/gameactors/WireActor.kt | 2 +- .../gamecontroller/IngameController.kt | 7 +- .../torvald/terrarum/gameitems/GameItem.kt | 2 + .../terrarum/modulebasegame/BuildingMaker.kt | 6 +- .../terrarum/modulebasegame/TerrarumIngame.kt | 2 +- .../terrarum/modulebasegame/TitleScreen.kt | 2 +- .../gameactors/ActorHumanoid.kt | 6 +- .../gameactors/ActorPrimedBomb.kt | 46 +++++++---- .../gameactors/CreatureBuilder.kt | 2 +- .../modulebasegame/gameactors/DroppedItem.kt | 4 +- .../modulebasegame/gameactors/FixtureBase.kt | 6 +- .../modulebasegame/gameactors/ItemCarrying.kt | 2 +- .../modulebasegame/gameactors/PhysTestBall.kt | 2 +- .../gameactors/PhysTestLuarLander.kt | 2 +- .../gameactors/ProjectileSimple.kt | 2 +- .../modulebasegame/gameitems/ItemMisc.kt | 50 ++++++++++++ .../modulebasegame/gameitems/ItemThrowable.kt | 65 ++++++++++++++++ .../modulebasegame/gameitems/OreItemBase.kt | 15 ---- work_files/graphics/items/basegame_items.kra | 4 +- 31 files changed, 306 insertions(+), 78 deletions(-) create mode 100644 assets/mods/basegame/crafting/items.json create mode 100644 src/net/torvald/spriteanimation/SingleImageSprite.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt diff --git a/assets/mods/basegame/crafting/items.json b/assets/mods/basegame/crafting/items.json new file mode 100644 index 000000000..360547ddc --- /dev/null +++ b/assets/mods/basegame/crafting/items.json @@ -0,0 +1,10 @@ +{ + "item@basegame:31": { /* gunpowder */ + "workbench": "basiccrafting", + "ingredients": [[3, 1, "item@basegame:147", 1, "item@basegame:29", 1, "item@basegame:129"]] /* 1 nitre, 1 charcoal, 1 iron ore */ + }, + "item@basegame:32": { /* cherry bomb */ + "workbench": "", + "ingredients": [[1, 1, "item@basegame:31", 1, "item@basegame:25"]] /* 1 gunpowder, 1 clay ball */ + } +} \ No newline at end of file diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 954adc91f..ad4f61ae1 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -29,6 +29,8 @@ id;classname;tags 28;net.torvald.terrarum.modulebasegame.gameitems.ItemJukebox;FIXTURE,MUSIC 29;net.torvald.terrarum.modulebasegame.gameitems.ItemCharcoal;COMBUSTIBLE 30;net.torvald.terrarum.modulebasegame.gameitems.ItemMusicalTurntable;FIXTURE,MUSIC +31;net.torvald.terrarum.modulebasegame.gameitems.ItemGunpowder;POWDER,EXPLOSIVE +32;net.torvald.terrarum.modulebasegame.gameitems.ItemCherryBomb;EXPLOSIVE,THROWABLE # ingots 26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT diff --git a/assets/mods/basegame/items/items.tga b/assets/mods/basegame/items/items.tga index 6803212d4..3ce5d3a51 100644 --- a/assets/mods/basegame/items/items.tga +++ b/assets/mods/basegame/items/items.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2a30fb3bba561a397f32eac7530ccbc718592fefdb3267a9b6b700f2e4aed9b6 +oid sha256:f1135ff2beb22d57e9453a1fc058071b54d62d7d79dd3bbfef61c98d4fdc7eab size 2408466 diff --git a/assets/mods/basegame/locales/en/items.json b/assets/mods/basegame/locales/en/items.json index f14b39ee0..c71496684 100644 --- a/assets/mods/basegame/locales/en/items.json +++ b/assets/mods/basegame/locales/en/items.json @@ -14,6 +14,7 @@ "ITEM_GEM_DIAMOND": "Raw Diamond", "ITEM_GEM_AMETHYST": "Raw Amethyst", "ITEM_GEM_QUARTZ": "Raw Quartz", + "ITEM_GUNPOWDER": "Gunpowder", "ITEM_HATCHET_COPPER": "Copper Axe", "ITEM_HATCHET_IRON": "Iron Axe", "ITEM_HATCHET_STEEL": "Steel Axe", diff --git a/assets/mods/basegame/locales/koKR/items.json b/assets/mods/basegame/locales/koKR/items.json index 11a245eab..4119b8e33 100644 --- a/assets/mods/basegame/locales/koKR/items.json +++ b/assets/mods/basegame/locales/koKR/items.json @@ -14,6 +14,7 @@ "ITEM_GEM_DIAMOND": "금강석", "ITEM_GEM_AMETHYST": "자수정석", "ITEM_GEM_QUARTZ": "석영석", + "ITEM_GUNPOWDER": "화약", "ITEM_HATCHET_COPPER": "구리 도끼", "ITEM_HATCHET_IRON": "철 도끼", "ITEM_HATCHET_STEEL": "강철 도끼", diff --git a/src/net/torvald/spriteanimation/SingleImageSprite.kt b/src/net/torvald/spriteanimation/SingleImageSprite.kt new file mode 100644 index 000000000..7be03d90b --- /dev/null +++ b/src/net/torvald/spriteanimation/SingleImageSprite.kt @@ -0,0 +1,76 @@ +package net.torvald.spriteanimation + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.jme3.math.FastMath +import net.torvald.terrarum.Second +import net.torvald.terrarum.gameactors.ActorWithBody + +/** + * Created by minjaesong on 2024-02-14. + */ +class SingleImageSprite(parentActor: ActorWithBody, val img: TextureRegion) : SpriteAnimation(parentActor) { + + override val currentDelay: Second = 1f + + override fun update(delta: Float) { + } + + var cellWidth: Int = img.regionWidth + var cellHeight: Int = img.regionHeight + + override fun render( + frameDelta: Float, + batch: SpriteBatch, + posX: Float, + posY: Float, + scale: Float, + mode: Int, + forcedColourFilter: Color? + ) { + batch.color = forcedColourFilter ?: colourFilter + + val tx = (parentActor.hitboxTranslateX) * scale + val txF = (parentActor.hitboxTranslateX + parentActor.baseHitboxW) * scale + val ty = (parentActor.hitboxTranslateY + (cellHeight - parentActor.baseHitboxH)) * scale + val tyF = (parentActor.hitboxTranslateY + parentActor.baseHitboxH) * scale + + if (flipHorizontal && flipVertical) { + batch.draw(img, + FastMath.floor(posX).toFloat() + txF, + FastMath.floor(posY).toFloat() + tyF, + -FastMath.floor(cellWidth * scale).toFloat(), + -FastMath.floor(cellHeight * scale).toFloat() + ) + } + else if (flipHorizontal && !flipVertical) { + batch.draw(img, + FastMath.floor(posX).toFloat() + txF, + FastMath.floor(posY).toFloat() - ty, + -FastMath.floor(cellWidth * scale).toFloat(), + FastMath.floor(cellHeight * scale).toFloat() + ) + } + else if (!flipHorizontal && flipVertical) { + batch.draw(img, + FastMath.floor(posX).toFloat() - tx, + FastMath.floor(posY).toFloat() + tyF, + FastMath.floor(cellWidth * scale).toFloat(), + -FastMath.floor(cellHeight * scale).toFloat() + ) + } + else { + batch.draw(img, + FastMath.floor(posX).toFloat() - tx, + FastMath.floor(posY).toFloat() - ty, + FastMath.floor(cellWidth * scale).toFloat(), + FastMath.floor(cellHeight * scale).toFloat() + ) + } + } + + override fun dispose() { + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index cf7058ca9..c561113f3 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -355,7 +355,7 @@ object Terrarum : Disposable { * * override var referenceID: Int = generateUniqueReferenceID() */ - fun generateUniqueReferenceID(renderOrder: Actor.RenderOrder): ActorID { + fun generateUniqueReferenceID(): ActorID { // render orders can be changed arbitrarily so the whole "renderorder to actor id" is only there for an initial sorting fun hasCollision(value: ActorID) = try { @@ -644,6 +644,7 @@ inline fun Boolean.toInt(shift: Int = 0) = if (this) 1.shl(shift) else 0 inline fun Boolean.toLong(shift: Int = 0) = if (this) 1L.shl(shift) else 0L inline fun Int.bitCount() = java.lang.Integer.bitCount(this) inline fun Long.bitCount() = java.lang.Long.bitCount(this) +inline fun Double.signedSqrt() = this.abs().sqrt() * this.sign fun absMax(left: Double, right: Double): Double { @@ -1011,9 +1012,15 @@ fun distBetweenPoints(a: Vector2, b: Vector2): Double { * @return positive if the otherActor is on the right side of the player, negative if on the left */ fun relativeXposition(thisActor: ActorWithBody, otherActor: ActorWithBody): Double { + return relativeXposition(thisActor, otherActor.centrePosVector) +} +/** + * @return positive if the otherActor is on the right side of the player, negative if on the left + */ +fun relativeXposition(thisActor: ActorWithBody, otherActor: Vector2): Double { val ww = INGAME.world.width * TILE_SIZED val thisPos = thisActor.centrePosVector - val pos1 = otherActor.centrePosVector + val pos1 = otherActor val pos2 = Vector2(pos1.x + ww, pos1.y) val pos3 = Vector2(pos1.x - ww, pos1.y) val posToUse = listOf( @@ -1023,6 +1030,7 @@ fun relativeXposition(thisActor: ActorWithBody, otherActor: ActorWithBody): Doub ).sortedBy { it.second }.first().first return posToUse.x - thisPos.x } + fun distBetween(a: ActorWithBody, bpos: Vector2): Double { val ww = INGAME.world.width * TILE_SIZED val apos1 = a.centrePosVector diff --git a/src/net/torvald/terrarum/gameactors/Actor.kt b/src/net/torvald/terrarum/gameactors/Actor.kt index ecaa35be6..2a40cb982 100644 --- a/src/net/torvald/terrarum/gameactors/Actor.kt +++ b/src/net/torvald/terrarum/gameactors/Actor.kt @@ -27,7 +27,7 @@ abstract class Actor : Comparable, Runnable { * Valid RefID is equal to or greater than 16777216. * @return Reference ID. (16777216-0x7FFF_FFFF) */ - open var referenceID: ActorID = 0 // in old time this was nullable without initialiser. If you're going to revert to that, add the reason why this should be nullable. + open var referenceID: ActorID = Terrarum.generateUniqueReferenceID() // in old time this was nullable without initialiser. If you're going to revert to that, add the reason why this should be nullable. /** * RenderOrder does not affect ReferenceID "too much" (ID generation will still depend on it, but it's just because of ye olde tradition by now) @@ -40,7 +40,8 @@ abstract class Actor : Comparable, Runnable { // needs zero-arg constructor for serialiser to work constructor(renderOrder: RenderOrder, id: ActorID?) : this() { - referenceID = id ?: Terrarum.generateUniqueReferenceID(renderOrder) + if (id != null) referenceID = id + this.renderOrder = renderOrder } diff --git a/src/net/torvald/terrarum/gameactors/ActorMovingPlatform.kt b/src/net/torvald/terrarum/gameactors/ActorMovingPlatform.kt index 3edfcd985..b72209e23 100644 --- a/src/net/torvald/terrarum/gameactors/ActorMovingPlatform.kt +++ b/src/net/torvald/terrarum/gameactors/ActorMovingPlatform.kt @@ -14,7 +14,7 @@ open class ActorMovingPlatform() : ActorWithBody() { @Transient protected val actorsRiding = ArrayList() // saving actorID due to serialisation issues init { - physProp = PhysProperties.PHYSICS_OBJECT + physProp = PhysProperties.PHYSICS_OBJECT() setHitboxDimension(TILE_SIZE * tilewiseWidth, TILE_SIZE, 0, 0) } diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 815962120..05a50c696 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -44,7 +44,7 @@ import kotlin.math.* */ open class ActorWithBody : Actor { - var physProp = PhysProperties.HUMANOID_DEFAULT + var physProp = PhysProperties.HUMANOID_DEFAULT() // copied from old interface Luminous /** @@ -1460,7 +1460,7 @@ open class ActorWithBody : Actor { externalV.y + (controllerV?.y ?: 0.0) >= 0.0 && this.downButtonHeld == 0 && this.axisY <= 0f) || // platforms, moving downward, for the case of NOT ActorHumanoid - (this !is ActorHumanoid && BlockCodex[tile].isPlatform && + (this !is ActorHumanoid && !physProp.ignorePlatform && BlockCodex[tile].isPlatform && externalV.y + (controllerV?.y ?: 0.0) >= 0.0) // TODO: as for the platform, only apply it when it's a feet tile diff --git a/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt b/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt index 80e9a5327..e3ee23991 100644 --- a/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt +++ b/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt @@ -22,7 +22,7 @@ import kotlin.math.floor * * MarkerMode must be set manually after calling `setGhost` -- the `unsetGhost` will not reset the field. */ -class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT), NoSerialise { +class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT()), NoSerialise { enum class MarkerMode { FIXTURE_GHOST, BLOCK_MARKER diff --git a/src/net/torvald/terrarum/gameactors/PhysProperties.kt b/src/net/torvald/terrarum/gameactors/PhysProperties.kt index 2075ce040..474a4f8c7 100644 --- a/src/net/torvald/terrarum/gameactors/PhysProperties.kt +++ b/src/net/torvald/terrarum/gameactors/PhysProperties.kt @@ -1,33 +1,35 @@ package net.torvald.terrarum.gameactors data class PhysProperties( - val immobileBody: Boolean = false, - var usePhysics: Boolean = true, - val useStairs: Boolean = false + val immobileBody: Boolean = false, + var usePhysics: Boolean = true, + val useStairs: Boolean = false, + val ignorePlatform: Boolean = true ) { companion object { - val HUMANOID_DEFAULT = PhysProperties( - immobileBody = false, - usePhysics = true, - useStairs = true + fun HUMANOID_DEFAULT() = PhysProperties( + immobileBody = false, + usePhysics = true, + useStairs = true, + ignorePlatform = false, ) /** e.g. dropped items, balls */ - val PHYSICS_OBJECT = PhysProperties( - immobileBody = false, - usePhysics = true, - useStairs = false + fun PHYSICS_OBJECT() = PhysProperties( + immobileBody = false, + usePhysics = true, + useStairs = false, ) /** e.g. voice maker */ - val IMMOBILE = PhysProperties( - immobileBody = true, - usePhysics = false, - useStairs = false + fun IMMOBILE() = PhysProperties( + immobileBody = true, + usePhysics = false, + useStairs = false, ) /** e.g. camera */ - val MOBILE_OBJECT = PhysProperties( - immobileBody = false, - usePhysics = false, - useStairs = false + fun MOBILE_OBJECT() = PhysProperties( + immobileBody = false, + usePhysics = false, + useStairs = false, ) } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/WireActor.kt b/src/net/torvald/terrarum/gameactors/WireActor.kt index 884b58ca0..52ef5f131 100644 --- a/src/net/torvald/terrarum/gameactors/WireActor.kt +++ b/src/net/torvald/terrarum/gameactors/WireActor.kt @@ -24,7 +24,7 @@ class WireActor : ActorWithBody, NoSerialise { private constructor() - constructor(id: ActorID) : super(RenderOrder.OVERLAY, PhysProperties.IMMOBILE, id) + constructor(id: ActorID) : super(RenderOrder.OVERLAY, PhysProperties.IMMOBILE(), id) init { setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0) diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index 468e42f5f..2fd23895d 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -149,12 +149,17 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() { terrarumIngame.worldSecondaryClickStart(actor, App.UPDATE_RATE) } + val itemProp = ItemCodex[itemOnGrip] + // unlatch when: // - not clicking anymore // - using any item that is not fixture (blocks, picks) // DON'T unlatch when: // - performing barehand action - if (!Terrarum.mouseDown || inventoryCategoryAllowClickAndDrag.contains(ItemCodex[itemOnGrip]?.inventoryCategory) || ItemCodex[itemOnGrip]?.tags?.contains("ACTINGBLOCK") == true) { + if (!Terrarum.mouseDown || + inventoryCategoryAllowClickAndDrag.contains(itemProp?.inventoryCategory) && itemProp?.disallowToolDragging != true || + itemProp?.tags?.contains("ACTINGBLOCK") == true + ) { worldPrimaryClickLatched = false } diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index d5ab69ac6..c69bb183e 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -217,6 +217,8 @@ abstract class GameItem(val originalID: ItemID) : Comparable, Cloneabl */ open val extra = Codex() + @Transient open val disallowToolDragging = false + /* called when the instance of the dynamic is loaded from the save; one may use this function to "re-sync" some values, * for the purpose of savegame format update, defence against rogue savegame manipulation, etc. */ diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index 2af156e04..c74d9fb73 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -104,7 +104,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { val blockMarkings = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common") internal var showSelection = true - val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT) { + val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT()) { override var referenceID: ActorID = 1048575 // custom refID override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0) @@ -145,7 +145,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { private var _testMarkerDrawCalls = 0L - private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT) { + private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT()) { override var referenceID: ActorID = blockPosToRefID(x, y) // custom refID override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0) @@ -661,7 +661,7 @@ class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() { } } -class MovableWorldCamera(val parent: BuildingMaker) : ActorHumanoid(0, physProp = PhysProperties.MOBILE_OBJECT) { +class MovableWorldCamera(val parent: BuildingMaker) : ActorHumanoid(0, physProp = PhysProperties.MOBILE_OBJECT()) { init { referenceID = Terrarum.PLAYER_REF_ID diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index e87d1a704..c0245574e 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -403,7 +403,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { printdbg(this, "Player localhash: ${codices.player.localHashStr}, hasSprite: ${codices.player.sprite != null}") // assign new random referenceID for player - codices.player.referenceID = Terrarum.generateUniqueReferenceID(Actor.RenderOrder.MIDDLE) + codices.player.referenceID = Terrarum.generateUniqueReferenceID() forceAddActor(codices.player) diff --git a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt index d3c6aafd7..ca2afaf0b 100644 --- a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt +++ b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt @@ -591,7 +591,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) { } } - private class CameraPlayer(val demoWorld: GameWorld, override var ai: ActorAI) : ActorWithBody(RenderOrder.FRONT, physProp = PhysProperties.MOBILE_OBJECT), AIControlled { + private class CameraPlayer(val demoWorld: GameWorld, override var ai: ActorAI) : ActorWithBody(RenderOrder.FRONT, physProp = PhysProperties.MOBILE_OBJECT()), AIControlled { override val hitbox = Hitbox(0.0, 0.0, 2.0, 2.0) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt index c0b8c1a2d..6eb591ea5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt @@ -29,9 +29,13 @@ import kotlin.math.pow */ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, LandHolder, HistoricalFigure { + init { + this.physProp = PhysProperties.HUMANOID_DEFAULT() + } + protected constructor() - constructor(birth: Long, death: Long? = null, physProp: PhysProperties = PhysProperties.HUMANOID_DEFAULT) : super() { + constructor(birth: Long, death: Long? = null, physProp: PhysProperties = PhysProperties.HUMANOID_DEFAULT()) : super() { actorValue[AVKey.__HISTORICAL_BORNTIME] = birth death?.let { actorValue[AVKey.__HISTORICAL_DEADTIME] = death } this.physProp = physProp diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt index 2368359c0..0b1fad2b8 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorPrimedBomb.kt @@ -1,33 +1,29 @@ package net.torvald.terrarum.modulebasegame.gameactors +import net.torvald.spriteanimation.SingleImageSprite +import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.INGAME import net.torvald.terrarum.Second import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.gameactors.PhysProperties import net.torvald.terrarum.modulebasegame.ExplosionManager -import org.dyn4j.geometry.Vector2 /** * Created by minjaesong on 2024-02-13. */ -open class ActorPrimedBomb : ActorWithBody { +open class ActorPrimedBomb( + private var explosionPower: Float = 1f, + private var fuse: Second = 1f, +) : ActorWithBody() { - protected constructor() { + init { renderOrder = RenderOrder.MIDTOP + physProp = PhysProperties.PHYSICS_OBJECT() } - private var explosionPower: Float = 1f - private var fuse: Second = 1f - - constructor( - initialPos: Vector2, - initialVelo: Vector2, - power: Float, - fuse: Second - ) { + protected constructor() : this(1f, 1f) { renderOrder = RenderOrder.MIDTOP - - this.explosionPower = power - this.fuse = fuse + physProp = PhysProperties.PHYSICS_OBJECT() } override fun updateImpl(delta: Float) { @@ -41,4 +37,24 @@ open class ActorPrimedBomb : ActorWithBody { flagDespawn() } } +} + + +/** + * Created by minjaesong on 2024-02-14. + */ +class ActorCherryBomb : ActorPrimedBomb(500f, 4.5f) { + + init { + val itemImage = CommonResourcePool.getAsItemSheet("basegame.items").get(0,13) + + setHitboxDimension(7, 7, 2, -2) + sprite = SingleImageSprite(this, itemImage) + + avBaseMass = 1.0 + density = 1400.0 + } + + + } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt index 5ba099017..d96eceab0 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt @@ -17,7 +17,7 @@ object CreatureBuilder { * @Param jsonFileName with extension */ operator fun invoke(module: String, jsonFileName: String): ActorWithBody { - val actor = ActorWithBody(Actor.RenderOrder.MIDDLE, physProp = PhysProperties.HUMANOID_DEFAULT) + val actor = ActorWithBody(Actor.RenderOrder.MIDDLE, physProp = PhysProperties.HUMANOID_DEFAULT()) InjectCreatureRaw(actor.actorValue, module, jsonFileName) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt index 7b01e74d8..5be2d5766 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt @@ -33,7 +33,7 @@ open class DroppedItem : ActorWithBody { var itemCount = 1L - protected constructor() : super(RenderOrder.OVERLAY, PhysProperties.PHYSICS_OBJECT) + protected constructor() : super(RenderOrder.OVERLAY, PhysProperties.PHYSICS_OBJECT()) private var timeSinceSpawned = 0f @@ -51,7 +51,7 @@ open class DroppedItem : ActorWithBody { * @param topLeftX world-wise coord * @param topLeftY world-wise coord */ - constructor(itemID: ItemID, centreX: Double, bottomY: Double, spawnVelo: Vector2? = null) : super(RenderOrder.OVERLAY, PhysProperties.PHYSICS_OBJECT) { + constructor(itemID: ItemID, centreX: Double, bottomY: Double, spawnVelo: Vector2? = null) : super(RenderOrder.OVERLAY, PhysProperties.PHYSICS_OBJECT()) { this.itemID = itemID if (itemID.isActor()) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 5c38bd691..e44ce13d2 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -39,7 +39,7 @@ open class Electric : FixtureBase { mainUI: UICanvas? = null, inventory: FixtureInventory? = null, id: ActorID? = null - ) : super(renderOrder, PhysProperties.IMMOBILE, id) { + ) : super(renderOrder, PhysProperties.IMMOBILE(), id) { blockBox = blockBox0 setHitboxDimension(TILE_SIZE * blockBox.width, TILE_SIZE * blockBox.height, 0, 0) this.blockBoxProps = blockBoxProps @@ -162,7 +162,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { internal var actorThatInstalledThisFixture: UUID? = null - protected constructor() : super(RenderOrder.BEHIND, PhysProperties.IMMOBILE, null) + protected constructor() : super(RenderOrder.BEHIND, PhysProperties.IMMOBILE(), null) protected constructor(renderOrder: RenderOrder, physProp: PhysProperties, id: ActorID?) : super(renderOrder, physProp, id) /** @@ -186,7 +186,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { mainUI: UICanvas? = null, inventory: FixtureInventory? = null, id: ActorID? = null - ) : super(renderOrder, PhysProperties.IMMOBILE, id) { + ) : super(renderOrder, PhysProperties.IMMOBILE(), id) { blockBox = blockBox0 setHitboxDimension(TILE_SIZE * blockBox.width, TILE_SIZE * blockBox.height, 0, 0) this.blockBoxProps = blockBoxProps diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt index 14489d481..323f2596f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt @@ -13,7 +13,7 @@ class ItemCarrying : ActorWithBody { private constructor() - constructor(itemID: ItemID) : super(RenderOrder.MIDTOP, PhysProperties.IMMOBILE) { + constructor(itemID: ItemID) : super(RenderOrder.MIDTOP, PhysProperties.IMMOBILE()) { this.itemID = itemID } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt index a0955a29f..5384414a5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt @@ -12,7 +12,7 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser /** * Created by minjaesong on 2016-03-05. */ -class PhysTestBall : ActorWithBody(RenderOrder.MIDDLE, PhysProperties.PHYSICS_OBJECT) { +class PhysTestBall : ActorWithBody(RenderOrder.MIDDLE, PhysProperties.PHYSICS_OBJECT()) { private var color = Color.GOLD diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt index 7540a8a78..ea0af5346 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt @@ -11,7 +11,7 @@ import net.torvald.terrarum.gameactors.* /** * Created by minjaesong on 2018-01-17. */ -class PhysTestLuarLander : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT), Controllable { +class PhysTestLuarLander : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT()), Controllable { @Transient private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga")) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt index eea0b2e2e..bbb0205b3 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt @@ -52,7 +52,7 @@ open class ProjectileSimple : ActorWithBody, Projectile { constructor(type: Int, fromPoint: Vector2, // projected coord toPoint: Vector2 // arriving coord - ) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) { + ) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT()) { this.type = type diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt new file mode 100644 index 000000000..1ef10df3b --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt @@ -0,0 +1,50 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.gameitems.GameItem +import net.torvald.terrarum.gameitems.ItemID + +/** + * Created by minjaesong on 2024-02-14. + */ +open class LightIngredientBase(originalID: ItemID) : GameItem(originalID) { + override var baseMass = 1.0 + override var baseToolSize: Double? = null + override var inventoryCategory = Category.GENERIC + override val canBeDynamic = false + override val materialId = "OORE" + override var equipPosition = EquipPosition.HAND_GRIP +} + + + +/** + * Created by minjaesong on 2023-10-11. + */ +class OreStick(originalID: ItemID) : LightIngredientBase(originalID) { + override var originalName = "ITEM_WOOD_STICK" + override val materialId = "WOOD" + override var calories = 600.0 + override var smokiness = 0.2f + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,6) +} + +/** + * Created by minjaesong on 2023-12-01. + */ +class ItemClayBall(originalID: ItemID) : LightIngredientBase(originalID) { + override var originalName = "BLOCK_CLAY" + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(11,6) +} + +/** + * Created by minjaesong on 2024-02-14. + */ +class ItemGunpowder(originalID: ItemID) : LightIngredientBase(originalID) { + override var originalName = "ITEM_GUNPOWDER" + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,12) +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt new file mode 100644 index 000000000..43fb3ee86 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt @@ -0,0 +1,65 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.* +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED +import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.gameitems.GameItem +import net.torvald.terrarum.gameitems.ItemID +import net.torvald.terrarum.gameitems.mouseInInteractableRange +import net.torvald.terrarum.ui.MouseLatch +import org.dyn4j.geometry.Vector2 + +/** + * Created by minjaesong on 2024-02-14. + */ +open class ItemThrowable(originalID: ItemID, private val throwableActorClassName: String) : GameItem(originalID) { + override var baseMass = 1.0 + override var baseToolSize: Double? = baseMass + override var inventoryCategory = Category.TOOL + override val canBeDynamic = false + override val materialId = "" + override var equipPosition = EquipPosition.HAND_GRIP + override val disallowToolDragging = true + + init { + ItemCodex.fixtureToSpawnerItemID[throwableActorClassName] = originalID + } + + protected open fun setupLobbedActor(actor: ActorWithBody) { + + } + + override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long = mouseInInteractableRange(actor) { mx, my, mtx, mty -> + + val playerCentrePos = actor.centrePosVector + val mousePos = Vector2(mx, my) + + val actorPowMult = actor.avStrength / 2000.0 + val relativeX = relativeXposition(actor, mousePos) + val relativeY = my - playerCentrePos.y + val powX = relativeX / TILE_SIZED * 3.0 * actorPowMult + val powY = relativeY / TILE_SIZED * 3.0 * actorPowMult + + val lobbed = Class.forName(throwableActorClassName).getDeclaredConstructor().newInstance() as ActorWithBody + lobbed.setPosition(playerCentrePos) + lobbed.externalV.set(powX, powY) + setupLobbedActor(lobbed) + + Terrarum.ingame?.queueActorAddition(lobbed) + + + + 1L + } +} + + +/** + * Created by minjaesong on 2024-02-14. + */ +class ItemCherryBomb(originalID: ItemID) : ItemThrowable(originalID, "net.torvald.terrarum.modulebasegame.gameactors.ActorCherryBomb") { + override var originalName = "ITEM_CHERRY_BOMB" + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,13) +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt index 5aa56e988..9cb07cec2 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt @@ -89,14 +89,6 @@ class ItemLogsRosewood(originalID: ItemID) : OreItemBase(originalID) { return BlockBase.blockStartPrimaryUse(actor, this, "basegame:75", delta) } } -class OreStick(originalID: ItemID) : OreItemBase(originalID) { - override var originalName = "ITEM_WOOD_STICK" - override val materialId = "WOOD" - override var calories = 600.0 - override var smokiness = 0.2f - override val itemImage: TextureRegion - get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,6) -} @@ -262,10 +254,3 @@ class IngotSolder(originalID: ItemID) : OreItemBase(originalID) { override val itemImage: TextureRegion get() = CommonResourcePool.getAsItemSheet("basegame.items").get(14,5) } - - -class ItemClayBall(originalID: ItemID) : OreItemBase(originalID) { - override var originalName = "BLOCK_CLAY" - override val itemImage: TextureRegion - get() = CommonResourcePool.getAsItemSheet("basegame.items").get(11,6) -} \ No newline at end of file diff --git a/work_files/graphics/items/basegame_items.kra b/work_files/graphics/items/basegame_items.kra index beaaaea16..5f3fbfb2c 100644 --- a/work_files/graphics/items/basegame_items.kra +++ b/work_files/graphics/items/basegame_items.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:93815d16aa8e4c7a22347ac387cdf974d0a897a136e40da744e12accdf6f0061 -size 1207457 +oid sha256:d7ed83fc39e033cb6fba1ba9e452408df5c9e53a5486ca367d38e282bbff48af +size 1357591