walking is now normal, no more sticking to the walls (the Q&D soluction was used), noclip movement is also normal now

Former-commit-id: 5a8de3e31e1f39e1591a5a60abc9d0dd37c3f87e
Former-commit-id: 9c685d31d6f8c75b512f41e467fac8586a22bc59
This commit is contained in:
Song Minjae
2016-07-31 17:51:06 +09:00
parent 30a0464820
commit 5e7a95a3b9
9 changed files with 158 additions and 123 deletions

View File

@@ -12,12 +12,12 @@ object AVKey {
* walking/running speed
*/
const val SPEED = "speed"
const val SPEEDMULT = "speed$MULT"
const val SPEEDMULT = "$SPEED$MULT"
/** pixels per frame squared
* acceleration of the movement (e.g. running, flying, driving, etc.)
*/
const val ACCEL = "accel"
const val ACCELMULT = "accel$MULT"
const val ACCELMULT = "$ACCEL$MULT"
const val SCALE = "scale"
/** pixels */
const val BASEHEIGHT = "baseheight"
@@ -25,7 +25,7 @@ object AVKey {
const val BASEMASS = "basemass"
/** pixels per frame */
const val JUMPPOWER = "jumppower"
const val JUMPPOWERMULT = "jumppower$MULT"
const val JUMPPOWERMULT = "$JUMPPOWER$MULT"
/** Int
* "Default" value of 1 000
@@ -72,7 +72,10 @@ object AVKey {
* current defence point of worn armour(s)
*/
const val ARMOURDEFENCE = "armourdefence"
const val ARMOURDEFENCEMULT = "armourdefence$MULT"
const val ARMOURDEFENCEMULT = "$ARMOURDEFENCE$MULT"
const val MAGICREGENRATE = "magicregenrate"
const val MAGICREGENRATEMULT = "$MAGICREGENRATE$MULT"

View File

@@ -331,8 +331,8 @@ open class ActorWithBody : Actor(), Visible {
}
// cheap solution for sticking into the wall while Left or Right is held
walledLeft = false//isTouchingSide(hitbox, COLLIDING_LEFT)
walledRight = false//isTouchingSide(hitbox, COLLIDING_RIGHT)
walledLeft = isTouchingSide(nextHitbox, COLLIDING_LEFT)
walledRight = isTouchingSide(nextHitbox, COLLIDING_RIGHT)
}
}
@@ -421,10 +421,10 @@ open class ActorWithBody : Actor(), Visible {
}
}
// axis X
if (isTouchingSide(nextHitbox, COLLIDING_LEFT) && isTouchingSide(nextHitbox, COLLIDING_RIGHT)
if (isTouchingSide(nextHitbox, COLLIDING_LEFT) || isTouchingSide(nextHitbox, COLLIDING_RIGHT)
&& moveDelta.x != 0.0) { // check right and left
// the actor is hitting the wall
//hitAndReflectX()
hitAndReflectX()
}
}
}
@@ -444,11 +444,6 @@ open class ActorWithBody : Actor(), Visible {
if (ccdDelta.x != 0.0 || ccdDelta.y != 0.0)
ccdDelta.set(ccdDelta.setMagnitude(CCD_TICK))
//////TEST//////
ccdDelta.x = 0.0
//////TEST//////
// Result: player CAN WALK with ccdDelta.x of zero, which means previous method is a shit.
//println("deltaMax: $deltaMax")
//println("ccdDelta: $ccdDelta")

View File

@@ -143,7 +143,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
* @author minjaesong
*/
private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
if (true) {//(!walledLeft && left) || (!walledRight && !left)) {
if ((!walledLeft && left) || (!walledRight && !left)) {
readonly_totalX =
absMax( // keyboard
actorValue.getAsDouble(AVKey.ACCEL)!! *
@@ -156,6 +156,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
(if (left) -1f else 1f) * absAxisVal
// do not add applyVelo(walkCounterY) here, as it prevents player from moving with gamepad
)
//applyForce(Vector2(readonly_totalX, 0.0))
@@ -192,7 +193,6 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
applyVelo(walkCounterY) *
(if (up) -1f else 1f) * absAxisVal
)
@@ -275,10 +275,20 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
* TODO linear function (play Super Mario Bros. and you'll get what I'm talking about)
*/
private fun jump() {
if (jumping) {
val len = MAX_JUMP_LENGTH.toFloat()
val pwr = actorValue.getAsDouble(AVKey.JUMPPOWER)!! * (actorValue.getAsDouble(AVKey.JUMPPOWERMULT) ?: 1.0)
val len = MAX_JUMP_LENGTH.toFloat()
val pwr = actorValue.getAsDouble(AVKey.JUMPPOWER)!! * (actorValue.getAsDouble(AVKey.JUMPPOWERMULT) ?: 1.0)
val jumpLinearThre = 0.08
fun jumpFunc(x: Int): Double {
if (x >= len) return 0.0
val ret = pwr - 0.02 * x
if (ret < jumpLinearThre) return jumpLinearThre
else return ret
}
if (jumping) {
// increment jump counter
if (jumpCounter < len) jumpCounter += 1
@@ -287,6 +297,9 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
var timedJumpCharge = init - init / len * jumpCounter
if (timedJumpCharge < 0) timedJumpCharge = 0.0
// one that uses jumpFunc(x)
//val timedJumpCharge = jumpFunc(jumpCounter)
jumpAcc = -pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * Math.sqrt(scale) // positive value
applyForce(Vector2(0.0, jumpAcc))
@@ -390,7 +403,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
if (noClip) {
if (Terrarum.hasController) {
if (axisY != 0f) {
walkVertical(axisY > 0, axisY.abs())
walkVertical(axisY < 0, axisY.abs())
}
}
// ↑E, ↓D