mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
phys arguments are now single PhysProperties object
This commit is contained in:
@@ -366,7 +366,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CameraPlayer(val demoWorld: GameWorld, override val ai: ActorAI) : ActorWithBody(RenderOrder.FRONT, usePhysics = false), AIControlled {
|
private class CameraPlayer(val demoWorld: GameWorld, override val ai: ActorAI) : ActorWithBody(RenderOrder.FRONT, physProp = PhysProperties.MOBILE_OBJECT), AIControlled {
|
||||||
|
|
||||||
override val hitbox = Hitbox(0.0, 0.0, 2.0, 2.0)
|
override val hitbox = Hitbox(0.0, 0.0, 2.0, 2.0)
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import java.util.*
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2016-01-13.
|
* Created by minjaesong on 2016-01-13.
|
||||||
*/
|
*/
|
||||||
open class ActorWithBody(renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) :
|
open class ActorWithBody(renderOrder: RenderOrder, val physProp: PhysProperties) :
|
||||||
Actor(renderOrder) {
|
Actor(renderOrder) {
|
||||||
|
|
||||||
|
|
||||||
@@ -389,7 +389,7 @@ open class ActorWithBody(renderOrder: RenderOrder, val immobileBody: Boolean = f
|
|||||||
isNoSubjectToFluidResistance = isNoClip
|
isNoSubjectToFluidResistance = isNoClip
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usePhysics) {
|
if (!physProp.usePhysics) {
|
||||||
isNoCollideWorld = true
|
isNoCollideWorld = true
|
||||||
isNoSubjectToFluidResistance = true
|
isNoSubjectToFluidResistance = true
|
||||||
isNoSubjectToGrav = true
|
isNoSubjectToGrav = true
|
||||||
@@ -1154,7 +1154,7 @@ open class ActorWithBody(renderOrder: RenderOrder, val immobileBody: Boolean = f
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTileFriction(tile: Int) =
|
private fun getTileFriction(tile: Int) =
|
||||||
if (immobileBody && tile == Block.AIR)
|
if (physProp.immobileBody && tile == Block.AIR)
|
||||||
BlockCodex[Block.AIR].friction.frictionToMult().div(500)
|
BlockCodex[Block.AIR].friction.frictionToMult().div(500)
|
||||||
.times(if (!grounded) elasticity else 1.0)
|
.times(if (!grounded) elasticity else 1.0)
|
||||||
else
|
else
|
||||||
|
|||||||
33
src/net/torvald/terrarum/gameactors/PhysProperties.kt
Normal file
33
src/net/torvald/terrarum/gameactors/PhysProperties.kt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package net.torvald.terrarum.gameactors
|
||||||
|
|
||||||
|
data class PhysProperties(
|
||||||
|
val immobileBody: Boolean,
|
||||||
|
var usePhysics: Boolean,
|
||||||
|
val useStairs: Boolean
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
val HUMANOID_DEFAULT = PhysProperties(
|
||||||
|
immobileBody = false,
|
||||||
|
usePhysics = true,
|
||||||
|
useStairs = true
|
||||||
|
)
|
||||||
|
/** e.g. dropped items, balls */
|
||||||
|
val PHYSICS_OBJECT = PhysProperties(
|
||||||
|
immobileBody = false,
|
||||||
|
usePhysics = true,
|
||||||
|
useStairs = false
|
||||||
|
)
|
||||||
|
/** e.g. voice maker */
|
||||||
|
val IMMOBILE = PhysProperties(
|
||||||
|
immobileBody = true,
|
||||||
|
usePhysics = false,
|
||||||
|
useStairs = false
|
||||||
|
)
|
||||||
|
/** e.g. camera */
|
||||||
|
val MOBILE_OBJECT = PhysProperties(
|
||||||
|
immobileBody = false,
|
||||||
|
usePhysics = false,
|
||||||
|
useStairs = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,7 +134,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
val blockMarkings = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common")
|
val blockMarkings = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common")
|
||||||
internal var showSelection = true
|
internal var showSelection = true
|
||||||
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY, usePhysics = false) {
|
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT) {
|
||||||
|
|
||||||
override var referenceID: ActorID = 1048575 // custom refID
|
override var referenceID: ActorID = 1048575 // custom refID
|
||||||
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
|
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
|
||||||
@@ -175,7 +175,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
private var _testMarkerDrawCalls = 0L
|
private var _testMarkerDrawCalls = 0L
|
||||||
|
|
||||||
private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY, usePhysics = false) {
|
private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT) {
|
||||||
override var referenceID: ActorID = blockPosToRefID(x, y) // custom refID
|
override var referenceID: ActorID = blockPosToRefID(x, y) // custom refID
|
||||||
override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0)
|
override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0)
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MovableWorldCamera(val parent: BuildingMaker) : ActorHumanoid(0, usePhysics = false) {
|
class MovableWorldCamera(val parent: BuildingMaker) : ActorHumanoid(0, physProp = PhysProperties.MOBILE_OBJECT) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
referenceID = Terrarum.PLAYER_REF_ID
|
referenceID = Terrarum.PLAYER_REF_ID
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import java.util.*
|
|||||||
open class ActorHumanoid(
|
open class ActorHumanoid(
|
||||||
birth: Long,
|
birth: Long,
|
||||||
death: Long? = null,
|
death: Long? = null,
|
||||||
usePhysics: Boolean = true
|
physProp: PhysProperties = PhysProperties.HUMANOID_DEFAULT
|
||||||
) : ActorWithBody(RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
|
) : ActorWithBody(RenderOrder.MIDDLE, physProp = physProp), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
|
||||||
|
|
||||||
private val world: GameWorld?
|
private val world: GameWorld?
|
||||||
get() = Terrarum.ingame?.world
|
get() = Terrarum.ingame?.world
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
|||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.Actor
|
import net.torvald.terrarum.gameactors.Actor
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ object CreatureBuilder {
|
|||||||
* @Param jsonFileName with extension
|
* @Param jsonFileName with extension
|
||||||
*/
|
*/
|
||||||
operator fun invoke(module: String, jsonFileName: String): ActorWithBody {
|
operator fun invoke(module: String, jsonFileName: String): ActorWithBody {
|
||||||
val actor = ActorWithBody(Actor.RenderOrder.MIDDLE)
|
val actor = ActorWithBody(Actor.RenderOrder.MIDDLE, physProp = PhysProperties.HUMANOID_DEFAULT)
|
||||||
InjectCreatureRaw(actor.actorValue, module, jsonFileName)
|
InjectCreatureRaw(actor.actorValue, module, jsonFileName)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-03-15.
|
* Created by minjaesong on 2016-03-15.
|
||||||
*/
|
*/
|
||||||
open class DroppedItem(private val item: GameItem) : ActorWithBody(RenderOrder.MIDTOP) {
|
open class DroppedItem(private val item: GameItem) : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (item.dynamicID >= ItemCodex.ACTORID_MIN)
|
if (item.dynamicID >= ItemCodex.ACTORID_MIN)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import net.torvald.terrarum.Terrarum
|
|||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ open class FixtureBase(
|
|||||||
val mainUI: UICanvas? = null
|
val mainUI: UICanvas? = null
|
||||||
|
|
||||||
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
|
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
|
||||||
) : ActorWithBody(renderOrder, immobileBody = true, usePhysics = false), CuedByTerrainChange {
|
) : ActorWithBody(renderOrder, PhysProperties.IMMOBILE), CuedByTerrainChange {
|
||||||
|
|
||||||
var blockBox: BlockBox = blockBox0
|
var blockBox: BlockBox = blockBox0
|
||||||
protected set // something like TapestryObject will want to redefine this
|
protected set // something like TapestryObject will want to redefine this
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ import net.torvald.terrarum.itemproperties.Material
|
|||||||
*/
|
*/
|
||||||
open class HumanoidNPC(
|
open class HumanoidNPC(
|
||||||
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
|
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
|
||||||
born: Long,
|
born: Long
|
||||||
usePhysics: Boolean = true
|
|
||||||
//forceAssignRefID: Int? = null
|
//forceAssignRefID: Int? = null
|
||||||
) : ActorHumanoid(born, usePhysics = usePhysics), AIControlled, CanBeAnItem {
|
) : ActorHumanoid(born), AIControlled, CanBeAnItem {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT_COLLISION_TYPE = COLLISION_DYNAMIC
|
val DEFAULT_COLLISION_TYPE = COLLISION_DYNAMIC
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-03-05.
|
* Created by minjaesong on 2016-03-05.
|
||||||
*/
|
*/
|
||||||
class PhysTestBall : ActorWithBody(RenderOrder.MIDDLE, immobileBody = true) {
|
class PhysTestBall : ActorWithBody(RenderOrder.MIDDLE, PhysProperties.PHYSICS_OBJECT) {
|
||||||
|
|
||||||
private var color = Color.GOLD
|
private var color = Color.GOLD
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.gameactors.*
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2018-01-17.
|
* Created by minjaesong on 2018-01-17.
|
||||||
*/
|
*/
|
||||||
class PhysTestLuarLander : ActorWithBody(RenderOrder.MIDTOP), Controllable {
|
class PhysTestLuarLander : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT), Controllable {
|
||||||
|
|
||||||
private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga"))
|
private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga"))
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex
|
|||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameactors.Hitbox
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
import net.torvald.terrarum.gameactors.Luminous
|
import net.torvald.terrarum.gameactors.Luminous
|
||||||
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ open class ProjectileSimple(
|
|||||||
private val type: Int,
|
private val type: Int,
|
||||||
fromPoint: Vector2, // projected coord
|
fromPoint: Vector2, // projected coord
|
||||||
toPoint: Vector2 // arriving coord
|
toPoint: Vector2 // arriving coord
|
||||||
) : ActorWithBody(RenderOrder.MIDTOP), Luminous, Projectile {
|
) : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT), Luminous, Projectile {
|
||||||
|
|
||||||
val damage: Int
|
val damage: Int
|
||||||
val displayColour: Color
|
val displayColour: Color
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import net.torvald.gdx.graphics.Cvec
|
|||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameactors.Hitbox
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
import net.torvald.terrarum.gameactors.Luminous
|
import net.torvald.terrarum.gameactors.Luminous
|
||||||
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-04-26.
|
* Created by minjaesong on 2016-04-26.
|
||||||
*/
|
*/
|
||||||
class WeaponSwung(val itemID: Int) : ActorWithBody(RenderOrder.MIDTOP), Luminous {
|
class WeaponSwung(val itemID: Int) : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.IMMOBILE), Luminous {
|
||||||
// just let the solver use AABB; it's cheap but works just enough
|
// just let the solver use AABB; it's cheap but works just enough
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ object CollisionSolver {
|
|||||||
|
|
||||||
// mark list x
|
// mark list x
|
||||||
(Terrarum.ingame!! as TerrarumIngame).actorContainerActive.forEach { it ->
|
(Terrarum.ingame!! as TerrarumIngame).actorContainerActive.forEach { it ->
|
||||||
if (it is ActorWithBody && it.usePhysics) {
|
if (it is ActorWithBody && it.physProp.usePhysics) {
|
||||||
collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it))
|
collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it))
|
||||||
collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it))
|
collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it))
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ object CollisionSolver {
|
|||||||
|
|
||||||
// mark list y
|
// mark list y
|
||||||
(Terrarum.ingame!! as TerrarumIngame).actorContainerActive.forEach { it ->
|
(Terrarum.ingame!! as TerrarumIngame).actorContainerActive.forEach { it ->
|
||||||
if (it is ActorWithBody && it.usePhysics) {
|
if (it is ActorWithBody && it.physProp.usePhysics) {
|
||||||
collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it))
|
collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it))
|
||||||
collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it))
|
collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ object BlockBase {
|
|||||||
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
|
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
|
||||||
var ret1 = true
|
var ret1 = true
|
||||||
ingame.actorContainerActive.forEach {
|
ingame.actorContainerActive.forEach {
|
||||||
if (it is ActorWithBody && it.usePhysics && it.intTilewiseHitbox.intersects(mousePoint))
|
if (it is ActorWithBody && it.physProp.usePhysics && it.intTilewiseHitbox.intersects(mousePoint))
|
||||||
ret1 = false // return is not allowed here
|
ret1 = false // return is not allowed here
|
||||||
}
|
}
|
||||||
if (!ret1) return ret1
|
if (!ret1) return ret1
|
||||||
|
|||||||
BIN
work_files/physics_staircasing.kra
Normal file
BIN
work_files/physics_staircasing.kra
Normal file
Binary file not shown.
Reference in New Issue
Block a user