mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
abolished a need to pass world as parametre
+ simply changing the single variable (ingame.world) will update all the renderer's behaviour + somehow my git changelogs are exploding
This commit is contained in:
@@ -139,7 +139,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
||||
})
|
||||
|
||||
|
||||
cameraPlayer = object : HumanoidNPC(demoWorld, cameraAI, born = 0, usePhysics = false, forceAssignRefID = Terrarum.PLAYER_REF_ID) {
|
||||
cameraPlayer = object : HumanoidNPC(cameraAI, born = 0, usePhysics = false, forceAssignRefID = Terrarum.PLAYER_REF_ID) {
|
||||
init {
|
||||
setHitboxDimension(2, 2, 0, 0)
|
||||
hitbox.setPosition(
|
||||
@@ -224,7 +224,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
||||
|
||||
demoWorld.globalLight = WeatherMixer.globalLightNow
|
||||
demoWorld.updateWorldTime(delta)
|
||||
WeatherMixer.update(delta, cameraPlayer)
|
||||
WeatherMixer.update(delta, cameraPlayer, demoWorld)
|
||||
cameraPlayer.update(delta)
|
||||
|
||||
// worldcamera update AFTER cameraplayer in this case; the other way is just an exception for actual ingame SFX
|
||||
|
||||
@@ -4,15 +4,13 @@ import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-17.
|
||||
*/
|
||||
internal object SetGlobalLightOverride : ConsoleCommand {
|
||||
|
||||
var lightOverride = false
|
||||
private set
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 5) {
|
||||
try {
|
||||
@@ -22,7 +20,7 @@ internal object SetGlobalLightOverride : ConsoleCommand {
|
||||
val a = args[4].toFloat()
|
||||
val GL = Color(r, g, b, a)
|
||||
|
||||
lightOverride = true
|
||||
WeatherMixer.globalLightOverridden = true
|
||||
(Terrarum.ingame!!.world).globalLight = GL
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
@@ -33,6 +31,9 @@ internal object SetGlobalLightOverride : ConsoleCommand {
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.size == 2 && args[1].trim().toLowerCase() == "none") {
|
||||
WeatherMixer.globalLightOverridden = false
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
|
||||
@@ -31,15 +31,21 @@ import java.util.*
|
||||
*
|
||||
* Created by minjaesong on 2016-01-13.
|
||||
*/
|
||||
open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) :
|
||||
open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) :
|
||||
ActorWithBody(renderOrder) {
|
||||
|
||||
|
||||
val COLLISION_TEST_MODE = false
|
||||
|
||||
/** !! ActorValue macros are on the very bottom of the source !! **/
|
||||
/* !! ActorValue macros are on the very bottom of the source !! */
|
||||
|
||||
/** This is GameWorld? only because the title screen also uses this thing as its camera;
|
||||
* titlescreen does not use instance of Ingame.
|
||||
*/
|
||||
private val world: GameWorld?
|
||||
get() = Terrarum.ingame?.world
|
||||
|
||||
|
||||
@Transient internal var sprite: SpriteAnimation? = null
|
||||
@Transient internal var spriteGlow: SpriteAnimation? = null
|
||||
|
||||
@@ -165,9 +171,11 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
*/
|
||||
|
||||
private inline val grounded: Boolean
|
||||
get() = isNoClip ||
|
||||
(world.gravitation.y > 0 && isWalled(hitbox, COLLIDING_BOTTOM) ||
|
||||
world.gravitation.y < 0 && isWalled(hitbox, COLLIDING_TOP))
|
||||
get() = if (world == null) true else {
|
||||
isNoClip ||
|
||||
(world!!.gravitation.y > 0 && isWalled(hitbox, COLLIDING_BOTTOM) ||
|
||||
world!!.gravitation.y < 0 && isWalled(hitbox, COLLIDING_TOP))
|
||||
}
|
||||
/** Default to 'true' */
|
||||
var isVisible = true
|
||||
/** Default to 'true' */
|
||||
@@ -190,7 +198,8 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
* s^2 = 1/FPS = 1/60 if FPS is targeted to 60
|
||||
* meter to pixel : 24/FPS
|
||||
*/
|
||||
@Transient private val gravitation: Vector2 = world.gravitation
|
||||
private val gravitation: Vector2
|
||||
get() = world?.gravitation ?: Vector2(0.0, 9.8)
|
||||
@Transient val DRAG_COEFF_DEFAULT = 1.2
|
||||
/** Drag coefficient. Parachutes have much higher value than bare body (1.2) */
|
||||
var dragCoefficient: Double
|
||||
@@ -565,257 +574,281 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
|
||||
private fun displaceHitbox() {
|
||||
|
||||
fun debug1(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (true) println(wut)
|
||||
}
|
||||
fun debug2(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (false) println(wut)
|
||||
}
|
||||
fun debug3(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (false) println(wut)
|
||||
}
|
||||
fun debug4(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (false) println(wut)
|
||||
}
|
||||
fun Double.modTile() = this.toInt().div(TILE_SIZE).times(TILE_SIZE)
|
||||
fun Double.modTileDelta() = this - this.modTile()
|
||||
if (world != null) {
|
||||
|
||||
fun debug1(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (true) println(wut)
|
||||
}
|
||||
|
||||
fun debug2(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (false) println(wut)
|
||||
}
|
||||
|
||||
fun debug3(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (false) println(wut)
|
||||
}
|
||||
|
||||
fun debug4(wut: Any?) {
|
||||
// vvvvv set it true to make debug print work
|
||||
if (false) println(wut)
|
||||
}
|
||||
|
||||
fun Double.modTile() = this.toInt().div(TILE_SIZE).times(TILE_SIZE)
|
||||
fun Double.modTileDelta() = this - this.modTile()
|
||||
|
||||
|
||||
val vectorSum = externalForce + controllerMoveDelta
|
||||
val ccdSteps = minOf(16, (vectorSum.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive
|
||||
val vectorSum = externalForce + controllerMoveDelta
|
||||
val ccdSteps = minOf(16, (vectorSum.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive
|
||||
|
||||
|
||||
|
||||
// * NEW idea: wall pushes the actors (ref. SM64 explained by dutch pancake) *
|
||||
// direction to push is determined by the velocity
|
||||
// proc:
|
||||
// 10 I detect being walled and displace myself
|
||||
// 11 There's 16 possible case so work all 16 (some can be merged obviously)
|
||||
// 12 Amount of displacement can be obtained with modTileDelta()
|
||||
// 13 isWalled() is confirmed to be working
|
||||
// 20 sixteenStep may be optional, I think, but it'd be good to have
|
||||
// * NEW idea: wall pushes the actors (ref. SM64 explained by dutch pancake) *
|
||||
// direction to push is determined by the velocity
|
||||
// proc:
|
||||
// 10 I detect being walled and displace myself
|
||||
// 11 There's 16 possible case so work all 16 (some can be merged obviously)
|
||||
// 12 Amount of displacement can be obtained with modTileDelta()
|
||||
// 13 isWalled() is confirmed to be working
|
||||
// 20 sixteenStep may be optional, I think, but it'd be good to have
|
||||
|
||||
// ignore MOST of the codes below (it might be possible to recycle the structure??)
|
||||
// ignore MOST of the codes below (it might be possible to recycle the structure??)
|
||||
|
||||
val sixteenStep = (0..ccdSteps).map { hitbox.clone().translate(vectorSum * (it / ccdSteps.toDouble())) } // zeroth step is for special condition
|
||||
val sixteenStep = (0..ccdSteps).map { hitbox.clone().translate(vectorSum * (it / ccdSteps.toDouble())) } // zeroth step is for special condition
|
||||
|
||||
val affectingTiles = ArrayList<BlockAddress>()
|
||||
var collidingStep: Int? = null
|
||||
val affectingTiles = ArrayList<BlockAddress>()
|
||||
var collidingStep: Int? = null
|
||||
|
||||
for (step in 1..ccdSteps) {
|
||||
for (step in 1..ccdSteps) {
|
||||
|
||||
val stepBox = sixteenStep[step]
|
||||
val stepBox = sixteenStep[step]
|
||||
|
||||
forEachOccupyingTilePos(stepBox) {
|
||||
val tileCoord = LandUtil.resolveBlockAddr(this.world, it)
|
||||
val tileProp = BlockCodex.getOrNull(world.getTileFromTerrain(tileCoord.first, tileCoord.second))
|
||||
forEachOccupyingTilePos(stepBox) {
|
||||
val tileCoord = LandUtil.resolveBlockAddr(world!!, it)
|
||||
val tileProp = BlockCodex.getOrNull(world!!.getTileFromTerrain(tileCoord.first, tileCoord.second))
|
||||
|
||||
if (tileProp == null || tileProp.isSolid) {
|
||||
affectingTiles.add(it)
|
||||
if (tileProp == null || tileProp.isSolid) {
|
||||
affectingTiles.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
if (affectingTiles.isNotEmpty()) {
|
||||
collidingStep = step
|
||||
break // collision found on this step, break and proceed to next step
|
||||
}
|
||||
}
|
||||
|
||||
if (affectingTiles.isNotEmpty()) {
|
||||
collidingStep = step
|
||||
break // collision found on this step, break and proceed to next step
|
||||
|
||||
val COLL_LEFTSIDE = 1
|
||||
val COLL_BOTTOMSIDE = 2
|
||||
val COLL_RIGHTSIDE = 4
|
||||
val COLL_TOPSIDE = 8
|
||||
|
||||
var bounceX = false
|
||||
var bounceY = false
|
||||
var zeroX = false
|
||||
var zeroY = false
|
||||
// collision NOT detected
|
||||
if (collidingStep == null) {
|
||||
hitbox.translate(vectorSum)
|
||||
// grounded = false
|
||||
}
|
||||
}
|
||||
// collision detected
|
||||
else {
|
||||
debug1("== Collision step: $collidingStep / $ccdSteps")
|
||||
|
||||
|
||||
val COLL_LEFTSIDE = 1
|
||||
val COLL_BOTTOMSIDE = 2
|
||||
val COLL_RIGHTSIDE = 4
|
||||
val COLL_TOPSIDE = 8
|
||||
val newHitbox = hitbox.reassign(sixteenStep[collidingStep])
|
||||
|
||||
var bounceX = false
|
||||
var bounceY = false
|
||||
var zeroX = false
|
||||
var zeroY = false
|
||||
// collision NOT detected
|
||||
if (collidingStep == null) {
|
||||
hitbox.translate(vectorSum)
|
||||
// grounded = false
|
||||
}
|
||||
// collision detected
|
||||
else {
|
||||
debug1("== Collision step: $collidingStep / $ccdSteps")
|
||||
var selfCollisionStatus = 0
|
||||
if (isWalled(newHitbox, COLLIDING_LEFT)) selfCollisionStatus += COLL_LEFTSIDE // 1
|
||||
if (isWalled(newHitbox, COLLIDING_RIGHT)) selfCollisionStatus += COLL_RIGHTSIDE // 4
|
||||
if (isWalled(newHitbox, COLLIDING_TOP)) selfCollisionStatus += COLL_TOPSIDE // 8
|
||||
if (isWalled(newHitbox, COLLIDING_BOTTOM)) selfCollisionStatus += COLL_BOTTOMSIDE // 2
|
||||
|
||||
// fixme UP and RIGHT && LEFT and DOWN bug
|
||||
|
||||
val newHitbox = hitbox.reassign(sixteenStep[collidingStep])
|
||||
debug1("Collision type: $selfCollisionStatus")
|
||||
affectingTiles.forEach {
|
||||
val tileCoord = LandUtil.resolveBlockAddr(world!!, it)
|
||||
debug2("affectign tile: ${tileCoord.first}, ${tileCoord.second}")
|
||||
}
|
||||
|
||||
var selfCollisionStatus = 0
|
||||
if (isWalled(newHitbox, COLLIDING_LEFT)) selfCollisionStatus += COLL_LEFTSIDE // 1
|
||||
if (isWalled(newHitbox, COLLIDING_RIGHT)) selfCollisionStatus += COLL_RIGHTSIDE // 4
|
||||
if (isWalled(newHitbox, COLLIDING_TOP)) selfCollisionStatus += COLL_TOPSIDE // 8
|
||||
if (isWalled(newHitbox, COLLIDING_BOTTOM)) selfCollisionStatus += COLL_BOTTOMSIDE // 2
|
||||
|
||||
// fixme UP and RIGHT && LEFT and DOWN bug
|
||||
|
||||
debug1("Collision type: $selfCollisionStatus")
|
||||
affectingTiles.forEach {
|
||||
val tileCoord = LandUtil.resolveBlockAddr(this.world, it)
|
||||
debug2("affectign tile: ${tileCoord.first}, ${tileCoord.second}")
|
||||
}
|
||||
|
||||
when (selfCollisionStatus) {
|
||||
0 -> { debug1("[ActorWBMovable] Contradiction -- collision detected by CCD, but isWalled() says otherwise") }
|
||||
5 -> { zeroX = true }
|
||||
10 -> { zeroY = true }
|
||||
15 -> { newHitbox.reassign(sixteenStep[0]); zeroX = true; zeroY = true }
|
||||
when (selfCollisionStatus) {
|
||||
0 -> {
|
||||
debug1("[ActorWBMovable] Contradiction -- collision detected by CCD, but isWalled() says otherwise")
|
||||
}
|
||||
5 -> {
|
||||
zeroX = true
|
||||
}
|
||||
10 -> {
|
||||
zeroY = true
|
||||
}
|
||||
15 -> {
|
||||
newHitbox.reassign(sixteenStep[0]); zeroX = true; zeroY = true
|
||||
}
|
||||
// one-side collision
|
||||
1, 11 -> { newHitbox.translatePosX(TILE_SIZE - newHitbox.startX.modTileDelta()); bounceX = true }
|
||||
4, 14 -> { newHitbox.translatePosX( - newHitbox.endX.modTileDelta()) ; bounceX = true }
|
||||
8, 13 -> { newHitbox.translatePosY(TILE_SIZE - newHitbox.startY.modTileDelta()); bounceY = true }
|
||||
2, 7 -> { newHitbox.translatePosY( - newHitbox.endY.modTileDelta()) ; bounceY = true }
|
||||
}
|
||||
1, 11 -> {
|
||||
newHitbox.translatePosX(TILE_SIZE - newHitbox.startX.modTileDelta()); bounceX = true
|
||||
}
|
||||
4, 14 -> {
|
||||
newHitbox.translatePosX(-newHitbox.endX.modTileDelta()); bounceX = true
|
||||
}
|
||||
8, 13 -> {
|
||||
newHitbox.translatePosY(TILE_SIZE - newHitbox.startY.modTileDelta()); bounceY = true
|
||||
}
|
||||
2, 7 -> {
|
||||
newHitbox.translatePosY(-newHitbox.endY.modTileDelta()); bounceY = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fire Collision Event with one/two/three-side collision
|
||||
// for the ease of writing, this jumptable is separated from above.
|
||||
when (selfCollisionStatus) {
|
||||
// fire Collision Event with one/two/three-side collision
|
||||
// for the ease of writing, this jumptable is separated from above.
|
||||
when (selfCollisionStatus) {
|
||||
// TODO compose CollisionInfo and fire collided()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// two-side collision
|
||||
if (selfCollisionStatus in listOf(3,6,9,12)) {
|
||||
debug1("twoside collision $selfCollisionStatus")
|
||||
// two-side collision
|
||||
if (selfCollisionStatus in listOf(3, 6, 9, 12)) {
|
||||
debug1("twoside collision $selfCollisionStatus")
|
||||
|
||||
// !! this code is based on Dyn4j Vector's coord system; V(1,0) -> 0, V(0,1) -> pi, V(0,-1) -> -pi !! //
|
||||
// !! this code is based on Dyn4j Vector's coord system; V(1,0) -> 0, V(0,1) -> pi, V(0,-1) -> -pi !! //
|
||||
|
||||
// we can use selfCollisionStatus to tell which of those four side we care
|
||||
// we can use selfCollisionStatus to tell which of those four side we care
|
||||
|
||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||
val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12))
|
||||
newHitbox.endX.div(TILE_SIZE).floor() * TILE_SIZE - 0.00001
|
||||
else
|
||||
newHitbox.startX.div(TILE_SIZE).ceil() * TILE_SIZE
|
||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||
val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12))
|
||||
newHitbox.endX.div(TILE_SIZE).floor() * TILE_SIZE - 0.00001
|
||||
else
|
||||
newHitbox.startX.div(TILE_SIZE).ceil() * TILE_SIZE
|
||||
|
||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||
val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6))
|
||||
newHitbox.endY.div(TILE_SIZE).floor() * TILE_SIZE - 0.00001
|
||||
else
|
||||
newHitbox.startY.div(TILE_SIZE).ceil() * TILE_SIZE
|
||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||
val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6))
|
||||
newHitbox.endY.div(TILE_SIZE).floor() * TILE_SIZE - 0.00001
|
||||
else
|
||||
newHitbox.startY.div(TILE_SIZE).ceil() * TILE_SIZE
|
||||
|
||||
val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12))
|
||||
newHitbox.endX
|
||||
else
|
||||
newHitbox.startX
|
||||
val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12))
|
||||
newHitbox.endX
|
||||
else
|
||||
newHitbox.startX
|
||||
|
||||
val offendingHitboxPointY = if (selfCollisionStatus in listOf(3, 6))
|
||||
newHitbox.endY
|
||||
else
|
||||
newHitbox.startY
|
||||
val offendingHitboxPointY = if (selfCollisionStatus in listOf(3, 6))
|
||||
newHitbox.endY
|
||||
else
|
||||
newHitbox.startY
|
||||
|
||||
|
||||
|
||||
val angleOfIncidence =
|
||||
if (selfCollisionStatus in listOf(3, 9))
|
||||
vectorSum.direction.toPositiveRad()
|
||||
else
|
||||
vectorSum.direction
|
||||
val angleOfIncidence =
|
||||
if (selfCollisionStatus in listOf(3, 9))
|
||||
vectorSum.direction.toPositiveRad()
|
||||
else
|
||||
vectorSum.direction
|
||||
|
||||
val angleThreshold =
|
||||
if (selfCollisionStatus in listOf(3, 9))
|
||||
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||
Vector2(offendingTileWorldX, offendingTileWorldY)).direction.toPositiveRad()
|
||||
else
|
||||
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||
Vector2(offendingTileWorldX, offendingTileWorldY)).direction
|
||||
val angleThreshold =
|
||||
if (selfCollisionStatus in listOf(3, 9))
|
||||
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||
Vector2(offendingTileWorldX, offendingTileWorldY)).direction.toPositiveRad()
|
||||
else
|
||||
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||
Vector2(offendingTileWorldX, offendingTileWorldY)).direction
|
||||
|
||||
|
||||
debug1("vectorSum: $vectorSum, vectorDirRaw: ${vectorSum.direction / Math.PI}pi")
|
||||
debug1("incidentAngle: ${angleOfIncidence / Math.PI}pi, threshold: ${angleThreshold / Math.PI}pi")
|
||||
debug1("vectorSum: $vectorSum, vectorDirRaw: ${vectorSum.direction / Math.PI}pi")
|
||||
debug1("incidentAngle: ${angleOfIncidence / Math.PI}pi, threshold: ${angleThreshold / Math.PI}pi")
|
||||
|
||||
|
||||
val displacementAbs = Vector2(
|
||||
(offendingTileWorldX - offendingHitboxPointX).abs(),
|
||||
(offendingTileWorldY - offendingHitboxPointY).abs()
|
||||
)
|
||||
val displacementAbs = Vector2(
|
||||
(offendingTileWorldX - offendingHitboxPointX).abs(),
|
||||
(offendingTileWorldY - offendingHitboxPointY).abs()
|
||||
)
|
||||
|
||||
|
||||
// FIXME jump-thru-ceil bug on 1px-wide (the edge), case-9 collision (does not occur on case-12 coll.)
|
||||
// FIXME jump-thru-ceil bug on 1px-wide (the edge), case-9 collision (does not occur on case-12 coll.)
|
||||
|
||||
|
||||
val displacementUnitVector =
|
||||
if (angleOfIncidence == angleThreshold)
|
||||
-vectorSum
|
||||
else {
|
||||
when (selfCollisionStatus) {
|
||||
3 -> if (angleOfIncidence > angleThreshold) Vector2(1.0, 0.0) else Vector2(0.0, -1.0)
|
||||
6 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, -1.0) else Vector2(-1.0, 0.0)
|
||||
9 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, 1.0) else Vector2(1.0, 0.0)
|
||||
12 -> if (angleOfIncidence > angleThreshold) Vector2(-1.0, 0.0) else Vector2(0.0, 1.0)
|
||||
else -> throw InternalError("Blame hardware or universe")
|
||||
val displacementUnitVector =
|
||||
if (angleOfIncidence == angleThreshold)
|
||||
-vectorSum
|
||||
else {
|
||||
when (selfCollisionStatus) {
|
||||
3 -> if (angleOfIncidence > angleThreshold) Vector2(1.0, 0.0) else Vector2(0.0, -1.0)
|
||||
6 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, -1.0) else Vector2(-1.0, 0.0)
|
||||
9 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, 1.0) else Vector2(1.0, 0.0)
|
||||
12 -> if (angleOfIncidence > angleThreshold) Vector2(-1.0, 0.0) else Vector2(0.0, 1.0)
|
||||
else -> throw InternalError("Blame hardware or universe")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val finalDisplacement =
|
||||
if (angleOfIncidence == angleThreshold)
|
||||
displacementUnitVector
|
||||
else
|
||||
Vector2(
|
||||
displacementAbs.x * displacementUnitVector.x,
|
||||
displacementAbs.y * displacementUnitVector.y
|
||||
)
|
||||
val finalDisplacement =
|
||||
if (angleOfIncidence == angleThreshold)
|
||||
displacementUnitVector
|
||||
else
|
||||
Vector2(
|
||||
displacementAbs.x * displacementUnitVector.x,
|
||||
displacementAbs.y * displacementUnitVector.y
|
||||
)
|
||||
|
||||
newHitbox.translate(finalDisplacement)
|
||||
newHitbox.translate(finalDisplacement)
|
||||
|
||||
|
||||
debug1("displacement: $finalDisplacement")
|
||||
debug1("displacement: $finalDisplacement")
|
||||
|
||||
|
||||
// TODO: translate other axis proportionally to the incident vector
|
||||
// TODO: translate other axis proportionally to the incident vector
|
||||
|
||||
bounceX = angleOfIncidence == angleThreshold || displacementUnitVector.x != 0.0
|
||||
bounceY = angleOfIncidence == angleThreshold || displacementUnitVector.y != 0.0
|
||||
bounceX = angleOfIncidence == angleThreshold || displacementUnitVector.x != 0.0
|
||||
bounceY = angleOfIncidence == angleThreshold || displacementUnitVector.y != 0.0
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// bounce X/Y
|
||||
if (bounceX) {
|
||||
externalForce.x *= elasticity
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.x *= elasticity }
|
||||
}
|
||||
if (bounceY) {
|
||||
externalForce.y *= elasticity
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.y *= elasticity }
|
||||
}
|
||||
if (zeroX) {
|
||||
externalForce.x = 0.0
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.x = 0.0 }
|
||||
}
|
||||
if (zeroY) {
|
||||
externalForce.y = 0.0
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.y = 0.0 }
|
||||
}
|
||||
// bounce X/Y
|
||||
if (bounceX) {
|
||||
externalForce.x *= elasticity
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.x *= elasticity }
|
||||
}
|
||||
if (bounceY) {
|
||||
externalForce.y *= elasticity
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.y *= elasticity }
|
||||
}
|
||||
if (zeroX) {
|
||||
externalForce.x = 0.0
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.x = 0.0 }
|
||||
}
|
||||
if (zeroY) {
|
||||
externalForce.y = 0.0
|
||||
controllerMoveDelta?.let { controllerMoveDelta!!.y = 0.0 }
|
||||
}
|
||||
|
||||
|
||||
hitbox.reassign(newHitbox)
|
||||
hitbox.reassign(newHitbox)
|
||||
|
||||
|
||||
// slam-into-whatever damage (such dirty; much hack; wow)
|
||||
// vvvv hack (supposed to be 1.0) vvv 50% hack
|
||||
val collisionDamage = mass * (vectorSum.magnitude / (10.0 / Terrarum.TARGET_FPS).sqr()) / fallDamageDampening.sqr() * GAME_TO_SI_ACC
|
||||
// kg * m / s^2 (mass * acceleration), acceleration -> (vectorMagn / (0.01)^2).gameToSI()
|
||||
if (collisionDamage != 0.0) debug1("Collision damage: $collisionDamage N")
|
||||
// FIXME instead of 0.5mv^2, we can model after "change of velocity (aka accel)", just as in real-life; big change of accel on given unit time is what kills
|
||||
// slam-into-whatever damage (such dirty; much hack; wow)
|
||||
// vvvv hack (supposed to be 1.0) vvv 50% hack
|
||||
val collisionDamage = mass * (vectorSum.magnitude / (10.0 / Terrarum.TARGET_FPS).sqr()) / fallDamageDampening.sqr() * GAME_TO_SI_ACC
|
||||
// kg * m / s^2 (mass * acceleration), acceleration -> (vectorMagn / (0.01)^2).gameToSI()
|
||||
if (collisionDamage != 0.0) debug1("Collision damage: $collisionDamage N")
|
||||
// FIXME instead of 0.5mv^2, we can model after "change of velocity (aka accel)", just as in real-life; big change of accel on given unit time is what kills
|
||||
|
||||
|
||||
// grounded = true
|
||||
}// end of collision not detected
|
||||
// grounded = true
|
||||
}// end of collision not detected
|
||||
|
||||
|
||||
return
|
||||
return
|
||||
|
||||
|
||||
|
||||
// if collision not detected, just don't care; it's not your job to apply moveDelta
|
||||
// if collision not detected, just don't care; it's not your job to apply moveDelta
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -909,9 +942,11 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun isCollidingInternal(txStart: Int, tyStart: Int, txEnd: Int, tyEnd: Int): Boolean {
|
||||
if (world == null) return false
|
||||
|
||||
for (y in tyStart..tyEnd) {
|
||||
for (x in txStart..txEnd) {
|
||||
val tile = world.getTileFromTerrain(x, y)
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (BlockCodex[tile].isSolid)
|
||||
return true
|
||||
}
|
||||
@@ -921,6 +956,8 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun getContactingAreaFluid(side: Int, translateX: Int = 0, translateY: Int = 0): Int {
|
||||
if (world == null) return 0
|
||||
|
||||
var contactAreaCounter = 0
|
||||
for (i in 0..(if (side % 2 == 0) hitbox.width else hitbox.height).roundInt() - 1) {
|
||||
// set tile positions
|
||||
@@ -951,7 +988,7 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
// evaluate
|
||||
if (BlockCodex[world.getTileFromTerrain(tileX, tileY)].isFluid) {
|
||||
if (BlockCodex[world!!.getTileFromTerrain(tileX, tileY)].isFluid) {
|
||||
contactAreaCounter += 1
|
||||
}
|
||||
}
|
||||
@@ -1166,7 +1203,10 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun clampHitbox() {
|
||||
val worldsizePxl = world.width.times(TILE_SIZE)
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val worldsizePxl = world!!.width.times(TILE_SIZE)
|
||||
|
||||
// DEAR FUTURE ME,
|
||||
//
|
||||
@@ -1223,7 +1263,10 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun drawSpriteInGoodPosition(sprite: SpriteAnimation, batch: SpriteBatch) {
|
||||
val leftsidePadding = world.width.times(TILE_SIZE) - WorldCamera.width.ushr(1)
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val leftsidePadding = world!!.width.times(TILE_SIZE) - WorldCamera.width.ushr(1)
|
||||
val rightsidePadding = WorldCamera.width.ushr(1)
|
||||
|
||||
val offsetX = hitboxTranslateX * scale
|
||||
@@ -1233,7 +1276,7 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
|
||||
// camera center neg, actor center pos
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat() + world.width * TILE_SIZE,
|
||||
(hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
@@ -1241,7 +1284,7 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
|
||||
// camera center pos, actor center neg
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat() - world.width * TILE_SIZE,
|
||||
(hitbox.startX - offsetX).toFloat() - world!!.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
@@ -1263,32 +1306,34 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
|
||||
|
||||
private fun clampW(x: Double): Double =
|
||||
if (x < TILE_SIZE + hitbox.width / 2) {
|
||||
if (world == null) x
|
||||
else if (x < TILE_SIZE + hitbox.width / 2) {
|
||||
TILE_SIZE + hitbox.width / 2
|
||||
}
|
||||
else if (x >= (world.width * TILE_SIZE).toDouble() - TILE_SIZE.toDouble() - hitbox.width / 2) {
|
||||
(world.width * TILE_SIZE).toDouble() - 1.0 - TILE_SIZE.toDouble() - hitbox.width / 2
|
||||
else if (x >= (world!!.width * TILE_SIZE).toDouble() - TILE_SIZE.toDouble() - hitbox.width / 2) {
|
||||
(world!!.width * TILE_SIZE).toDouble() - 1.0 - TILE_SIZE.toDouble() - hitbox.width / 2
|
||||
}
|
||||
else {
|
||||
x
|
||||
}
|
||||
|
||||
private fun clampH(y: Double): Double =
|
||||
if (y < TILE_SIZE + hitbox.height) {
|
||||
if (world == null) y
|
||||
else if (y < TILE_SIZE + hitbox.height) {
|
||||
TILE_SIZE + hitbox.height
|
||||
}
|
||||
else if (y >= (world.height * TILE_SIZE).toDouble() - TILE_SIZE.toDouble() - hitbox.height) {
|
||||
(world.height * TILE_SIZE).toDouble() - 1.0 - TILE_SIZE.toDouble() - hitbox.height
|
||||
else if (y >= (world!!.height * TILE_SIZE).toDouble() - TILE_SIZE.toDouble() - hitbox.height) {
|
||||
(world!!.height * TILE_SIZE).toDouble() - 1.0 - TILE_SIZE.toDouble() - hitbox.height
|
||||
}
|
||||
else {
|
||||
y
|
||||
}
|
||||
|
||||
private fun clampWtile(x: Int): Int =
|
||||
if (x < 0) 0 else if (x >= world.width) world.width - 1 else x
|
||||
if (x < 0) 0 else if (x >= world?.width ?: 0) (world?.width ?: 0) - 1 else x
|
||||
|
||||
private fun clampHtile(x: Int): Int =
|
||||
if (x < 0) 0 else if (x >= world.height) world.height - 1 else x
|
||||
if (x < 0) 0 else if (x >= world?.height ?: 0) (world?.height ?: 0) - 1 else x
|
||||
|
||||
|
||||
var isNoClip: Boolean = false
|
||||
@@ -1324,10 +1369,13 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
|
||||
|
||||
private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val tiles = ArrayList<Int?>()
|
||||
for (y in hIntTilewiseHitbox.startY.toInt()..hIntTilewiseHitbox.endY.toInt()) {
|
||||
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
||||
tiles.add(world.getTileFromTerrain(x, y))
|
||||
tiles.add(world!!.getTileFromTerrain(x, y))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1335,10 +1383,13 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val tileProps = ArrayList<BlockProp?>()
|
||||
for (y in hIntTilewiseHitbox.startY.toInt()..hIntTilewiseHitbox.endY.toInt()) {
|
||||
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
||||
tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)])
|
||||
tileProps.add(BlockCodex[world!!.getTileFromTerrain(x, y)])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1346,6 +1397,9 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val newTilewiseHitbox = Hitbox.fromTwoPoints(
|
||||
hitbox.startX.div(TILE_SIZE).floor(),
|
||||
hitbox.startY.div(TILE_SIZE).floor(),
|
||||
@@ -1356,7 +1410,7 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
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(this.world, x, y))
|
||||
tilePosList.add(LandUtil.getBlockAddr(world!!, x, y))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1364,26 +1418,32 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
|
||||
}
|
||||
|
||||
private fun forEachFeetTileNum(consumer: (Int?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val tiles = ArrayList<Int?>()
|
||||
|
||||
// offset 1 pixel to the down so that friction would work
|
||||
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt()
|
||||
|
||||
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
||||
tiles.add(world.getTileFromTerrain(x, y))
|
||||
tiles.add(world!!.getTileFromTerrain(x, y))
|
||||
}
|
||||
|
||||
return tiles.forEach(consumer)
|
||||
}
|
||||
|
||||
private fun forEachFeetTile(consumer: (BlockProp?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
val tileProps = ArrayList<BlockProp?>()
|
||||
|
||||
// offset 1 pixel to the down so that friction would work
|
||||
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt()
|
||||
|
||||
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
||||
tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)])
|
||||
tileProps.add(BlockCodex[world!!.getTileFromTerrain(x, y)])
|
||||
}
|
||||
|
||||
return tileProps.forEach(consumer)
|
||||
|
||||
@@ -39,7 +39,7 @@ open class GameWorld {
|
||||
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
|
||||
//physics
|
||||
/** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */
|
||||
var gravitation: Vector2 = Vector2(0.0, 9.8)
|
||||
var gravitation: Vector2 = Vector2(0.0, 9.80665)
|
||||
/** 0.0..1.0+ */
|
||||
var globalLight = Color(0f,0f,0f,0f)
|
||||
var averageTemperature = 288f // 15 deg celsius; simulates global warming
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.modulebasegame.ui.Notification
|
||||
@@ -46,7 +45,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
|
||||
override var actorNowPlaying: ActorHumanoid? = MovableWorldCamera(world)
|
||||
override var actorNowPlaying: ActorHumanoid? = MovableWorldCamera()
|
||||
|
||||
val uiToolbox = UIBuildingMakerToolbox()
|
||||
val notifier = Notification()
|
||||
@@ -170,7 +169,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
|
||||
class MovableWorldCamera(world: GameWorld) : ActorHumanoid(world, 0, usePhysics = false) {
|
||||
class MovableWorldCamera : ActorHumanoid(0, usePhysics = false) {
|
||||
|
||||
init {
|
||||
referenceID = Terrarum.PLAYER_REF_ID
|
||||
|
||||
@@ -523,10 +523,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
BlockPropUtil.dynamicLumFuncTickClock()
|
||||
world.updateWorldTime(delta)
|
||||
//WorldSimulator(player, delta)
|
||||
WeatherMixer.update(delta, actorNowPlaying)
|
||||
WeatherMixer.update(delta, actorNowPlaying, world)
|
||||
BlockStats.update()
|
||||
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
|
||||
gameworld.globalLight = WeatherMixer.globalLightNow
|
||||
|
||||
|
||||
|
||||
////////////////////////////
|
||||
|
||||
@@ -74,7 +74,12 @@ object IngameRenderer {
|
||||
uiListToDraw = uisToDraw
|
||||
}
|
||||
|
||||
init(world)
|
||||
init()
|
||||
|
||||
BlocksDrawer.world = world
|
||||
LightmapRenderer.setWorld(world)
|
||||
FeaturesDrawer.world = world
|
||||
|
||||
this.player = player
|
||||
|
||||
|
||||
@@ -389,7 +394,7 @@ object IngameRenderer {
|
||||
}
|
||||
|
||||
|
||||
private fun init(world: GameWorldExtension) {
|
||||
private fun init() {
|
||||
if (!initDone) {
|
||||
batch = SpriteBatch()
|
||||
camera = OrthographicCamera(widthf, heightf)
|
||||
@@ -402,11 +407,6 @@ object IngameRenderer {
|
||||
|
||||
initDone = true
|
||||
}
|
||||
|
||||
|
||||
BlocksDrawer.world = world
|
||||
LightmapRenderer.setWorld(world)
|
||||
FeaturesDrawer.world = world
|
||||
}
|
||||
|
||||
private fun clearBuffer() {
|
||||
|
||||
@@ -29,8 +29,6 @@ object ImportLayerData : ConsoleCommand {
|
||||
(Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
|
||||
)
|
||||
|
||||
IngameRenderer.
|
||||
|
||||
Echo("Successfully loaded ${args[1]}")
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,6 @@ import org.dyn4j.geometry.Vector2
|
||||
internal object SpawnPhysTestBall : ConsoleCommand {
|
||||
@Throws(Exception::class)
|
||||
override fun execute(args: Array<String>) {
|
||||
val world = (Terrarum.ingame!!.world)
|
||||
|
||||
|
||||
val mouseX = Terrarum.mouseX
|
||||
val mouseY = Terrarum.mouseY
|
||||
|
||||
@@ -25,7 +22,7 @@ internal object SpawnPhysTestBall : ConsoleCommand {
|
||||
val xvel = args[2].toDouble()
|
||||
val yvel = if (args.size >= 4) args[3].toDouble() else 0.0
|
||||
|
||||
val ball = PhysTestBall(world)
|
||||
val ball = PhysTestBall()
|
||||
ball.setPosition(mouseX, mouseY)
|
||||
ball.elasticity = elasticity
|
||||
ball.applyForce(Vector2(xvel, yvel))
|
||||
@@ -35,7 +32,7 @@ internal object SpawnPhysTestBall : ConsoleCommand {
|
||||
else if (args.size == 2) {
|
||||
val elasticity = args[1].toDouble()
|
||||
|
||||
val ball = PhysTestBall(world)
|
||||
val ball = PhysTestBall()
|
||||
ball.setPosition(mouseX, mouseY)
|
||||
ball.elasticity = elasticity
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ internal object SpawnPhysTestLunarLander : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val mouseX = Terrarum.mouseX
|
||||
val mouseY = Terrarum.mouseY
|
||||
val lander = PhysTestLuarLander((Terrarum.ingame!!.world))
|
||||
val lander = PhysTestLuarLander()
|
||||
|
||||
lander.setPosition(mouseX, mouseY)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
||||
*/
|
||||
internal object SpawnTikiTorch : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val torch = FixtureTikiTorch((Terrarum.ingame!!.world))
|
||||
val torch = FixtureTikiTorch()
|
||||
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
||||
|
||||
Terrarum.ingame!!.addNewActor(torch)
|
||||
|
||||
@@ -25,12 +25,13 @@ import java.util.*
|
||||
* Created by minjaesong on 2016-10-24.
|
||||
*/
|
||||
open class ActorHumanoid(
|
||||
world: GameWorld,
|
||||
birth: time_t,
|
||||
death: time_t? = null,
|
||||
usePhysics: Boolean = true
|
||||
) : ActorWBMovable(world, RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
|
||||
) : ActorWBMovable(RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
|
||||
|
||||
private val world: GameWorld?
|
||||
get() = Terrarum.ingame?.world
|
||||
|
||||
|
||||
var vehicleRiding: Controllable? = null // usually player only
|
||||
@@ -50,11 +51,11 @@ open class ActorHumanoid(
|
||||
override var houseDesignation: ArrayList<Long>? = ArrayList()
|
||||
|
||||
override fun addHouseTile(x: Int, y: Int) {
|
||||
if (houseDesignation != null) houseDesignation!!.add(LandUtil.getBlockAddr(world, 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(world, x, y))
|
||||
if (houseDesignation != null) houseDesignation!!.remove(LandUtil.getBlockAddr(world!!, x, y))
|
||||
}
|
||||
|
||||
override fun clearHouseDesignation() {
|
||||
|
||||
@@ -15,8 +15,8 @@ object CreatureBuilder {
|
||||
/**
|
||||
* @Param jsonFileName with extension
|
||||
*/
|
||||
operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWBMovable {
|
||||
val actor = ActorWBMovable(world, Actor.RenderOrder.MIDDLE)
|
||||
operator fun invoke(module: String, jsonFileName: String): ActorWBMovable {
|
||||
val actor = ActorWBMovable(Actor.RenderOrder.MIDDLE)
|
||||
InjectCreatureRaw(actor.actorValue, module, jsonFileName)
|
||||
|
||||
|
||||
|
||||
@@ -173,6 +173,6 @@ object DecodeTapestry {
|
||||
readCounter++
|
||||
}
|
||||
|
||||
return TapestryObject((Terrarum.ingame!!.world), outImageData, artName, authorName)
|
||||
return TapestryObject(outImageData, artName, authorName)
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-15.
|
||||
*/
|
||||
open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWBMovable(world, RenderOrder.MIDTOP) {
|
||||
open class DroppedItem(private val item: GameItem) : ActorWBMovable(RenderOrder.MIDTOP) {
|
||||
|
||||
init {
|
||||
if (item.dynamicID >= ItemCodex.ACTORID_MIN)
|
||||
|
||||
@@ -6,8 +6,8 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-17.
|
||||
*/
|
||||
open class FixtureBase(world: GameWorld, physics: Boolean = true) :
|
||||
ActorWBMovable(world, RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
|
||||
open class FixtureBase(physics: Boolean = true) :
|
||||
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
|
||||
/**
|
||||
* 0: Open
|
||||
* 1: Blocked
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.*
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-17.
|
||||
*/
|
||||
internal class FixtureTikiTorch(world: GameWorld) : FixtureBase(world), Luminous {
|
||||
internal class FixtureTikiTorch : FixtureBase(), Luminous {
|
||||
|
||||
override var color: Color
|
||||
get() = BlockCodex[Block.TORCH].luminosity
|
||||
|
||||
@@ -15,12 +15,11 @@ import net.torvald.terrarum.modulebasegame.gameworld.time_t
|
||||
* Created by minjaesong on 2016-01-31.
|
||||
*/
|
||||
open class HumanoidNPC(
|
||||
world: GameWorld,
|
||||
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
|
||||
born: time_t,
|
||||
usePhysics: Boolean = true,
|
||||
forceAssignRefID: Int? = null
|
||||
) : ActorHumanoid(world, born, usePhysics = usePhysics), AIControlled, CanBeAnItem {
|
||||
) : ActorHumanoid(born, usePhysics = usePhysics), AIControlled, CanBeAnItem {
|
||||
|
||||
companion object {
|
||||
val DEFAULT_COLLISION_TYPE = COLLISION_DYNAMIC
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.gameworld.time_t
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
|
||||
class IngamePlayer(world: GameWorldExtension, born: time_t) : ActorHumanoid(world, born) {
|
||||
class IngamePlayer(born: time_t) : ActorHumanoid(born) {
|
||||
|
||||
/**
|
||||
* Creates new Player instance with empty elements (sprites, actorvalue, etc.).
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-05.
|
||||
*/
|
||||
class PhysTestBall(world: GameWorld) : ActorWBMovable(world, RenderOrder.MIDDLE, immobileBody = true) {
|
||||
class PhysTestBall : ActorWBMovable(RenderOrder.MIDDLE, immobileBody = true) {
|
||||
|
||||
private var color = Color.GOLD
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
/**
|
||||
* Created by minjaesong on 2018-01-17.
|
||||
*/
|
||||
class PhysTestLuarLander(world: GameWorld) : ActorWBMovable(world, RenderOrder.MIDTOP), Controllable {
|
||||
class PhysTestLuarLander : ActorWBMovable(RenderOrder.MIDTOP), Controllable {
|
||||
|
||||
private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga"))
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ object PlayerBuilder {
|
||||
operator fun invoke(): Actor {
|
||||
val world = (Terrarum.ingame!! as Ingame).gameworld
|
||||
|
||||
val p: Actor = IngamePlayer(world, world.time.TIME_T)
|
||||
val p: Actor = IngamePlayer(world.time.TIME_T)
|
||||
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
|
||||
|
||||
// attach sprite
|
||||
|
||||
@@ -16,7 +16,6 @@ object PlayerBuilderCynthia {
|
||||
operator fun invoke(): ActorWBMovable {
|
||||
//val p: IngamePlayer = IngamePlayer(GameDate(100, 143)) // random value thrown
|
||||
val p: HumanoidNPC = HumanoidNPC(
|
||||
(Terrarum.ingame!!.world),
|
||||
NullAI(),
|
||||
-589141658L) // random value thrown
|
||||
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
object PlayerBuilderSigrid {
|
||||
|
||||
operator fun invoke(): IngamePlayer {
|
||||
val p = IngamePlayer((Terrarum.ingame!! as Ingame).gameworld, -9223372036854775807L) // XD
|
||||
val p = IngamePlayer(-9223372036854775807L) // XD
|
||||
|
||||
p.referenceID = 0x51621D // the only constant of this procedural universe
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
object PlayerBuilderTestSubject1 {
|
||||
operator fun invoke(): IngamePlayer {
|
||||
val p: IngamePlayer = IngamePlayer((Terrarum.ingame!! as Ingame).gameworld, -589141658L) // random value thrown
|
||||
val p: IngamePlayer = IngamePlayer(-589141658L) // random value thrown
|
||||
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
|
||||
|
||||
|
||||
|
||||
@@ -7,11 +7,10 @@ import org.dyn4j.geometry.Vector2
|
||||
* Created by minjaesong on 2016-08-29.
|
||||
*/
|
||||
class ProjectileHoming(
|
||||
world: GameWorld,
|
||||
type: Int,
|
||||
fromPoint: Vector2, // projected coord
|
||||
toPoint: Vector2 // arriving coord
|
||||
) : ProjectileSimple(world, type, fromPoint, toPoint) {
|
||||
) : ProjectileSimple(type, fromPoint, toPoint) {
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,11 +21,10 @@ 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
|
||||
) : ActorWBMovable(world, RenderOrder.MIDTOP), Luminous, Projectile {
|
||||
) : ActorWBMovable(RenderOrder.MIDTOP), Luminous, Projectile {
|
||||
|
||||
val damage: Int
|
||||
val displayColour: Color
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
/**
|
||||
* Created by minjaesong on 2017-01-07.
|
||||
*/
|
||||
class TapestryObject(world: GameWorld, pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(world, physics = false) {
|
||||
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(physics = false) {
|
||||
|
||||
// physics = false only speeds up for ~2 frames with 50 tapestries
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
/**
|
||||
* Created by minjaesong on 2016-04-26.
|
||||
*/
|
||||
class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWBMovable(world, RenderOrder.MIDTOP), Luminous {
|
||||
class WeaponSwung(val itemID: Int) : ActorWBMovable(RenderOrder.MIDTOP), Luminous {
|
||||
// just let the solver use AABB; it's cheap but works just enough
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,13 +3,17 @@ package net.torvald.terrarum.modulebasegame.weather
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.colourutil.*
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.console.CommandDict
|
||||
import net.torvald.terrarum.console.SetGlobalLightOverride
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.RNGConsumer
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
@@ -36,6 +40,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
override val RNG = HQRNG()
|
||||
|
||||
var globalLightOverridden = false
|
||||
|
||||
var weatherList: HashMap<String, ArrayList<BaseModularWeather>>
|
||||
|
||||
@@ -84,7 +89,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
/**
|
||||
* Part of Ingame update
|
||||
*/
|
||||
fun update(delta: Float, player: ActorWithBody?) {
|
||||
fun update(delta: Float, player: ActorWithBody?, world: GameWorldExtension) {
|
||||
if (player == null) return
|
||||
|
||||
currentWeather = weatherList[WEATHER_GENERIC]!![0]
|
||||
@@ -104,6 +109,10 @@ internal object WeatherMixer : RNGConsumer {
|
||||
//globalLightNow.set(getGlobalLightOfTime((Terrarum.ingame!!.world).time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f))
|
||||
}
|
||||
|
||||
|
||||
if (!globalLightOverridden) {
|
||||
world.globalLight = WeatherMixer.globalLightNow
|
||||
}
|
||||
}
|
||||
|
||||
//private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT * 0.75f // just an arb multiplier (266.66666 -> 200)
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
/**
|
||||
* Created by minjaesong on 2016-09-08.
|
||||
*/
|
||||
class FixtureBasicTerminal(world: GameWorld, phosphor: Color) : FixtureBase(world) {
|
||||
class FixtureBasicTerminal(phosphor: Color) : FixtureBase() {
|
||||
|
||||
/*val computer = TerrarumComputer(8)
|
||||
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
/**
|
||||
* Created by minjaesong on 2016-09-08.
|
||||
*/
|
||||
open class FixtureComputerBase(world: GameWorld) : FixtureBase(world) {
|
||||
open class FixtureComputerBase : FixtureBase() {
|
||||
|
||||
/** Connected terminal */
|
||||
var terminal: FixtureBasicTerminal? = null
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum.mouseTileX
|
||||
import net.torvald.terrarum.Terrarum.mouseTileY
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
|
||||
@@ -29,7 +30,10 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
private var ydelta = 0.0
|
||||
|
||||
private val ingame = Terrarum.ingame!! as Ingame
|
||||
private val world = ingame.world as GameWorldExtension
|
||||
|
||||
private val world: GameWorldExtension
|
||||
get() = Terrarum.ingame!!.world as GameWorldExtension
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
val player = ingame.actorNowPlaying
|
||||
|
||||
@@ -30,12 +30,18 @@ import kotlin.system.measureNanoTime
|
||||
|
||||
// NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable
|
||||
|
||||
internal object LightmapRenderer {
|
||||
/** This object should not be called by yourself; must be only being used and manipulated by your
|
||||
* own ingame renderer
|
||||
*/
|
||||
object LightmapRenderer {
|
||||
private lateinit var world: GameWorld
|
||||
|
||||
/** do not call this yourself! Let your game renderer handle this! */
|
||||
fun setWorld(world: GameWorld) {
|
||||
try {
|
||||
if (this.world != world) {
|
||||
println("World change detected -- old world: ${this.world.hashCode()}, new world: ${world.hashCode()}")
|
||||
|
||||
for (y in 0 until LIGHTMAP_HEIGHT) {
|
||||
for (x in 0 until LIGHTMAP_WIDTH) {
|
||||
lightmap[y][x] = Color(0)
|
||||
|
||||
BIN
work_files/graphics/fonts/latinExtA_variable.psd
LFS
Normal file
BIN
work_files/graphics/fonts/latinExtA_variable.psd
LFS
Normal file
Binary file not shown.
BIN
work_files/graphics/fonts/latinExtB_variable.psd
LFS
Normal file
BIN
work_files/graphics/fonts/latinExtB_variable.psd
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user