seven seg display

This commit is contained in:
minjaesong
2024-03-17 18:01:27 +09:00
parent aef1db49d6
commit 7bfff29a79
11 changed files with 168 additions and 25 deletions

View File

@@ -0,0 +1,87 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.toInt
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2024-03-16.
*/
class FixtureLogicSignalSevenSeg : Electric {
@Transient override val spawnNeedsFloor = true
@Transient override val spawnNeedsWall = true
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 4, 4),
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 placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
init {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/sevenseg.tga")
val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/sevenseg.tga")
density = 1400.0
setHitboxDimension(4*TILE_SIZE, 4*TILE_SIZE, 0, 1)
makeNewSprite(TextureRegionPack(itemImage.texture, 4*TILE_SIZE, 4*TILE_SIZE)).let {
it.setRowsAndFrames(2,16)
it.delays = FloatArray(16) { Float.POSITIVE_INFINITY }
}
makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, 4*TILE_SIZE, 4*TILE_SIZE)).let {
it.setRowsAndFrames(2,416)
it.delays = FloatArray(16) { Float.POSITIVE_INFINITY }
}
(sprite as SheetSpriteAnimation).currentRow = 0
(spriteEmissive as SheetSpriteAnimation).currentRow = 1
setWireSinkAt(0, 3, "digital_bit")
setWireSinkAt(1, 3, "digital_bit")
setWireSinkAt(2, 3, "digital_bit")
setWireSinkAt(3, 3, "digital_bit")
}
override fun reload() {
super.reload()
setWireSinkAt(0, 3, "digital_bit")
setWireSinkAt(1, 3, "digital_bit")
setWireSinkAt(2, 3, "digital_bit")
setWireSinkAt(3, 3, "digital_bit")
updateK()
}
override fun updateSignal() {
updateK()
}
private fun updateK() {
val state = isSignalHigh(0, 3).toInt(0) or
isSignalHigh(1, 3).toInt(1) or
isSignalHigh(2, 3).toInt(2) or
isSignalHigh(3, 3).toInt(3)
(sprite as SheetSpriteAnimation).currentFrame = state
(spriteEmissive as SheetSpriteAnimation).currentFrame = state
}
}

View File

@@ -0,0 +1,38 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter
/**
* Created by minjaesong on 2024-03-16.
*/
class ItemLogicSignalSevenSeg(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalSevenSeg") {
override var dynamicID: ItemID = originalID
override var baseMass = FixtureLogicSignalEmitter.MASS
override val canBeDynamic = false
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(15, 3)
override val itemImageEmissive: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(15, 4)
override var baseToolSize: Double? = baseMass
override var originalName = "ITEM_LOGIC_SIGNAL_NUMERIC_DISPLAY"
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
super.effectWhileEquipped(actor, delta)
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "signal"
}
override fun effectOnUnequip(actor: ActorWithBody) {
super.effectOnUnequip(actor)
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
}
}