mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
particle sprite animations (dependant on age)
This commit is contained in:
parent
75bef2eb7d
commit
53d7789e15
@ -19,7 +19,7 @@ import de.bixilon.minosoft.gui.rendering.RenderWindow
|
|||||||
import de.bixilon.minosoft.gui.rendering.Renderer
|
import de.bixilon.minosoft.gui.rendering.Renderer
|
||||||
import de.bixilon.minosoft.gui.rendering.RendererBuilder
|
import de.bixilon.minosoft.gui.rendering.RendererBuilder
|
||||||
import de.bixilon.minosoft.gui.rendering.modding.events.CameraMatrixChangeEvent
|
import de.bixilon.minosoft.gui.rendering.modding.events.CameraMatrixChangeEvent
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.HappyVillagerParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.ExplosionParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
||||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
@ -60,9 +60,9 @@ class ParticleRenderer(
|
|||||||
}
|
}
|
||||||
val random = Random.Default
|
val random = Random.Default
|
||||||
|
|
||||||
val type = connection.registries.particleTypeRegistry[HappyVillagerParticle.RESOURCE_LOCATION]!!
|
val type = connection.registries.particleTypeRegistry[ExplosionParticle.RESOURCE_LOCATION]!!
|
||||||
for (i in 0 until 10000) {
|
for (i in 0 until 10000) {
|
||||||
val particle = HappyVillagerParticle(connection, Vec3(random.nextFloat(0.0f, 50.0f), random.nextFloat(6.0f, 50.0f), random.nextFloat(0.0f, 50.0f)), ParticleData(type), Random(random.nextLong()))
|
val particle = ExplosionParticle(connection, Vec3(random.nextFloat(0.0f, 50.0f), random.nextFloat(6.0f, 50.0f), random.nextFloat(0.0f, 50.0f)), ParticleData(type), Random(random.nextLong()))
|
||||||
// particle.grow(0.5f, 20000L)
|
// particle.grow(0.5f, 20000L)
|
||||||
// particle.velocity = Vec3(1f, 0.2f, 1f)
|
// particle.velocity = Vec3(1f, 0.2f, 1f)
|
||||||
// particle.friction = Vec3(0.1f, 0.1f, 0.1f)
|
// particle.friction = Vec3(0.1f, 0.1f, 0.1f)
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.particle.types
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||||
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||||
|
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||||
|
import glm_.vec3.Vec3
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
class ExplosionParticle(connection: PlayConnection, position: Vec3, data: ParticleData, random: Random) : Particle(connection, position, data, random) {
|
||||||
|
|
||||||
|
companion object : ParticleFactory<ExplosionParticle> {
|
||||||
|
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:explosion".asResourceLocation()
|
||||||
|
|
||||||
|
override fun build(connection: PlayConnection, position: Vec3, data: ParticleData, random: Random): ExplosionParticle {
|
||||||
|
return ExplosionParticle(connection, position, data, random)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ import kotlin.math.abs
|
|||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
abstract class Particle(protected val connection: PlayConnection, protected val position: Vec3, protected val data: ParticleData, protected val random: Random) {
|
abstract class Particle(protected val connection: PlayConnection, protected val position: Vec3, protected val data: ParticleData, protected val random: Random) {
|
||||||
protected val texture = connection.rendering!!.renderWindow.textures.allTextures[data.type.textures.random()]!!
|
protected var texture = connection.rendering!!.renderWindow.textures.allTextures[data.type.textures.first()]!!
|
||||||
protected var scale: Float = 0.1f
|
protected var scale: Float = 0.1f
|
||||||
protected var color: RGBColor = ChatColors.WHITE
|
protected var color: RGBColor = ChatColors.WHITE
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ abstract class Particle(protected val connection: PlayConnection, protected val
|
|||||||
var dead = false
|
var dead = false
|
||||||
var age: Int = 0
|
var age: Int = 0
|
||||||
protected set
|
protected set
|
||||||
var maxAge: Int = 100000 + random.nextInt(0, 10000)
|
var maxAge: Int = 10000 + random.nextInt(0, 10000)
|
||||||
|
|
||||||
// moving
|
// moving
|
||||||
var friction = Vec3.EMPTY
|
var friction = Vec3.EMPTY
|
||||||
@ -107,7 +107,7 @@ abstract class Particle(protected val connection: PlayConnection, protected val
|
|||||||
hoverMaxY - position.y
|
hoverMaxY - position.y
|
||||||
}
|
}
|
||||||
val totalDistance = hoverMaxY - hoverMinY
|
val totalDistance = hoverMaxY - hoverMinY
|
||||||
val yVelocity = 1 / (totalDistance / distanceToMiddle)
|
val yFriction = 1 / (totalDistance / distanceToMiddle)
|
||||||
|
|
||||||
|
|
||||||
when {
|
when {
|
||||||
@ -120,11 +120,24 @@ abstract class Particle(protected val connection: PlayConnection, protected val
|
|||||||
velocity.y = -1.0f
|
velocity.y = -1.0f
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
friction.y = yVelocity
|
friction.y = yFriction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkSpriteTexture() {
|
||||||
|
val totalTextures = data.type.textures.size
|
||||||
|
if (totalTextures <= 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// calculate next texture
|
||||||
|
val nextTextureResourceLocation = data.type.textures[age / ((maxAge / totalTextures) + 1)]
|
||||||
|
if (texture.resourceLocation == nextTextureResourceLocation) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
texture = connection.rendering!!.renderWindow.textures.allTextures[nextTextureResourceLocation]!!
|
||||||
|
}
|
||||||
|
|
||||||
open fun tick() {
|
open fun tick() {
|
||||||
check(!dead) { "Cannot tick dead particle!" }
|
check(!dead) { "Cannot tick dead particle!" }
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
@ -147,6 +160,8 @@ abstract class Particle(protected val connection: PlayConnection, protected val
|
|||||||
move(deltaTime)
|
move(deltaTime)
|
||||||
hover(deltaTime)
|
hover(deltaTime)
|
||||||
|
|
||||||
|
checkSpriteTexture()
|
||||||
|
|
||||||
lastTickTime = currentTime
|
lastTickTime = currentTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user