mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
clouds parallax and can drift in 3D
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
"cloudChance": 20,
|
"cloudChance": 20,
|
||||||
"cloudGamma": [0.48, 1.8],
|
"cloudGamma": [0.48, 1.8],
|
||||||
"cloudGammaVariance": [0.1, 0.1],
|
"cloudGammaVariance": [0.1, 0.1],
|
||||||
"cloudDriftSpeed": 0.3,
|
"cloudDriftSpeed": 0.08,
|
||||||
"clouds": {
|
"clouds": {
|
||||||
"large": {
|
"large": {
|
||||||
"filename": "cloud_large.png",
|
"filename": "cloud_large.png",
|
||||||
|
|||||||
@@ -688,7 +688,7 @@ open class ActorWithBody : Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun displaceHitbox() {
|
private fun displaceHitbox() {
|
||||||
val printdbg1 = true && App.IS_DEVELOPMENT_BUILD
|
val printdbg1 = false && App.IS_DEVELOPMENT_BUILD
|
||||||
// // HOW IT SHOULD WORK // //
|
// // HOW IT SHOULD WORK // //
|
||||||
// ////////////////////////
|
// ////////////////////////
|
||||||
// combineVeloToMoveDelta now
|
// combineVeloToMoveDelta now
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ import net.torvald.terrarum.gameworld.GameWorld
|
|||||||
import net.torvald.terrarum.gameworld.WorldTime
|
import net.torvald.terrarum.gameworld.WorldTime
|
||||||
import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH
|
import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH
|
||||||
import net.torvald.terrarum.RNGConsumer
|
import net.torvald.terrarum.RNGConsumer
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
import net.torvald.terrarum.clut.Skybox
|
import net.torvald.terrarum.clut.Skybox
|
||||||
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
|
import net.torvald.terrarum.spriteassembler.ADPropertyObject
|
||||||
import net.torvald.terrarum.utils.JsonFetcher
|
import net.torvald.terrarum.utils.JsonFetcher
|
||||||
import net.torvald.terrarum.utils.forEachSiblings
|
import net.torvald.terrarum.utils.forEachSiblings
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
@@ -110,7 +113,9 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
Arrays.fill(clouds, null)
|
Arrays.fill(clouds, null)
|
||||||
cloudsSpawned = 0
|
cloudsSpawned = 0
|
||||||
cloudDriftVector = Vector3(-1f, 0f, 1f)
|
cloudDriftVector = Vector3(1f, 0f, 0f).rotate(Vector3(0f,1f,0f), 192f)
|
||||||
|
|
||||||
|
oldCamPos.set(WorldCamera.camVector)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -182,8 +187,29 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val cloudParallaxMultY = -0.035f
|
||||||
|
private val cloudParallaxMultX = -0.035f
|
||||||
private var cloudUpdateAkku = 0f
|
private var cloudUpdateAkku = 0f
|
||||||
|
private val oldCamPos = Vector2(0f, 0f)
|
||||||
|
private val camDelta = Vector2(0f, 0f)
|
||||||
|
|
||||||
private fun updateClouds(delta: Float, world: GameWorld) {
|
private fun updateClouds(delta: Float, world: GameWorld) {
|
||||||
|
val camvec = WorldCamera.camVector
|
||||||
|
val camvec2 = camvec.cpy()
|
||||||
|
val testCamDelta = camvec.cpy().sub(oldCamPos)
|
||||||
|
|
||||||
|
if (testCamDelta.x.absoluteValue > world.width * TILE_SIZEF / 2f) {
|
||||||
|
if (testCamDelta.x >= 0)
|
||||||
|
camvec2.x -= world.width * TILE_SIZEF
|
||||||
|
else
|
||||||
|
camvec2.x += world.width * TILE_SIZEF
|
||||||
|
|
||||||
|
testCamDelta.set(camvec2.sub(oldCamPos))
|
||||||
|
}
|
||||||
|
|
||||||
|
camDelta.set(testCamDelta)
|
||||||
|
|
||||||
|
|
||||||
val cloudChanceEveryMin = 60f / (currentWeather.cloudChance * currentWeather.cloudDriftSpeed) // if chance = 0, the result will be +inf
|
val cloudChanceEveryMin = 60f / (currentWeather.cloudChance * currentWeather.cloudDriftSpeed) // if chance = 0, the result will be +inf
|
||||||
|
|
||||||
if (cloudUpdateAkku >= cloudChanceEveryMin) {
|
if (cloudUpdateAkku >= cloudChanceEveryMin) {
|
||||||
@@ -193,11 +219,15 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
clouds.forEach {
|
clouds.forEach {
|
||||||
it?.let {
|
it?.let {
|
||||||
|
// do parallax scrolling
|
||||||
|
it.posX += camDelta.x * cloudParallaxMultX
|
||||||
|
it.posY += camDelta.y * cloudParallaxMultY
|
||||||
|
|
||||||
it.update(cloudDriftVector, currentWeather.cloudDriftSpeed)
|
it.update(cloudDriftVector, currentWeather.cloudDriftSpeed)
|
||||||
|
|
||||||
val pjx = it.posX / it.posZ
|
val pjx = it.posX / it.posZ
|
||||||
|
|
||||||
if (pjx !in -1500f..App.scr.wf + 1500f || it.scale < 1f / 2048f) {
|
if (pjx !in -1500f..App.scr.wf + 1500f || it.scale < 1f / 2048f || it.posZ !in 0.001f..100f) {
|
||||||
it.flagToDespawn = true
|
it.flagToDespawn = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,6 +242,9 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cloudUpdateAkku += delta
|
cloudUpdateAkku += delta
|
||||||
|
|
||||||
|
|
||||||
|
oldCamPos.set(camvec)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val scrHscaler = App.scr.height / 720f
|
private val scrHscaler = App.scr.height / 720f
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ class WeatherObjectCloud(private val texture: TextureRegion, private val flipW:
|
|||||||
* Resulting vector: (x + dX, y + dY, scale * dScale)
|
* Resulting vector: (x + dX, y + dY, scale * dScale)
|
||||||
*/
|
*/
|
||||||
fun update(flowVector: Vector3, gait: Float) {
|
fun update(flowVector: Vector3, gait: Float) {
|
||||||
posX += flowVector.x * gait * scale
|
val vecMult = Vector3(1f, 1f, 1f / (2f * App.scr.hf * 0.35f))
|
||||||
posY += flowVector.y * gait * scale
|
pos.add(flowVector.cpy().scl(vecMult).scl(gait))
|
||||||
scale *= flowVector.z
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ object WorldCamera {
|
|||||||
var worldHeight = 0
|
var worldHeight = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
inline val camVector: com.badlogic.gdx.math.Vector2
|
||||||
|
get() = com.badlogic.gdx.math.Vector2(gdxCamX, gdxCamY)
|
||||||
|
|
||||||
fun update(world: GameWorld, player: ActorWithBody?) {
|
fun update(world: GameWorld, player: ActorWithBody?) {
|
||||||
if (player == null) return
|
if (player == null) return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user