now dropped items can produce light (e.g. dropped torch)

This commit is contained in:
minjaesong
2022-09-11 17:10:01 +09:00
parent 430ad4e703
commit bec47e81e2
15 changed files with 140 additions and 140 deletions

View File

@@ -9,7 +9,6 @@ import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameitems.GameItem
@@ -28,7 +27,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2016-10-24.
*/
open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, LandHolder, HistoricalFigure {
protected constructor()
@@ -100,15 +99,10 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList: List<Lightbox>
get() = arrayOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), actorValueColour)).toList() // things are asymmetric!!
// use getter; dimension of the player may change by time.
// scaling of the lightbox is performed on the LightmapRenderer. Getter is still required because of the changing actorValueColour. Lightbox.light cannot be `() -> Cvec` due to performance and serialising issue.
override val shadeBoxList: List<Lightbox>
get() = arrayOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), actorValueShade)).toList() // things are asymmetric!!
// use getter; dimension of the player may change by time.
// scaling of the shadebox is performed on the LightmapRenderer. Getter is still required because of the changing actorValueColour. Lightbox.light cannot be `() -> Cvec` due to performance and serialising issue.
@Transient override var lightBoxList: List<Lightbox> = listOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), Cvec(0)))
// the actual values are update on the update()
@Transient override var shadeBoxList: List<Lightbox> = listOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), Cvec(0)))
// the actual values are update on the update()
@Transient val BASE_DENSITY = 980.0
@@ -201,6 +195,11 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
}
override fun update(delta: Float) {
// update lightbox
lightBoxList[0].light = actorValueColour
shadeBoxList[0].light = actorValueShade
super.update(delta)
if (vehicleRiding is IngamePlayer)

View File

@@ -3,16 +3,14 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.PhysProperties
import net.torvald.terrarum.gameactors.drawBodyInGoodPosition
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitems.*
/**
* Created by minjaesong on 2016-03-15.
@@ -38,6 +36,14 @@ open class DroppedItem : ActorWithBody {
fun canBePickedUp() = timeSinceSpawned > NO_PICKUP_TIME && !flagDespawn
private val randKey1 = (Math.random() * 256).toInt()
private val randKey2 = (Math.random() * 256).toInt()
override var lightBoxList = listOf(Lightbox(this.hitbox.clone().setPosition(0.0, 0.0), Cvec(0)))
// the Cvec will be calculated dynamically on Update
override var shadeBoxList = listOf(Lightbox(this.hitbox.clone().setPosition(0.0, 0.0), Cvec(0)))
// the Cvec will be calculated dynamically on Update
/**
* @param topLeftX world-wise coord
* @param topLeftY world-wise coord
@@ -45,12 +51,12 @@ open class DroppedItem : ActorWithBody {
constructor(itemID: ItemID, topLeftX: Double, topLeftY: Double) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
this.itemID = itemID
if (itemID.startsWith("actor@"))
if (itemID.isActor())
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
isVisible = true
avBaseMass = if (itemID.startsWith("item@") || itemID.startsWith("wire@"))
avBaseMass = if (itemID.isItem() || itemID.isWire())
(ItemCodex[itemID]?.mass ?: 2.0).coerceAtMost(2.0)
else
BlockCodex[itemID].density / 1000.0 // block and wall
@@ -73,7 +79,6 @@ open class DroppedItem : ActorWithBody {
Math.cos(Math.random() * Math.PI / 2 + Math.PI / 2) * magn
else
Math.cos(Math.random() * Math.PI) * magn
}
override fun drawBody(batch: SpriteBatch) {
@@ -104,6 +109,12 @@ open class DroppedItem : ActorWithBody {
}
override fun update(delta: Float) {
if (this.itemID.isBlock() || this.itemID.isItem()) {
BlockCodex[this.itemID].let {
this.lightBoxList[0].light = it.getLumCol(randKey1, randKey2)
}
}
super.update(delta)
timeSinceSpawned += delta

View File

@@ -22,7 +22,7 @@ import kotlin.math.absoluteValue
*
* Created by minjaesong on 2022-07-15.
*/
open class FixtureSwingingDoorBase : FixtureBase, Luminous {
open class FixtureSwingingDoorBase : FixtureBase {
/* OVERRIDE THESE TO CUSTOMISE */
var tw = 2 // tilewise width of the door when opened
@@ -45,8 +45,10 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous {
private var pixelwiseHitboxHeight = TILE_SIZE * tilewiseHitboxHeight
private var tilewiseDistToAxis = tw - twClosed
@Transient override val lightBoxList: ArrayList<Lightbox> = ArrayList()
@Transient override val shadeBoxList: ArrayList<Lightbox> = ArrayList()
@Transient override var lightBoxList = listOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
// the Cvec will be calculated dynamically on Update
@Transient override var shadeBoxList = listOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
// the Cvec will be calculated dynamically on Update
protected var doorState = 0 // -1: open toward left, 0: closed, 1: open toward right
protected var doorStateTimer: Second = 0f
@@ -123,8 +125,7 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous {
// define light/shadebox
// TODO: redefine when opened to left/right
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add(
Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), opacity))
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList)[0].light = opacity
// define physical size
setHitboxDimension(TILE_SIZE * tilewiseHitboxWidth, TILE_SIZE * tilewiseHitboxHeight, 0, 0)
@@ -148,8 +149,7 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous {
// define light/shadebox
// TODO: redefine when opened to left/right
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add(
Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), opacity))
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList)[0].light = opacity
}

