first working instance of wire signal source block

This commit is contained in:
minjaesong
2021-08-09 17:00:02 +09:00
parent 4c4817f2fb
commit a9f46613a2
4 changed files with 84 additions and 77 deletions

View File

@@ -37,13 +37,23 @@ open class FixtureBase(
/**
* Block-wise position of this fixture when it's placed on the world. Null if it's not on the world
*/
private var worldBlockPos: Point2i? = null
protected var worldBlockPos: Point2i? = null
init {
if (mainUI != null)
AppLoader.disposableSingletonsPool.add(mainUI)
}
fun forEachBlockbox(action: (Int, Int) -> Unit) {
worldBlockPos?.let { (posX, posY) ->
for (y in posY until posY + blockBox.height) {
for (x in posX until posX + blockBox.width) {
action(x, y)
}
}
}
}
/**
* Adds this instance of the fixture to the world
*
@@ -80,8 +90,7 @@ open class FixtureBase(
// fill the area with the filler blocks
for (y in posY until posY + blockBox.height) {
for (x in posX until posX + blockBox.width) {
forEachBlockbox { x, y ->
if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) {
// if the collision type is allow_move_down, only the top surface tile should be "the platform"
// lower part must not have such property (think of the table!)
@@ -90,7 +99,6 @@ open class FixtureBase(
}
else
world!!.setTileTerrain(x, y, blockBox.collisionType, false)
}
}
// set the position of this actor
@@ -115,10 +123,8 @@ open class FixtureBase(
val posY = worldBlockPos!!.y
// remove filler block
for (x in posX until posX + blockBox.width) {
for (y in posY until posY + blockBox.height) {
forEachBlockbox { x, y ->
world!!.setTileTerrain(x, y, Block.AIR, false)
}
}
worldBlockPos = null
@@ -156,11 +162,9 @@ open class FixtureBase(
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, false)
}
forEachBlockbox { x, y ->
if (world!!.getTileFromTerrain(x, y) == blockBox.collisionType) {
world!!.setTileTerrain(x, y, Block.AIR, false)
}
}

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.WireCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
@@ -27,5 +28,14 @@ class FixtureLogicSignalEmitter(nameFun: () -> String) : FixtureBase(BlockBox(Bl
companion object {
const val MASS = 1.0
}
override fun update(delta: Float) {
// set emit
worldBlockPos?.let { (x, y) ->
WireCodex.getAll().filter { it.renderClass == "signal" }.forEach { prop ->
world?.setWireEmitStateOf(x, y, prop.id, wireEmission)
}
}
}
}