Player movement seems like back to working, res→assets

Former-commit-id: f91181caee4dabf4cb2e51d8077441c6b0f83757
Former-commit-id: 8b450303698c5c85dea9145a056b290b95a6a7b0
This commit is contained in:
Song Minjae
2016-08-02 17:32:42 +09:00
parent 5e7a95a3b9
commit 17c39c1824
248 changed files with 371 additions and 104 deletions

View File

@@ -112,6 +112,8 @@ open class ActorWithBody : Actor(), Visible {
set(value) { elasticity = 1.0 - value }
get() = 1.0 - elasticity
@Transient private val CEILING_HIT_ELASTICITY = 0.3
var density = 1000.0
set(value) {
if (value < 0)
@@ -374,7 +376,7 @@ open class ActorWithBody : Actor(), Visible {
* Apply only if not grounded; normal force is precessed separately.
*/
private fun applyGravitation() {
if (!isTouchingSide(hitbox, COLLIDING_BOTTOM)) {//(!isColliding(COLLIDING_BOTTOM)) { // or !grounded
if (!isTouchingSide(hitbox, COLLIDING_BOTTOM)) {
/**
* weight; gravitational force in action
* W = mass * G (9.8 [m/s^2])
@@ -388,7 +390,7 @@ open class ActorWithBody : Actor(), Visible {
* Drag of atmosphere
* D = Cd (drag coefficient) * 0.5 * rho (density) * V^2 (velocity sqr) * A (area)
*/
val D: Vector2 = velocity * DRAG_COEFF * 0.5 * A// * tileDensityFluid.toDouble()
val D: Vector2 = Vector2(veloX.magnSqr(), veloY.magnSqr()) * DRAG_COEFF * 0.5 * A// * tileDensityFluid.toDouble()
val V: Vector2 = (W - D) / mass * SI_TO_GAME_ACC
@@ -398,9 +400,13 @@ open class ActorWithBody : Actor(), Visible {
private fun applyNormalForce() {
if (!isNoCollideWorld) {
// axis Y. Use operand >=
if (moveDelta.y >= 0.0) { // was moving downward?
if (isColliding(nextHitbox)) { // FIXME if standing: standard box, if walking: top-squished box
// axis Y. Using operand >= and hitting the ceiling will lock the player to the position
if (moveDelta.y > 0.0) { // was moving downward?
if (isColliding(nextHitbox, COLLIDING_TOP)) { // hit the ceiling
hitAndForciblyReflectY()
grounded = false
}
else if (isColliding(nextHitbox)) { // FIXME if standing: standard box, if walking: top-squished box
hitAndReflectY()
grounded = true
}
@@ -415,7 +421,7 @@ open class ActorWithBody : Actor(), Visible {
else if (moveDelta.y < 0.0) { // or was moving upward?
grounded = false
if (isTouchingSide(nextHitbox, COLLIDING_TOP)) { // actor hit something on its top
hitAndReflectY()
hitAndForciblyReflectY()
}
else { // the actor is not grounded at all
}
@@ -478,6 +484,13 @@ open class ActorWithBody : Actor(), Visible {
}
}
private fun hitAndForciblyReflectY() {
if (veloY.abs() * CEILING_HIT_ELASTICITY > A_PIXEL)
veloY = -veloY * CEILING_HIT_ELASTICITY
else
veloY = veloY.sign() * -A_PIXEL
}
private fun isColliding(hitbox: Hitbox) = isColliding(hitbox, 0)
private fun isColliding(hitbox: Hitbox, option: Int): Boolean {
@@ -915,33 +928,6 @@ open class ActorWithBody : Actor(), Visible {
private val AUTO_CLIMB_RATE: Int
get() = Math.min(TSIZE / 8 * Math.sqrt(scale), TSIZE.toDouble()).toInt()
fun Double.floorInt() = Math.floor(this).toInt()
fun Double.round() = Math.round(this).toDouble()
fun Double.floor() = Math.floor(this)
fun Double.ceil() = this.floor() + 1.0
fun Double.roundInt(): Int = Math.round(this).toInt()
fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this
fun Int.abs() = if (this < 0) -this else this
fun Double.bipolarClamp(limit: Double) =
if (this > 0 && this > limit) limit
else if (this < 0 && this < -limit) -limit
else this
fun absMax(left: Double, right: Double): Double {
if (left > 0 && right > 0)
if (left > right) return left
else return right
else if (left < 0 && right < 0)
if (left < right) return left
else return right
else {
val absL = left.abs()
val absR = right.abs()
if (absL > absR) return left
else return right
}
}
private fun assertInit() {
// errors
if (baseHitboxW == 0 || baseHitboxH == 0)
@@ -983,3 +969,32 @@ open class ActorWithBody : Actor(), Visible {
}
}
}
fun Double.floorInt() = Math.floor(this).toInt()
fun Double.round() = Math.round(this).toDouble()
fun Double.floor() = Math.floor(this)
fun Double.ceil() = this.floor() + 1.0
fun Double.roundInt(): Int = Math.round(this).toInt()
fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this
fun Int.abs() = if (this < 0) -this else this
fun Double.bipolarClamp(limit: Double) =
if (this > 0 && this > limit) limit
else if (this < 0 && this < -limit) -limit
else this
fun absMax(left: Double, right: Double): Double {
if (left > 0 && right > 0)
if (left > right) return left
else return right
else if (left < 0 && right < 0)
if (left < right) return left
else return right
else {
val absL = left.abs()
val absR = right.abs()
if (absL > absR) return left
else return right
}
}
fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr()
fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0

View File

@@ -0,0 +1,166 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import java.util.*
/**
* Provides MDL interpretation, pre-compilation and stores state of the interpreter
*
* Created by minjaesong on 16-07-30.
*/
class MDLInterpreterState {
val stack = MagicArrayStack(20)
fun interpret(line: String) {
}
fun execute(property: MagicWords, power: MagicWords? = null, arg: Int? = null) {
}
enum class MagicWords {
// properties
ELDR, IS, STORMR, HREYFING, LAEKNING, GLEYPI, TJON,
//fire, ice, storm, kinesis, heal, absorb, harm
// reserved words
LAEKNINGHRADI, HREYFINGHRADI, LAEKNINGAUKI, HREYFINGAUKI, STOEKKAUKI, HEILSASTIG,
// heal rate,movement speed, healratemult,movespeedmult, jump boost, health point
// adjectives (power)
// operators
ITA, POP, PLUS, MINUS, SINNUM, DEILING, LEIFASTOFN, AFRIT, TALASKIPTI, HENDA
// push, pop, +, -, *, /, %, dup, swap, drop
}
class MagicOrInt() {
private var magic: MagicWords? = null
private var number: Int? = null
constructor(kynngi: MagicWords): this() {
magic = kynngi
}
constructor(integer: Int) : this() {
number = integer
}
fun toMagic() = if (magic != null) magic!! else throw TypeCastException("$this: cannot be cast to MagicWord")
fun toInt() = if (number != null) number!! else throw TypeCastException("$this: cannot be cast to MagicWord")
fun isMagic() = (magic != null)
fun isInt() = (number != null)
override fun toString(): String = if (magic != null && number == null) "$magic" else if (magic == null && number != null) "$number" else "INVALID"
}
class MagicArrayStack {
/**
* Number of elements in the stack
*/
var depth: Int = 0
private set
var size: Int
get() = data.size
set(newSize) {
if (newSize > depth) inflate(newSize - data.size)
else deflate(data.size - newSize)
}
private lateinit var data: Array<MagicOrInt?>
constructor(stackSize: Int) {
data = Array(stackSize, { null })
}
constructor(arr: Array<MagicOrInt?>) {
data = arr.copyOf()
depth = size
}
fun push(v: MagicOrInt) {
if (depth >= data.size) throw StackOverflowError()
data[depth++] = v
}
fun pop(): MagicOrInt {
if (depth == 0) throw EmptyStackException()
return data[--depth]!!
}
fun peek(): MagicOrInt? {
if (depth == 0) return null
return data[depth - 1]
}
fun dup() {
if (depth == 0) throw EmptyStackException()
if (depth == data.size) throw StackOverflowError()
push(peek()!!)
}
fun swap() {
if (depth < 2) throw UnsupportedOperationException("Stack is empty or has only one element.")
val up = pop()
val dn = pop()
push(up)
push(dn)
}
fun drop() {
if (depth == 0) throw EmptyStackException()
--depth
}
fun defineFromArray(arr: Array<MagicOrInt?>) { data = arr.copyOf() }
/**
* Increase the stack size by a factor.
*/
fun inflate(sizeToAdd: Int) {
if (sizeToAdd < 0) throw UnsupportedOperationException("$sizeToAdd: Cannot deflate the stack with this function. Use deflate(int) instead.")
size += sizeToAdd
val oldStack = this.asArray()
data = Array(size, { if (it < oldStack.size) oldStack[it] else null })
}
/**
* Decrease the stack size by a factor. Overflowing data will be removed.
*/
fun deflate(sizeToTake: Int) {
if (size - sizeToTake < 1) throw UnsupportedOperationException("$sizeToTake: Cannot deflate the stack to the size of zero or negative.")
size -= sizeToTake
val oldStack = this.asArray()
data = Array(size, { oldStack[it] })
if (depth > data.size) depth = data.size
}
/**
* Convert stack as array. Index zero is the bottommost element.
* @return array of data, with array size equivalent to the stack depth.
*/
fun asArray() = data.copyOfRange(0, depth - 1)
fun equalTo(other: MagicArrayStack) = (this.asArray() == other.asArray())
fun plus() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() + (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun minus() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() - (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun times() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() * (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun div() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() / (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun mod() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() % (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
}
}

View File

@@ -16,7 +16,7 @@ object PBCynthia {
p.sprite = SpriteAnimation()
p.sprite!!.setDimension(26, 42)
p.sprite!!.setSpriteImage("res/graphics/sprites/test_player_2.png")
p.sprite!!.setSpriteImage("assets/graphics/sprites/test_player_2.png")
p.sprite!!.setDelay(200)
p.sprite!!.setRowsAndFrames(1, 1)
p.sprite!!.setAsVisible()

View File

@@ -20,14 +20,14 @@ object PBSigrid {
p.sprite = SpriteAnimation()
p.sprite!!.setDimension(28, 51)
p.sprite!!.setSpriteImage("res/graphics/sprites/test_player.png")
p.sprite!!.setSpriteImage("assets/graphics/sprites/test_player.png")
p.sprite!!.setDelay(200)
p.sprite!!.setRowsAndFrames(1, 1)
p.sprite!!.setAsVisible()
p.spriteGlow = SpriteAnimation()
p.spriteGlow!!.setDimension(28, 51)
p.spriteGlow!!.setSpriteImage("res/graphics/sprites/test_player_glow.png")
p.spriteGlow!!.setSpriteImage("assets/graphics/sprites/test_player_glow.png")
p.spriteGlow!!.setDelay(200)
p.spriteGlow!!.setRowsAndFrames(1, 1)
p.spriteGlow!!.setAsVisible()

View File

@@ -79,7 +79,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
override val lightBoxList: List<Hitbox>
get() = arrayOf(Hitbox(0.0, 0.0, hitbox.width, hitbox.height)).toList() // use getter; dimension of the player may change by time.
var gamepad: Controller? = Controllers.getController(0)
var gamepad: Controller? = null
var axisX = 0f
var axisY = 0f
var axisRX = 0f
@@ -105,6 +105,13 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
referenceID = PLAYER_REF_ID // forcibly set ID
density = BASE_DENSITY
collisionType = KINEMATIC
try {
gamepad = Controllers.getController(0)
}
catch (e: IndexOutOfBoundsException) {
println("[Player] gamepad not detected.")
}
}
override fun update(gc: GameContainer, delta: Int) {

View File

@@ -7,7 +7,7 @@ import java.io.IOException
* Created by minjaesong on 16-03-15.
*/
object PlayerBuilder {
private val JSONPATH = "./res/raw/"
private val JSONPATH = "./assets/raw/"
private val jsonString = String()
@Throws(IOException::class, SlickException::class)

View File

@@ -10,7 +10,7 @@ import java.io.IOException
*/
object FactionFactory {
const val JSONPATH = "./res/raw/factions/"
const val JSONPATH = "./assets/raw/factions/"
/**
* @param filename with extension