more flexible blockbox definition and their utilisation

This commit is contained in:
minjaesong
2024-10-04 01:22:45 +09:00
parent 0e58879216
commit af0be41a82
10 changed files with 61 additions and 72 deletions

View File

@@ -176,20 +176,12 @@ class FixtureAlloyingFurnace : FixtureBase {
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TILE_SIZED * 2, TILE_SIZED * 2), light))
@Transient private val actorBlocks = arrayOf(
arrayOf(Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
override fun getBlockBoxPositions(posX: Int, posY: Int): List<Pair<Int, Int>> {
return listOf(
(posX+0 to posY+0),
(posX+0 to posY+1), (posX+1 to posY+1),
)
override fun placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
private var nextDelayBase = 0.25f // use smokiness value of the item
private var nextDelay = 0.25f // use smokiness value of the item

View File

@@ -6,7 +6,6 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang
@@ -129,13 +128,11 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
open fun forEachBlockbox(action: (Int, Int, Int, Int) -> Unit) {
// TODO scale-aware
worldBlockPos?.let { (posX, posY) ->
for (y in posY until posY + blockBox.height) {
for (x in posX until posX + blockBox.width) {
getBlockBoxPositions(posX, posY).forEach { (x, y) ->
action(x, y, x - posX, y - posY)
}
}
}
}
val everyBlockboxPos: List<Pair<Int, Int>>?
get() = worldBlockPos?.let { (posX, posY) ->
@@ -147,7 +144,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
}
// something like TapestryObject will want to redefine this
open protected fun placeActorBlocks() {
protected open fun placeActorBlocks() {
forEachBlockbox { x, y, _, _ ->
//printdbg(this, "fillerblock ${blockBox.collisionType} at ($x, $y)")
if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) {
@@ -175,8 +172,17 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
return canSpawnHere0(posX, posY)
}
/**
* @param posX start position of the BlockBox, top-left
* @param posY start position of the BlockBox, top-left
* @return real block positions, in List of Pair(x, y)
*/
open fun getBlockBoxPositions(posX: Int, posY: Int): List<Pair<Int, Int>> {
return (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
}
open fun canSpawnHere0(posX: Int, posY: Int): Boolean {
val everyBlockboxPos = (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
val everyBlockboxPos = getBlockBoxPositions(posX, posY)
// check for existing blocks (and fixtures)
var cannotSpawn = false
@@ -195,10 +201,9 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
// check for floors, if spawnNeedsFloor == true
if (spawnNeedsFloor || spawnNeedsCeiling) {
val y = posY + if (spawnNeedsFloor) blockBox.height else -1
val xs = posX until posX + blockBox.width
cannotSpawnNoFloor = xs.any { x ->
world!!.getTileFromTerrain(x, y).let {
val yOff = if (spawnNeedsFloor) 1 else -1
cannotSpawnNoFloor = everyBlockboxPos.filter { if (spawnNeedsFloor) it.second == posY + blockBox.height - 1 else it.second == posY }.any { (x, y) ->
world!!.getTileFromTerrain(x, y + yOff).let {
!canSpawnOnThisFloor(it)
}
}

View File

@@ -61,19 +61,12 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TerrarumAppConfiguration.TILE_SIZED * 2, TerrarumAppConfiguration.TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f)))
@Transient private val actorBlocks = arrayOf(
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
override fun getBlockBoxPositions(posX: Int, posY: Int): List<Pair<Int, Int>> {
return listOf(
(posX+0 to posY+0), (posX+1 to posY+0),
(posX+0 to posY+1), (posX+1 to posY+1), (posX+2 to posY+1)
)
override fun placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
private var nextDelay = 0.25f
private var spawnTimer = 0f

View File

@@ -17,10 +17,20 @@ class FixtureInductionMotor : Electric {
@Transient override val spawnNeedsWall = false
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 1),
BlockBox(BlockBox.NO_COLLISION, 3, 1),
nameFun = { Lang["ITEM_INDUCTION_MOTOR"] }
)
override fun placeActorBlocks() {
worldBlockPos?.let { (x, y) ->
world!!.setTileTerrain(x+1, y, blockBox.collisionType, true)
}
}
override fun getBlockBoxPositions(posX: Int, posY: Int): List<Pair<Int, Int>> {
return listOf(posX+1 to posY)
}
init {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/induction_motor.tga")
@@ -34,11 +44,14 @@ class FixtureInductionMotor : Electric {
actorValue[AVKey.BASEMASS] = MASS
setWireEmitterAt(0, 0, "axle")
setWireEmitterAt(2, 0, "axle")
setWireEmissionAt(0, 0, Vector2(16.0, 1024.0)) // speed and torque
setWireEmissionAt(2, 0, Vector2(16.0, 1024.0)) // speed and torque
}
override fun updateSignal() {
setWireEmissionAt(0, 0, Vector2(16.0, 1024.0)) // speed and torque
setWireEmissionAt(2, 0, Vector2(16.0, 1024.0)) // speed and torque
}
override fun dispose() {

View File

@@ -21,20 +21,13 @@ class FixtureLogicSignalSevenSeg : Electric {
nameFun = { Lang["ITEM_LOGIC_SIGNAL_DISPLAY"] }
)
@Transient private val actorBlocks = arrayOf(
arrayOf(null, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(null, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(null, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
override fun getBlockBoxPositions(posX: Int, posY: Int): List<Pair<Int, Int>> {
return listOf(
(posX+1 to posY+0), (posX+2 to posY+0),
(posX+1 to posY+1), (posX+2 to posY+1),
(posX+1 to posY+2), (posX+2 to posY+2),
(posX+0 to posY+3), (posX+1 to posY+3), (posX+2 to posY+3), (posX+3 to posY+3)
)
override fun placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
init {

View File

@@ -161,19 +161,13 @@ class FixtureSmelterBasic : FixtureBase {
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 2*TILE_SIZED, TILE_SIZED * 2, TILE_SIZED * 2), light))
@Transient private val actorBlocks = arrayOf(
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
override fun getBlockBoxPositions(posX: Int, posY: Int): List<Pair<Int, Int>> {
return listOf(
(posX+0 to posY+0), (posX+1 to posY+0),
(posX+0 to posY+1), (posX+1 to posY+1),
(posX+0 to posY+2), (posX+1 to posY+2),
(posX+0 to posY+3), (posX+1 to posY+3), (posX+2 to posY+3)
)
override fun placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
private var nextDelayBase = 0.25f // use smokiness value of the item

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.Gdx
import net.torvald.gdx.graphics.Cvec
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
@@ -9,7 +8,6 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -191,7 +189,7 @@ open class FixtureSwingingDoorBase : FixtureBase {
}
override fun canSpawnHere0(posX: Int, posY: Int): Boolean {
val everyBlockboxPos = (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList())
val everyBlockboxPos = getBlockBoxPositions(posX, posY)
val xoffToFrame = (tilewiseHitboxWidth - twClosed) / 2
val everyDoorframePos = (posX + xoffToFrame until posX + blockBox.width - 1).toList().cartesianProduct((posY until posY + blockBox.height).toList())

View File

@@ -48,7 +48,8 @@ class UIQuickslotBar : UICanvas() {
const val SLOT_COUNT = 10
const val DISPLAY_OPACITY = 0.92f
const val COMMON_OPEN_CLOSE = 0.12f
val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0xde4185ff.toInt())
// val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0xdb6f00ff.toInt())
val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0x0099bbff.toInt())
}