actors can now block light

This commit is contained in:
minjaesong
2022-02-24 17:51:18 +09:00
parent 2e3a9e6fa0
commit 428cdefb80
7 changed files with 82 additions and 46 deletions

View File

@@ -64,7 +64,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
if (houseDesignation != null) houseDesignation!!.clear()
}
override var color: Cvec
var actorValueColour: Cvec
get() = Cvec(
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f),
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f),
@@ -78,14 +78,32 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
actorValue[AVKey.LUMA] = value.a
}
var actorValueShade: Cvec
get() = Cvec(
(actorValue.getAsFloat(AVKey.OPAR) ?: 0f),
(actorValue.getAsFloat(AVKey.OPAG) ?: 0f),
(actorValue.getAsFloat(AVKey.OPAB) ?: 0f),
(actorValue.getAsFloat(AVKey.OPAA) ?: 0f)
)
set(value) {
actorValue[AVKey.OPAR] = value.r
actorValue[AVKey.OPAG] = value.g
actorValue[AVKey.OPAB] = value.b
actorValue[AVKey.OPAA] = value.a
}
/**
* Arguments:
*
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList: List<Hitbox>
get() = arrayOf(Hitbox(2.0, 2.0, hitbox.width - 3, hitbox.height - 3)).toList() // things are asymmetric!!
override val lightBoxList: List<Lightbox>
get() = arrayOf(Lightbox(Hitbox(2.0, 2.0, hitbox.width - 3, hitbox.height - 3)) { actorValueColour }).toList() // things are asymmetric!!
// use getter; dimension of the player may change by time.
override val shadeBoxList: List<Lightbox>
get() = arrayOf(Lightbox(Hitbox(2.0, 2.0, hitbox.width - 3, hitbox.height - 3)) { actorValueShade }).toList() // things are asymmetric!!
// use getter; dimension of the player may change by time.
@Transient val BASE_DENSITY = 980.0

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.Terrarum
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
@@ -25,13 +26,14 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
private val rndHash1 = rng.nextInt()
private val rndHash2 = rng.nextInt()
override var color: Cvec
private var color: Cvec
get() = BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2)
set(value) {
throw UnsupportedOperationException()
}
override val lightBoxList: ArrayList<Hitbox> = ArrayList(1)
override val lightBoxList: ArrayList<Lightbox> = ArrayList(1)
override val shadeBoxList: ArrayList<Lightbox> = ArrayList(1)
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 2),
@@ -51,7 +53,7 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
setHitboxDimension(16, 32, 0, 0)
lightBoxList.add(Hitbox(6.0, 5.0, 4.0, 3.0))
lightBoxList.add(Lightbox(Hitbox(6.0, 5.0, 4.0, 3.0)) { color })
makeNewSprite(CommonResourcePool.getAsTextureRegionPack("sprites-fixtures-tiki_torch.tga"))
sprite!!.setRowsAndFrames(1, 2)

View File

@@ -7,13 +7,10 @@ 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.Luminous
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.
@@ -31,7 +28,7 @@ open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
var speed: Int = 0
override var color: Cvec
private var color: Cvec
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Cvec).cpy()
set(value) {
}
@@ -41,7 +38,8 @@ open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList = ArrayList<Hitbox>()
override val lightBoxList = ArrayList<Lightbox>()
override val shadeBoxList = ArrayList<Lightbox>()
private val lifetimeMax = 2500
private var lifetimeCounter = 0f
@@ -60,7 +58,7 @@ 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(Hitbox(-4.0, -4.0, 8.0, 8.0))
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

@@ -1,10 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameactors.PhysProperties
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitems.ItemID
/**
@@ -32,7 +29,7 @@ class WeaponSwung : ActorWithBody, Luminous {
actorValue[AVKey.LUMINOSITY] = value
}
*/
override var color: Cvec
private var color: Cvec
get() = throw UnsupportedOperationException()
set(value) {
}
@@ -42,7 +39,9 @@ class WeaponSwung : ActorWithBody, Luminous {
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList: List<Hitbox>
override val lightBoxList: List<Lightbox>
get() = throw UnsupportedOperationException()
override val shadeBoxList: List<Lightbox>
get() = throw UnsupportedOperationException()
init {