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

@@ -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) {
}