adopting Java 9/Kotlin 1.2

This commit is contained in:
minjaesong
2018-02-10 21:40:17 +09:00
parent 941d9fa107
commit 40423ede52
31 changed files with 326 additions and 69 deletions

View File

@@ -1,7 +1,51 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.HumanoidNPC
import net.torvald.terrarum.gameactors.Second
/**
* Slime's stupid AI but can adjust his jump power to smack you as fast as possible
* by achieving "allostasis".
*
* Created by minjaesong on 2017-12-10.
*/
class SmarterSlimes {
class SmarterSlimes : ActorAI {
val memoryCells = IntArray(12, { 0 })
// index 0: most recent memory
// intentionally making it stupid by using less precise INT
// also we're not discrimination different enemies, making it further dumb
// stores "overshoot" amount (learn target) of x position
var maxJumpDist: Double = -1.0
var cooltime: Second = 5f
override fun update(actor: HumanoidNPC, delta: Float) {
// sensor: compare(my X pos, nearest enemy's X pos)
maxJumpDist = actor.avSpeedCap * actor.jumpAirTime // speed * air_time
// (to be precise, we need simulation just like jumpAirTime, but oh well; we like it LINEAR)
// TEST: just target player
val playerXPos = Terrarum.ingame!!.player.centrePosPoint.x
val thisXPos = actor.centrePosPoint.x
val xDiff = thisXPos - playerXPos
// extrapolate from memories:
// otherwise linear extp. except the slope is d of 0th and 2nd point
if (xDiff > 0) {
actor.moveLeft()
}
}
}