mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
WIP removing fluid marker block
see "work_files/todo_platforms.png"
This commit is contained in:
@@ -2,12 +2,11 @@
|
|||||||
package net.torvald.terrarum.gameworld
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.blockproperties.Fluid
|
import net.torvald.terrarum.blockproperties.Fluid
|
||||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
|
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
|
||||||
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import net.torvald.terrarum.serialise.ReadLayerDataLzma
|
import net.torvald.terrarum.serialise.ReadLayerDataLzma
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
@@ -367,7 +366,7 @@ open class GameWorld {
|
|||||||
val addr = LandUtil.getBlockAddr(this, x, y)
|
val addr = LandUtil.getBlockAddr(this, x, y)
|
||||||
|
|
||||||
if (fill > WorldSimulator.FLUID_MIN_MASS) {
|
if (fill > WorldSimulator.FLUID_MIN_MASS) {
|
||||||
setTileTerrain(x, y, fluidTypeToBlock(fluidType))
|
//setTileTerrain(x, y, fluidTypeToBlock(fluidType))
|
||||||
fluidFills[addr] = fill
|
fluidFills[addr] = fill
|
||||||
fluidTypes[addr] = fluidType
|
fluidTypes[addr] = fluidType
|
||||||
}
|
}
|
||||||
@@ -377,7 +376,7 @@ open class GameWorld {
|
|||||||
|
|
||||||
// if old tile was fluid
|
// if old tile was fluid
|
||||||
if (BlockCodex[getTileFromTerrain(x, y) ?: Block.STONE].isFluid) {
|
if (BlockCodex[getTileFromTerrain(x, y) ?: Block.STONE].isFluid) {
|
||||||
setTileTerrain(x, y, Block.AIR)
|
//setTileTerrain(x, y, Block.AIR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +402,8 @@ open class GameWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class FluidInfo(val type: FluidType, val amount: Float) {
|
data class FluidInfo(val type: FluidType, val amount: Float) {
|
||||||
|
/** test if this fluid should be considered as one */
|
||||||
|
fun isFluid() = type != Fluid.NULL && amount >= WorldSimulator.FLUID_MIN_MASS
|
||||||
override fun toString() = "Fluid type: ${type.value}, amount: $amount"
|
override fun toString() = "Fluid type: ${type.value}, amount: $amount"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,22 @@ open class FixtureBase(val blockBox: BlockBox) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class BlockBox(val collisionType: Int, val width: Int, val height: Int) {
|
data class BlockBox(var collisionType: Int, var width: Int, var height: Int) {
|
||||||
|
|
||||||
|
fun redefine(collisionType: Int, width: Int, height: Int) {
|
||||||
|
redefine(collisionType)
|
||||||
|
redefine(width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun redefine(width: Int, height: Int) {
|
||||||
|
this.width = width
|
||||||
|
this.height = height
|
||||||
|
}
|
||||||
|
|
||||||
|
fun redefine(collisionType: Int) {
|
||||||
|
this.collisionType = collisionType
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val NO_COLLISION = Block.ACTORBLOCK_NO_COLLISION
|
const val NO_COLLISION = Block.ACTORBLOCK_NO_COLLISION
|
||||||
const val FULL_COLLISION = Block.ACTORBLOCK_FULL_COLLISION
|
const val FULL_COLLISION = Block.ACTORBLOCK_FULL_COLLISION
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ import com.badlogic.gdx.graphics.Pixmap
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.ceilInt
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-01-07.
|
* Created by minjaesong on 2017-01-07.
|
||||||
*/
|
*/
|
||||||
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(physics = false) {
|
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String) :
|
||||||
|
FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1)) // placeholder blockbox
|
||||||
|
{
|
||||||
|
|
||||||
// physics = false only speeds up for ~2 frames with 50 tapestries
|
// physics = false only speeds up for ~2 frames with 50 tapestries
|
||||||
|
|
||||||
@@ -24,6 +26,9 @@ class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String)
|
|||||||
setHitboxDimension(texture.width, texture.height, 0, 0)
|
setHitboxDimension(texture.width, texture.height, 0, 0)
|
||||||
setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
// you CAN'T destroy the image
|
// you CAN'T destroy the image
|
||||||
|
|
||||||
|
// redefine blockbox
|
||||||
|
blockBox.redefine(texture.width.div(TILE_SIZEF).ceilInt(), texture.height.div(TILE_SIZEF).ceilInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-09-08.
|
* Created by minjaesong on 2016-09-08.
|
||||||
*/
|
*/
|
||||||
class FixtureBasicTerminal(phosphor: Color) : FixtureBase() {
|
class FixtureBasicTerminal(phosphor: Color) : FixtureBase(BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1)) {
|
||||||
|
|
||||||
/*val computer = TerrarumComputer(8)
|
/*val computer = TerrarumComputer(8)
|
||||||
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)
|
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
|
||||||
|
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-09-08.
|
* Created by minjaesong on 2016-09-08.
|
||||||
*/
|
*/
|
||||||
open class FixtureComputerBase : FixtureBase() {
|
open class FixtureComputerBase : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1)) {
|
||||||
|
|
||||||
/** Connected terminal */
|
/** Connected terminal */
|
||||||
var terminal: FixtureBasicTerminal? = null
|
var terminal: FixtureBasicTerminal? = null
|
||||||
@@ -18,7 +18,6 @@ open class FixtureComputerBase : FixtureBase() {
|
|||||||
actorValue["computerid"] = "none"
|
actorValue["computerid"] = "none"
|
||||||
|
|
||||||
|
|
||||||
collisionFlag = COLLISION_PLATFORM
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|||||||
@@ -400,28 +400,7 @@ internal object BlocksDrawer {
|
|||||||
*
|
*
|
||||||
* As a consequence, fluids.tga must have the same width as tiles.tga.
|
* As a consequence, fluids.tga must have the same width as tiles.tga.
|
||||||
*/
|
*/
|
||||||
private fun GameWorld.FluidInfo.toFluidTile(): Int {
|
private fun GameWorld.FluidInfo.toTileInFluidAtlas(): Int {
|
||||||
/*
|
|
||||||
val fluid = world.getFluid(x, y)
|
|
||||||
|
|
||||||
if (AppLoader.IS_DEVELOPMENT_BUILD && fluid.type == Fluid.NULL && fluid.amount != 0f) {
|
|
||||||
throw Error("Illegal fluid at ($x,$y): $fluid")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fluid.amount >= WorldSimulator.FLUID_MIN_MASS) {
|
|
||||||
val fluidLevel = fluid.amount.coerceIn(0f,1f).times(PairedMapLayer.RANGE - 1).roundToInt()
|
|
||||||
val baseTileID = (GameWorld.TILES_SUPPORTED) - fluid.type.abs()
|
|
||||||
val tileX = fluidLevel + (baseTileID % 16) * PairedMapLayer.RANGE
|
|
||||||
val tileY = baseTileID / 16
|
|
||||||
|
|
||||||
//printdbg(this, "$fluid")
|
|
||||||
//printdbg(this, "$fluidLevel, $baseTileID, $tileX, $tileY")
|
|
||||||
|
|
||||||
writeToBuffer(mode, bufferX, bufferY, tileX, tileY, 0)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
val fluidNum = this.type.abs()
|
val fluidNum = this.type.abs()
|
||||||
|
|
||||||
if (this.amount >= WorldSimulator.FLUID_MIN_MASS) {
|
if (this.amount >= WorldSimulator.FLUID_MIN_MASS) {
|
||||||
@@ -471,7 +450,7 @@ internal object BlocksDrawer {
|
|||||||
WALL -> world.getTileFromWall(x, y)
|
WALL -> world.getTileFromWall(x, y)
|
||||||
TERRAIN -> world.getTileFromTerrain(x, y)
|
TERRAIN -> world.getTileFromTerrain(x, y)
|
||||||
WIRE -> world.getTileFromWire(x, y)
|
WIRE -> world.getTileFromWire(x, y)
|
||||||
FLUID -> world.getFluid(x, y).toFluidTile()
|
FLUID -> world.getFluid(x, y).toTileInFluidAtlas()
|
||||||
else -> throw IllegalArgumentException()
|
else -> throw IllegalArgumentException()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,16 +557,19 @@ internal object BlocksDrawer {
|
|||||||
*/
|
*/
|
||||||
internal fun getNearbyTilesInfoFluids(x: Int, y: Int): Int {
|
internal fun getNearbyTilesInfoFluids(x: Int, y: Int): Int {
|
||||||
val nearbyTiles = IntArray(4)
|
val nearbyTiles = IntArray(4)
|
||||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFromTerrain(x - 1, y) ?: Block.NULL
|
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFromTerrain(x , y - 1) ?: Block.NULL
|
||||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFromTerrain(x + 1, y) ?: Block.NULL
|
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFromTerrain(x + 1, y) ?: Block.NULL
|
||||||
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFromTerrain(x , y - 1) ?: Block.NULL
|
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFromTerrain(x , y + 1) ?: Block.NULL
|
||||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFromTerrain(x , y + 1) ?: Block.NULL
|
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFromTerrain(x - 1, y) ?: Block.NULL
|
||||||
|
|
||||||
|
val nearX = intArrayOf(x, x+1, x, x-1)
|
||||||
|
val nearY = intArrayOf(y-1, y, y+1, y)
|
||||||
|
|
||||||
// try for
|
// try for
|
||||||
var ret = 0
|
var ret = 0
|
||||||
for (i in 0..3) {
|
for (i in 0..3) {
|
||||||
try {
|
try {
|
||||||
if (!BlockCodex[nearbyTiles[i]].isFluid &&
|
if (!world.getFluid(nearX[i], nearY[i]).isFluid() && // is not a fluid and...
|
||||||
!BlockCodex[nearbyTiles[i]].isSolid) {
|
!BlockCodex[nearbyTiles[i]].isSolid) {
|
||||||
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||||
}
|
}
|
||||||
@@ -601,7 +583,7 @@ internal object BlocksDrawer {
|
|||||||
val upTile = world.getTileFromTerrain(x , y - 1) ?: Block.NULL
|
val upTile = world.getTileFromTerrain(x , y - 1) ?: Block.NULL
|
||||||
return if (ret == 15 || ret == 10)
|
return if (ret == 15 || ret == 10)
|
||||||
ret
|
ret
|
||||||
else if (BlockCodex[upTile].isFluid)
|
else if (world.getFluid(x, y-1).isFluid())
|
||||||
0
|
0
|
||||||
else
|
else
|
||||||
1
|
1
|
||||||
|
|||||||
BIN
work_files/todo_platforms.png
Normal file
BIN
work_files/todo_platforms.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 KiB |
Reference in New Issue
Block a user