mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
CIELab and CIELch colour util
Former-commit-id: f8b0413223c2c968e4627e7c251220d32e2c6bf5 Former-commit-id: 2bce3479a8ad95ac06fbbd6c35cf73967a49568d
This commit is contained in:
@@ -200,7 +200,7 @@ constructor() : BasicGameState() {
|
||||
// determine whether the inactive actor should be re-active
|
||||
wakeDormantActors()
|
||||
// determine whether the actor should be active or dormant
|
||||
InactivateDistantActors()
|
||||
KillOrKnockdownActors()
|
||||
updateActors(gc, delta)
|
||||
// TODO thread pool(?)
|
||||
CollisionSolver.process()
|
||||
@@ -424,17 +424,21 @@ constructor() : BasicGameState() {
|
||||
* If the actor must be dormant, the target actor will be put to the list specifically for them.
|
||||
* if the actor is not to be dormant, it will be just ignored.
|
||||
*/
|
||||
fun InactivateDistantActors() {
|
||||
fun KillOrKnockdownActors() {
|
||||
var actorContainerSize = actorContainer.size
|
||||
var i = 0
|
||||
while (i < actorContainerSize) { // loop through actorContainer
|
||||
val actor = actorContainer[i]
|
||||
val actorIndex = i
|
||||
if (actor is Visible && !actor.inUpdateRange()) {
|
||||
// inactive instead of delete, if not flagged to delete
|
||||
if (!actor.flagDespawn)
|
||||
actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated
|
||||
|
||||
// kill actors flagged to despawn
|
||||
if (actor.flagDespawn) {
|
||||
actorContainer.removeAt(actorIndex)
|
||||
actorContainerSize -= 1
|
||||
i-- // array removed 1 elem, so we also decrement counter by 1
|
||||
}
|
||||
// inactivate distant actors
|
||||
else if (actor is Visible && !actor.inUpdateRange()) {
|
||||
actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated
|
||||
actorContainer.removeAt(actorIndex)
|
||||
actorContainerSize -= 1
|
||||
i-- // array removed 1 elem, so we also decrement counter by 1
|
||||
|
||||
@@ -100,7 +100,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
gc.graphics.clear() // clean up any 'dust' in the buffer
|
||||
|
||||
//addState(StateSplash())
|
||||
addState(StateMonitorCheck())
|
||||
//addState(StateMonitorCheck())
|
||||
//addState(StateFontTester())
|
||||
ingame = StateInGame()
|
||||
addState(ingame)
|
||||
|
||||
@@ -186,9 +186,9 @@ open class ActorWithBody : Actor(), Visible {
|
||||
|
||||
@Transient internal val BASE_FRICTION = 0.3
|
||||
|
||||
@Transient val KINEMATIC = 1 // does not be budged by external forces
|
||||
@Transient val DYNAMIC = 2
|
||||
@Transient val STATIC = 3 // does not be budged by external forces, target of collision
|
||||
@Transient val KINEMATIC = 1 // does not displaced by external forces
|
||||
@Transient val DYNAMIC = 2 // displaced by external forces
|
||||
@Transient val STATIC = 3 // does not displaced by external forces, target of collision
|
||||
var collisionType = DYNAMIC
|
||||
|
||||
@Transient private val CCD_TICK = 1.0 / 16.0
|
||||
@@ -214,7 +214,11 @@ open class ActorWithBody : Actor(), Visible {
|
||||
internal var walledLeft = false
|
||||
internal var walledRight = false
|
||||
|
||||
/**
|
||||
* true: This actor had just made collision
|
||||
*/
|
||||
var ccdCollided = false
|
||||
private set
|
||||
|
||||
var isWalkingH = false
|
||||
var isWalkingV = false
|
||||
@@ -945,6 +949,8 @@ open class ActorWithBody : Actor(), Visible {
|
||||
assertPrinted = true
|
||||
}
|
||||
|
||||
internal fun flagDespawn() { flagDespawn = true }
|
||||
|
||||
companion object {
|
||||
|
||||
@Transient private val TSIZE = MapDrawer.TILE_SIZE
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.colourutil.CIELabUtil.brighterLab
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -34,18 +34,28 @@ open class ProjectileSimple(
|
||||
|
||||
damage = bulletDatabase[type][0] as Int
|
||||
displayColour = bulletDatabase[type][1] as Color
|
||||
|
||||
collisionType = KINEMATIC
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
// hit something and despawn! (use ```flagDespawn = true```)
|
||||
|
||||
// hit something and despawn
|
||||
if (ccdCollided) flagDespawn()
|
||||
|
||||
super.update(gc, delta)
|
||||
}
|
||||
|
||||
override fun drawBody(gc: GameContainer, g: Graphics) {
|
||||
// draw trail of solid colour (Terraria style maybe?)
|
||||
|
||||
g.lineWidth = 3f
|
||||
g.drawGradientLine(
|
||||
nextHitbox.centeredX.toFloat(),
|
||||
nextHitbox.centeredY.toFloat(),
|
||||
displayColour,
|
||||
hitbox.centeredX.toFloat(),
|
||||
hitbox.centeredY.toFloat(),
|
||||
displayColour.brighterLab(0.8f)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.weather
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.JsonFetcher
|
||||
import net.torvald.colourutil.CIELchUtil
|
||||
import net.torvald.colourutil.ColourUtil
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum
|
||||
@@ -108,11 +109,8 @@ object WeatherMixer {
|
||||
// interpolate R, G and B
|
||||
val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance // [0.0, 1.0]
|
||||
|
||||
val r = interpolateLinear(scale, colourThis.red, colourNext.red)
|
||||
val g = interpolateLinear(scale, colourThis.green, colourNext.green)
|
||||
val b = interpolateLinear(scale, colourThis.blue, colourNext.blue)
|
||||
|
||||
val newCol = ColourUtil.toSlickColor(r, g, b)
|
||||
//val newCol = ColourUtil.getGradient(scale, colourThis, colourNext)
|
||||
val newCol = CIELchUtil.getGradient(scale, colourThis, colourNext)
|
||||
|
||||
/* // very nice monitor code
|
||||
// 65 -> 66 | 300 | 19623 | RGB8(255, 0, 255) -[41%]-> RGB8(193, 97, 23) | * `230`40`160`
|
||||
@@ -127,19 +125,6 @@ object WeatherMixer {
|
||||
|
||||
fun Color.toStringRGB() = "RGB8(${this.red}, ${this.green}, ${this.blue})"
|
||||
|
||||
fun interpolateLinear(scale: Float, startValue: Int, endValue: Int): Int {
|
||||
if (startValue == endValue) {
|
||||
return startValue
|
||||
}
|
||||
if (scale <= 0f) {
|
||||
return startValue
|
||||
}
|
||||
if (scale >= 1f) {
|
||||
return endValue
|
||||
}
|
||||
return Math.round((1f - scale) * startValue + scale * endValue)
|
||||
}
|
||||
|
||||
fun getWeatherList(classification: String) = weatherList[classification]!!
|
||||
fun getRandomWeather(classification: String) =
|
||||
getWeatherList(classification)[HQRNG().nextInt(getWeatherList(classification).size)]
|
||||
|
||||
Reference in New Issue
Block a user