mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-10 13:51:53 +09:00
some changes regarding actorblocks
This commit is contained in:
@@ -131,12 +131,4 @@ object Block {
|
||||
|
||||
const val NULL = "basegame:-1"
|
||||
|
||||
val actorblocks = listOf(
|
||||
ACTORBLOCK_TILING_PLACEHOLDER,
|
||||
ACTORBLOCK_NO_COLLISION,
|
||||
ACTORBLOCK_FULL_COLLISION,
|
||||
ACTORBLOCK_ALLOW_MOVE_DOWN,
|
||||
ACTORBLOCK_NO_PASS_RIGHT,
|
||||
ACTORBLOCK_NO_PASS_LEFT
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import java.nio.file.FileSystems
|
||||
import net.torvald.terrarum.App
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.Path
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-07.
|
||||
@@ -10,7 +11,7 @@ internal object Batch : ConsoleCommand {
|
||||
@Throws(Exception::class)
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
Files.lines(FileSystems.getDefault().getPath(args[1])).forEach(
|
||||
Files.lines(Path(App.defaultDir, args[1])).forEach(
|
||||
{ CommandInterpreter.execute(it) })
|
||||
}
|
||||
else {
|
||||
@@ -19,6 +20,6 @@ internal object Batch : ConsoleCommand {
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: batch path/to/batch.txt")
|
||||
Echo("Usage: batch path/to/batch.txt relative to the app data folder")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1281,7 +1281,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
else if (canAttackOrDig) {
|
||||
val punchBlockSize = punchSize.div(TILE_SIZED).floorInt()
|
||||
if (punchBlockSize > 0) {
|
||||
PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize, false)
|
||||
PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
|
||||
/** Real time, in nanoseconds */
|
||||
@Transient var spawnRequestedTime: Long = 0L
|
||||
private set
|
||||
protected set
|
||||
|
||||
lateinit var blockBox: BlockBox // something like TapestryObject will want to redefine this
|
||||
fun blockBoxIndexToPoint2i(it: BlockBoxIndex): Point2i = this.blockBox.width.let { w -> Point2i(it % w, it / w) }
|
||||
@@ -74,7 +74,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
* Tile-wise position of this fixture when it's placed on the world, top-left origin. Null if it's not on the world
|
||||
*/
|
||||
var worldBlockPos: Point2i? = null
|
||||
private set
|
||||
protected set
|
||||
|
||||
// something like TapestryObject will want to redefine this
|
||||
/**
|
||||
@@ -138,7 +138,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
for (y in posY until posY + blockBox.height) {
|
||||
for (x in posX until posX + blockBox.width) {
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (BlockCodex[tile].isSolid || tile in Block.actorblocks) {
|
||||
if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) {
|
||||
hasCollision = true
|
||||
break@checkForCollision
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Lightbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
@@ -37,14 +38,89 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous {
|
||||
|
||||
protected var doorState = 0 // -1: open toward left, 0: closed, 1: open toward right
|
||||
|
||||
@Transient private var placeActorBlockLatch = false
|
||||
// @Transient private var placeActorBlockLatch = false
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.FULL_COLLISION, 1, 3), // temporary value, will be overwritten by reload()
|
||||
nameFun = { "item not loaded properly, alas!" }
|
||||
) {
|
||||
val hbw = TILE_SIZE * (tw * 2 - twClosed)
|
||||
val hbh = TILE_SIZE * th
|
||||
|
||||
nameFun = customNameFun
|
||||
|
||||
density = 1200.0
|
||||
actorValue[AVKey.BASEMASS] = 10.0
|
||||
|
||||
// loading textures
|
||||
CommonResourcePool.addToLoadingList("$moduleName-$textureIdentifier") {
|
||||
TextureRegionPack(ModMgr.getGdxFile(moduleName, texturePath), hbw, hbh)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
makeNewSprite(FixtureBase.getSpritesheet(moduleName, texturePath, hbw, hbh)).let {
|
||||
it.setRowsAndFrames(3,1)
|
||||
}
|
||||
|
||||
// define light/shadebox
|
||||
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add(
|
||||
Lightbox(Hitbox(0.0, 0.0, TILE_SIZED, th * TILE_SIZED), opacity))
|
||||
|
||||
reload()
|
||||
placeActorBlockLatch = true
|
||||
}
|
||||
|
||||
override fun spawn(posX: Int, posY: Int) = spawn(posX, posY, TILE_SIZE * (tw * 2 - twClosed), TILE_SIZE * th)
|
||||
|
||||
// TODO move this function over FixtureBase once it's done and perfected
|
||||
protected fun spawn(posX: Int, posY: Int, hbw: Int, hbh: Int): Boolean {
|
||||
// wrap x-position
|
||||
val posX = posX fmod world!!.width
|
||||
|
||||
// define physical size
|
||||
setHitboxDimension(hbw, hbh, 0, 0)
|
||||
/*this.hitbox.setFromWidthHeight(
|
||||
posX * TILE_SIZED,
|
||||
posY * TILE_SIZED,
|
||||
blockBox.width * TILE_SIZED,
|
||||
blockBox.height * TILE_SIZED
|
||||
)*/
|
||||
blockBox = BlockBox(BlockBox.FULL_COLLISION, tw * 2 - twClosed, th)
|
||||
|
||||
// check for existing blocks (and fixtures)
|
||||
var hasCollision = false
|
||||
checkForCollision@
|
||||
for (y in posY until posY + blockBox.height) {
|
||||
for (x in posX until posX + blockBox.width) {
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) {
|
||||
hasCollision = true
|
||||
break@checkForCollision
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCollision) {
|
||||
printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; tilewise dim: (${blockBox.width}, ${blockBox.height}) ")
|
||||
return false
|
||||
}
|
||||
|
||||
printdbg(this, "spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, tilewise dim: (${blockBox.width}, ${blockBox.height})")
|
||||
|
||||
// set the position of this actor
|
||||
worldBlockPos = Point2i(posX - (hbw - 1) / 2, posY)
|
||||
|
||||
// fill the area with the filler blocks
|
||||
placeActorBlocks()
|
||||
|
||||
|
||||
this.isVisible = true
|
||||
|
||||
|
||||
// actually add this actor into the world
|
||||
INGAME.queueActorAddition(this)
|
||||
spawnRequestedTime = System.nanoTime()
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun reload() {
|
||||
@@ -55,28 +131,16 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous {
|
||||
val hbw = TILE_SIZE * (tw * 2 - twClosed)
|
||||
val hbh = TILE_SIZE * th
|
||||
|
||||
blockBox = BlockBox(BlockBox.FULL_COLLISION, tw * 2 - twClosed, th)
|
||||
// redefined things that are affected by sprite size
|
||||
// blockBox = BlockBox(BlockBox.FULL_COLLISION, tw * 2 - twClosed, th)
|
||||
|
||||
// loading textures
|
||||
CommonResourcePool.addToLoadingList("$moduleName-$textureIdentifier") {
|
||||
TextureRegionPack(ModMgr.getGdxFile(moduleName, texturePath), hbw, hbh)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
|
||||
density = 1200.0
|
||||
actorValue[AVKey.BASEMASS] = 10.0
|
||||
|
||||
// setHitboxDimension(hbw, hbh, TILE_SIZE * (tw * 2 - twClosed), 0)
|
||||
setHitboxDimension(hbw, hbh, TILE_SIZE * ((tw * 2 - twClosed - 1) / 2), 0)
|
||||
// setHitboxDimension(hbw, hbh, TILE_SIZE * ((tw * 2 - twClosed - 1) / 2), 0)
|
||||
|
||||
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add(
|
||||
Lightbox(Hitbox(0.0, 0.0, TILE_SIZED, th * TILE_SIZED), opacity))
|
||||
|
||||
makeNewSprite(FixtureBase.getSpritesheet(moduleName, texturePath, hbw, hbh)).let {
|
||||
it.setRowsAndFrames(3,1)
|
||||
}
|
||||
|
||||
placeActorBlockLatch = false
|
||||
// placeActorBlockLatch = false
|
||||
}
|
||||
|
||||
open protected fun closeDoor() {
|
||||
@@ -94,14 +158,14 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous {
|
||||
doorState = -1
|
||||
}
|
||||
|
||||
override fun forEachBlockbox(action: (Int, Int, Int, Int) -> Unit) {
|
||||
/*override fun forEachBlockbox(action: (Int, Int, Int, Int) -> Unit) {
|
||||
val xStart = worldBlockPos!!.x - ((tw * 2 - twClosed - 1) / 2) // worldBlockPos.x is where the mouse was, of when the tilewise width was 1.
|
||||
for (y in worldBlockPos!!.y until worldBlockPos!!.y + blockBox.height) {
|
||||
for (x in xStart until xStart + blockBox.width) {
|
||||
action(x, y, x - xStart, y - worldBlockPos!!.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
override fun placeActorBlocks() {
|
||||
forEachBlockbox { x, y, ox, oy ->
|
||||
@@ -131,10 +195,10 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous {
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
if (placeActorBlockLatch) {
|
||||
/*if (placeActorBlockLatch) {
|
||||
placeActorBlockLatch = false
|
||||
placeActorBlocks()
|
||||
}
|
||||
}*/
|
||||
|
||||
super.update(delta)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ object PickaxeCore {
|
||||
*/
|
||||
fun startPrimaryUse(
|
||||
actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int,
|
||||
dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1, attackActorBlocks: Boolean = true
|
||||
dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1
|
||||
) = mouseInInteractableRangeTools(actor, item) {
|
||||
// un-round the mx
|
||||
val ww = INGAME.world.width
|
||||
@@ -67,7 +67,7 @@ object PickaxeCore {
|
||||
if (!ret1) return ret1*/
|
||||
|
||||
// return false if here's no tile
|
||||
if (Block.AIR == tile || (!attackActorBlocks && tile in Block.actorblocks)) {
|
||||
if (Block.AIR == tile || BlockCodex[tile].isActorBlock) {
|
||||
usageStatus = usageStatus or false
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user