mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
new walk anim delay WIP
This commit is contained in:
@@ -37,7 +37,7 @@ SKELETON_STAND=HEADGEAR 0,78;\
|
|||||||
! When you move the arms/hands, make sure you move the HELD_ITEM as well
|
! When you move the arms/hands, make sure you move the HELD_ITEM as well
|
||||||
|
|
||||||
# RUNNING might need its own skeleton...
|
# RUNNING might need its own skeleton...
|
||||||
ANIM_RUN=DELAY 0.3;ROW 2;SKELETON SKELETON_STAND
|
ANIM_RUN=DELAY 0.16;ROW 2;SKELETON SKELETON_STAND
|
||||||
ANIM_RUN_1=LEG_REST_RIGHT 2,2;LEG_REST_LEFT -2,0;TAIL_0 1,0;TORSO_1 0,-999
|
ANIM_RUN_1=LEG_REST_RIGHT 2,2;LEG_REST_LEFT -2,0;TAIL_0 1,0;TORSO_1 0,-999
|
||||||
ANIM_RUN_2=ALL 0,2;LEG_REST_RIGHT 0,-2;LEG_REST_LEFT 0,2;TAIL_0 -1,0;TORSO_1 0,-999
|
ANIM_RUN_2=ALL 0,2;LEG_REST_RIGHT 0,-2;LEG_REST_LEFT 0,2;TAIL_0 -1,0;TORSO_1 0,-999
|
||||||
ANIM_RUN_3=LEG_REST_RIGHT -2,0;LEG_REST_LEFT 2,2;TAIL_0 -1,0;TORSO_1 0,-999
|
ANIM_RUN_3=LEG_REST_RIGHT -2,0;LEG_REST_LEFT 2,2;TAIL_0 -1,0;TORSO_1 0,-999
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ SKELETON_STAND=HEADGEAR 0,78;\
|
|||||||
! When you move the arms/hands, make sure you move the HELD_ITEM as well
|
! When you move the arms/hands, make sure you move the HELD_ITEM as well
|
||||||
|
|
||||||
# RUNNING might need its own skeleton...
|
# RUNNING might need its own skeleton...
|
||||||
ANIM_RUN=DELAY 0.3;ROW 2;SKELETON SKELETON_STAND
|
ANIM_RUN=DELAY 0.16;ROW 2;SKELETON SKELETON_STAND
|
||||||
ANIM_RUN_1=LEG_REST_RIGHT 2,2;LEG_REST_LEFT -2,0;TAIL_0 1,0;TORSO_1 0,-999
|
ANIM_RUN_1=LEG_REST_RIGHT 2,2;LEG_REST_LEFT -2,0;TAIL_0 1,0;TORSO_1 0,-999
|
||||||
ANIM_RUN_2=ALL 0,2;LEG_REST_RIGHT 0,-2;LEG_REST_LEFT 0,2;TAIL_0 -1,0;TORSO_1 0,-999
|
ANIM_RUN_2=ALL 0,2;LEG_REST_RIGHT 0,-2;LEG_REST_LEFT 0,2;TAIL_0 -1,0;TORSO_1 0,-999
|
||||||
ANIM_RUN_3=LEG_REST_RIGHT -2,0;LEG_REST_LEFT 2,2;TAIL_0 -1,0;TORSO_1 0,-999
|
ANIM_RUN_3=LEG_REST_RIGHT -2,0;LEG_REST_LEFT 2,2;TAIL_0 -1,0;TORSO_1 0,-999
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ interface HasAssembledSprite {
|
|||||||
|
|
||||||
/** ADL for main sprite. Necessary. */
|
/** ADL for main sprite. Necessary. */
|
||||||
var animDesc: ADProperties?
|
var animDesc: ADProperties?
|
||||||
|
|
||||||
/** ADL for glow sprite. Optional. */
|
/** ADL for glow sprite. Optional. */
|
||||||
var animDescGlow: ADProperties?
|
var animDescGlow: ADProperties?
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class SpriteAnimation(@Transient val parentActor: ActorWithBody) : Disposable {
|
|||||||
internal set
|
internal set
|
||||||
|
|
||||||
private val currentDelay: Second
|
private val currentDelay: Second
|
||||||
get() = delays[currentRow]
|
get() = delays[currentRow].coerceAtLeast(1f / 16f) // animation delay cannot be too short
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets delays for each rows. Array size must be the same as the rows of the sheet
|
* Sets delays for each rows. Array size must be the same as the rows of the sheet
|
||||||
|
|||||||
@@ -696,7 +696,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
|||||||
|
|
||||||
fun Float.abs() = FastMath.abs(this)
|
fun Float.abs() = FastMath.abs(this)
|
||||||
|
|
||||||
private fun updateSprite(delta: Float) {
|
open fun updateSprite(delta: Float) {
|
||||||
sprite?.update(delta)
|
sprite?.update(delta)
|
||||||
spriteGlow?.update(delta)
|
spriteGlow?.update(delta)
|
||||||
|
|
||||||
@@ -706,11 +706,24 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
|||||||
spriteGlow?.switchRow(SPRITE_ROW_WALK)
|
spriteGlow?.switchRow(SPRITE_ROW_WALK)
|
||||||
|
|
||||||
// set anim frame delay
|
// set anim frame delay
|
||||||
// 4f of the divider is a magic number, empirically decided
|
|
||||||
if (this is HasAssembledSprite) {
|
if (this is HasAssembledSprite) {
|
||||||
sprite?.delays?.set(SPRITE_ROW_WALK, scale.sqrt().toFloat() / (4f * (controllerV?.x ?: 0.0001).abs().toFloat())) // FIXME empirical value
|
try {
|
||||||
spriteGlow?.delays?.set(SPRITE_ROW_WALK, scale.sqrt().toFloat() / (4f * (controllerV?.x ?: 0.0001).abs().toFloat())) // FIXME empirical value
|
val baseDelay = animDesc!!.getAnimByFrameName("ANIM_RUN").delay
|
||||||
|
val moveSpeedMult = (controllerV?.x ?: 0.0).abs().coerceAtLeast(PHYS_EPSILON_VELO).toFloat() / 4f // FIXME empirical value
|
||||||
|
val stride = scale.toFloat()
|
||||||
|
val maxMoveSpeed = scale.sqrt().toFloat() // ActorWithBody uses scale.sqrt() for determining walk acceleration
|
||||||
|
val scaleCompensation = stride / maxMoveSpeed
|
||||||
|
|
||||||
|
val finalDelay = baseDelay * (scaleCompensation / moveSpeedMult)
|
||||||
|
|
||||||
|
sprite?.delays?.set(SPRITE_ROW_WALK, finalDelay)
|
||||||
|
spriteGlow?.delays?.set(SPRITE_ROW_WALK, finalDelay)
|
||||||
|
}
|
||||||
|
catch (e: NullPointerException) {
|
||||||
|
println(animDesc!!.animations.keys.joinToString())
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// flipping the sprite
|
// flipping the sprite
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
import net.torvald.spriteanimation.HasAssembledSprite
|
||||||
import net.torvald.spriteanimation.SpriteAnimation
|
import net.torvald.spriteanimation.SpriteAnimation
|
||||||
import net.torvald.terrarum.spriteassembler.ADProperties
|
import net.torvald.terrarum.spriteassembler.ADProperties
|
||||||
import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap
|
import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap
|
||||||
@@ -22,7 +23,7 @@ import java.util.*
|
|||||||
* Created by minjaesong on 2015-12-31.
|
* Created by minjaesong on 2015-12-31.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class IngamePlayer : ActorHumanoid {
|
class IngamePlayer : ActorHumanoid, HasAssembledSprite {
|
||||||
|
|
||||||
val creationTime = App.getTIME_T()
|
val creationTime = App.getTIME_T()
|
||||||
var lastPlayTime = App.getTIME_T() // cumulative value for the savegame
|
var lastPlayTime = App.getTIME_T() // cumulative value for the savegame
|
||||||
@@ -31,13 +32,13 @@ class IngamePlayer : ActorHumanoid {
|
|||||||
val uuid = UUID.randomUUID()
|
val uuid = UUID.randomUUID()
|
||||||
var worldCurrentlyPlaying: UUID = UUID(0L,0L) // only filled up on save and load; DO NOT USE THIS
|
var worldCurrentlyPlaying: UUID = UUID(0L,0L) // only filled up on save and load; DO NOT USE THIS
|
||||||
|
|
||||||
var spriteHeadTexture: TextureRegion? = null
|
@Transient override var spriteHeadTexture: TextureRegion? = null
|
||||||
|
|
||||||
|
|
||||||
/** ADL for main sprite. Necessary. */
|
/** ADL for main sprite. Necessary. */
|
||||||
@Transient var animDesc: ADProperties? = null
|
@Transient override var animDesc: ADProperties? = null
|
||||||
/** ADL for glow sprite. Optional. */
|
/** ADL for glow sprite. Optional. */
|
||||||
@Transient var animDescGlow: ADProperties? = null
|
@Transient override var animDescGlow: ADProperties? = null
|
||||||
|
|
||||||
|
|
||||||
private constructor()
|
private constructor()
|
||||||
@@ -75,8 +76,8 @@ class IngamePlayer : ActorHumanoid {
|
|||||||
/** To be used later by the game to rebuild the sprite.
|
/** To be used later by the game to rebuild the sprite.
|
||||||
* Which `_rebuild` function to use is determined at the load time.
|
* Which `_rebuild` function to use is determined at the load time.
|
||||||
*/
|
*/
|
||||||
private lateinit var rebuildfun: (item: GameItem?) -> Unit
|
@Transient private lateinit var rebuildfun: (item: GameItem?) -> Unit
|
||||||
private lateinit var rebuildfunGlow: (item: GameItem?) -> Unit
|
@Transient private lateinit var rebuildfunGlow: (item: GameItem?) -> Unit
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +90,7 @@ class IngamePlayer : ActorHumanoid {
|
|||||||
* reassembleSprite(this.sprite, this.spriteGlow)
|
* reassembleSprite(this.sprite, this.spriteGlow)
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
fun reassembleSprite(sprite: SpriteAnimation?, spriteGlow: SpriteAnimation?, heldItem: GameItem?) {
|
override fun reassembleSprite(sprite: SpriteAnimation?, spriteGlow: SpriteAnimation?, heldItem: GameItem?) {
|
||||||
if (animDesc != null && sprite != null) {
|
if (animDesc != null && sprite != null) {
|
||||||
rebuildfun = { item: GameItem? -> _rebuild(animDesc!!, sprite, item) }; rebuildfun(heldItem)
|
rebuildfun = { item: GameItem? -> _rebuild(animDesc!!, sprite, item) }; rebuildfun(heldItem)
|
||||||
spriteHeadTexture = AssembleSheetPixmap.getMugshotFromAssetsDir(animDesc!!)
|
spriteHeadTexture = AssembleSheetPixmap.getMugshotFromAssetsDir(animDesc!!)
|
||||||
@@ -164,7 +165,7 @@ class IngamePlayer : ActorHumanoid {
|
|||||||
return spriteHeadTexture
|
return spriteHeadTexture
|
||||||
}
|
}
|
||||||
|
|
||||||
private var unequipNoSpriteUpdate = false
|
@Transient private var unequipNoSpriteUpdate = false
|
||||||
|
|
||||||
override fun equipItem(item: GameItem) {
|
override fun equipItem(item: GameItem) {
|
||||||
val oldItemID = inventory.itemEquipped[item.equipPosition]
|
val oldItemID = inventory.itemEquipped[item.equipPosition]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum.spriteassembler
|
package net.torvald.terrarum.spriteassembler
|
||||||
|
|
||||||
import com.badlogic.gdx.files.FileHandle
|
import com.badlogic.gdx.files.FileHandle
|
||||||
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.linearSearchBy
|
import net.torvald.terrarum.linearSearchBy
|
||||||
import net.torvald.terrarum.serialise.Common
|
import net.torvald.terrarum.serialise.Common
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
@@ -238,7 +239,16 @@ class ADProperties {
|
|||||||
internal fun getSkeleton(name: String) = skeletons[name]!!
|
internal fun getSkeleton(name: String) = skeletons[name]!!
|
||||||
internal fun getTransform(name: String) = transforms[name]!!
|
internal fun getTransform(name: String) = transforms[name]!!
|
||||||
|
|
||||||
private fun getAnimNameFromFrame(s: String) = s.substring(0 until s.lastIndexOf('_'))
|
/**
|
||||||
|
* Removes number suffix from the animation name
|
||||||
|
*/
|
||||||
|
private fun getAnimNameFromFrame(s: String): String {
|
||||||
|
val ret = if (s.matches(reAnimWithNumber)) s.substringBeforeLast('_') else s
|
||||||
|
// printdbg(this, "getAnimNameFromFrame $s -> $ret")
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
private val reAnimWithNumber = Regex("""ANIM_[A-Z]+_[0-9]+""")
|
||||||
|
|
||||||
private fun List<ADPropertyObject>.toJoints() = List(this.size) {
|
private fun List<ADPropertyObject>.toJoints() = List(this.size) {
|
||||||
Joint(this[it].name.toUpperCase(), this[it].input!! as ADPropertyObject.Vector2i)
|
Joint(this[it].name.toUpperCase(), this[it].input!! as ADPropertyObject.Vector2i)
|
||||||
|
|||||||
Reference in New Issue
Block a user