generalised things so that they would work outside of ingame.world; title screen wip

This commit is contained in:
minjaesong
2017-07-21 19:59:51 +09:00
parent f51417e709
commit a5dd5b9e98
68 changed files with 1141 additions and 328 deletions

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.realestate.LandUtil
@@ -18,8 +19,14 @@ import java.util.*
*
* Created by minjaesong on 16-10-24.
*/
open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
: HistoricalFigure(birth, death), Controllable, Pocketed, Factionable, Luminous, LandHolder {
open class ActorHumanoid(
world: GameWorld,
birth: GameDate,
death: GameDate? = null,
usePhysics: Boolean = true
) : HistoricalFigure(world, birth, death, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder {
var vehicleRiding: Controllable? = null // usually player only
@@ -38,11 +45,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
override var houseDesignation: ArrayList<Long>? = ArrayList()
override fun addHouseTile(x: Int, y: Int) {
if (houseDesignation != null) houseDesignation!!.add(LandUtil.getBlockAddr(x, y))
if (houseDesignation != null) houseDesignation!!.add(LandUtil.getBlockAddr(world, x, y))
}
override fun removeHouseTile(x: Int, y: Int) {
if (houseDesignation != null) houseDesignation!!.remove(LandUtil.getBlockAddr(x, y))
if (houseDesignation != null) houseDesignation!!.remove(LandUtil.getBlockAddr(world, x, y))
}
override fun clearHouseDesignation() {
@@ -135,7 +142,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
protected var isRightDown = false
protected var isJumpDown = false
protected inline val isGamer: Boolean
get() = this == Terrarum.ingame!!.player
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.player
private val nullItem = object : GameItem() {
@@ -164,6 +171,8 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// don't put this into keyPressed; execution order is important!
updateGamerControlBox()
processInput(delta)
updateSprite(delta)
if (noClip) {
@@ -224,7 +233,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
get() = if (isGamer) Terrarum.controller != null
else true
override fun processInput(delta: Float) {
private fun processInput(delta: Float) {
/**
* L-R stop
@@ -538,11 +547,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// flipping the sprite
if (walkHeading == LEFT) {
sprite!!.flip(true, false)
sprite?.flip(true, false)
spriteGlow?.flip(true, false)
}
else {
sprite!!.flip(false, false)
sprite?.flip(false, false)
spriteGlow?.flip(false, false)
}
}

View File

@@ -202,7 +202,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
actor.avStrength / 1000.0
else
1.0 // TODO variable: scale, strength
val swingDmgToFrameDmg = Gdx.graphics.deltaTime.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
val swingDmgToFrameDmg = Terrarum.deltaTime.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
// damage the item
newItem.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.point.Point2d
@@ -23,15 +22,15 @@ typealias Second = Float
/**
* Base class for every actor that has animated sprites. This includes furnishings, paintings, gadgets, etc.
* Also has all the physics
* Also has all the usePhysics
*
* @param renderOrder Rendering order (BEHIND, MIDDLE, MIDTOP, FRONT)
* @param immobileBody use realistic air friction (1/1000 of "unrealistic" canonical setup)
* @param physics use physics simulation
* @param usePhysics use usePhysics simulation
*
* Created by minjaesong on 16-01-13.
*/
open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) :
open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) :
ActorWithBody(renderOrder) {
@@ -45,8 +44,6 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
var drawMode = BlendMode.NORMAL
@Transient private val world: GameWorld = Terrarum.ingame!!.world
var hitboxTranslateX: Int = 0// relative to spritePosX
protected set
var hitboxTranslateY: Int = 0// relative to spritePosY
@@ -133,7 +130,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
@Transient private val ELASTICITY_MAX = 1.0//0.993 // No perpetual motion!
/**
* what pretty much every physics engine has, instead of my 'elasticity'
* what pretty much every usePhysics engine has, instead of my 'elasticity'
*
* This is just a simple macro for 'elasticity'.
*
@@ -164,7 +161,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
/** Default to 'true' */
var isVisible = true
/** Default to 'true' */
var isUpdate = physics
var isUpdate = true
var isNoSubjectToGrav = false
var isNoCollideWorld = false
var isNoSubjectToFluidResistance = false
@@ -239,7 +236,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
internal var colliding = false
protected inline val updateDelta: Float
get() = Gdx.graphics.deltaTime
get() = Terrarum.deltaTime
var isWalkingH = false
@@ -336,6 +333,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
isNoSubjectToFluidResistance = isPlayerNoClip
}
if (!usePhysics) {
isNoCollideWorld = true
isNoSubjectToFluidResistance = true
isNoSubjectToGrav = true
}
////////////////////////////////////////////////////////////////
// Codes that modifies velocity (moveDelta and externalForce) //
@@ -366,7 +369,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
* If and only if:
* This body is NON-STATIC and the other body is STATIC
*/
if (!isPlayerNoClip) {
if (!isNoCollideWorld) {
// // HOW IT SHOULD WORK // //
// ////////////////////////
// combineVeloToMoveDelta now
@@ -428,7 +431,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
walledTop = isWalled(hitbox, COLLIDING_TOP)
walledBottom = isWalled(hitbox, COLLIDING_BOTTOM)
colliding = isColliding(hitbox)
if (isPlayerNoClip) {
if (isNoCollideWorld) {
walledLeft = false
walledRight = false
walledTop = false
@@ -586,7 +589,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
val stepBox = sixteenStep[step]
forEachOccupyingTilePos(stepBox) {
val tileCoord = LandUtil.resolveBlockAddr(it)
val tileCoord = LandUtil.resolveBlockAddr(this.world, it)
val tileProp = BlockCodex.getOrNull(world.getTileFromTerrain(tileCoord.first, tileCoord.second))
if (tileProp == null || tileProp.isSolid) {
@@ -632,7 +635,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
debug1("Collision type: $selfCollisionStatus")
affectingTiles.forEach {
val tileCoord = LandUtil.resolveBlockAddr(it)
val tileCoord = LandUtil.resolveBlockAddr(this.world, it)
debug2("affectign tile: ${tileCoord.first}, ${tileCoord.second}")
}
@@ -1265,7 +1268,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
private fun assertInit() {
// errors
if (baseHitboxW == 0 || baseHitboxH == 0)
throw Error("Hitbox dimension was not set.")
throw Error("Hitbox dimension was not set. (don't modify hitbox directly -- use 'setHitboxDimension()')")
// warnings
if (sprite == null && isVisible)
@@ -1315,7 +1318,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
val tilePosList = ArrayList<BlockAddress>()
for (y in newTilewiseHitbox.startY.toInt()..newTilewiseHitbox.endY.toInt()) {
for (x in newTilewiseHitbox.startX.toInt()..newTilewiseHitbox.endX.toInt()) {
tilePosList.add(LandUtil.getBlockAddr(x, y))
tilePosList.add(LandUtil.getBlockAddr(this.world, x, y))
}
}
@@ -1437,12 +1440,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
}
internal val avAcceleration: Double
get() = actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELBUFF)!! *
(actorValue.getAsDouble(AVKey.ACCELBUFF) ?: 1.0) *
accelMultMovement *
scale.sqrt()
internal val avSpeedCap: Double
get() = actorValue.getAsDouble(AVKey.SPEED)!! *
actorValue.getAsDouble(AVKey.SPEEDBUFF)!! *
(actorValue.getAsDouble(AVKey.SPEEDBUFF) ?: 1.0) *
speedMultByTile *
scale.sqrt()

View File

@@ -7,8 +7,6 @@ package net.torvald.terrarum.gameactors
* Created by minjaesong on 15-12-31.
*/
interface Controllable {
fun processInput(delta: Float)
fun keyDown(keycode: Int): Boolean
}

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-02-05.
@@ -10,8 +12,8 @@ object CreatureBuilder {
/**
* @Param jsonFileName with extension
*/
operator fun invoke(module: String, jsonFileName: String): ActorWithPhysics {
val actor = ActorWithPhysics(Actor.RenderOrder.MIDDLE)
operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWithPhysics {
val actor = ActorWithPhysics(world, Actor.RenderOrder.MIDDLE)
InjectCreatureRaw(actor.actorValue, module, jsonFileName)

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.toUint
import java.io.File
import java.nio.charset.Charset
@@ -171,6 +172,6 @@ object DecodeTapestry {
readCounter++
}
return TapestryObject(outImageData, artName, authorName)
return TapestryObject(Terrarum.ingame!!.world, outImageData, artName, authorName)
}
}

View File

@@ -4,11 +4,12 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-03-15.
*/
open class DroppedItem(private val item: GameItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWithPhysics(world, Actor.RenderOrder.MIDTOP) {
init {
if (item.dynamicID >= ItemCodex.ACTORID_MIN)

View File

@@ -1,12 +1,12 @@
package net.torvald.terrarum.gameactors
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-06-17.
*/
open class FixtureBase(physics: Boolean = true) :
ActorWithPhysics(Actor.RenderOrder.BEHIND, immobileBody = true, physics = physics) {
open class FixtureBase(world: GameWorld, physics: Boolean = true) :
ActorWithPhysics(world, Actor.RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
/**
* 0: Open
* 1: Blocked

View File

@@ -4,13 +4,14 @@ import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
/**
* Created by minjaesong on 16-06-17.
*/
internal class FixtureTikiTorch : FixtureBase(), Luminous {
internal class FixtureTikiTorch(world: GameWorld) : FixtureBase(world), Luminous {
override var color: Color
get() = BlockCodex[Block.TORCH].luminosity

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors
import net.torvald.random.HQRNG
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldTime
typealias AnyPlayer = HistoricalFigure
@@ -15,10 +16,12 @@ typealias AnyPlayer = HistoricalFigure
* Created by minjaesong on 16-10-10.
*/
open class HistoricalFigure(
world: GameWorld,
val born: GameDate,
val dead: GameDate? = null,
realAirFriction: Boolean = false
) : ActorWithPhysics(Actor.RenderOrder.MIDDLE, realAirFriction) {
realAirFriction: Boolean = false,
usePhysics: Boolean = true
) : ActorWithPhysics(world, Actor.RenderOrder.MIDDLE, realAirFriction, usePhysics) {
var historicalFigureIdentifier: Int = generateHistoricalFigureIdentifier()
internal set

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material
@@ -12,11 +13,13 @@ import net.torvald.terrarum.itemproperties.Material
* Created by minjaesong on 16-01-31.
*/
open class HumanoidNPC(
world: GameWorld,
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
born: GameDate
) : ActorHumanoid(born), AIControlled, CanBeAnItem {
born: GameDate,
usePhysics: Boolean = true
) : ActorHumanoid(world, born, usePhysics = usePhysics), AIControlled, CanBeAnItem {
constructor(luaAi: LuaAIWrapper, born: GameDate) : this(luaAi as ActorAI, born) {
constructor(world: GameWorld, luaAi: LuaAIWrapper, born: GameDate) : this(world, luaAi as ActorAI, born) {
luaAi.attachActor(this)
}
@@ -78,8 +81,8 @@ open class HumanoidNPC(
}
override fun update(delta: Float) {
ai.update(this, delta)
super.update(delta)
ai.update(delta)
}
override fun moveLeft(amount: Float) { // hit the buttons on the controller box

View File

@@ -20,7 +20,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, maxLifeTime: Second? = n
/** Will NOT actually delete from the CircularArray */
@Volatile var flagDespawn = false
override fun run() = update(Gdx.graphics.deltaTime)
override fun run() = update(Terrarum.deltaTime)
var isNoSubjectToGrav = false
var dragCoefficient = 3.0

View File

@@ -3,12 +3,13 @@ package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
/**
* Created by minjaesong on 16-03-05.
*/
class PhysTestBall : ActorWithPhysics(Actor.RenderOrder.MIDDLE, immobileBody = true) {
class PhysTestBall(world: GameWorld) : ActorWithPhysics(world, Actor.RenderOrder.MIDDLE, immobileBody = true) {
private var color = Color.GOLD

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameworld.GameWorld
/**
* Game player (YOU!)
@@ -7,7 +9,7 @@ package net.torvald.terrarum.gameactors
* Created by minjaesong on 15-12-31.
*/
class Player(born: GameDate) : ActorHumanoid(born) {
class Player(world: GameWorld, born: GameDate) : ActorHumanoid(world, born) {
companion object {
@Transient const val PLAYER_REF_ID: Int = 0x91A7E2

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.Terrarum
object PlayerBuilder {
operator fun invoke(): Actor {
val p: Actor = Player(Terrarum.ingame!!.world.time.currentTimeAsGameDate)
val p: Actor = Player(Terrarum.ingame!!.world, Terrarum.ingame!!.world.time.currentTimeAsGameDate)
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
// attach sprite

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -13,6 +14,7 @@ object PlayerBuilderCynthia {
operator fun invoke(): ActorWithPhysics {
//val p: Player = Player(GameDate(100, 143)) // random value thrown
val p: HumanoidNPC = HumanoidNPC(
Terrarum.ingame!!.world,
LuaAIWrapper("/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua"),
GameDate(100, 143)) // random value thrown
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.FactionFactory
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
@@ -14,7 +15,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
object PlayerBuilderSigrid {
operator fun invoke(): Player {
val p = Player(GameDate(-2147483648, 0)) // XD
val p = Player(Terrarum.ingame!!.world, GameDate(-2147483648, 0)) // XD
p.referenceID = 0x51621D // the only constant of this procedural universe
p.historicalFigureIdentifier = 0x51621D // the only constant of this procedural universe

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -9,7 +10,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
object PlayerBuilderTestSubject1 {
operator fun invoke(): Player {
val p: Player = Player(GameDate(100, 143)) // random value thrown
val p: Player = Player(Terrarum.ingame!!.world, GameDate(100, 143)) // random value thrown
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Gdx
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
@@ -27,7 +28,7 @@ interface Pocketed {
}
inventory.itemEquipped[item.equipPosition] = null
item.effectOnUnequip(Gdx.graphics.deltaTime)
item.effectOnUnequip(Terrarum.deltaTime)
}
// no need for equipSlot(Int)
@@ -49,7 +50,7 @@ interface Pocketed {
if (item.equipPosition >= 0) {
inventory.itemEquipped[item.equipPosition] = item
item.effectWhenEquipped(Gdx.graphics.deltaTime)
item.effectWhenEquipped(Terrarum.deltaTime)
}
// else do nothing
}
@@ -68,13 +69,13 @@ interface Pocketed {
fun consumePrimary(item: GameItem) {
if (item.primaryUse(Gdx.graphics.deltaTime)) {
if (item.primaryUse(Terrarum.deltaTime)) {
inventory.consumeItem(this as Actor, item) // consume on successful
}
}
fun consumeSecondary(item: GameItem) {
if (item.secondaryUse(Gdx.graphics.deltaTime))
if (item.secondaryUse(Terrarum.deltaTime))
inventory.consumeItem(this as Actor, item) // consume on successful
}
}

View File

@@ -1,15 +1,17 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameworld.GameWorld
import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 16-08-29.
*/
class ProjectileHoming(
world: GameWorld,
type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2 // arriving coord
) : ProjectileSimple(type, fromPoint, toPoint) {
) : ProjectileSimple(world, type, fromPoint, toPoint) {

View File

@@ -6,6 +6,7 @@ import net.torvald.point.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameworld.GameWorld
import org.dyn4j.geometry.Vector2
import java.util.*
@@ -17,10 +18,11 @@ import java.util.*
// TODO simplified, lightweight physics (does not call PhysicsSolver)
open class ProjectileSimple(
world: GameWorld,
private val type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2 // arriving coord
) : ActorWithPhysics(Actor.RenderOrder.MIDTOP), Luminous, Projectile {
) : ActorWithPhysics(world, Actor.RenderOrder.MIDTOP), Luminous, Projectile {
val damage: Int
val displayColour: Color

View File

@@ -4,12 +4,13 @@ import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2017-01-07.
*/
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(physics = false) {
class TapestryObject(world: GameWorld, pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(world, physics = false) {
// physics = false only speeds up for ~2 frames with 50 tapestries

View File

@@ -10,13 +10,13 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
override fun run() {
for (i in startIndex..endIndex) {
val it = Terrarum.ingame!!.actorContainer[i]
it.update(Gdx.graphics.deltaTime)
it.update(Terrarum.deltaTime)
if (it is Pocketed) {
it.inventory.forEach { inventoryEntry ->
inventoryEntry.item.effectWhileInPocket(Gdx.graphics.deltaTime)
inventoryEntry.item.effectWhileInPocket(Terrarum.deltaTime)
if (it.equipped(inventoryEntry.item)) {
inventoryEntry.item.effectWhenEquipped(Gdx.graphics.deltaTime)
inventoryEntry.item.effectWhenEquipped(Terrarum.deltaTime)
}
}
}

View File

@@ -1,11 +1,12 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-04-26.
*/
class WeaponSwung(val itemID: Int) : ActorWithPhysics(Actor.RenderOrder.MIDTOP), Luminous {
class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWithPhysics(world, Actor.RenderOrder.MIDTOP), Luminous {
// just let the solver use AABB; it's cheap but works just enough
/**

View File

@@ -1,8 +1,10 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.gameactors.HumanoidNPC
/**
* Created by minjaesong on 16-03-02.
*/
interface ActorAI {
fun update(delta: Float)
fun update(actor: HumanoidNPC, delta: Float)
}

View File

@@ -1,7 +1,9 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.HumanoidNPC
import org.luaj.vm2.Globals
import org.luaj.vm2.LuaError
import org.luaj.vm2.LuaInteger
@@ -45,7 +47,7 @@ class LuaAIWrapper(private val scriptPath: String) : ActorAI {
luaInstance.call()
}
override fun update(delta: Float) {
override fun update(actor: HumanoidNPC, delta: Float) {
// run "update()" function in the script
luag.get("update").call(delta.toLua())
}