mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
modulecomputers: alsmost working terrain rader
This commit is contained in:
Binary file not shown.
@@ -43,7 +43,7 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
|
||||
private val vm = VM(32768, TheRealWorld(), arrayOf(
|
||||
private val vm = VM(73728, TheRealWorld(), arrayOf(
|
||||
VMProgramRom(ModMgr.getPath("dwarventech", "bios/pipboot.rom")),
|
||||
VMProgramRom(ModMgr.getPath("dwarventech", "bios/pipcode.bas"))
|
||||
))
|
||||
@@ -59,6 +59,7 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
|
||||
ExtDisp(vm, 160, 140), 32768, 1, 0
|
||||
)
|
||||
|
||||
// MMIO stops working when somethingStream is not defined
|
||||
vm.getPrintStream = { System.out }
|
||||
vm.getErrorStream = { System.err }
|
||||
vm.getInputStream = { System.`in` }
|
||||
@@ -100,7 +101,7 @@ class WearableWorldRadarUI(val device: VM) : UICanvas() {
|
||||
batch.end()
|
||||
|
||||
batch.color = Color.WHITE
|
||||
(device.peripheralTable[1].peripheral as? ExtDisp)?.render(batch, posX.toFloat(), posY.toFloat())
|
||||
(device.peripheralTable[1].peripheral as? ExtDisp)?.render(batch, posX.toFloat(), posY.toFloat(), true)
|
||||
|
||||
batch.begin()
|
||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.torvald.terrarum.modulecomputers.tsvmperipheral
|
||||
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.Point2i
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
@@ -15,8 +14,8 @@ import java.io.ByteArrayOutputStream
|
||||
*/
|
||||
class WorldRadar : BlockTransferInterface(false, true) {
|
||||
|
||||
private val W = 162
|
||||
private val H = 142
|
||||
private val W = 160
|
||||
private val H = 140
|
||||
|
||||
private val AIR_OUT = 0.toByte()
|
||||
private val GRASS_OUT = 2.toByte()
|
||||
@@ -96,22 +95,26 @@ class WorldRadar : BlockTransferInterface(false, true) {
|
||||
val px = it.intTilewiseHitbox.canonicalX.toInt()
|
||||
val py = it.intTilewiseHitbox.canonicalY.toInt()
|
||||
|
||||
for (y in 1..H - 2) {
|
||||
for (x in 1..W - 2) {
|
||||
val yx = (y - 1).shl(8) or x
|
||||
val nearby = getNearbyTilesPos(px, py).map { ingame.world.getTileFromTerrain(it.x, it.y) } // up, left, right, down
|
||||
val block = ingame.world.getTileFromTerrain(px, py)
|
||||
for (yy in 1..H) {
|
||||
for (xx in 1..W) {
|
||||
val tx = px - (W/2) + xx
|
||||
val ty = py - (H/2) + yy
|
||||
|
||||
val yx = (yy - 1).shl(8) or xx
|
||||
val nearby = getNearbyTilesPos(tx, ty).map { ingame.world.getTileFromTerrain(it.x, it.y) } // up, left, right, down
|
||||
val block = ingame.world.getTileFromTerrain(tx, ty)
|
||||
val blockprop = Terrarum.blockCodex[block]
|
||||
|
||||
if (blockprop.isSolid) {
|
||||
// TODO create extension function nearby.contains { predicate :: ItemID -> Boolean }
|
||||
if (blockprop.material == "GRSS" && nearby.contains(Block.AIR)) {
|
||||
// for some reason I can't use material?
|
||||
if (block == Block.GRASS && nearby.contains(Block.AIR)) {
|
||||
cmdbuf[yx] = GRASS_OUT
|
||||
}
|
||||
else if (blockprop.material == "DIRT" && nearby.contains(Block.AIR)) {
|
||||
else if (block == Block.DIRT && nearby.contains(Block.AIR)) {
|
||||
cmdbuf[yx] = DIRT_OUT
|
||||
}
|
||||
else if (blockprop.material == "ROCK" && (nearby.contains(Block.AIR) || nearby.contains(Block.GRASS) || nearby.contains(Block.DIRT))) {
|
||||
else if (block == Block.STONE && (nearby.contains(Block.AIR) || nearby.contains(Block.GRASS) || nearby.contains(Block.DIRT))) {
|
||||
cmdbuf[yx] = STONE_OUT
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
20 s=cput(1,"POLL")
|
||||
30 if s><0 then goto 900
|
||||
40 l=cget(1,0)
|
||||
41 print("length: "+l+", pixels: "+l/3)
|
||||
41 REM print("length: "+l+", pixels: "+l/3)
|
||||
50 for i=0 to l-1 step 3
|
||||
60 m=peek(i)*160+peek(i+1)
|
||||
62 p=peek(i+2)
|
||||
@@ -11,3 +11,4 @@
|
||||
80 REM poke(-1070977,0)
|
||||
90 goto 20
|
||||
900 print("Polling failed: "+s)
|
||||
910 goto 10
|
||||
|
||||
Reference in New Issue
Block a user