mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
pressure plates
This commit is contained in:
@@ -15,6 +15,10 @@
|
|||||||
"workbench": "",
|
"workbench": "",
|
||||||
"ingredients": [[2, 1, "item@basegame:112", 1, "$ROCK", 1, "item@basegame:113"]] /* 1 copper ingot, 1 rock, 1 iron */
|
"ingredients": [[2, 1, "item@basegame:112", 1, "$ROCK", 1, "item@basegame:113"]] /* 1 copper ingot, 1 rock, 1 iron */
|
||||||
},
|
},
|
||||||
|
"item@basegame:58": { /* signal pressure plate */
|
||||||
|
"workbench": "",
|
||||||
|
"ingredients": [[1, 1, "item@basegame:112", 1, "$ROCK", 1, "item@basegame:113"]] /* 1 copper ingot, 1 rock, 1 iron */
|
||||||
|
},
|
||||||
"item@basegame:1048576": { /* wooden bucket */
|
"item@basegame:1048576": { /* wooden bucket */
|
||||||
"workbench": "basiccrafting",
|
"workbench": "basiccrafting",
|
||||||
"ingredients": [[1, 3, "$WOOD"]] /* 3 planks */
|
"ingredients": [[1, 3, "$WOOD"]] /* 3 planks */
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ id;classname;tags
|
|||||||
55;net.torvald.terrarum.modulebasegame.gameitems.ItemGlowOrb;LIGHT,THROWABLE
|
55;net.torvald.terrarum.modulebasegame.gameitems.ItemGlowOrb;LIGHT,THROWABLE
|
||||||
56;net.torvald.terrarum.modulebasegame.gameitems.ItemClayBrick;
|
56;net.torvald.terrarum.modulebasegame.gameitems.ItemClayBrick;
|
||||||
57;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPushbutton;FIXTURE,SIGNAL
|
57;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPushbutton;FIXTURE,SIGNAL
|
||||||
|
58;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPressurePlate;FIXTURE,SIGNAL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
|
Binary file not shown.
@@ -50,6 +50,8 @@
|
|||||||
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
|
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
|
||||||
"ITEM_LOGIC_SIGNAL_LATCH": "Logic Signal Latch",
|
"ITEM_LOGIC_SIGNAL_LATCH": "Logic Signal Latch",
|
||||||
"ITEM_LOGIC_SIGNAL_NUMERIC_DISPLAY": "Logic Signal Numeric Display",
|
"ITEM_LOGIC_SIGNAL_NUMERIC_DISPLAY": "Logic Signal Numeric Display",
|
||||||
|
"ITEM_LOGIC_SIGNAL_PRESSURE_PLATE": "Logic Signal Pressure Plate",
|
||||||
|
"ITEM_LOGIC_SIGNAL_PUSHBUTTON": "Logic Signal Push-Button",
|
||||||
"ITEM_LOGIC_SIGNAL_REPEATER": "Logic Signal Repeater",
|
"ITEM_LOGIC_SIGNAL_REPEATER": "Logic Signal Repeater",
|
||||||
"ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch",
|
"ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch",
|
||||||
"ITEM_LOGS_BIRCH": "Birch Logs",
|
"ITEM_LOGS_BIRCH": "Birch Logs",
|
||||||
|
|||||||
BIN
assets/mods/basegame/sprites/fixtures/signal_pressure_plate.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_pressure_plate.tga
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/sprites/fixtures/signal_pressure_plate_emsv.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_pressure_plate_emsv.tga
LFS
Normal file
Binary file not shown.
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
|||||||
|
|
||||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.INGAME
|
||||||
|
import net.torvald.terrarum.Point2d
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration
|
import net.torvald.terrarum.TerrarumAppConfiguration
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
@@ -131,3 +132,81 @@ class FixtureLogicSignalPushbutton : Electric {
|
|||||||
triggeredTime = INGAME.world.worldTime.TIME_T
|
triggeredTime = INGAME.world.worldTime.TIME_T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FixtureLogicSignalPressurePlate : Electric {
|
||||||
|
|
||||||
|
@Transient override val spawnNeedsFloor = true
|
||||||
|
@Transient override val spawnNeedsWall = false
|
||||||
|
|
||||||
|
constructor() : super(
|
||||||
|
BlockBox(BlockBox.NO_COLLISION, 2, 1),
|
||||||
|
nameFun = { Lang["ITEM_LOGIC_SIGNAL_PRESSURE_PLATE"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
@Transient open val minMass = 2.0 // different types of switches can have different minimal mass?
|
||||||
|
@Transient open val holdTime = 30 // ticks
|
||||||
|
|
||||||
|
|
||||||
|
private var triggeredTime: Long? = null // null = off; number: TIME_T that the button was held down
|
||||||
|
|
||||||
|
private val state: Int
|
||||||
|
get() = (triggeredTime != null).toInt()
|
||||||
|
|
||||||
|
init {
|
||||||
|
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_pressure_plate.tga")
|
||||||
|
val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_pressure_plate_emsv.tga")
|
||||||
|
|
||||||
|
density = 1400.0
|
||||||
|
setHitboxDimension(2*TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE, 0, 1)
|
||||||
|
|
||||||
|
makeNewSprite(TextureRegionPack(itemImage.texture, 2*TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE)).let {
|
||||||
|
it.setRowsAndFrames(2,1)
|
||||||
|
it.delays = floatArrayOf(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
|
||||||
|
}
|
||||||
|
makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, 2*TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE)).let {
|
||||||
|
it.setRowsAndFrames(2,1)
|
||||||
|
it.delays = floatArrayOf(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
|
||||||
|
}
|
||||||
|
|
||||||
|
actorValue[AVKey.BASEMASS] = FixtureLogicSignalEmitter.MASS
|
||||||
|
|
||||||
|
|
||||||
|
setWireEmitterAt(0, 0, "digital_bit")
|
||||||
|
// right side of the plate can be used to route signal wire
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateState() {
|
||||||
|
val pointStart = Point2d(hitbox.startX + 5, hitbox.endY - 6)
|
||||||
|
val pointEnd = Point2d(hitbox.startX + 5 + 22, hitbox.endY)
|
||||||
|
|
||||||
|
val massSum = INGAME.getActorsAt(pointStart, pointEnd).filter {
|
||||||
|
it.physProp.usePhysics
|
||||||
|
}.sumOf { it.mass }
|
||||||
|
|
||||||
|
if (massSum >= minMass)
|
||||||
|
triggeredTime = INGAME.world.worldTime.TIME_T
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateSignal() {
|
||||||
|
// detect and measure weight of actors
|
||||||
|
updateState()
|
||||||
|
|
||||||
|
// decide when to un-trigger
|
||||||
|
if (INGAME.world.worldTime.TIME_T - (triggeredTime ?: 0L) >= holdTime) {
|
||||||
|
triggeredTime = null
|
||||||
|
}
|
||||||
|
|
||||||
|
(sprite as SheetSpriteAnimation).currentRow = state
|
||||||
|
(spriteEmissive as SheetSpriteAnimation).currentRow = state
|
||||||
|
setWireEmissionAt(0, 0, Vector2(state.toDouble(), 0.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reload() {
|
||||||
|
super.reload()
|
||||||
|
|
||||||
|
(sprite as SheetSpriteAnimation).currentRow = state
|
||||||
|
(spriteEmissive as SheetSpriteAnimation).currentRow = state
|
||||||
|
setWireEmissionAt(0, 0, Vector2(state.toDouble(), 0.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,3 +62,28 @@ class ItemLogicSignalPushbutton(originalID: ItemID) : FixtureItemBase(originalID
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ItemLogicSignalPressurePlate(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalPressurePlate") {
|
||||||
|
|
||||||
|
override var dynamicID: ItemID = originalID
|
||||||
|
override var baseMass = FixtureLogicSignalEmitter.MASS
|
||||||
|
override val canBeDynamic = false
|
||||||
|
override val materialId = ""
|
||||||
|
init {
|
||||||
|
itemImage = CommonResourcePool.getAsItemSheet("basegame.items").get(9, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
override var baseToolSize: Double? = baseMass
|
||||||
|
override var originalName = "ITEM_LOGIC_SIGNAL_PRESSURE_PLATE"
|
||||||
|
|
||||||
|
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 = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
BIN
work_files/graphics/sprites/fixtures/signal_pressure_plate.kra
LFS
Normal file
BIN
work_files/graphics/sprites/fixtures/signal_pressure_plate.kra
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user