mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
tapestry now spawns thanks to all the code that made door to spawn correctly
This commit is contained in:
@@ -130,7 +130,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
// using the actor's hitbox
|
||||
|
||||
|
||||
val posX = (posX0 - blockBox.width.div(2)) fmod world!!.width
|
||||
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||
val posY = posY0 - blockBox.height + 1
|
||||
|
||||
// set the position of this actor
|
||||
@@ -184,7 +184,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
* @return true if successfully spawned, false if was not (e.g. space to spawn is occupied by something else)
|
||||
*/
|
||||
open fun spawn(posX0: Int, posY0: Int, thbw: Int, thbh: Int): Boolean {
|
||||
val posX = (posX0 - thbw.div(2)) fmod world!!.width
|
||||
val posX = (posX0 - thbw.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||
val posY = posY0 - thbh + 1
|
||||
|
||||
// set the position of this actor
|
||||
@@ -238,7 +238,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
*/
|
||||
open fun despawn() {
|
||||
|
||||
if (this !is FixtureTapestry && canBeDespawned) {
|
||||
if (canBeDespawned) {
|
||||
printdbg(this, "despawn at T${INGAME.WORLD_UPDATE_TIMER}: ${nameFun()}")
|
||||
printStackTrace(this)
|
||||
|
||||
@@ -259,7 +259,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// printdbg(this, "despawn at T${INGAME.WORLD_UPDATE_TIMER}: ${nameFun()}")
|
||||
printdbg(this, "failed to despawn at T${INGAME.WORLD_UPDATE_TIMER}: ${nameFun()}")
|
||||
printdbg(this, "cannot despawn a fixture with non-empty inventory")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-01-07.
|
||||
@@ -18,12 +19,15 @@ internal class FixtureTapestry : FixtureBase {
|
||||
var artName = ""; private set
|
||||
var artAuthor = ""; private set
|
||||
|
||||
val tw = 1
|
||||
val th = 1
|
||||
// val tw = 1
|
||||
// val th = 1
|
||||
|
||||
private var rawBytes = ByteArray(tw * th * 256)
|
||||
private var rawBytes = ByteArray(256)
|
||||
private var frameBlock: ItemID = Block.PLANK_NORMAL
|
||||
|
||||
private var tilewiseHitboxWidth by Delegates.notNull<Int>()
|
||||
private var tilewiseHitboxHeight by Delegates.notNull<Int>()
|
||||
|
||||
private constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
||||
renderOrder = RenderOrder.BEHIND,
|
||||
@@ -40,6 +44,8 @@ internal class FixtureTapestry : FixtureBase {
|
||||
reload()
|
||||
}
|
||||
|
||||
override fun spawn(posX: Int, posY: Int) = spawn(posX, posY, tilewiseHitboxWidth, tilewiseHitboxHeight)
|
||||
|
||||
override fun reload() {
|
||||
super.reload()
|
||||
|
||||
@@ -61,8 +67,8 @@ internal class FixtureTapestry : FixtureBase {
|
||||
Pixmap(ModMgr.getGdxFilesFromEveryMod("tapestries/common/canvas.tga").last().second)
|
||||
} as Pixmap
|
||||
|
||||
val tw = pixmap.width.div(TILE_SIZEF).ceilInt()
|
||||
val th = pixmap.height.div(TILE_SIZEF).ceilInt()
|
||||
tilewiseHitboxWidth = pixmap.width.div(TILE_SIZEF).ceilInt()
|
||||
tilewiseHitboxHeight = pixmap.height.div(TILE_SIZEF).ceilInt()
|
||||
|
||||
// blend canvas texture
|
||||
for (y in 0 until pixmap.height) { for (x in 0 until pixmap.width) {
|
||||
@@ -72,9 +78,9 @@ internal class FixtureTapestry : FixtureBase {
|
||||
} }
|
||||
|
||||
// draw frame
|
||||
for (ty in 0 until th) { for (tx in 0 until tw) {
|
||||
val srcx = TILE_SIZE * (if (tw == 1) 0 else if (tx == 0) 1 else if (tx == tw - 1) 3 else 2)
|
||||
val srcy = TILE_SIZE * (if (th == 1) 0 else if (ty == 0) 1 else if (ty == th - 1) 3 else 2)
|
||||
for (ty in 0 until tilewiseHitboxHeight) { for (tx in 0 until tilewiseHitboxWidth) {
|
||||
val srcx = TILE_SIZE * (if (tilewiseHitboxWidth == 1) 0 else if (tx == 0) 1 else if (tx == tilewiseHitboxWidth - 1) 3 else 2)
|
||||
val srcy = TILE_SIZE * (if (tilewiseHitboxHeight == 1) 0 else if (ty == 0) 1 else if (ty == tilewiseHitboxHeight - 1) 3 else 2)
|
||||
val dstx = tx * TILE_SIZE
|
||||
val dsty = ty * TILE_SIZE
|
||||
pixmap.drawPixmap(frame, srcx, srcy, TILE_SIZE, TILE_SIZE, dstx, dsty, TILE_SIZE, TILE_SIZE)
|
||||
@@ -90,7 +96,7 @@ internal class FixtureTapestry : FixtureBase {
|
||||
setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
||||
|
||||
// redefine blockbox
|
||||
this.blockBox = BlockBox(BlockBox.NO_COLLISION, tw, th)
|
||||
this.blockBox = BlockBox(BlockBox.NO_COLLISION, tilewiseHitboxWidth, tilewiseHitboxHeight)
|
||||
this.renderOrder = RenderOrder.BEHIND
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user