mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-22 16:34:05 +09:00
ability to change current player as other NPC (maybe… maybe not…)
Former-commit-id: 54773bfa17456aaf42003c1d514e80dd860f58eb Former-commit-id: e84f8312c99cff0e0692a492b7b850d09ffe4e44
This commit is contained in:
@@ -3,6 +3,8 @@ package net.torvald.terrarum.gameactors
|
||||
import net.torvald.terrarum.gameactors.ai.ActorAI
|
||||
|
||||
/**
|
||||
* Note: AI-controlled actor must be 'Controllable'
|
||||
*
|
||||
* Created by minjaesong on 16-03-14.
|
||||
*/
|
||||
interface AIControlled {
|
||||
|
||||
@@ -443,8 +443,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
|
||||
//hitAndForciblyReflectY()
|
||||
hitAndReflectY()
|
||||
hitAndForciblyReflectY() // prevents sticking to the ceiling
|
||||
}
|
||||
else { // the actor is not grounded at all
|
||||
}
|
||||
@@ -507,7 +506,9 @@ open class ActorWithBody : Actor(), Visible {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("it's no use!")
|
||||
/**
|
||||
* prevents sticking to the ceiling
|
||||
*/
|
||||
private fun hitAndForciblyReflectY() {
|
||||
if (veloY.abs() * CEILING_HIT_ELASTICITY > A_PIXEL)
|
||||
veloY = -veloY * CEILING_HIT_ELASTICITY
|
||||
@@ -965,7 +966,7 @@ open class ActorWithBody : Actor(), Visible {
|
||||
private fun assertInit() {
|
||||
// errors
|
||||
if (baseHitboxW == 0 || baseHitboxH == 0)
|
||||
throw RuntimeException("Hitbox dimension was not set.")
|
||||
throw Error("Hitbox dimension was not set.")
|
||||
|
||||
// warnings
|
||||
if (sprite == null && isVisible)
|
||||
|
||||
23
src/net/torvald/terrarum/gameactors/AnyPlayer.kt
Normal file
23
src/net/torvald/terrarum/gameactors/AnyPlayer.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-10-23.
|
||||
*/
|
||||
class AnyPlayer(val actor: HistoricalFigure) {
|
||||
|
||||
init {
|
||||
if (actor !is Controllable)
|
||||
throw IllegalArgumentException("Player must be 'Controllable'!")
|
||||
}
|
||||
|
||||
fun processInput(input: Input) {
|
||||
(actor as Controllable).processInput(input)
|
||||
}
|
||||
|
||||
fun keyPressed(key: Int, c: Char) {
|
||||
(actor as Controllable).keyPressed(key, c)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* An actor (NPC) which has life and death,
|
||||
* though death might not exist if it has achieved immortality :)
|
||||
*
|
||||
* NOTE: all canonical NPCs are must be HistoricalFigure!! (double excl mark, bitch)
|
||||
*
|
||||
* Created by minjaesong on 16-10-10.
|
||||
*/
|
||||
open class HistoricalFigure(born: GameDate, dead: GameDate? = null) : ActorWithBody() {
|
||||
open class HistoricalFigure(val born: GameDate, val dead: GameDate? = null) : ActorWithBody(), Controllable {
|
||||
|
||||
init {
|
||||
this.actorValue["_bornyear"] = born.year
|
||||
@@ -20,6 +23,21 @@ open class HistoricalFigure(born: GameDate, dead: GameDate? = null) : ActorWithB
|
||||
}
|
||||
}
|
||||
|
||||
override fun processInput(input: Input) {
|
||||
// let out children play
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
// let out children play
|
||||
}
|
||||
|
||||
open internal var noClip = false
|
||||
|
||||
open fun isNoClip() = noClip
|
||||
|
||||
open fun setNoClip(b: Boolean) {
|
||||
noClip = b
|
||||
}
|
||||
}
|
||||
|
||||
data class GameDate(val year: Int, val yearlyDay: Int) {
|
||||
|
||||
@@ -46,7 +46,7 @@ object PBSigrid {
|
||||
* fixed value, or 'base value', from creature strength of Dwarf Fortress.
|
||||
* Human race uses 1000. (see CreatureHuman.json)
|
||||
*/
|
||||
p.actorValue[AVKey.STRENGTH] = 1414
|
||||
p.actorValue[AVKey.STRENGTH] = 1414 // this is test character, after all.
|
||||
p.actorValue[AVKey.ENCUMBRANCE] = 1000
|
||||
p.actorValue[AVKey.BASEHEIGHT] = 46
|
||||
|
||||
@@ -59,8 +59,8 @@ object PBSigrid {
|
||||
p.actorValue[AVKey.BASEDEFENCE] = 141
|
||||
|
||||
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
|
||||
p.actorValue["__selectedtile"] = 16 // test code; replace with <tile_item>.primaryUse(gc, delta)
|
||||
p.actorValue["__aimhelper"] = true
|
||||
p.actorValue["__selectedtile"] = 147 // test code; replace with <tile_item>.primaryUse(gc, delta)
|
||||
p.actorValue["__aimhelper"] = true // TODO when you'll gonna implement it?
|
||||
|
||||
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 10, 0)
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.newdawn.slick.SlickException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Game player (YOU!)
|
||||
*
|
||||
* Created by minjaesong on 16-03-14.
|
||||
*/
|
||||
|
||||
@@ -53,7 +55,7 @@ class Player(born: GameDate) : HistoricalFigure(born), Controllable, Pocketed, F
|
||||
@Transient private var prevHMoveKey = KEY_NULL
|
||||
@Transient private var prevVMoveKey = KEY_NULL
|
||||
|
||||
internal var noClip = false
|
||||
override internal var noClip = false
|
||||
|
||||
@Transient private val AXIS_POSMAX = 1.0f
|
||||
@Transient private val GAMEPAD_JUMP = 7
|
||||
@@ -491,11 +493,11 @@ class Player(born: GameDate) : HistoricalFigure(born), Controllable, Pocketed, F
|
||||
}
|
||||
}
|
||||
|
||||
fun isNoClip(): Boolean {
|
||||
override fun isNoClip(): Boolean {
|
||||
return noClip
|
||||
}
|
||||
|
||||
fun setNoClip(b: Boolean) {
|
||||
override fun setNoClip(b: Boolean) {
|
||||
noClip = b
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,8 @@ object PlayerBuilder {
|
||||
private val JSONPATH = "./assets/raw/"
|
||||
private val jsonString = String()
|
||||
|
||||
@Throws(IOException::class, SlickException::class)
|
||||
fun create(): Player {
|
||||
val p: Player = Player(Terrarum.ingame.world.time.currentTimeAsGameDate)
|
||||
fun create(): Actor {
|
||||
val p: Actor = Player(Terrarum.ingame.world.time.currentTimeAsGameDate)
|
||||
CreatureRawInjector.inject(p.actorValue, "CreatureHuman.json")
|
||||
|
||||
// attach sprite
|
||||
|
||||
Reference in New Issue
Block a user