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

@@ -1375,7 +1375,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
* Constants
*/
@Transient private val METER = 24.0
@Transient val METER = 24.0
/**
* [m / s^2] * SI_TO_GAME_ACC -> [px / InternalFrame^2]
*/

View File

@@ -10,7 +10,7 @@ import net.torvald.terrarum.Terrarum
/**
* Created by minjaesong on 2017-12-18.
*/
class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, false, 3.2f) {
class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, 3.2f) {
init {
body = MegaRainGovernor.get()
@@ -22,7 +22,7 @@ class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOr
w, h
)
velocity.y = 18.0
velocity.y = 11.5 * ActorWithPhysics.SI_TO_GAME_VEL
}
}
@@ -46,11 +46,12 @@ object MegaRainGovernor {
val h = body.height
bodies = Array(1024) {
val pixmap = Pixmap(Terrarum.WIDTH * 2, Terrarum.HEIGHT / 4, Pixmap.Format.RGBA8888)
//val pixmap = Pixmap(Terrarum.WIDTH * 2, Terrarum.HEIGHT / 4, Pixmap.Format.RGBA8888)
val pixmap = Pixmap(64, 64, Pixmap.Format.RGBA8888)
val rng = HQRNG()
repeat(64) {
repeat(rng.nextInt(2) + 3) { // 3 or 4
val rndX = rng.nextInt(pixmap.width - body.width)
val rndY = rng.nextInt(pixmap.height - body.height)
@@ -71,7 +72,7 @@ object MegaRainGovernor {
fun get(): TextureRegion {
if (withdrawCounter >= bodies.size) {
withdrawCounter = 0
bodies.shuffle()
//bodies.shuffle() // if pre-rendered random set is sufficiently large, it'd look random enough
}
return bodies[withdrawCounter++]

View File

@@ -0,0 +1,60 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2018-01-17.
*/
class PhysTestLuarLander(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDTOP), Controllable {
private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga"))
override val hitbox: Hitbox
init {
hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
setHitboxDimension(texture.width, texture.height, 0, 0)
actorValue[AVKey.SPEED] = 8.0
avBaseMass = 18650.0
}
override fun run() {
super.run()
}
override fun update(delta: Float) {
super.update(delta)
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
controllerMoveDelta!!.y = avSpeedCap
}
}
override fun keyDown(keycode: Int): Boolean {
return true
}
override fun drawGlow(batch: SpriteBatch) {
}
override fun drawBody(batch: SpriteBatch) {
batch.color = Color.WHITE
batch.draw(texture, hitbox.startX.toFloat(), hitbox.endY.toFloat(), hitbox.width.toFloat(), -hitbox.height.toFloat())
}
override fun onActorValueChange(key: String, value: Any?) {
super.onActorValueChange(key, value)
}
override fun dispose() {
super.dispose()
texture.dispose()
}
}

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()
}
}
}