tiki torch correctly spawns; gotta check for collision

This commit is contained in:
minjaesong
2019-05-29 23:00:37 +09:00
parent c00a8235e1
commit ef72075fd6
3 changed files with 13 additions and 12 deletions

View File

@@ -10,9 +10,12 @@ import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2016-06-17.
*/
open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0)) :
open class FixtureBase(blockBox0: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0), renderOrder: RenderOrder = RenderOrder.MIDDLE) :
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false), CuedByTerrainChange {
ActorWBMovable(renderOrder, immobileBody = true, usePhysics = false), CuedByTerrainChange {
var blockBox: BlockBox = blockBox0
protected set // something like TapestryObject will want to redefine this
private val world: GameWorld
get() = Terrarum.ingame!!.world
@@ -53,16 +56,16 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps
// 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, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
this.hitbox.setFromWidthHeight(posX * TSIZE + posXoff, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
// actually add this actor into the world
Terrarum.ingame!!.addNewActor(this)
return true // TODO for the tests' sake, just get fucking spawned
// TODO TESTING RESULTS SO FAR: tiki torch spawns but is not centred
}
/**
@@ -162,8 +165,8 @@ inline class BlockBoxProps(val flags: Int) {
/**
* To not define the blockbox, simply use BlockBox.NULL
*
* Null blockbox means the fixture won't bar any block placement. Fixtures like paintings will want to have such feature.
*
* Null blockbox means the fixture won't bar any block placement. Fixtures like paintings will want to have such feature. (e.g. torch placed on top; buried)
*
* @param collisionType Collision type defined in BlockBox.Companion
* @param width Width of the block box, tile-wise
* @param height Height of the block box, tile-wise

View File

@@ -13,9 +13,7 @@ import java.util.*
/**
* Created by minjaesong on 2016-06-17.
*/
internal class FixtureTikiTorch : FixtureBase(
BlockBox(BlockBox.NO_COLLISION, 1, 2)
), Luminous {
internal class FixtureTikiTorch : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 2)), Luminous {
override var color: Color
get() = BlockCodex[Block.TORCH].luminosity

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
* Created by minjaesong on 2017-01-07.
*/
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String) :
FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1)) // placeholder blockbox
FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1), renderOrder = RenderOrder.BEHIND) // placeholder blockbox
{
// physics = false only speeds up for ~2 frames with 50 tapestries
@@ -28,7 +28,7 @@ class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String)
// you CAN'T destroy the image
// redefine blockbox
blockBox.redefine(texture.width.div(TILE_SIZEF).ceilInt(), texture.height.div(TILE_SIZEF).ceilInt())
blockBox = BlockBox(BlockBox.NO_COLLISION, texture.width.div(TILE_SIZEF).ceilInt(), texture.height.div(TILE_SIZEF).ceilInt())
}
override fun update(delta: Float) {