shitty implementaion of "air jumping"

This commit is contained in:
minjaesong
2019-08-15 00:20:42 +09:00
parent 7b12f878dd
commit 8a4bc98657
3 changed files with 56 additions and 6 deletions

View File

@@ -29,6 +29,15 @@ object AVKey {
const val JUMPPOWER = "jumppower" const val JUMPPOWER = "jumppower"
const val JUMPPOWERBUFF = "$JUMPPOWER$BUFF" const val JUMPPOWERBUFF = "$JUMPPOWER$BUFF"
/** How much air jumping you can perform. INT */
const val AIRJUMPPOINT = "airjumppoint"
/** How much air jumping you have performed before you run out of the point. INT */
const val AIRJUMPCOUNT = "_airjumpcount"
/** How long you can fly. DOUBLE */
const val FLIGHTPOINT = "flightpoint"
/** How long you have been flying before you reach your maximum flight time */
const val FLIGHTTIMER = "_flighttimer"
/** NOT meant for living creatures. Also, only effective when noclip=true. E.g. camera actor */ /** NOT meant for living creatures. Also, only effective when noclip=true. E.g. camera actor */
const val FRICTIONMULT = "frictionmult" const val FRICTIONMULT = "frictionmult"

View File

@@ -5,6 +5,7 @@ import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec import net.torvald.gdx.graphics.Cvec
import net.torvald.spriteanimation.HasAssembledSprite import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
@@ -133,7 +134,21 @@ open class ActorHumanoid(
private var readonly_totalY = 0.0 private var readonly_totalY = 0.0
internal var jumping = false internal var jumping = false
internal var airJumpingAllowed = false
/** Make air-jumping (sometimes referred as "double jumping) work
* Valid values: 0 or 2; 1 is same as 0, and because of the "failed" implementation, any value greater than
* 2 will allow tremendous jump height if you control it right, so it's not recommended to use those values.
*/
internal var airJumpingPoint: Int
get() = actorValue.getAsInt(AVKey.AIRJUMPPOINT) ?: 0
set(value) {
actorValue[AVKey.AIRJUMPPOINT] = value
}
internal var airJumpingCount: Int
get() = actorValue.getAsInt(AVKey.AIRJUMPCOUNT) ?: 0
set(value) {
actorValue[AVKey.AIRJUMPCOUNT] = value
}
internal var walkHeading: Int = 0 internal var walkHeading: Int = 0
@@ -244,6 +259,8 @@ open class ActorHumanoid(
get() = if (isGamer) AppLoader.gamepad != null get() = if (isGamer) AppLoader.gamepad != null
else true else true
private var playerJumpKeyHeldDown = false
private fun processInput(delta: Float) { private fun processInput(delta: Float) {
// Good control is simple: it move as the player meant: if I push the stick forward, it goes forward, rather than // Good control is simple: it move as the player meant: if I push the stick forward, it goes forward, rather than
@@ -334,20 +351,38 @@ open class ActorHumanoid(
*/ */
if (isJumpDown) { if (isJumpDown) {
if (!isNoClip) { if (!isNoClip) {
if (airJumpingAllowed || if (!playerJumpKeyHeldDown && (walledBottom || airJumpingCount < airJumpingPoint)) {
(!airJumpingAllowed && walledBottom)) {
jumping = true jumping = true
// make airjumping work
if (airJumpingCount < airJumpingPoint) {
printdbg(this, "airjump!")
// reset jumping-related variables
jumpCounter = 0
airJumpingCount += 1
// also reset the velocity because otherwise the jump is not truly reset
jumpAcc = 0.0
//controllerV?.y = 0.0
}
} }
jump() jump()
} }
else { else {
walkVertical(true, AXIS_KEYBOARD) walkVertical(true, AXIS_KEYBOARD)
} }
playerJumpKeyHeldDown = true
} }
else { else {
jumping = false jumping = false
jumpCounter = 0 jumpCounter = 0
jumpAcc = 0.0 jumpAcc = 0.0
playerJumpKeyHeldDown = false
// reset airjump counter
if (walledBottom) {
airJumpingCount = 0
}
} }
} }
@@ -565,8 +600,12 @@ open class ActorHumanoid(
grounded = false // just in case... grounded = false // just in case...
}*/ }*/
// release "jump key" of AIs // release "jump key" (of AIs?)
if (jumpCounter >= MAX_JUMP_LENGTH && !isGamer) { if (jumpCounter >= MAX_JUMP_LENGTH) {
if (isGamer) {
playerJumpKeyHeldDown = false
}
isJumpDown = false isJumpDown = false
jumping = false jumping = false
jumpCounter = 0 jumpCounter = 0

View File

@@ -43,6 +43,8 @@ object PlayerBuilderTestSubject1 {
//p.actorValue[AVKey.LUMB] = 1.37 //p.actorValue[AVKey.LUMB] = 1.37
//p.actorValue[AVKey.LUMA] = 1.93 //p.actorValue[AVKey.LUMA] = 1.93
p.actorValue[AVKey.AIRJUMPPOINT] = 0
return p return p
} }
} }