mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 14:04: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:
@@ -58,7 +58,9 @@ constructor() : BasicGameState() {
|
||||
lateinit var debugWindow: UIHandler
|
||||
lateinit var notifier: UIHandler
|
||||
|
||||
lateinit internal var player: Player
|
||||
lateinit internal var playerWrapper: AnyPlayer
|
||||
internal val player: HistoricalFigure // currently POSSESSED actor :)
|
||||
get() = playerWrapper.actor
|
||||
|
||||
//private var GRADIENT_IMAGE: Image? = null
|
||||
//private var skyBox: Rectangle? = null
|
||||
@@ -119,7 +121,7 @@ constructor() : BasicGameState() {
|
||||
|
||||
|
||||
// add new player and put it to actorContainer
|
||||
player = PBSigrid.create()
|
||||
playerWrapper = AnyPlayer(PBSigrid.create())
|
||||
//player = PBCynthia.create()
|
||||
//player.setNoClip(true);
|
||||
addActor(player)
|
||||
@@ -199,6 +201,8 @@ constructor() : BasicGameState() {
|
||||
///////////////////////////
|
||||
// actor-related updates //
|
||||
///////////////////////////
|
||||
repossessActor()
|
||||
|
||||
// determine whether the inactive actor should be re-active
|
||||
wakeDormantActors()
|
||||
// determine whether the actor should be active or dormant
|
||||
@@ -226,6 +230,31 @@ constructor() : BasicGameState() {
|
||||
Terrarum.gameConfig["smoothlighting"] = KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH)
|
||||
}
|
||||
|
||||
private fun repossessActor() {
|
||||
// check if currently pocessed actor is removed from game
|
||||
if (!hasActor(player))
|
||||
// re-possess canonical player
|
||||
changePossession(Player.PLAYER_REF_ID) // TODO completely other behaviour?
|
||||
}
|
||||
|
||||
private fun changePossession(newActor: AnyPlayer) {
|
||||
if (!hasActor(player)) {
|
||||
throw IllegalArgumentException("No such actor in actorContainer: $newActor")
|
||||
}
|
||||
|
||||
playerWrapper = newActor
|
||||
WorldSimulator(world, player, UPDATE_DELTA)
|
||||
}
|
||||
|
||||
private fun changePossession(refid: Int) {
|
||||
if (!hasActor(refid)) {
|
||||
throw IllegalArgumentException("No such actor in actorContainer: $refid")
|
||||
}
|
||||
|
||||
playerWrapper = AnyPlayer(getActorByID(refid) as HistoricalFigure)
|
||||
WorldSimulator(world, player, UPDATE_DELTA)
|
||||
}
|
||||
|
||||
private fun setAppTitle() {
|
||||
Terrarum.appgc.setTitle(
|
||||
"${Terrarum.NAME}" +
|
||||
@@ -319,7 +348,7 @@ constructor() : BasicGameState() {
|
||||
}
|
||||
// fluidmap debug
|
||||
if (KeyToggler.isOn(Key.F4))
|
||||
WorldSimulator.drawFluidMapDebug(player, g)
|
||||
WorldSimulator.drawFluidMapDebug(g)
|
||||
|
||||
|
||||
//////////////
|
||||
@@ -482,7 +511,7 @@ constructor() : BasicGameState() {
|
||||
|
||||
fun Double.sqr() = this * this
|
||||
fun Int.sqr() = this * this
|
||||
private fun distToActorSqr(a: Visible, p: Player): Double =
|
||||
private fun distToActorSqr(a: Visible, p: ActorWithBody): Double =
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr()
|
||||
/** whether the actor is within screen */
|
||||
private fun Visible.inScreen() = distToActorSqr(this, player) <=
|
||||
|
||||
Reference in New Issue
Block a user