View File

@@ -1,8 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.CommonResourcePool
@@ -12,7 +10,6 @@ import net.torvald.terrarum.blockproperties.Block
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.gameparticles.ParticleVanishingSprite
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -21,20 +18,12 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2016-06-17.
*/
internal class FixtureTikiTorch : FixtureBase, Luminous {
internal class FixtureTikiTorch : FixtureBase {
private val rng = HQRNG()
private val rndHash1 = rng.nextInt()
private val rndHash2 = rng.nextInt()
private val rndHash1 = (Math.random() * 256).toInt()
private val rndHash2 = (Math.random() * 256).toInt()
private var color: Cvec
get() = try { BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2) } catch (e: NullPointerException) { Cvec() }
set(value) {
throw UnsupportedOperationException()
}
@Transient override val lightBoxList: ArrayList<Lightbox> = ArrayList(1)
@Transient override val shadeBoxList: ArrayList<Lightbox> = ArrayList(1)
@Transient override var lightBoxList = listOf(Lightbox(Hitbox(6.0, 5.0, 4.0, 3.0), BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2)))
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 2),
@@ -51,8 +40,6 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
setHitboxDimension(16, 32, 0, 0)
lightBoxList.add(Lightbox(Hitbox(6.0, 5.0, 4.0, 3.0), color))
makeNewSprite(FixtureBase.getSpritesheet("basegame", "sprites/fixtures/tiki_torch.tga", 16, 32)).let {
it.setRowsAndFrames(1,2)
}
@@ -64,18 +51,20 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
private var spawnTimer = 0f
override fun update(delta: Float) {
lightBoxList[0].light = BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2)
super.update(delta)
if (spawnTimer >= nextDelay) {
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingSprite(
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
25f, true, hitbox.centeredX, hitbox.startY, false, rng.nextInt(256)
25f, true, hitbox.centeredX, hitbox.startY, false, (Math.random() * 256).toInt()
))
spawnTimer -= nextDelay
nextDelay = rng.nextFloat() * 0.25f + 0.25f
nextDelay = Math.random().toFloat() * 0.25f + 0.25f
(sprite as? SheetSpriteAnimation)?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f)
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
}
spawnTimer += delta

View File

@@ -1,13 +1,13 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.PhysProperties
import net.torvald.terrarum.gameitems.ItemID
/**
* Created by minjaesong on 2016-04-26.
*/
class ItemCarrying : ActorWithBody, Luminous {
class ItemCarrying : ActorWithBody {
var itemID: ItemID = ""; private set
@@ -20,30 +20,6 @@ class ItemCarrying : ActorWithBody, Luminous {
// just let the solver use AABB; it's cheap but works just enough
/**
* Recommended implementation:
*
override var color: Int
get() = actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
set(value) {
actorValue[AVKey.LUMINOSITY] = value
}
*/
private var color: Cvec
get() = throw UnsupportedOperationException()
set(value) {
}
/**
* Arguments:
*
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList: List<Lightbox>
get() = throw UnsupportedOperationException()
override val shadeBoxList: List<Lightbox>
get() = throw UnsupportedOperationException()
init {
}

View File

@@ -3,14 +3,15 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gameactors.PhysProperties
import org.dyn4j.geometry.Vector2
import java.util.*
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.*
/**
* Simplest projectile.
@@ -19,7 +20,7 @@ import net.torvald.terrarum.gameactors.*
*/
// TODO simplified, lightweight physics (does not call PhysicsSolver)
open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
open class ProjectileSimple : ActorWithBody, Projectile {
private var type: Int = 0
var damage: Int = 0
@@ -38,8 +39,8 @@ open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
@Transient override val lightBoxList = ArrayList<Lightbox>()
@Transient override val shadeBoxList = ArrayList<Lightbox>()
@Transient override var lightBoxList = listOf(Lightbox(Hitbox(-4.0, -4.0, 8.0, 8.0), color)) // lightbox sized 8x8 centered to the bullet
private val lifetimeMax = 2500
private var lifetimeCounter = 0f
@@ -57,8 +58,6 @@ open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
setPosition(fromPoint.x, fromPoint.y)
posPre = Point2d(fromPoint.x, fromPoint.y)
// lightbox sized 8x8 centered to the bullet
lightBoxList.add(Lightbox(Hitbox(-4.0, -4.0, 8.0, 8.0), color))
//this.externalV.set(velocity)
damage = bulletDatabase[type][OFFSET_DAMAGE] as Int

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isWall
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -40,7 +41,7 @@ object BlockBase {
if (!ret1) return@mouseInInteractableRange -1L
}
val isWall = itemID.startsWith("wall@")
val isWall = itemID.isWall()
val terrainUnderCursor = ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)
val wallUnderCursor = ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)