blockprop: fall is now grav

This commit is contained in:
minjaesong
2019-06-11 20:55:28 +09:00
parent 196ae40bbb
commit 23b103892e
11 changed files with 139 additions and 137 deletions

View File

@@ -128,7 +128,7 @@ object BlockCodex {
//prop.isClear = boolVal(record, "clear")
prop.isPlatform = boolVal(record, "plat")
prop.isWallable = boolVal(record, "wall")
prop.isFallable = boolVal(record, "fall")
prop.maxSupport = intVal(record, "grav")
prop.isVertFriction = boolVal(record, "fv")
prop.dynamicLuminosityFunction = intVal(record, "dlfn")

View File

@@ -46,7 +46,7 @@ class BlockProp {
var drop: Int = 0
var isFallable: Boolean = false
var maxSupport: Int? = null
var friction: Int = 0

View File

@@ -28,7 +28,7 @@ import java.util.Properties;
public class CSVEditor extends JFrame {
/** Default columns. When you open existing csv, it should overwrite this. */
private String[] columns = new String[]{"id", "drop", "name", "shdr", "shdg", "shdb", "shduv", "str", "dsty", "mate", "solid", "plat", "wall", "fall", "dlfn", "fv", "fr", "lumr", "lumg", "lumb", "lumuv", "colour", "vscs"};
private String[] columns = new String[]{"id", "drop", "name", "shdr", "shdg", "shdb", "shduv", "str", "dsty", "mate", "solid", "plat", "wall", "grav", "dlfn", "fv", "fr", "lumr", "lumg", "lumb", "lumuv", "colour", "vscs"};
private final int FOUR_DIGIT = 42;
private final int SIX_DIGIT = 50;
private final int TWO_DIGIT = 30;
@@ -496,7 +496,7 @@ public class CSVEditor extends JFrame {
"solid=Whether the file has full collision\n" +
"plat=Whether the block should behave like a platform\n" +
"wall=Whether the block can be used as a wall\n" +
"fall=Whether the block should fall through the empty space\n" +
"grav=Whether the block should fall through the empty space. N/A to not make it fall; 0 to fall immediately (e.g. Sand), nonzero to indicate that number of floating blocks can be supported (e.g. Scaffolding)\n" +
"dlfn=Dynamic Light Function. 0=Static. Please see <strong>notes</strong>\n" +
"fv=Vertical friction when player slide on the cliff. 0 means not slide-able\n" +
"fr=Horizontal friction. &lt;16:slippery 16:regular &gt;16:sticky\n" +

View File

@@ -67,30 +67,30 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
override val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double;
/** half integer tilewise hitbox.
* May hold width/height of zero; the end point should be inclusive!
* Used by physics-related shits.
*
* e.g. USE `for (x in hitbox.startX..hitbox.endX)`, NOT `for (x in hitbox.startX until hitbox.endX)`
*/ // got the idea from gl_FragCoord
val hIntTilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints(
hitbox.startX.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.startY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.endX.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.startX.plus(0.00001).div(TILE_SIZE).floor() + 0.5,
hitbox.startY.plus(0.00001).div(TILE_SIZE).floor() + 0.5,
hitbox.endX.plus(0.00001).div(TILE_SIZE).floor() + 0.5,
hitbox.endY.plus(0.00001).div(TILE_SIZE).floor() + 0.5,
true
)
/** May hold width/height of zero; the end point should be inclusive!
/** Used by non-physics shits. (e.g. BlockBase determining "occupied" blocks)
*
* e.g. USE `for (x in hitbox.startX..hitbox.endX)`, NOT `for (x in hitbox.startX until hitbox.endX)`
*/
val intTilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints(
hitbox.startX.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.startY.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.endX.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.startX.div(TILE_SIZE).floor(),
hitbox.startY.div(TILE_SIZE).floor(),
hitbox.endX.minus(0.00001).div(TILE_SIZE).floor(),
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor(),
true
)
@@ -1365,7 +1365,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
if (KeyToggler.isOn(Input.Keys.F9)) {
val blockMark = AppLoader.resourcePool.getAsTextureRegionPack("blockmarkings_common").get(0, 0)
batch.color = HITBOX_COLOURS[0]
batch.color = HITBOX_COLOURS0
for (y in 0..intTilewiseHitbox.height.toInt()) {
for (x in 0..intTilewiseHitbox.width.toInt()) {
batch.draw(blockMark,
@@ -1646,7 +1646,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
return if (Math.abs(x) > ceil) ceil else x
}
@Transient private val HITBOX_COLOURS = arrayOf(Color(0xFF00FF88.toInt()), Color(0xFFFF0088.toInt()))
@Transient private val HITBOX_COLOURS0 = Color(0xFF00FF88.toInt())
@Transient private val HITBOX_COLOURS1 = Color(0xFFFF0088.toInt())
}
// gameplay-related actorvalue macros

View File

@@ -226,7 +226,7 @@ import org.luaj.vm2.LuaValue
val tile = BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(x, y) ?: Block.NULL]
val solidity = tile.isSolid.toInt()
val liquidity = tile.isFluid.toInt()
val gravity = tile.isFallable.toInt()
val gravity = tile.maxSupport.toInt()
val tileFlag: Int = gravity.shl(2) + liquidity.shl(1) + solidity
luatable[y - feetTilePos[1]][x - feetTilePos[0]] = tileFlag.toLua()

View File

@@ -44,7 +44,10 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
init {
if (!unsafeArrayInitialised) {
unsafe.setMemory(layerPtr, width * height * BYTES_PER_BLOCK.toLong(), 0)
//unsafe.setMemory(layerPtr, width * height * BYTES_PER_BLOCK.toLong(), 0) // sometimes does not work?!
for (i in 0 until width * height * BYTES_PER_BLOCK.toLong()) {
unsafe.putByte(layerPtr + i, 0)
}
unsafeArrayInitialised = true
}
}

View File

@@ -80,10 +80,8 @@ open class FixtureBase(blockBox0: BlockBox, val blockBoxProps: BlockBoxProps = B
// set the position of this actor
worldBlockPos = Point2i(posX, posY)
val posXoff = (TSIZE % (this.sprite?.cellWidth ?: 0)) / 2
this.isVisible = true
this.hitbox.setFromWidthHeight(posX * TSIZE + posXoff, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
this.hitbox.setFromWidthHeight(posX * TSIZE, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
// actually add this actor into the world
Terrarum.ingame!!.addNewActor(this)

View File

@@ -26,10 +26,10 @@ internal class FixtureTikiTorch : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1,
init {
density = 1200.0
setHitboxDimension(10, 24, 0, 0)
setHitboxDimension(16, 32, 0, 0)
lightBoxList = ArrayList(1)
lightBoxList.add(Hitbox(3.0, 0.0, 4.0, 3.0))
lightBoxList.add(Hitbox(6.0, 5.0, 4.0, 3.0))
makeNewSprite(TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 10, 27))
sprite!!.setRowsAndFrames(1, 1)

View File

@@ -254,7 +254,7 @@ object WorldSimulator {
val tile = world.getTileFromTerrain(x, y) ?: Block.STONE
val tileBelow = world.getTileFromTerrain(x, y + 1) ?: Block.STONE
if (tile.isFallable()) {
if (tile.maxSupport()) {
// displace fluid. This statement must precede isSolid()
if (tileBelow.isFluid()) {
// remove tileThis to create air pocket
@@ -316,7 +316,7 @@ object WorldSimulator {
}
fun Int.isFallable() = BlockCodex[this].isFallable
fun Int.isFallable() = BlockCodex[this].maxSupport