diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt index 5addff751..17582c843 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt @@ -273,11 +273,6 @@ open class ActorHumanoid( /** * U-D stop */ - if (hasController) { - if (axisY == 0f) { - walkVStop() - } - } // ↑E // ↑D if (isNoClip && !isUpDown && !isDownDown && axisY == 0f) { @@ -319,7 +314,7 @@ open class ActorHumanoid( if (isNoClip || COLLISION_TEST_MODE) { if (hasController) { if (axisY != 0f) { - walkVertical(axisY < 0, axisY.abs()) + walkVertical(axisY > 0, axisY.abs()) } } // ↑E, ↓D diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 524647b01..836d3361c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -1,26 +1,36 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.IngameInstance -import net.torvald.terrarum.Point2d +import net.torvald.terrarum.Point2i +import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameactors.ActorWBMovable +import net.torvald.terrarum.gameworld.GameWorld /** * Created by minjaesong on 2016-06-17. */ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0)) : -// disabling physics (not allowing the fixture to move) WILL make things easier +// disabling physics (not allowing the fixture to move) WILL make things easier in many ways ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false), CuedByTerrainChange { + private val world: GameWorld + get() = Terrarum.ingame!!.world + + private val TSIZE = TILE_SIZE.toDouble() + /** * Block-wise position of this fixture when it's placed on the world. Null if it's not on the world */ - private var worldBlockPos: Point2d? = null + private var worldBlockPos: Point2i? = null /** * Adds this instance of the fixture to the world + * + * @param posX top-left position of the fixture, tile-wise + * @param posY top-left position of the fixture, tile-wise */ - open fun spawn() { + open fun spawn(posX: Int, posY: Int) { // place filler blocks // place the filler blocks where: // origin posX: centre-left if mouseX is on the right-half of the game window, @@ -31,10 +41,22 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps // posY: bottom of the blockBox // using the actor's hitbox + for (x in posX until posX + blockBox.width) { + for (y in posY until posY + blockBox.height) { + world.setTileTerrain(x, y, blockBox.collisionType) + } + } + worldBlockPos = Point2i(posX, posY) + + this.isVisible = true + this.hitbox.setFromWidthHeight(posX * TSIZE, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE) } + /** + * Update code that runs once for every frame + */ open fun updateSelf() { } @@ -43,7 +65,61 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps * Removes this instance of the fixture from the world */ open fun despawn() { + val posX = worldBlockPos!!.x + val posY = worldBlockPos!!.y + // remove filler block + for (x in posX until posX + blockBox.width) { + for (y in posY until posY + blockBox.height) { + world.setTileTerrain(x, y, Block.AIR) + } + } + + worldBlockPos = null + + this.isVisible = false + } + + /** + * Fired by world's BlockChanged event (fired when blocks are placed/removed). + * The flooding check must run on every frame. use updateSelf() for that. + * + * E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self. + */ + override fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) { + // check for marker blocks. + // if at least one of them is missing, destroy all the markers and drop self as an item + + // you need to implement Dropped Item first to satisfyingly implement this function + + val posX = worldBlockPos!!.x + val posY = worldBlockPos!!.y + var dropThis = false + + // remove filler block + outerLoop@ + for (x in posX until posX + blockBox.width) { + for (y in posY until posY + blockBox.height) { + if (world.getTileFromTerrain(x, y) != blockBox.collisionType) { + dropThis = true + break@outerLoop + } + } + } + + if (dropThis) { + // fill blockbox with air + for (x in posX until posX + blockBox.width) { + for (y in posY until posY + blockBox.height) { + if (world.getTileFromTerrain(x, y) == blockBox.collisionType) { + world.setTileTerrain(x, y, Block.AIR) + } + } + } + + // TODO drop self as an item (instance of DroppedItem) + + } } } @@ -54,9 +130,7 @@ interface CuedByTerrainChange { * * E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self. */ - fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) { - - } + fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) } /** @@ -74,6 +148,11 @@ inline class BlockBoxProps(val flags: Int) { } +/** + * @param collisionType Collision type defined in BlockBox.Companion + * @param width Width of the block box, tile-wise + * @param height Height of the block box, tile-wise + */ data class BlockBox(var collisionType: Int, var width: Int, var height: Int) { fun redefine(collisionType: Int, width: Int, height: Int) { diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt index 246795246..18d00264c 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -103,7 +103,7 @@ open class UIItemTextButton( else inactiveCol font.draw(batch, - label, + label, //"$label/H:${highlighted.toInt()}, M:${mouseUp.toInt()}", when (alignment) { Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2) Alignment.LEFT -> posX.toFloat() + preGapX