fixed a bug where colourmap won't interpolate properly. BUG: fadeout/fadein is somewhat glitched, UIQuickBar does not fade-in/out instead it just (dis)appears with no effect

Former-commit-id: 029f504b7e2e4d85676ec8b36b27dcbed5e5db47
Former-commit-id: 0b56ca1e8976bfc5e7ea8d665e6ed6496a52de85
This commit is contained in:
Song Minjae
2016-07-27 00:20:36 +09:00
parent 00dd5e99bb
commit ee647652d2
36 changed files with 368 additions and 223 deletions

View File

@@ -64,12 +64,11 @@ open class ActorWithBody : Actor(), Visible {
get() = controllerVel!!.x
internal set(value) { controllerVel!!.x = value }
var walkY: Double
get() = controllerVel!!.x
internal set(value) { controllerVel!!.x = value }
get() = controllerVel!!.y
internal set(value) { controllerVel!!.y = value }
/**
* Physical properties.
* Values derived from ActorValue must be @Transient.
*/
var scale: Double
get() = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0
@@ -212,6 +211,8 @@ open class ActorWithBody : Actor(), Visible {
var ccdCollided = false
var isWalking = false
init {
// some initialiser goes here...
}
@@ -291,6 +292,7 @@ open class ActorWithBody : Actor(), Visible {
* Actual physics thing (altering velocity) starts from here
*/
// Combine velo and walk
applyMovementVelocity()
// applyBuoyancy()
@@ -308,14 +310,13 @@ open class ActorWithBody : Actor(), Visible {
// Set 'next' position (hitbox) from canonical and walking velocity
setNewNextHitbox()
applyNormalForce()
/**
* solveCollision()?
* If and only if:
* This body is NON-STATIC and the other body is STATIC
*/
setNewNextHitbox()
displaceByCCD()
applyNormalForce()
setHorizontalFriction()
if (isPlayerNoClip) // or hanging on the rope, etc.
@@ -394,21 +395,15 @@ open class ActorWithBody : Actor(), Visible {
}
}
/**
* FIXME the culprit!
* (5566 -> no collision but player does not "sink")
* (5567 -> collision)
* How to fix:
*/
private fun applyNormalForce() {
if (!isNoCollideWorld) {
// axis Y. Use operand >=
if (moveDelta.y >= 0.0) { // was moving downward?
if (isColliding(nextHitbox)) {
if (isColliding(nextHitbox)) { // FIXME if standing: standard box, if walking: top-squished box
hitAndReflectY()
grounded = true
}
else if (isTouchingSide(nextHitbox, COLLIDING_BOTTOM)) { // actor hit something on its bottom
else if (isTouchingSide(nextHitbox, COLLIDING_BOTTOM) && !isColliding(nextHitbox)) { // actor hit something on its bottom
grounded = true
}
else { // the actor is not grounded at all
@@ -427,7 +422,7 @@ open class ActorWithBody : Actor(), Visible {
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()
}
}
}
@@ -436,31 +431,32 @@ open class ActorWithBody : Actor(), Visible {
* nextHitbox must NOT be altered before this method is called!
*/
private fun displaceByCCD() {
ccdCollided = false
if (!isNoCollideWorld){
if (!isColliding(nextHitbox, COLLIDING_ALLSIDE))
return
// do some CCD between hitbox and nextHitbox
val ccdBox = nextHitbox.clone()//.snapToPixel()
val ccdDelta = nextHitbox.toVector() to hitbox.toVector()
val deltaMax = Math.max(ccdDelta.x.abs(), ccdDelta.y.abs())
// set ccdDelta so that CCD move a pixel per round
if (deltaMax > 1.0)
ccdDelta *= (1.0 / deltaMax)
val ccdDelta = (nextHitbox.toVector() - hitbox.toVector())
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")
while (!ccdDelta.isZero && isColliding(ccdBox, COLLIDING_ALLSIDE)) {
nextHitbox.translate(ccdDelta)
while (!ccdDelta.isZero && isColliding(nextHitbox, COLLIDING_ALLSIDE)) {
nextHitbox.translate(-ccdDelta)
ccdCollided = true
//ccdBox.reassign(nextHitbox).snapToPixel()
ccdBox.reassign(nextHitbox)
}
//println("ccdCollided: $ccdCollided")
}
else {
ccdCollided = false
}
}
private fun hitAndReflectX() {
@@ -625,7 +621,7 @@ open class ActorWithBody : Actor(), Visible {
}
return false*/
return if (tyEnd <= 347) false else true
return if (tyEnd < 348) false else true
}
private fun getContactingAreaFluid(side: Int, translateX: Int = 0, translateY: Int = 0): Int {
@@ -749,17 +745,23 @@ open class ActorWithBody : Actor(), Visible {
/**
* Get highest friction value from feet tiles.
* Get highest friction value from surrounding tiles
* @return
*/
internal val bodyFriction: Int
get() {
/*var friction = 0
var friction = 0
val frictionCalcHitbox = if (isWalking)
Hitbox(nextHitbox.posX + 1.0, nextHitbox.posY + 1.0,
nextHitbox.width - 2.0, nextHitbox.height - 2.0)
else
nextHitbox.clone()
// take highest value
val tilePosXStart = (hitbox.posX / TSIZE).roundInt()
val tilePosXEnd = (hitbox.hitboxEnd.x / TSIZE).roundInt()
val tilePosY = (hitbox.pointedY.plus(1) / TSIZE).roundInt()
val tilePosXStart = (frictionCalcHitbox.posX / TSIZE).floorInt()
val tilePosXEnd = (frictionCalcHitbox.hitboxEnd.x / TSIZE).floorInt()
val tilePosY = (frictionCalcHitbox.pointedY / TSIZE).floorInt()
for (x in tilePosXStart..tilePosXEnd) {
val tile = world.getTileFromTerrain(x, tilePosY)
val thisFriction = TilePropCodex.getProp(tile).friction
@@ -767,16 +769,10 @@ open class ActorWithBody : Actor(), Visible {
if (thisFriction > friction) friction = thisFriction
}
return friction*/
return 1
return friction
}
fun Int.tileFrictionToMult(): Double = this / 16.0
internal val feetFriction: Int
get() {
return 16
}
/**
* Get highest tile density from occupying tiles, fluid only
*/

View File

@@ -54,7 +54,7 @@ object PBSigrid {
p.actorValue[AVKey.INTELLIGENT] = true
p.actorValue[AVKey.LUMINOSITY] = 95487100
p.actorValue[AVKey.LUMINOSITY] = 0//95487100
p.actorValue[AVKey.BASEDEFENCE] = 141

View File

@@ -36,8 +36,10 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
/** how long the jump button has down, in frames */
internal var jumpCounter = 0
internal var jumpAcc = 0.0
/** how long the walk button has down, in frames */
internal var walkCounter = 0
internal var walkCounterX = 0
internal var walkCounterY = 0
@Transient private val MAX_JUMP_LENGTH = 17 // use 17; in internal frames
private var readonly_totalX = 0.0
@@ -134,7 +136,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
* @author minjaesong
*/
private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
if ((!walledLeft && left) || (!walledRight && !left)) {
if (true) {//(!walledLeft && left) || (!walledRight && !left)) {
readonly_totalX = //veloX +
/*actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
@@ -145,7 +147,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
applyVelo(walkCounter) *
applyVelo(walkCounterX) *
(if (left) -1 else 1).toFloat() *
absAxisVal
@@ -153,7 +155,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkX += readonly_totalX
walkX = absClamp(walkX, actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDMULT)!!)
walkCounter += 1
walkCounterX += 1
// Heading flag
if (left)
@@ -162,6 +164,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkHeading = RIGHT
// println("$walkCounter: ${readonly_totalX}")
isWalking = true
}
}
@@ -176,13 +179,16 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
applyVelo(walkCounter) *
applyVelo(walkCounterY) *
(if (up) -1 else 1).toFloat() *
absAxisVal
applyForce(Vector2(0.0, readonly_totalY))
walkY += readonly_totalY
walkY = absClamp(walkY, actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDMULT)!!)
if (walkCounter <= WALK_FRAMES_TO_MAX_ACCEL) walkCounter += 1
//if (walkCounterY <= WALK_FRAMES_TO_MAX_ACCEL) walkCounterY += 1
isWalking = true
}
private fun applyAccel(x: Int): Double {
@@ -219,7 +225,8 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
//veloX = 0f
walkCounter = 0
walkCounterX = 0
isWalking = false
}
// stops; let the friction kick in by doing nothing to the velocity here
@@ -245,7 +252,8 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
///veloY = 0f
walkCounter = 0
walkCounterY = 0
isWalking = false
}
/**
@@ -266,9 +274,11 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
var timedJumpCharge = init - init / len * jumpCounter
if (timedJumpCharge < 0) timedJumpCharge = 0.0
val jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * Math.sqrt(scale) // positive value
jumpAcc = -pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * Math.sqrt(scale) // positive value
applyForce(Vector2(0.0, -jumpAcc))
applyForce(Vector2(0.0, jumpAcc))
if (jumpAcc != 0.0) println(jumpAcc)
}
// for mob ai:
@@ -359,7 +369,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkHorizontal(true, AXIS_POSMAX)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)
} // ↓F, ↓S
else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
/*else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
walkHorizontal(false, AXIS_POSMAX)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)
@@ -367,7 +377,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkHorizontal(true, AXIS_POSMAX)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)
}
}
}*/
}
/**
@@ -388,7 +398,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkVertical(true, AXIS_POSMAX)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)
} // ↓E, ↓D
else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) && isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
/*else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) && isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
walkVertical(false, AXIS_POSMAX)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)
@@ -396,7 +406,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkVertical(true, AXIS_POSMAX)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)
}
}
}*/
}
}