mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 14:04:05 +09:00
get operator on Tile/ItemPropCodex
Former-commit-id: f6c4ecbad8c0ce2486524be70e68292d6aae799e Former-commit-id: 9738a693eb55861d1292e59d8df2bec7f5603c40
This commit is contained in:
@@ -26,16 +26,16 @@ open class ActorWithBody : Actor() {
|
||||
@Transient internal var sprite: SpriteAnimation? = null
|
||||
@Transient internal var spriteGlow: SpriteAnimation? = null
|
||||
|
||||
internal var drawMode: DrawMode = DrawMode.NORMAL
|
||||
protected var drawMode: DrawMode = DrawMode.NORMAL
|
||||
|
||||
@Transient private val world: GameWorld = Terrarum.ingame.world
|
||||
|
||||
var hitboxTranslateX: Double = 0.0// relative to spritePosX
|
||||
var hitboxTranslateY: Double = 0.0// relative to spritePosY
|
||||
var baseHitboxW: Int = 0
|
||||
var baseHitboxH: Int = 0
|
||||
internal var baseSpriteWidth: Int = 0
|
||||
internal var baseSpriteHeight: Int = 0
|
||||
protected var hitboxTranslateX: Double = 0.0// relative to spritePosX
|
||||
protected var hitboxTranslateY: Double = 0.0// relative to spritePosY
|
||||
protected var baseHitboxW: Int = 0
|
||||
protected var baseHitboxH: Int = 0
|
||||
protected var baseSpriteWidth: Int = 0
|
||||
protected var baseSpriteHeight: Int = 0
|
||||
/**
|
||||
* * Position: top-left point
|
||||
* * Unit: pixel
|
||||
@@ -228,6 +228,11 @@ open class ActorWithBody : Actor() {
|
||||
internal @Volatile var walledLeft = false
|
||||
internal @Volatile var walledRight = false
|
||||
|
||||
protected val gameContainer: GameContainer
|
||||
get() = Terrarum.appgc
|
||||
protected val updateDelta: Int
|
||||
get() = Terrarum.ingame.UPDATE_DELTA
|
||||
|
||||
/**
|
||||
* true: This actor had just made collision
|
||||
*/
|
||||
@@ -292,7 +297,7 @@ open class ActorWithBody : Actor() {
|
||||
val feetPosition: Vector2
|
||||
get() = Vector2(hitbox.centeredX, hitbox.posY + hitbox.height)
|
||||
|
||||
override fun run() = update(Terrarum.appgc, Terrarum.ingame.UPDATE_DELTA)
|
||||
override fun run() = update(gameContainer, updateDelta)
|
||||
|
||||
/**
|
||||
* Add vector value to the velocity, in the time unit of single frame.
|
||||
@@ -681,7 +686,7 @@ open class ActorWithBody : Actor() {
|
||||
for (y in tyStart..tyEnd) {
|
||||
for (x in txStart..txEnd) {
|
||||
val tile = world.getTileFromTerrain(x, y)
|
||||
if (TilePropCodex.getProp(tile).isSolid)
|
||||
if (TilePropCodex[tile].isSolid)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -723,7 +728,7 @@ open class ActorWithBody : Actor() {
|
||||
}
|
||||
|
||||
// evaluate
|
||||
if (TilePropCodex.getProp(world.getTileFromTerrain(tileX, tileY)).isFluid) {
|
||||
if (TilePropCodex[world.getTileFromTerrain(tileX, tileY)].isFluid) {
|
||||
contactAreaCounter += 1
|
||||
}
|
||||
}
|
||||
@@ -733,7 +738,7 @@ open class ActorWithBody : Actor() {
|
||||
|
||||
private fun setHorizontalFriction() {
|
||||
val friction = if (isPlayerNoClip)
|
||||
BASE_FRICTION * TilePropCodex.getProp(TileNameCode.STONE).friction.tileFrictionToMult()
|
||||
BASE_FRICTION * TilePropCodex[TileNameCode.STONE].friction.tileFrictionToMult()
|
||||
else
|
||||
BASE_FRICTION * bodyFriction.tileFrictionToMult()
|
||||
|
||||
@@ -760,7 +765,7 @@ open class ActorWithBody : Actor() {
|
||||
|
||||
private fun setVerticalFriction() {
|
||||
val friction = if (isPlayerNoClip)
|
||||
BASE_FRICTION * TilePropCodex.getProp(TileNameCode.STONE).friction.tileFrictionToMult()
|
||||
BASE_FRICTION * TilePropCodex[TileNameCode.STONE].friction.tileFrictionToMult()
|
||||
else
|
||||
BASE_FRICTION * bodyFriction.tileFrictionToMult()
|
||||
|
||||
@@ -835,7 +840,7 @@ open class ActorWithBody : Actor() {
|
||||
|
||||
for (x in tilePosXStart..tilePosXEnd) {
|
||||
val tile = world.getTileFromTerrain(x, tilePosY)
|
||||
val thisFriction = TilePropCodex.getProp(tile).friction
|
||||
val thisFriction = TilePropCodex[tile].friction
|
||||
|
||||
if (thisFriction > friction) friction = thisFriction
|
||||
}
|
||||
@@ -860,7 +865,7 @@ open class ActorWithBody : Actor() {
|
||||
for (y in tilePosXStart..tilePosYEnd) {
|
||||
for (x in tilePosXStart..tilePosXEnd) {
|
||||
val tile = world.getTileFromTerrain(x, y)
|
||||
val prop = TilePropCodex.getProp(tile)
|
||||
val prop = TilePropCodex[tile]
|
||||
|
||||
if (prop.isFluid && prop.density > density)
|
||||
density = prop.density
|
||||
@@ -885,7 +890,7 @@ open class ActorWithBody : Actor() {
|
||||
for (y in tilePosYStart..tilePosYEnd) {
|
||||
for (x in tilePosXStart..tilePosXEnd) {
|
||||
val tile = world.getTileFromTerrain(x, y)
|
||||
val thisFluidDensity = TilePropCodex.getProp(tile).density
|
||||
val thisFluidDensity = TilePropCodex[tile].density
|
||||
|
||||
if (thisFluidDensity > density) density = thisFluidDensity
|
||||
}
|
||||
|
||||
@@ -12,17 +12,17 @@ import org.newdawn.slick.Graphics
|
||||
class DroppedItem(private val item: InventoryItem) : ActorWithBody() {
|
||||
|
||||
init {
|
||||
if (item.itemID >= ItemPropCodex.ITEM_COUNT_MAX)
|
||||
if (item.id >= ItemPropCodex.ITEM_COUNT_MAX)
|
||||
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
|
||||
|
||||
isVisible = true
|
||||
|
||||
mass = if (item.itemID < TilePropCodex.TILE_UNIQUE_MAX)
|
||||
TilePropCodex.getProp(item.itemID).density / 1000.0
|
||||
mass = if (item.id < TilePropCodex.TILE_UNIQUE_MAX)
|
||||
TilePropCodex[item.id].density / 1000.0
|
||||
else
|
||||
ItemPropCodex.getProp(item.itemID).mass
|
||||
ItemPropCodex[item.id].mass
|
||||
|
||||
scale = ItemPropCodex.getProp(item.itemID).scale
|
||||
scale = ItemPropCodex[item.id].scale
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*
|
||||
class FixtureTikiTorch : FixtureBase(), Luminous {
|
||||
|
||||
override var luminosity: Int
|
||||
get() = TilePropCodex.getProp(TileNameCode.TORCH).luminosity
|
||||
get() = TilePropCodex[TileNameCode.TORCH].luminosity
|
||||
set(value) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
@@ -35,6 +35,6 @@ class FixtureTikiTorch : FixtureBase(), Luminous {
|
||||
|
||||
actorValue[AVKey.BASEMASS] = 1.0
|
||||
|
||||
luminosity = TilePropCodex.getProp(TileNameCode.TORCH).luminosity
|
||||
luminosity = TilePropCodex[TileNameCode.TORCH].luminosity
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package net.torvald.terrarum.gameactors
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.gameitem.InventoryItemAdapter
|
||||
import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LoadState
|
||||
import org.luaj.vm2.LuaError
|
||||
@@ -41,8 +40,8 @@ open class HumanoidNPC(aiFile: String, born: GameDate) : ActorHumanoid(born), AI
|
||||
}
|
||||
|
||||
// we're having InventoryItem data so that this class could be somewhat universal
|
||||
override var itemData: InventoryItem = object : InventoryItemAdapter() {
|
||||
override var itemID = referenceID
|
||||
override var itemData: InventoryItem = object : InventoryItem() {
|
||||
override var id = referenceID
|
||||
override val equipPosition: Int = EquipPosition.HAND_GRIP
|
||||
|
||||
override var mass: Double
|
||||
|
||||
@@ -77,7 +77,7 @@ object PlayerBuilderSigrid {
|
||||
|
||||
// Test fill up inventory
|
||||
p.inventory.add(16)
|
||||
p.itemEquipped[EquipPosition.HAND_GRIP] = ItemPropCodex.getProp(16)
|
||||
p.equipItem(ItemPropCodex[16])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user