diff --git a/assets/graphics/gui/quickbar/item_slots_atlas2.tga b/assets/graphics/gui/quickbar/item_slots_atlas2.tga new file mode 100644 index 000000000..fa208287f --- /dev/null +++ b/assets/graphics/gui/quickbar/item_slots_atlas2.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:881758957010a6d9c4974020d78b9360e07f3c0c7c520e6cdfae95c5592709aa +size 254188 diff --git a/src/net/torvald/UnsafePtr.kt b/src/net/torvald/UnsafePtr.kt index e52c5e1d7..57f6b9228 100644 --- a/src/net/torvald/UnsafePtr.kt +++ b/src/net/torvald/UnsafePtr.kt @@ -68,7 +68,7 @@ class UnsafePtr(pointer: Long, allocSize: Long) { // commenting out because of the suspected (or minor?) performance impact. // You may break the glass and use this tool when some fucking incomprehensible bugs ("vittujen vitun bugit") // appear (e.g. getting garbage values when it fucking shouldn't) - if (destroyed) throw NullPointerException("The pointer is already destroyed ($this)") + assert(destroyed) { throw NullPointerException("The pointer is already destroyed ($this)") } // OOB Check: debugging purposes only -- comment out for the production //if (index !in 0 until size) throw IndexOutOfBoundsException("Index: $index; alloc size: $size") diff --git a/src/net/torvald/spriteanimation/HasAssembledSprite.kt b/src/net/torvald/spriteanimation/HasAssembledSprite.kt index d7d3ccf32..294eab559 100644 --- a/src/net/torvald/spriteanimation/HasAssembledSprite.kt +++ b/src/net/torvald/spriteanimation/HasAssembledSprite.kt @@ -20,7 +20,7 @@ interface HasAssembledSprite { fun reassembleSprite(sprite: SpriteAnimation, spriteGlow: SpriteAnimation? = null) { _rebuild(ADProperties(Gdx.files.internal(animDescPath).read()), sprite) - if (spriteGlow != null) + if (animDescPathGlow != null && spriteGlow != null) _rebuild(ADProperties(Gdx.files.internal(animDescPathGlow).read()), spriteGlow) } diff --git a/src/net/torvald/spriteanimation/SpriteAnimation.kt b/src/net/torvald/spriteanimation/SpriteAnimation.kt index 0eaace654..0c8d3900b 100644 --- a/src/net/torvald/spriteanimation/SpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/SpriteAnimation.kt @@ -122,7 +122,7 @@ class SpriteAnimation(@Transient val parentActor: ActorWBMovable) { * @param scale */ fun render(batch: SpriteBatch, posX: Float, posY: Float, scale: Float = 1f) { - if (cellWidth == 0 || cellHeight == 0) { + assert(cellWidth == 0 || cellHeight == 0) { throw Error("Sprite width or height is set to zero! ($cellWidth, $cellHeight); master: $parentActor") } diff --git a/src/net/torvald/terrarum/Point2d.kt b/src/net/torvald/terrarum/Point2d.kt index f4f9a7478..93db60e9c 100644 --- a/src/net/torvald/terrarum/Point2d.kt +++ b/src/net/torvald/terrarum/Point2d.kt @@ -57,6 +57,8 @@ data class Point2d(var x: Double, var y: Double) : Cloneable { fun length(other: Point2d) = distSqr(other).sqrt() fun distSqr(other: Point2d) = ((this.x - other.x).sqr() + (this.y - other.y).sqr()) + fun toDoubleArray() = doubleArrayOf(x, y) + } data class Point2i(var x: Int, var y: Int) { diff --git a/src/net/torvald/terrarum/gameactors/ActorWBMovable.kt b/src/net/torvald/terrarum/gameactors/ActorWBMovable.kt index e76fad62a..e8ec2d487 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWBMovable.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWBMovable.kt @@ -361,6 +361,9 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = private val bounceDampenVelThreshold = 0.5 override fun update(delta: Float) { + + val oldHitbox = hitbox.clone() + if (isUpdate && !flagDespawn) { if (!assertPrinted) assertInit() @@ -411,7 +414,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = * This body is NON-STATIC and the other body is STATIC */ if (!isNoCollideWorld) { - displaceHitbox(delta.toDouble()) + displaceHitbox() + //collisionInterpolatorRun() } else { val vecSum = externalV + (controllerV ?: Vector2(0.0, 0.0)) @@ -464,6 +468,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = feetPosTile.y = hIntTilewiseHitbox.endY.floorInt() } + + hasMoved = (oldHitbox != hitbox) } /** @@ -583,7 +589,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = } }*/ - private fun displaceHitbox(delta: Double) { + private fun displaceHitbox() { // // HOW IT SHOULD WORK // // // //////////////////////// // combineVeloToMoveDelta now @@ -612,7 +618,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = fun debug1(wut: Any?) { // vvvvv set it true to make debug print work - if (true) printdbg(this, wut) + if (false) printdbg(this, wut) } fun debug2(wut: Any?) { @@ -674,13 +680,18 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = val stepBox = sixteenStep[step] - forEachOccupyingTilePos(stepBox) { + /*forEachOccupyingTilePos(stepBox) { val tileCoord = LandUtil.resolveBlockAddr(world!!, it) val tile = world!!.getTileFromTerrain(tileCoord.first, tileCoord.second) ?: Block.STONE if (shouldICollideWithThis(tile) || (it.isFeetTile(stepBox) && shouldICollideWithThisFeet(tile))) { collidingStep = step } + }*/ + + // trying to use same function as the others, in an effort to eliminate the "contradiction" mentioned below + if (isColliding(stepBox)) { + collidingStep = step } if (collidingStep != null) break @@ -891,6 +902,62 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = } } + fun collisionInterpolatorRun() { + + fun isWalled2(hitbox: Hitbox, option: Int): Boolean { + val newHB = Hitbox.fromTwoPoints( + hitbox.startX + A_PIXEL, hitbox.startY + A_PIXEL, + hitbox.endX - A_PIXEL, hitbox.endY - A_PIXEL + ) + + return isWalled(newHB, option) + } + + // kinda works but the jump is inconsistent because of the nondeterministic nature of the values (doesn't get fixed to the integer value when collided) + + if (world != null) { + val intpStep = 64.0 + + // make interpolation even if the "next" position is clear of collision + var clearOfCollision = true + val testHitbox = hitbox.clone() + + // divide the vectors by the constant + externalV /= intpStep + controllerV?.let { controllerV!! /= intpStep } + + repeat(intpStep.toInt()) { // basically we don't care if we're already been encased (e.g. entrapped by falling sand) + + // change the order and the player gets stuck in the vertical wall + // so leave as-is + + testHitbox.translate(externalV + controllerV) + + // vertical collision + if (isWalled2(testHitbox, COLLIDING_UD)) { + externalV.y *= elasticity // TODO also multiply the friction value + controllerV?.let { controllerV!!.y *= elasticity } // TODO also multiply the friction value + clearOfCollision = false + } + // horizontal collision + if (isWalled2(testHitbox, COLLIDING_LR)) { + externalV.x *= elasticity // TODO also multiply the friction value + controllerV?.let { controllerV!!.x *= elasticity } // TODO also multiply the friction value + clearOfCollision = false + } + + } + + hitbox.reassign(testHitbox) + + // revert the division because the Acceleration depends on being able to integrate onto the velo values + // don't want to mess up with the value they're expecting + externalV *= intpStep + controllerV?.let { controllerV!! *= intpStep } + + // TODO collision damage + } + } /** * @see /work_files/hitbox_collision_detection_compensation.jpg diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 25334319e..ec8aa874b 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.gameactors import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.Terrarum /** * Actor with visible body @@ -11,5 +12,9 @@ abstract class ActorWithBody(renderOrder: RenderOrder) : Actor(renderOrder) { abstract val hitbox: Hitbox abstract fun drawBody(batch: SpriteBatch) abstract fun drawGlow(batch: SpriteBatch) + open var hasMoved: Boolean = false + protected set open var tooltipText: String? = null // null: display nothing + val mouseUp: Boolean + get() = hitbox.containsPoint(Terrarum.mouseX, Terrarum.mouseY) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/Hitbox.kt b/src/net/torvald/terrarum/gameactors/Hitbox.kt index 357f85101..7c74e7261 100644 --- a/src/net/torvald/terrarum/gameactors/Hitbox.kt +++ b/src/net/torvald/terrarum/gameactors/Hitbox.kt @@ -27,7 +27,7 @@ class Hitbox (x1: Double, y1: Double, width: Double, height: Double, var suppres this.width = width this.height = height - if (!suppressWarning && (width == 0.0 || height == 0.0)) { + assert(!suppressWarning && (width == 0.0 || height == 0.0)) { println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?") printStackTrace(this) } @@ -66,7 +66,7 @@ class Hitbox (x1: Double, y1: Double, width: Double, height: Double, var suppres this.width = width this.height = height - if (!suppressWarning && (width == 0.0 || height == 0.0)) { + assert(!suppressWarning && (width == 0.0 || height == 0.0)) { println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?") printStackTrace(this) } @@ -84,7 +84,7 @@ class Hitbox (x1: Double, y1: Double, width: Double, height: Double, var suppres fun setPosition(x1: Double, y1: Double): Hitbox { hitboxStart = Point2d(x1, y1) - if (!suppressWarning && (width == 0.0 || height == 0.0)) { + assert(!suppressWarning && (width == 0.0 || height == 0.0)) { println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?") printStackTrace(this) } @@ -117,6 +117,9 @@ class Hitbox (x1: Double, y1: Double, width: Double, height: Double, var suppres return this } + fun containsPoint(x: Double, y: Double) = (hitboxStart.x - x) in 0.0..width && (hitboxStart.y - y) in 0.0..height + fun containsPoint(p: Point2d) = containsPoint(p.x, p.y) + /** * Returns x value of start point * @return top-left point startX @@ -155,6 +158,8 @@ class Hitbox (x1: Double, y1: Double, width: Double, height: Double, var suppres } override fun equals(other: Any?): Boolean { - return this.hitboxStart == (other as Hitbox).hitboxStart && this.hitboxEnd == (other as Hitbox).hitboxEnd + return this.hitboxStart == (other as Hitbox).hitboxStart && + this.width == other.width && + this.height == other.height } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/ItemSlotImageFactory.kt b/src/net/torvald/terrarum/modulebasegame/ui/ItemSlotImageFactory.kt index e8acae85e..7b9e2aa6f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/ItemSlotImageFactory.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/ItemSlotImageFactory.kt @@ -27,7 +27,7 @@ object ItemSlotImageFactory { /** Blend mode: screen */ val CELLCOLOUR_BLACK_ACTIVE = Color(0x282828ff) - val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge + val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas2.tga"), 38, 38) // must have same w/h as slotLarge fun produce(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage { return ItemSlotImage(slotImage.get(number, 0 or isBlack.toInt().shl(1)), ItemCodex.getItemImage(item))