working vital meter for tool durability

This commit is contained in:
Song Minjae
2017-04-21 18:11:30 +09:00
parent 4e14b24011
commit e9c8f03000
35 changed files with 338 additions and 185 deletions

View File

@@ -0,0 +1,36 @@
package net.torvald.terrarum
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.ui.UIVitalMetre
/**
* Created by SKYHi14 on 2017-04-21.
*/
object AmmoMeterProxy {
operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) {
val currentItem = actor.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]
if (currentItem == null) {
meter.vitalGetterMax = { null }
meter.vitalGetterVal = { null }
}
else {
meter.vitalGetterVal = {
if (ItemCodex[currentItem.id].consumable)
actor.inventory.getByID(currentItem.id)!!.amount.toFloat()
else
actor.inventory.getByID(currentItem.id)!!.item.durability
}
meter.vitalGetterMax = {
if (ItemCodex[currentItem.id].consumable)
500f
else
actor.inventory.getByID(currentItem.id)!!.item.maxDurability.toFloat()
}
}
}
}

View File

@@ -72,7 +72,8 @@ class StateInGame : BasicGameState() {
lateinit var notifier: UIHandler
private var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT!
var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT!
private set
internal val player: ActorHumanoid? // currently POSSESSED actor :)
get() = playableActorDelegate?.actor
@@ -95,21 +96,20 @@ class StateInGame : BasicGameState() {
val KEY_LIGHTMAP_SMOOTH = Key.F8
// UI aliases (no pause)
val uiAliases = HashMap<String, UIHandler>()
val UI_PIE_MENU = "uiPieMenu"
val UI_QUICK_BAR = "uiQuickBar"
val UI_INVENTORY_PLAYER = "uiInventoryPlayer"
val UI_INVENTORY_CONTAINER = "uiInventoryContainer"
val UI_VITAL_PRIMARY = "uiVital1"
val UI_VITAL_SECONDARY = "uiVital2"
val UI_VITAL_ITEM = "uiVital3" // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
val UI_CONSOLE = "uiConsole"
lateinit var uiPieMenu: UIHandler
lateinit var uiQuickBar: UIHandler
lateinit var uiInventoryPlayer: UIHandler
lateinit var uiInventoryContainer: UIHandler
lateinit var uiVitalPrimary: UIHandler
lateinit var uiVitalSecondary: UIHandler
lateinit var uiVitalItem: UIHandler // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
lateinit var uiAliases: Array<UIHandler>
// UI aliases (pause)
val uiAlasesPausing = HashMap<String, UIHandler>()
val uiAlasesPausing = ArrayList<UIHandler>()
var paused: Boolean = false
get() = uiAlasesPausing.map { if (it.value.isOpened) 1 else 0 }.sum() > 0
get() = uiAlasesPausing.map { if (it.isOpened) 1 else 0 }.sum() > 0
/**
* Set to false if UI is opened; set to true if UI is closed.
*/
@@ -155,7 +155,6 @@ class StateInGame : BasicGameState() {
// init console window
consoleHandler = UIHandler(ConsoleWindow())
consoleHandler.setPosition(0, 0)
uiAlasesPausing[UI_CONSOLE] = consoleHandler
// init debug window
@@ -175,7 +174,7 @@ class StateInGame : BasicGameState() {
// >- queue up game UIs that should pause the world -<
// inventory
uiAlasesPausing[UI_INVENTORY_PLAYER] = UIHandler(
uiInventoryPlayer = UIHandler(
UIInventory(player,
width = 840,
height = Terrarum.HEIGHT - 160,
@@ -183,42 +182,48 @@ class StateInGame : BasicGameState() {
),
toggleKey = Terrarum.getConfigInt("keyinventory")
)
uiAlasesPausing[UI_INVENTORY_PLAYER]!!.setPosition(
-uiAlasesPausing[UI_INVENTORY_PLAYER]!!.UI.width,
uiInventoryPlayer.setPosition(
-uiInventoryPlayer.UI.width,
70
)
// >- lesser UIs -<
// quick bar
uiAliases[UI_QUICK_BAR] = UIHandler(UIQuickBar())
uiAliases[UI_QUICK_BAR]!!.isVisible = true
uiAliases[UI_QUICK_BAR]!!.setPosition(0, 0)
uiQuickBar = UIHandler(UIQuickBar())
uiQuickBar.isVisible = true
uiQuickBar.setPosition(0, 0)
// pie menu
uiAliases[UI_PIE_MENU] = UIHandler(UIPieMenu())
uiAliases[UI_PIE_MENU]!!.setPosition(
(Terrarum.WIDTH - uiAliases[UI_PIE_MENU]!!.UI.width) / 2,
(Terrarum.HEIGHT - uiAliases[UI_PIE_MENU]!!.UI.height) / 2
uiPieMenu = UIHandler(UIPieMenu())
uiPieMenu.setPosition(
(Terrarum.WIDTH - uiPieMenu.UI.width) / 2,
(Terrarum.HEIGHT - uiPieMenu.UI.height) / 2
)
// vital metre
// fill in getter functions by
// (uiAliases[UI_QUICK_BAR]!!.UI as UIVitalMetre).vitalGetterMax = { some_function }
uiAliases[UI_VITAL_PRIMARY] = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 0), customPositioning = true)
uiAliases[UI_VITAL_PRIMARY]!!.setAsAlwaysVisible()
uiAliases[UI_VITAL_SECONDARY] = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true)
uiAliases[UI_VITAL_SECONDARY]!!.setAsAlwaysVisible()
uiAliases[UI_VITAL_ITEM] = UIHandler(UIVitalMetre(player, { 32f }, { 100f }, Color(0xffcc00), 2), customPositioning = true)
uiAliases[UI_VITAL_ITEM]!!.setAsAlwaysVisible()
uiVitalPrimary = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2), customPositioning = true)
uiVitalPrimary.setAsAlwaysVisible()
uiVitalSecondary = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true)
uiVitalSecondary.setAsAlwaysVisible()
uiVitalItem = UIHandler(UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0), customPositioning = true)
uiVitalItem.setAsAlwaysVisible()
// batch-process uiAliases
uiAlasesPausing.forEach { _, uiHandler ->
uiContainer.add(uiHandler) // put them all to the UIContainer
}
uiAliases.forEach { _, uiHandler ->
uiContainer.add(uiHandler) // put them all to the UIContainer
}
uiAliases = arrayOf(
uiPieMenu,
uiQuickBar,
uiInventoryPlayer,
//uiInventoryContainer,
uiVitalPrimary,
uiVitalSecondary,
uiVitalItem
)
uiAlasesPausing.forEach { uiContainer.add(it) } // put them all to the UIContainer
uiAliases.forEach { uiContainer.add(it) } // put them all to the UIContainer
@@ -346,7 +351,7 @@ class StateInGame : BasicGameState() {
playableActorDelegate!!.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE
// accept new delegate
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
playableActorDelegate!!.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC
playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC
WorldSimulator(player, UPDATE_DELTA)
}
@@ -446,7 +451,7 @@ class StateInGame : BasicGameState() {
// debug physics
if (KeyToggler.isOn(Key.F11)) {
actorContainer.forEachIndexed { i, actor ->
if (actor is ActorWithSprite) {
if (actor is ActorWithPhysics) {
worldG.color = Color(1f, 0f, 1f, 1f)
worldG.font = Terrarum.fontSmallNumbers
worldG.lineWidth = 1f
@@ -527,8 +532,8 @@ class StateInGame : BasicGameState() {
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|| key == Terrarum.getConfigInt("keyquicksel")) {
uiAliases[UI_PIE_MENU]!!.setAsOpen()
uiAliases[UI_QUICK_BAR]!!.setAsClose()
uiPieMenu.setAsOpen()
uiQuickBar.setAsClose()
}
uiContainer.forEach { it.keyPressed(key, c) } // for KeyboardControlled UIcanvases
@@ -539,8 +544,8 @@ class StateInGame : BasicGameState() {
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|| key == Terrarum.getConfigInt("keyquicksel")) {
uiAliases[UI_PIE_MENU]!!.setAsClose()
uiAliases[UI_QUICK_BAR]!!.setAsOpen()
uiPieMenu.setAsClose()
uiQuickBar.setAsOpen()
}
uiContainer.forEach { it.keyReleased(key, c) } // for KeyboardControlled UIcanvases
@@ -679,6 +684,7 @@ class StateInGame : BasicGameState() {
}
}
}
AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre)
}
}

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
/**
* Created by minjaesong on 2017-01-20.
@@ -15,8 +15,8 @@ object SetScale : ConsoleCommand {
val target = Terrarum.ingame!!.getActorByID(targetID)
if (target !is ActorWithSprite) {
EchoError("Target is not ActorWithSprite")
if (target !is ActorWithPhysics) {
EchoError("Target is not ActorWithPhysics")
}
else {
target.scale = scale

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.PhysTestBall
import net.torvald.terrarum.mapdrawer.TilesDrawer
import net.torvald.terrarum.Terrarum

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.console
import net.torvald.terrarum.StateInGame
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
/**
* Created by minjaesong on 16-01-24.
@@ -31,8 +31,8 @@ internal object Teleport : ConsoleCommand {
EchoError("missing 'to' on teleport command")
return
}
val fromActor: ActorWithSprite
val targetActor: ActorWithSprite
val fromActor: ActorWithPhysics
val targetActor: ActorWithPhysics
try {
val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player")
@@ -43,13 +43,13 @@ internal object Teleport : ConsoleCommand {
// if from == target, ignore the action
if (fromActorID == targetActorID) return
if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWithSprite ||
Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWithSprite) {
if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWithPhysics ||
Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWithPhysics) {
throw IllegalArgumentException()
}
else {
fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWithSprite
targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWithSprite
fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWithPhysics
targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWithPhysics
}
}
catch (e: NumberFormatException) {
@@ -72,7 +72,7 @@ internal object Teleport : ConsoleCommand {
return
}
val actor: ActorWithSprite
val actor: ActorWithPhysics
val x: Int
val y: Int
try {
@@ -80,11 +80,11 @@ internal object Teleport : ConsoleCommand {
y = args[4].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
val actorID = args[1].toInt()
if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWithSprite) {
if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWithPhysics) {
throw IllegalArgumentException()
}
else {
actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWithSprite
actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWithPhysics
}
}
catch (e: NumberFormatException) {

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.SetAV
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
import java.awt.BorderLayout
import java.awt.GridLayout
@@ -28,7 +28,7 @@ class ActorValueTracker constructor() : JFrame() {
private val avPosArea = JTextArea()
private val avPosScroller = JScrollPane(avPosArea)
private var actor: ActorWithSprite? = null
private var actor: ActorWithPhysics? = null
private var actorValue: ActorValue? = null
private val modavInputKey = JTextField()
@@ -87,7 +87,7 @@ class ActorValueTracker constructor() : JFrame() {
actorValue = actor!!.actorValue
}
else if (actorIDField.text.isNotBlank()) {
actor = Terrarum.ingame!!.getActorByID(actorIDField.text.toInt()) as ActorWithSprite
actor = Terrarum.ingame!!.getActorByID(actorIDField.text.toInt()) as ActorWithPhysics
actorValue = actor!!.actorValue
}
}
@@ -151,7 +151,7 @@ class ActorValueTracker constructor() : JFrame() {
this.title = "AVTracker — $actor"
if (actor is ActorWithSprite) {
if (actor is ActorWithPhysics) {
this.actor = actor
}

View File

@@ -344,7 +344,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
* this code base, ACCELERATION must be changed (in other words, we must deal with JERK) accordingly
* to the FRICTION.
*
* So I'm adding walkX/Y and getting the ActorWithSprite.setNewNextHitbox to use the velocity value of
* So I'm adding walkX/Y and getting the ActorWithPhysics.setNewNextHitbox to use the velocity value of
* walkX/Y + velocity, which is stored in variable moveDelta.
*
* Be warned.

View File

@@ -26,7 +26,7 @@ import java.util.*
*
* Created by minjaesong on 16-01-13.
*/
open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) : ActorVisible(renderOrder) {
open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) : ActorVisible(renderOrder) {
/** !! ActorValue macros are on the very bottom of the source !! **/
@@ -113,7 +113,7 @@ open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean =
if (value <= 0)
throw IllegalArgumentException("mass cannot be less than or equal to zero.")
else if (value < MASS_LOWEST) {
println("[ActorWithSprite] input too small; using $MASS_LOWEST instead.")
println("[ActorWithPhysics] input too small; using $MASS_LOWEST instead.")
actorValue[AVKey.BASEMASS] = MASS_LOWEST
}
@@ -126,7 +126,7 @@ open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean =
if (value < 0)
throw IllegalArgumentException("invalid elasticity value $value; valid elasticity value is [0, 1].")
else if (value >= ELASTICITY_MAX) {
println("[ActorWithSprite] Elasticity were capped to $ELASTICITY_MAX.")
println("[ActorWithPhysics] Elasticity were capped to $ELASTICITY_MAX.")
field = ELASTICITY_MAX
}
else
@@ -150,7 +150,7 @@ open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean =
var density = 1000.0
set(value) {
if (value < 0)
throw IllegalArgumentException("[ActorWithSprite] $value: density cannot be negative.")
throw IllegalArgumentException("[ActorWithPhysics] $value: density cannot be negative.")
field = value
}
@@ -190,7 +190,7 @@ open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean =
get() = actorValue.getAsDouble(AVKey.DRAGCOEFF) ?: DRAG_COEFF_DEFAULT
set(value) {
if (value < 0)
throw IllegalArgumentException("[ActorWithSprite] drag coefficient cannot be negative.")
throw IllegalArgumentException("[ActorWithPhysics] drag coefficient cannot be negative.")
actorValue[AVKey.DRAGCOEFF] = value
}
@@ -272,8 +272,8 @@ open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean =
* @param h
* @param tx positive: translate sprite to LEFT.
* @param ty positive: translate sprite to DOWN.
* @see ActorWithSprite.drawBody
* @see ActorWithSprite.drawGlow
* @see ActorWithPhysics.drawBody
* @see ActorWithPhysics.drawGlow
*/
fun setHitboxDimension(w: Int, h: Int, tx: Int, ty: Int) {
baseHitboxH = h
@@ -1166,9 +1166,9 @@ open class ActorWithSprite(renderOrder: RenderOrder, val immobileBody: Boolean =
// warnings
if (sprite == null && isVisible)
println("[ActorWithSprite] Caution: actor ${this.javaClass.simpleName} is echo but the sprite was not set.")
println("[ActorWithPhysics] Caution: actor ${this.javaClass.simpleName} is echo but the sprite was not set.")
else if (sprite != null && !isVisible)
println("[ActorWithSprite] Caution: actor ${this.javaClass.simpleName} is invisible but the sprite was given.")
println("[ActorWithPhysics] Caution: actor ${this.javaClass.simpleName} is invisible but the sprite was given.")
assertPrinted = true
}

View File

@@ -18,8 +18,8 @@ object CreatureBuilder {
* @Param jsonFileName with extension
*/
@Throws(IOException::class, SlickException::class)
operator fun invoke(module: String, jsonFileName: String): ActorWithSprite {
val actor = ActorWithSprite(Actor.RenderOrder.MIDDLE)
operator fun invoke(module: String, jsonFileName: String): ActorWithPhysics {
val actor = ActorWithPhysics(Actor.RenderOrder.MIDDLE)
InjectCreatureRaw(actor.actorValue, module, jsonFileName)

View File

@@ -9,7 +9,7 @@ import org.newdawn.slick.Graphics
/**
* Created by minjaesong on 16-03-15.
*/
class DroppedItem(private val item: InventoryItem) : ActorWithSprite(Actor.RenderOrder.MIDTOP) {
class DroppedItem(private val item: InventoryItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
init {
if (item.id >= ItemCodex.ACTOR_ID_MIN)

View File

@@ -6,7 +6,7 @@ import net.torvald.spriteanimation.SpriteAnimation
* Created by minjaesong on 16-06-17.
*/
open class FixtureBase(physics: Boolean = true) :
ActorWithSprite(Actor.RenderOrder.BEHIND, immobileBody = true, physics = physics) {
ActorWithPhysics(Actor.RenderOrder.BEHIND, immobileBody = true, physics = physics) {
/**
* 0: Open
* 1: Blocked

View File

@@ -13,7 +13,7 @@ typealias AnyPlayer = HistoricalFigure
*
* Created by minjaesong on 16-10-10.
*/
open class HistoricalFigure(val born: GameDate, val dead: GameDate? = null, realAirFriction: Boolean = false) : ActorWithSprite(Actor.RenderOrder.MIDDLE, realAirFriction) {
open class HistoricalFigure(val born: GameDate, val dead: GameDate? = null, realAirFriction: Boolean = false) : ActorWithPhysics(Actor.RenderOrder.MIDDLE, realAirFriction) {
init {
this.actorValue["_bornyear"] = born.year

View File

@@ -34,7 +34,7 @@ open class HumanoidNPC(
}
companion object {
val DEFAULT_COLLISION_TYPE = ActorWithSprite.COLLISION_DYNAMIC
val DEFAULT_COLLISION_TYPE = ActorWithPhysics.COLLISION_DYNAMIC
}
init {

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithSprite.Companion.SI_TO_GAME_ACC
import net.torvald.terrarum.gameactors.ActorWithPhysics.Companion.SI_TO_GAME_ACC
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex

View File

@@ -10,7 +10,7 @@ import org.newdawn.slick.Graphics
/**
* Created by minjaesong on 16-03-05.
*/
class PhysTestBall : ActorWithSprite(Actor.RenderOrder.MIDDLE, immobileBody = true) {
class PhysTestBall : ActorWithPhysics(Actor.RenderOrder.MIDDLE, immobileBody = true) {
private var color = Color.orange

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.AmmoMeterProxy
import net.torvald.terrarum.gameactors.ActorHumanoid
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
@@ -17,12 +18,4 @@ class PlayableActorDelegate(val actor: ActorHumanoid) {
throw IllegalArgumentException("Player must be 'Controllable'!")
}
fun processInput(gc: GameContainer, delta: Int, input: Input) {
(actor as Controllable).processInput(gc, delta, input)
}
fun keyPressed(key: Int, c: Char) {
(actor as Controllable).keyPressed(key, c)
}
}

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.mapdrawer.FeaturesDrawer
*/
object PlayerBuilderCynthia {
operator fun invoke(): ActorWithSprite {
operator fun invoke(): ActorWithPhysics {
//val p: Player = Player(GameDate(100, 143)) // random value thrown
val p: HumanoidNPC = HumanoidNPC(
LuaAIWrapper("/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua"),

View File

@@ -23,7 +23,7 @@ open class ProjectileSimple(
private val type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2 // arriving coord
) : ActorWithSprite(Actor.RenderOrder.MIDTOP), Luminous, Projectile {
) : ActorWithPhysics(Actor.RenderOrder.MIDTOP), Luminous, Projectile {
val damage: Int
val displayColour: Color

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.gameactors
/**
* Created by minjaesong on 16-04-26.
*/
class WeaponSwung(val itemID: Int) : ActorWithSprite(Actor.RenderOrder.MIDTOP), Luminous {
class WeaponSwung(val itemID: Int) : ActorWithPhysics(Actor.RenderOrder.MIDTOP), Luminous {
// just let the solver use AABB; it's cheap but works just enough
/**

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AIControlled
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.mapdrawer.LightmapRenderer
import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex
@@ -14,7 +14,7 @@ import org.luaj.vm2.lib.ZeroArgFunction
/**
* Created by minjaesong on 16-10-24.
*/
internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
internal class AILuaAPI(g: Globals, actor: ActorWithPhysics) {
// FIXME when actor jumps, the actor releases left/right stick
@@ -51,9 +51,9 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
companion object {
/**
* Reads arbitrary ActorWithSprite and returns its information as Lua table
* Reads arbitrary ActorWithPhysics and returns its information as Lua table
*/
fun composeActorObject(actor: ActorWithSprite): LuaTable {
fun composeActorObject(actor: ActorWithPhysics): LuaTable {
val t: LuaTable = LuaTable()
t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
@@ -87,7 +87,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
operator fun LuaTable.set(index: Int, value: Int) { this[index] = value.toLua() }
}
class GetSelfActorInfo(val actor: ActorWithSprite) : ZeroArgFunction() {
class GetSelfActorInfo(val actor: ActorWithPhysics) : ZeroArgFunction() {
override fun call(): LuaValue {
return composeActorObject(actor)
}
@@ -123,13 +123,13 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
}
}
class GetX(val actor: ActorWithSprite) : ZeroArgFunction() {
class GetX(val actor: ActorWithPhysics) : ZeroArgFunction() {
override fun call(): LuaValue {
return LuaValue.valueOf(actor.hitbox.centeredX)
}
}
class GetY(val actor: ActorWithSprite) : ZeroArgFunction() {
class GetY(val actor: ActorWithPhysics) : ZeroArgFunction() {
override fun call(): LuaValue {
return LuaValue.valueOf(actor.hitbox.centeredY)
}
@@ -212,7 +212,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
}
}
class GetNearbyTiles(val actor: ActorWithSprite) : OneArgFunction() {
class GetNearbyTiles(val actor: ActorWithPhysics) : OneArgFunction() {
/** @param radius
*
* 3 will return 7x7 array, 0 will return 1x1, 1 will return 3x3
@@ -254,7 +254,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
}
}
class GetFloorsHeight(val actor: ActorWithSprite) : OneArgFunction() {
class GetFloorsHeight(val actor: ActorWithPhysics) : OneArgFunction() {
/** @param radius
*
* 3 will return len:7 array, 0 will return len:1, 1 will return len:3
@@ -297,7 +297,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
}
}
class GetCeilingsHeight(val actor: ActorWithSprite) : OneArgFunction() {
class GetCeilingsHeight(val actor: ActorWithPhysics) : OneArgFunction() {
/** @param arg radius
*
* 3 will return 7x7 array, 0 will return 1x1, 1 will return 3x3
@@ -340,7 +340,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithSprite) {
}
}
class GetLedgesHeight(val actor: ActorWithSprite) : OneArgFunction() {
class GetLedgesHeight(val actor: ActorWithPhysics) : OneArgFunction() {
/** @param arg radius
* ==
* <- (non-solid found)

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import org.luaj.vm2.Globals
import org.luaj.vm2.LuaError
import org.luaj.vm2.LuaInteger
@@ -25,14 +25,14 @@ class LuaAIWrapper(private val scriptPath: String) : ActorAI {
private lateinit var aiLuaAPI: AILuaAPI
private lateinit var targetActor: ActorWithSprite
private lateinit var targetActor: ActorWithPhysics
/**
* The initialiser
*
* Use ```(p.ai as LuaAIWrapper).attachActor(p)```
*/
fun attachActor(actor: ActorWithSprite) {
fun attachActor(actor: ActorWithPhysics) {
targetActor = actor
luag["io"] = LuaValue.NIL

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum.gameactors.physicssolver
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import java.util.*
/**
@@ -20,9 +20,9 @@ object CollisionSolver {
private val collListX = ArrayList<CollisionMarkings>(COLL_LIST_SIZE)
private val collListY = ArrayList<CollisionMarkings>(COLL_LIST_SIZE)
private val collCandidateX = ArrayList<Pair<ActorWithSprite, ActorWithSprite>>(COLL_CANDIDATES_SIZE)
private val collCandidateY = ArrayList<Pair<ActorWithSprite, ActorWithSprite>>(COLL_CANDIDATES_SIZE)
private var collCandidates = ArrayList<Pair<ActorWithSprite, ActorWithSprite>>(COLL_FINAL_CANDIDATES_SIZE)
private val collCandidateX = ArrayList<Pair<ActorWithPhysics, ActorWithPhysics>>(COLL_CANDIDATES_SIZE)
private val collCandidateY = ArrayList<Pair<ActorWithPhysics, ActorWithPhysics>>(COLL_CANDIDATES_SIZE)
private var collCandidates = ArrayList<Pair<ActorWithPhysics, ActorWithPhysics>>(COLL_FINAL_CANDIDATES_SIZE)
private val collCandidateStack = Stack<CollisionMarkings>()
@@ -40,7 +40,7 @@ object CollisionSolver {
// mark list x
Terrarum.ingame!!.actorContainer.forEach { it ->
if (it is ActorWithSprite) {
if (it is ActorWithPhysics) {
collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it))
collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it))
}
@@ -73,7 +73,7 @@ object CollisionSolver {
// mark list y
Terrarum.ingame!!.actorContainer.forEach { it ->
if (it is ActorWithSprite) {
if (it is ActorWithPhysics) {
collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it))
collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it))
}
@@ -89,7 +89,7 @@ object CollisionSolver {
else if (it.kind == ENDPOINT) {
val mark_this = it
val mark_other = collCandidateStack.pop()
val collCandidate: Pair<ActorWithSprite, ActorWithSprite>
val collCandidate: Pair<ActorWithPhysics, ActorWithPhysics>
// make sure actor with lower ID comes first
if (mark_this.actor < mark_other.actor)
collCandidate = Pair(mark_this.actor, mark_other.actor)
@@ -137,7 +137,7 @@ object CollisionSolver {
return indexOfEqFn(this, other) >= 0
}
private fun solveCollision(a: ActorWithSprite, b: ActorWithSprite) {
private fun solveCollision(a: ActorWithPhysics, b: ActorWithPhysics) {
// some of the Pair(a, b) are either duplicates or erroneously reported.
// e.g. (A, B), (B, C) and then (A, C);
// in some situation (A, C) will not making any contact with each other
@@ -170,11 +170,11 @@ object CollisionSolver {
}
}
private infix fun ActorWithSprite.makesCollisionWith(other: ActorWithSprite) =
this.collisionType != ActorWithSprite.COLLISION_NOCOLLIDE &&
other.collisionType != ActorWithSprite.COLLISION_NOCOLLIDE
private infix fun ActorWithPhysics.makesCollisionWith(other: ActorWithPhysics) =
this.collisionType != ActorWithPhysics.COLLISION_NOCOLLIDE &&
other.collisionType != ActorWithPhysics.COLLISION_NOCOLLIDE
private infix fun ActorWithSprite.isCollidingWith(other: ActorWithSprite): Boolean {
private infix fun ActorWithPhysics.isCollidingWith(other: ActorWithPhysics): Boolean {
val ax = this.hitbox.centeredX
val ay = this.hitbox.centeredY
val bx = other.hitbox.centeredX
@@ -205,7 +205,7 @@ object CollisionSolver {
data class CollisionMarkings(
val pos: Double,
val kind: Int,
val actor: ActorWithSprite
val actor: ActorWithPhysics
)
/**

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors.physicssolver
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
/**
* Created by minjaesong on 16-05-01.
@@ -11,7 +11,7 @@ object VelocitySolver {
}
private fun applyGravity(actor: ActorWithSprite) {
private fun applyGravity(actor: ActorWithPhysics) {
}

View File

@@ -115,6 +115,7 @@ object GameController {
fun mouseReleased(button: Int, x: Int, y: Int) {
if (Terrarum.ingame != null) {
val ingame = Terrarum.ingame!!
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.player != null && ingame.canPlayerControl) {
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]

View File

@@ -20,6 +20,8 @@ class GameWorld(val width: Int, val height: Int) {
val layerWallLowBits: PairedMapLayer
val layerTerrainLowBits: PairedMapLayer
val layerThermal: MapLayerFloat // in Kelvins
val spawnX: Int
val spawnY: Int
@@ -46,6 +48,9 @@ class GameWorld(val width: Int, val height: Int) {
layerTerrainLowBits = PairedMapLayer(width, height)
layerWallLowBits = PairedMapLayer(width, height)
layerThermal = MapLayerFloat(width / 2, height / 2)
time = WorldTime(
71 * WorldTime.DAY_LENGTH +
7 * WorldTime.HOUR_SEC +

View File

@@ -0,0 +1,60 @@
package net.torvald.terrarum.gameworld
import net.torvald.dataclass.Float16
import net.torvald.dataclass.Float16Bits
/**
* MapLayer that contains raw Float16 values
*
* Created by SKYHi14 on 2017-04-21.
*/
class MapLayerFloat(val width: Int, val height: Int) : Iterable<Float16Bits> {
internal @Volatile var data: Array<Array<Float16Bits>> // in parallel programming: do not trust your register; always read freshly from RAM!
init {
data = Array(height) { Array(width, { 0.toShort() }) }
}
/**
* Returns an iterator over elements of type `T`.
* @return an Iterator.
*/
override fun iterator(): Iterator<Float16Bits> {
return object : Iterator<Float16Bits> {
private var iteratorCount = 0
override fun hasNext(): Boolean {
return iteratorCount < width * height
}
override fun next(): Float16Bits {
val y = iteratorCount / width
val x = iteratorCount % width
// advance counter
iteratorCount += 1
return data[y][x]
}
}
}
internal fun getValue(x: Int, y: Int): Float? {
return if (x !in 0..width - 1 || y !in 0..height - 1)
null
else
data[y][x].toFloat()
}
internal fun setValue(x: Int, y: Int, value: Float) {
data[y][x] = Float16.fromFloat(value)
}
fun isInBound(x: Int, y: Int) = (x >= 0 && y >= 0 && x < width && y < height)
companion object {
@Transient const val SIZEOF: Byte = 2 // 1 for 8-bit, 2 for 16-bit, ...
}
}

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.gameactors.CanBeAnItem
import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.gamecontroller.mouseTileX
import net.torvald.terrarum.gamecontroller.mouseTileY
import net.torvald.terrarum.itemproperties.IVKey
@@ -71,7 +71,7 @@ object ItemCodex {
val mousePoint = Point2d(gc.mouseTileX.toDouble(), gc.mouseTileY.toDouble())
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
Terrarum.ingame!!.actorContainer.forEach {
if (it is ActorWithSprite && it.tilewiseHitbox.intersects(mousePoint))
if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint))
return false
}
@@ -109,7 +109,7 @@ object ItemCodex {
override var baseMass = 10.0
override var baseToolSize: Double? = 10.0
override var consumable = false
override var maxDurability = 606 // this much tiles before breaking
override var maxDurability = 147//606 // this much tiles before breaking
override var durability = maxDurability.toFloat()
override var equipPosition = EquipPosition.HAND_GRIP
override var inventoryCategory = Category.TOOL
@@ -132,7 +132,7 @@ object ItemCodex {
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
Terrarum.ingame!!.actorContainer.forEach {
if (it is ActorWithSprite && it.tilewiseHitbox.intersects(mousePoint))
if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint))
return false
}

View File

@@ -7,7 +7,7 @@ import com.jme3.math.FastMath
import net.torvald.colourutil.RGB
import net.torvald.colourutil.CIELuvUtil.additiveLuv
import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.abs
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.gameworld.GameWorld
@@ -217,7 +217,7 @@ object LightmapRenderer {
private fun buildLanternmap() {
lanternMap.clear()
Terrarum.ingame!!.actorContainer.forEach { it ->
if (it is Luminous && it is ActorWithSprite) {
if (it is Luminous && it is ActorWithPhysics) {
// put lanterns to the area the luminantBox is occupying
for (lightBox in it.lightBoxList) {
val lightBoxX = it.hitbox.posX + lightBox.posX

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.ui
import net.torvald.gadgets.HistoryArray
import net.torvald.dataclass.HistoryArray
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.Authenticator