mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
vanishing particle test
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
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.terrarum.AppLoader
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameparticles.ParticleVanishingText
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-17.
|
||||
*/
|
||||
internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 2), nameFun = nameFun), Luminous {
|
||||
|
||||
private val rng = HQRNG()
|
||||
private val rndHash1: Int
|
||||
private val rndHash2: Int
|
||||
|
||||
@@ -40,11 +48,31 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
|
||||
|
||||
actorValue[AVKey.BASEMASS] = MASS
|
||||
|
||||
val rng = HQRNG()
|
||||
rndHash1 = rng.nextInt()
|
||||
rndHash2 = rng.nextInt()
|
||||
}
|
||||
|
||||
private var nextDelay = 0.4f
|
||||
private var spawnTimer = 0f
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
if (spawnTimer >= nextDelay) {
|
||||
val s = rng.nextInt(1, 1000).toString()
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingText(s, hitbox.centeredX, hitbox.startY + 10))
|
||||
|
||||
spawnTimer -= nextDelay
|
||||
nextDelay = rng.nextFloat() * 0.4f + 0.4f
|
||||
}
|
||||
|
||||
spawnTimer += delta
|
||||
}
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
super.drawBody(batch)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MASS = 1.0
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
* Actors with static sprites and very simple physics
|
||||
*
|
||||
* Created by minjaesong on 2017-01-20.
|
||||
*/
|
||||
open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision: Boolean, maxLifeTime: Second? = null) : Runnable {
|
||||
|
||||
/** Will NOT actually delete from the CircularArray */
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
override fun run() = update(AppLoader.UPDATE_RATE)
|
||||
|
||||
var isNoSubjectToGrav = false
|
||||
var dragCoefficient = 3.0
|
||||
|
||||
private val lifetimeMax = maxLifeTime ?: 5f
|
||||
private var lifetimeCounter = 0f
|
||||
|
||||
val velocity = Vector2(0.0, 0.0)
|
||||
val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
open lateinit var body: TextureRegion // you might want to use SpriteAnimation
|
||||
open var glow: TextureRegion? = null
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
fun update(delta: Float) {
|
||||
if (!flagDespawn) {
|
||||
lifetimeCounter += delta
|
||||
if (despawnUponCollision) {
|
||||
if (velocity.isZero ||
|
||||
// simple stuck check
|
||||
BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(
|
||||
hitbox.canonicalX.div(TILE_SIZE).floorInt(),
|
||||
hitbox.canonicalY.div(TILE_SIZE).floorInt()
|
||||
) ?: Block.STONE].isSolid) {
|
||||
flagDespawn = true
|
||||
}
|
||||
}
|
||||
|
||||
if (lifetimeCounter >= lifetimeMax) {
|
||||
flagDespawn = true
|
||||
}
|
||||
|
||||
// gravity, winds, etc. (external forces)
|
||||
if (!isNoSubjectToGrav) {
|
||||
velocity.plusAssign((Terrarum.ingame!!.world).gravitation / dragCoefficient)
|
||||
}
|
||||
|
||||
|
||||
// combine external forces
|
||||
hitbox.translate(velocity)
|
||||
}
|
||||
}
|
||||
|
||||
fun drawBody(batch: SpriteBatch) {
|
||||
if (!flagDespawn) {
|
||||
batch.draw(body, hitbox.startX.toFloat(), hitbox.startY.toFloat(), hitbox.width.toFloat(), hitbox.height.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
fun drawGlow(batch: SpriteBatch) {
|
||||
if (!flagDespawn && glow != null) {
|
||||
batch.draw(glow, hitbox.startX.toFloat(), hitbox.startY.toFloat(), hitbox.width.toFloat(), hitbox.height.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-12-18.
|
||||
*/
|
||||
class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, 3.2f) {
|
||||
|
||||
init {
|
||||
body = MegaRainGovernor.get()
|
||||
val w = body.regionWidth.toDouble()
|
||||
val h = body.regionHeight.toDouble()
|
||||
hitbox.setFromWidthHeight(
|
||||
posX - w.times(0.5),
|
||||
posY - h.times(0.5),
|
||||
w, h
|
||||
)
|
||||
|
||||
velocity.y = 11.5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object MegaRainGovernor {
|
||||
|
||||
private var reseedTimer = 0f
|
||||
var reseedTime: Second = 90f
|
||||
|
||||
private val body = Pixmap(ModMgr.getGdxFile("basegame", "weathers/raindrop.tga"))
|
||||
private lateinit var bodies: Array<TextureRegion>
|
||||
|
||||
private var withdrawCounter = 0
|
||||
|
||||
init {
|
||||
seed()
|
||||
}
|
||||
|
||||
private fun seed() {
|
||||
val w = body.width
|
||||
val h = body.height
|
||||
|
||||
bodies = Array(1024) {
|
||||
//val pixmap = Pixmap(AppLoader.terrarumAppConfig.screenW * 2, AppLoader.terrarumAppConfig.screenH / 4, Pixmap.Format.RGBA8888)
|
||||
val pixmap = Pixmap(64, 64, Pixmap.Format.RGBA8888)
|
||||
|
||||
val rng = HQRNG()
|
||||
|
||||
repeat(rng.nextInt(2) + 3) { // 3 or 4
|
||||
val rndX = rng.nextInt(pixmap.width - body.width)
|
||||
val rndY = rng.nextInt(pixmap.height - body.height)
|
||||
|
||||
pixmap.drawPixmap(body, rndX, rndY)
|
||||
}
|
||||
|
||||
// return composed (mega)pixmap
|
||||
val region = TextureRegion(Texture(pixmap))
|
||||
region.flip(false, true)
|
||||
|
||||
/*return*/region
|
||||
}
|
||||
|
||||
// randomise
|
||||
bodies.shuffle()
|
||||
}
|
||||
|
||||
fun get(): TextureRegion {
|
||||
if (withdrawCounter >= bodies.size) {
|
||||
withdrawCounter = 0
|
||||
//bodies.shuffle() // if pre-rendered random set is sufficiently large, it'd look random enough
|
||||
}
|
||||
|
||||
return bodies[withdrawCounter++]
|
||||
}
|
||||
|
||||
@Deprecated("re-seeding freezes the game a little and large enough randomnesses ought to be good")
|
||||
fun update(delta: Float) {
|
||||
if (reseedTimer >= reseedTime) {
|
||||
seed()
|
||||
reseedTimer -= reseedTime
|
||||
}
|
||||
|
||||
reseedTimer += delta
|
||||
}
|
||||
|
||||
fun resize() {
|
||||
seed()
|
||||
withdrawCounter = 0
|
||||
reseedTimer = 0f
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun Array<TextureRegion>.shuffle() {
|
||||
for (i in this.size - 1 downTo 1) {
|
||||
val rndIndex = (Math.random() * (i + 1)).toInt()
|
||||
|
||||
val t = this[rndIndex]
|
||||
this[rndIndex] = this[i]
|
||||
this[i] = t
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-01-20.
|
||||
*/
|
||||
class ParticleTestRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, 6f) {
|
||||
|
||||
init {
|
||||
body = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "weathers/raindrop.tga")))
|
||||
val w = body.regionWidth.toDouble()
|
||||
val h = body.regionHeight.toDouble()
|
||||
hitbox.setFromWidthHeight(
|
||||
posX - w.times(0.5),
|
||||
posY - h.times(0.5),
|
||||
w, h
|
||||
)
|
||||
|
||||
velocity.y = 10.0
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user