axle test with test-motor

This commit is contained in:
minjaesong
2024-10-03 21:35:52 +09:00
parent dd643005a4
commit 0e58879216
10 changed files with 133 additions and 7 deletions

View File

@@ -57,7 +57,7 @@ id;classname;tags
56;net.torvald.terrarum.modulebasegame.gameitems.ItemClayBrick;
57;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPushbutton;FIXTURE,SIGNAL
58;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPressurePlate;FIXTURE,SIGNAL
59;net.torvald.terrarum.modulebasegame.gameitems.ItemInductionMotor;FIXTURE,POWER,KINETIC
# ingots
1 id classname tags
57 57 net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPushbutton FIXTURE,SIGNAL
58 58 net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalPressurePlate FIXTURE,SIGNAL
59 # ingots 59 net.torvald.terrarum.modulebasegame.gameitems.ItemInductionMotor FIXTURE,POWER,KINETIC
60 112 # ingots
61 113 112 net.torvald.terrarum.modulebasegame.gameitems.IngotIron net.torvald.terrarum.modulebasegame.gameitems.IngotCopper INGOT
62 114 113 net.torvald.terrarum.modulebasegame.gameitems.ItemCoalCoke net.torvald.terrarum.modulebasegame.gameitems.IngotIron COMBUSTIBLE INGOT
63 115 114 net.torvald.terrarum.modulebasegame.gameitems.IngotZinc net.torvald.terrarum.modulebasegame.gameitems.ItemCoalCoke INGOT COMBUSTIBLE

Binary file not shown.

View File

@@ -1055,3 +1055,4 @@ fun <S, T> List<S>.cartesianProduct(other: List<T>) = this.flatMap { thisIt ->
fun Float.ditherToInt() = (this + Math.random() - 0.5).roundToInt()
fun Double.ditherToInt() = (this + Math.random() - 0.5).roundToInt()
fun Double.ditherToLong() = (this + Math.random() - 0.5).roundToLong()

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.App.UPDATE_RATE
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameitems.ItemID
@@ -11,6 +12,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.WireEmissionType
import net.torvald.terrarum.ui.Toolkit
import kotlin.math.cos
import kotlin.math.roundToLong
/**
* Created by minjaesong on 2024-03-05.
@@ -57,11 +59,33 @@ class WireActor : ActorWithBody, NoSerialise, InternalActor {
this.worldY = worldY
setPosition((worldX + 0.5) * TILE_SIZE, (worldY + 1.0) * TILE_SIZE - 1.0) // what the fuck?
(sprite as SheetSpriteAnimation).currentRow = 0
(sprite as SheetSpriteAnimation).currentFrame = cnx
}
override fun updateImpl(delta: Float) {
// axles: animate by changing currentRow
if (WireCodex.wireProps[wireID]?.accepts == "axle") {
val speed = world?.getWireEmitStateOf(worldX, worldY, wireID)?.x ?: 0.0
val targetTick = (App.TICK_SPEED / speed).let {
it.coerceIn(0.0, Long.MAX_VALUE.toDouble())
}.roundToLong()
val sprite = (sprite as SheetSpriteAnimation)
val cnx = sprite.currentFrame
val phaseShift = if (cnx == 5) (worldY % 2 == 0) else (worldX % 2 == 0)
if (targetTick > 0) {
(INGAME.WORLD_UPDATE_TIMER % (targetTick * 2)).let {
sprite.currentRow =
if (phaseShift)
(it < targetTick).toInt()
else
(it >= targetTick).toInt()
}
}
}
}
private fun essfun0(x: Double) = -cos(Math.PI * x) / 2.0 + 0.5
@@ -85,6 +109,10 @@ class WireActor : ActorWithBody, NoSerialise, InternalActor {
(sprite as SheetSpriteAnimation).currentRow = 1
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 0, alpha)
}
// axles?
else if (WireCodex.wireProps[wireID]?.accepts == "axle") {
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 0, Color.WHITE)
}
else {
(sprite as SheetSpriteAnimation).currentRow = 0
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 0, Color.WHITE)

View File

@@ -531,7 +531,7 @@ object WorldSimulator {
}
private fun calculateDecay(signal: Vector2, dist: Int, wire: ItemID, signalType: WireEmissionType): Vector2 {
val d = WireCodex.wireDecays[wire]!!
val d = WireCodex.wireDecays[wire] ?: 1.0
return signal * d.pow(dist.toDouble())
}

View File

@@ -0,0 +1,53 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 2024-10-03.
*/
class FixtureInductionMotor : Electric {
@Transient override val spawnNeedsFloor = true
@Transient override val spawnNeedsWall = false
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 1),
nameFun = { Lang["ITEM_INDUCTION_MOTOR"] }
)
init {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/induction_motor.tga")
density = 7874.0
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE, TILE_SIZE)).let {
it.setRowsAndFrames(1,1)
}
actorValue[AVKey.BASEMASS] = MASS
setWireEmitterAt(0, 0, "axle")
setWireEmissionAt(0, 0, Vector2(16.0, 1024.0)) // speed and torque
}
override fun updateSignal() {
setWireEmissionAt(0, 0, Vector2(16.0, 1024.0)) // speed and torque
}
override fun dispose() {
tooltipShowing.remove(tooltipHash)
}
companion object {
const val MASS = 20.0
}
}

View File

@@ -0,0 +1,37 @@
package net.torvald.terrarum.modulebasegame.gameitems
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInductionMotor
/**
* Created by minjaesong on 2024-10-03.
*/
class ItemInductionMotor(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureInductionMotor") {
override var dynamicID: ItemID = originalID
override var baseMass = FixtureInductionMotor.MASS
override val canBeDynamic = false
override val materialId = ""
init {
itemImage = getItemImageFromSheet("basegame", "sprites/fixtures/induction_motor.tga", TILE_SIZE, TILE_SIZE)
}
override var baseToolSize: Double? = baseMass
override var originalName = "ITEM_INDUCTION_MOTOR"
override var inventoryCategory = Category.FIXTURE
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
super.effectWhileEquipped(actor, delta)
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "axle"
}
override fun effectOnUnequip(actor: ActorWithBody) {
super.effectOnUnequip(actor)
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
}
}

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import kotlin.math.roundToInt
@@ -47,6 +48,7 @@ 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())
}
@@ -98,8 +100,6 @@ class UIQuickslotBar : UICanvas() {
private val drawColor = Color(1f, 1f, 1f, 1f)
private val itemCntTextCol = Color(0x404040ff)
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.let { actor ->
@@ -139,7 +139,7 @@ class UIQuickslotBar : UICanvas() {
}
else if (item.stackable) {
val amountString = qs!!.qty.toItemCountText()
batch.color = Color(0xfff066_ff.toInt())
batch.color = QUICKSLOT_ITEMCOUNT_TEXTCOL
val textLen = amountString.length * App.fontSmallNumbers.W
val y = slotY + 25 - App.fontSmallNumbers.H
val x = slotX - 19 + (38 - textLen) / 2

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.QUICKSLOT_ITEMCOUNT_TEXTCOL
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
@@ -110,7 +111,7 @@ class UIQuickslotPie : UICanvas() {
}
else if (item.stackable) {
val amountString = qs!!.qty.toItemCountText()
batch.color = Color(0xfff066_ff.toInt())
batch.color = QUICKSLOT_ITEMCOUNT_TEXTCOL
val textLen = amountString.length * App.fontSmallNumbers.W
val y = slotY + 25 - App.fontSmallNumbers.H
val x = slotX - 19 + (38 - textLen) / 2

Binary file not shown.