mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
sprite shift re-fixed with a correct method
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.point.Point2d
|
||||
@@ -11,6 +13,7 @@ import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockProp
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.BlockAddress
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -575,7 +578,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
|
||||
|
||||
|
||||
// TODO NEW idea: wall pushes the actors (ref. SM64 explained by dutch pancake)
|
||||
// * 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
|
||||
@@ -810,11 +813,10 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
val y2 = hitbox.endY - A_PIXEL
|
||||
// this commands and the commands on isWalled WILL NOT match (1 px gap on endX/Y). THIS IS INTENDED!
|
||||
|
||||
|
||||
val txStart = x1.div(TILE_SIZE).floorInt()
|
||||
val txEnd = x2.div(TILE_SIZE).floorInt()
|
||||
val tyStart = y1.div(TILE_SIZE).floorInt()
|
||||
val tyEnd = y2.div(TILE_SIZE).floorInt()
|
||||
val txStart = x1.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
val txEnd = x2.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
val tyStart = y1.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
val tyEnd = y2.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
|
||||
return isCollidingInternal(txStart, tyStart, txEnd, tyEnd)
|
||||
}
|
||||
@@ -878,10 +880,10 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
}
|
||||
else throw IllegalArgumentException()
|
||||
|
||||
val txStart = x1.div(TILE_SIZE).floorInt()
|
||||
val txEnd = x2.div(TILE_SIZE).floorInt()
|
||||
val tyStart = y1.div(TILE_SIZE).floorInt()
|
||||
val tyEnd = y2.div(TILE_SIZE).floorInt()
|
||||
val txStart = x1.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
val txEnd = x2.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
val tyStart = y1.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
val tyEnd = y2.plus(0.5f).div(TILE_SIZE).floorInt()
|
||||
|
||||
return isCollidingInternal(txStart, tyStart, txEnd, tyEnd)
|
||||
}
|
||||
@@ -1179,8 +1181,24 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
if (isVisible && sprite != null) {
|
||||
BlendMode.resolve(drawMode)
|
||||
drawSpriteInGoodPosition(sprite!!, batch)
|
||||
if (!KeyToggler.isOn(Input.Keys.F12)) {
|
||||
BlendMode.resolve(drawMode)
|
||||
drawSpriteInGoodPosition(sprite!!, batch)
|
||||
}
|
||||
else {
|
||||
batch.color = Color.NAVY
|
||||
val hb = intTilewiseHitbox
|
||||
|
||||
batch.fillRect(
|
||||
hb.startX.toFloat() * TILE_SIZE,
|
||||
hb.startY.toFloat() * TILE_SIZE,
|
||||
hb.width.toFloat() * TILE_SIZE,
|
||||
hb.height.toFloat() * TILE_SIZE
|
||||
)
|
||||
|
||||
batch.color = Color.VIOLET
|
||||
batch.fillRect(hitbox.startX.toFloat(), hitbox.startY.toFloat(), hitbox.width.toFloat(), hitbox.height.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1195,7 +1213,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
|
||||
// camera center neg, actor center pos
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX + hitbox.width).toFloat() + world.width * TILE_SIZE,
|
||||
(hitbox.startX - offsetX).toFloat() + world.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
@@ -1203,14 +1221,14 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
|
||||
// camera center pos, actor center neg
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX + hitbox.width).toFloat() - world.width * TILE_SIZE,
|
||||
(hitbox.startX - offsetX).toFloat() - world.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
}
|
||||
else {
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX + hitbox.width).toFloat(),
|
||||
(hitbox.startX - offsetX).toFloat(),
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
@@ -1383,6 +1401,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
@Transient const val COLLISION_KNOCKBACK_TAKER = 5 // benevolent NPCs
|
||||
|
||||
@Transient val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
@Transient val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
|
||||
|
||||
private fun div16TruncateToMapWidth(x: Int): Int {
|
||||
if (x < 0)
|
||||
|
||||
@@ -459,7 +459,7 @@ object BlocksDrawer {
|
||||
val for_y_start = WorldCamera.y / TILE_SIZE
|
||||
val for_y_end = for_y_start + tilesBuffer.height - 1//clampHTile(for_y_start + (WorldCamera.height / TILE_SIZE) + 2)
|
||||
|
||||
val for_x_start = WorldCamera.x / TILE_SIZE - 1
|
||||
val for_x_start = WorldCamera.x / TILE_SIZE
|
||||
val for_x_end = for_x_start + tilesBuffer.width - 1//for_x_start + (WorldCamera.width / TILE_SIZE) + 3
|
||||
|
||||
// loop
|
||||
|
||||
@@ -546,12 +546,12 @@ object LightmapRenderer {
|
||||
|
||||
// input: 0..1 for int 0..1023
|
||||
fun hdr(intensity: Float): Float {
|
||||
val intervalStart = (intensity * MUL).floorInt()
|
||||
val intervalEnd = minOf(rgbHDRLookupTable.lastIndex, (intensity * MUL).floorInt() + 1)
|
||||
val intervalStart = (intensity * CHANNEL_MAX).floorInt()
|
||||
val intervalEnd = minOf(rgbHDRLookupTable.lastIndex, (intensity * CHANNEL_MAX).floorInt() + 1)
|
||||
|
||||
if (intervalStart == intervalEnd) return rgbHDRLookupTable[intervalStart]
|
||||
|
||||
val intervalPos = (intensity * MUL) - (intensity * MUL).toInt()
|
||||
val intervalPos = (intensity * CHANNEL_MAX) - (intensity * CHANNEL_MAX).toInt()
|
||||
|
||||
return interpolateLinear(
|
||||
intervalPos,
|
||||
|
||||
@@ -37,7 +37,7 @@ object WorldCamera {
|
||||
|
||||
// some hacky equation to position player at the dead centre
|
||||
// NOT tested for WorldDrawer sampling negative coord for its drawing (which causes some fucking artefacts)
|
||||
x = ((player.hitbox.centeredX + player.hitbox.width).toFloat() - (width / 2)).floorInt() // X only: ROUNDWORLD implementation
|
||||
x = ((player.hitbox.centeredX).toFloat() - (width / 2)).floorInt() // X only: ROUNDWORLD implementation
|
||||
|
||||
|
||||
y = (FastMath.clamp(
|
||||
|
||||
Reference in New Issue
Block a user