fixed roundworld anormaly, camera zoom still broken

Former-commit-id: ec08c302349c962992a111e820b60eb0a46d7c2e
Former-commit-id: 5bcf3baf2ec194c431b009aa2839ff11caa4d82d
This commit is contained in:
Song Minjae
2016-12-18 01:39:03 +09:00
parent 56530a6041
commit 9c7e7ed266
9 changed files with 170 additions and 91 deletions

View File

@@ -21,6 +21,7 @@ import net.torvald.terrarum.mapdrawer.LightmapRenderer
import net.torvald.terrarum.mapdrawer.LightmapRenderer.constructRGBFromInt
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
import net.torvald.terrarum.mapgenerator.WorldGenerator
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import net.torvald.terrarum.tileproperties.TileCodex
@@ -236,7 +237,7 @@ constructor() : BasicGameState() {
private fun repossessActor() {
// check if currently pocessed actor is removed from game
if (!hasActor(player))
// re-possess canonical player
// re-possess canonical player
changePossession(Player.PLAYER_REF_ID) // TODO completely other behaviour?
}
@@ -280,8 +281,8 @@ constructor() : BasicGameState() {
// make camara work //
// compensate for zoom. UIs must be treated specially! (see UIHandler)
//g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
tilesDrawFrameBuffer.graphics.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
actorsDrawFrameBuffer.graphics.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
tilesDrawFrameBuffer.graphics.translate(-MapCamera.cameraX.toFloat(), -MapCamera.cameraY.toFloat())
actorsDrawFrameBuffer.graphics.translate(-MapCamera.cameraX.toFloat(), -MapCamera.cameraY.toFloat())
// TODO add new framebuffer so that whole map is zoomed at once, yet not the UI
@@ -295,7 +296,7 @@ constructor() : BasicGameState() {
// draw actors //
/////////////////
actorContainer.forEach { actor ->
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) { // if echo and within screen
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) {
actor.drawBody(gc, actorsDrawFrameBuffer.graphics)
}
}
@@ -312,10 +313,10 @@ constructor() : BasicGameState() {
blendMul()
MapDrawer.drawEnvOverlay(actorsDrawFrameBuffer.graphics)
MapDrawer.drawEnvOverlay(actorsDrawFrameBuffer.graphics)
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal()
LightmapRenderer.draw(actorsDrawFrameBuffer.graphics)
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal()
LightmapRenderer.draw(actorsDrawFrameBuffer.graphics)
blendNormal()
@@ -323,7 +324,7 @@ constructor() : BasicGameState() {
// draw actor glows //
//////////////////////
actorContainer.forEach { actor ->
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) { // if echo and within screen
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) {
actor.drawGlow(gc, actorsDrawFrameBuffer.graphics)
}
}
@@ -382,7 +383,7 @@ constructor() : BasicGameState() {
GameController.keyPressed(key, c)
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|| key == Terrarum.getConfigInt("keyquicksel")) {
|| key == Terrarum.getConfigInt("keyquicksel")) {
uiAliases[UI_PIE_MENU]!!.setAsOpen()
uiAliases[UI_QUICK_BAR]!!.setAsClose()
}
@@ -394,7 +395,7 @@ constructor() : BasicGameState() {
GameController.keyReleased(key, c)
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|| key == Terrarum.getConfigInt("keyquicksel")) {
|| key == Terrarum.getConfigInt("keyquicksel")) {
uiAliases[UI_PIE_MENU]!!.setAsClose()
uiAliases[UI_QUICK_BAR]!!.setAsOpen()
}
@@ -529,18 +530,36 @@ constructor() : BasicGameState() {
fun Double.sqr() = this * this
fun Int.sqr() = this * this
private fun distToActorSqr(a: ActorWithBody, p: ActorWithBody): Double =
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr()
private fun distToActorSqr(a: ActorWithBody, p: ActorWithBody) =
Math.min(// take min of normal position and wrapped (x < 0) position
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() +
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
(a.hitbox.centeredX - p.hitbox.centeredX + world.width * TILE_SIZE).sqr() +
(a.hitbox.centeredY - p.hitbox.centeredY).sqr()
)
private fun distToCameraSqr(a: ActorWithBody) =
Math.min(
(a.hitbox.posX - MapCamera.cameraX).sqr() +
(a.hitbox.posY - MapCamera.cameraY).sqr(),
(a.hitbox.posX - MapCamera.cameraX + world.width * TILE_SIZE).sqr() +
(a.hitbox.posY - MapCamera.cameraY).sqr()
)
/** whether the actor is within screen */
private fun ActorWithBody.inScreen() = distToActorSqr(this, player) <=
(Terrarum.WIDTH.plus(this.hitbox.width.div(2)).times(1 / Terrarum.ingame.screenZoom).sqr() +
Terrarum.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / Terrarum.ingame.screenZoom).sqr())
private fun ActorWithBody.inScreen() =
distToCameraSqr(this) <=
(Terrarum.WIDTH.plus(this.hitbox.width.div(2)).times(1 / Terrarum.ingame.screenZoom).sqr() +
Terrarum.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / Terrarum.ingame.screenZoom).sqr())
/** whether the actor is within update range */
private fun ActorWithBody.inUpdateRange() = distToActorSqr(this, player) <= ACTOR_UPDATE_RANGE.sqr()
private fun ActorWithBody.inUpdateRange() = distToCameraSqr(this) <= ACTOR_UPDATE_RANGE.sqr()
/**
* actorContainer extensions
*/
fun hasActor(actor: Actor) = hasActor(actor.referenceID)
fun hasActor(ID: Int): Boolean =
if (actorContainer.size == 0)
false

View File

@@ -30,7 +30,6 @@ object CommandDict {
Pair("setgl", SetGlobalLightOverride),
Pair("getfaction", GetFactioning),
Pair("auth", Authenticator),
Pair("spawnball", SpawnPhysTestBall),
Pair("batch", Batch),
Pair("settime", SetTime),
Pair("gettime", GetTime),
@@ -38,7 +37,6 @@ object CommandDict {
Pair("help", Help),
Pair("version", Version),
Pair("seed", Seed),
Pair("testgetlight", TestGetLight),
Pair("println", EchoConsole),
Pair("inventory", Inventory),
@@ -47,6 +45,9 @@ object CommandDict {
Pair("gsontest", GsonTest),
Pair("tips", PrintRandomTips),
Pair("langtest", LangTest),
Pair("testgetlight", TestGetLight),
Pair("spawnball", SpawnPhysTestBall),
Pair("spawntorch", SpawnTikiTorch),
Pair("musictest", MusicTest)
)

View File

@@ -0,0 +1,22 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.FixtureTikiTorch
import net.torvald.terrarum.gamecontroller.mouseX
import net.torvald.terrarum.gamecontroller.mouseY
/**
* Created by SKYHi14 on 2016-12-17.
*/
object SpawnTikiTorch : ConsoleCommand {
override fun execute(args: Array<String>) {
val torch = FixtureTikiTorch()
torch.setPosition(Terrarum.appgc.mouseX, Terrarum.appgc.mouseY)
Terrarum.ingame.addActor(torch)
}
override fun printUsage() {
Echo("Usage: spawntorch")
}
}

View File

@@ -909,6 +909,12 @@ open class ActorWithBody : Actor() {
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
// Q&D fix for Roundworld anormaly
spriteGlow!!.render(g,
(hitbox.posX - hitboxTranslateX * scale).toFloat() + world.width * TILE_SIZE,
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
}
else {
spriteGlow!!.render(g,
@@ -916,6 +922,12 @@ open class ActorWithBody : Actor() {
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
// Q&D fix for Roundworld anormaly
spriteGlow!!.render(g,
(hitbox.posX - scale).toFloat() + world.width * TILE_SIZE,
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
}
}
}
@@ -934,6 +946,12 @@ open class ActorWithBody : Actor() {
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
// Q&D fix for Roundworld anormaly
sprite!!.render(g,
(hitbox.posX - hitboxTranslateX * scale).toFloat() + world.width * TILE_SIZE,
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
}
else {
sprite!!.render(g,
@@ -941,6 +959,12 @@ open class ActorWithBody : Actor() {
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
// Q&D fix for Roundworld anormaly
sprite!!.render(g,
(hitbox.posX - scale).toFloat() + world.width * TILE_SIZE,
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
}
}
}

View File

@@ -28,13 +28,11 @@ class FixtureTikiTorch : FixtureBase(), Luminous {
sprite = SpriteAnimation()
sprite!!.setDimension(10, 27)
sprite!!.setSpriteImage("res/graphics/sprites/fixtures/tiki_torch.png")
sprite!!.setSpriteImage("assets/graphics/sprites/fixtures/tiki_torch.png")
sprite!!.setDelay(200)
sprite!!.setRowsAndFrames(1, 1)
sprite!!.setAsVisible()
actorValue[AVKey.BASEMASS] = 1.0
luminosity = TileCodex[Tile.TORCH].luminosity
}
}

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
@@ -28,5 +30,11 @@ class PhysTestBall : ActorWithBody() {
hitbox.posY.toFloat(),
hitbox.width.toFloat(),
hitbox.height.toFloat())
g.fillOval(
hitbox.posX.toFloat() + Terrarum.ingame.world.width * TILE_SIZE,
hitbox.posY.toFloat(),
hitbox.width.toFloat(),
hitbox.height.toFloat())
}
}

View File

@@ -6,6 +6,7 @@ import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ProjectileSimple
import net.torvald.terrarum.gameactors.floorInt
import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex
import net.torvald.terrarum.ui.UIHandler
@@ -29,10 +30,10 @@ object GameController {
get() = (MapCamera.cameraY + Terrarum.appgc.input.mouseY / Terrarum.ingame.screenZoom)
/** currently pointing tile coordinate */
internal val mouseTileX: Int
get() = (mouseX / MapDrawer.TILE_SIZE).toInt()
get() = (mouseX / MapDrawer.TILE_SIZE).floorInt()
/** currently pointing tile coordinate */
internal val mouseTileY: Int
get() = (mouseY / MapDrawer.TILE_SIZE).toInt()
get() = (mouseY / MapDrawer.TILE_SIZE).floorInt()
fun processInput(gc: GameContainer, delta: Int, input: Input) {
@@ -164,11 +165,11 @@ object GameController {
}
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseX: Float
get() = GameController.mouseX
val GameContainer.mouseX: Double
get() = GameController.mouseX.toDouble()
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseY: Float
get() = GameController.mouseY
val GameContainer.mouseY: Double
get() = GameController.mouseY.toDouble()
/** currently pointing tile coordinate */
val GameContainer.mouseTileX: Int
get() = GameController.mouseTileX

View File

@@ -7,6 +7,7 @@ import com.jme3.math.FastMath
import net.torvald.colourutil.RGB
import net.torvald.colourutil.CIELuvUtil.additiveLuv
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.mapdrawer.MapCamera.world
import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TilePropUtil
import org.newdawn.slick.Color
@@ -38,7 +39,7 @@ object LightmapRenderer {
private val OFFSET_G = 1
private val OFFSET_B = 0
private const val TSIZE = MapDrawer.TILE_SIZE
private const val TILE_SIZE = MapDrawer.TILE_SIZE
// color model related constants
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB
@@ -79,11 +80,11 @@ object LightmapRenderer {
}
fun renderLightMap() {
for_x_start = MapCamera.cameraX / TSIZE - 1 // fix for premature lightmap rendering
for_y_start = MapCamera.cameraY / TSIZE - 1 // on topmost/leftmost side
for_x_start = MapCamera.cameraX / TILE_SIZE - 1 // fix for premature lightmap rendering
for_y_start = MapCamera.cameraY / TILE_SIZE - 1 // on topmost/leftmost side
for_x_end = for_x_start + MapCamera.renderWidth / TSIZE + 3
for_y_end = for_y_start + MapCamera.renderHeight / TSIZE + 2 // same fix as above
for_x_end = for_x_start + MapCamera.renderWidth / TILE_SIZE + 3
for_y_end = for_y_start + MapCamera.renderHeight / TILE_SIZE + 2 // same fix as above
/**
* * true: overscanning is limited to 8 tiles in width (overscan_opaque)
@@ -182,11 +183,15 @@ object LightmapRenderer {
val lightBoxY = it.hitbox.posY + lightBox.posY
val lightBoxW = lightBox.width
val lightBoxH = lightBox.height
for (y in lightBoxY.div(TSIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TSIZE).floorInt())
for (x in lightBoxX.div(TSIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TSIZE).floorInt())
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
lanternMap.add(Lantern(x, y, it.luminosity))
// Q&D fix for Roundworld anormaly
lanternMap.add(Lantern(x + world.width, y, it.luminosity))
}
}
}
}
}
@@ -339,10 +344,10 @@ object LightmapRenderer {
g.color = Color(0)
g.fillRect(
(x.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
(y.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
((TSIZE * Terrarum.ingame.screenZoom).ceil() * zeroLevelCounter).toFloat(),
(TSIZE * Terrarum.ingame.screenZoom).ceil().toFloat()
(x.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
(y.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
((TILE_SIZE * Terrarum.ingame.screenZoom).ceil() * zeroLevelCounter).toFloat(),
(TILE_SIZE * Terrarum.ingame.screenZoom).ceil().toFloat()
)
x += zeroLevelCounter - 1
@@ -380,12 +385,12 @@ object LightmapRenderer {
g.color = colourMapItoL[iy * 2 + ix].normaliseToColour()
g.fillRect(
(x.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).round()
+ ix * TSIZE / 2 * Terrarum.ingame.screenZoom,
(y.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).round()
+ iy * TSIZE / 2 * Terrarum.ingame.screenZoom,
(TSIZE * Terrarum.ingame.screenZoom / 2).ceil().toFloat(),
(TSIZE * Terrarum.ingame.screenZoom / 2).ceil().toFloat()
(x.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).round()
+ ix * TILE_SIZE / 2 * Terrarum.ingame.screenZoom,
(y.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).round()
+ iy * TILE_SIZE / 2 * Terrarum.ingame.screenZoom,
(TILE_SIZE * Terrarum.ingame.screenZoom / 2).ceil().toFloat(),
(TILE_SIZE * Terrarum.ingame.screenZoom / 2).ceil().toFloat()
)
}
}
@@ -406,10 +411,10 @@ object LightmapRenderer {
g.color = (getLight(x, y) ?: 0).normaliseToColour()
g.fillRect(
(x.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
(y.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
((TSIZE * Terrarum.ingame.screenZoom).ceil() * sameLevelCounter).toFloat(),
(TSIZE * Terrarum.ingame.screenZoom).ceil().toFloat()
(x.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
(y.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).round().toFloat(),
((TILE_SIZE * Terrarum.ingame.screenZoom).ceil() * sameLevelCounter).toFloat(),
(TILE_SIZE * Terrarum.ingame.screenZoom).ceil().toFloat()
)
x += sameLevelCounter - 1

View File

@@ -9,6 +9,7 @@ import com.jme3.math.FastMath
import net.torvald.terrarum.concurrent.ThreadPool
import net.torvald.terrarum.blendMul
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
import org.lwjgl.opengl.GL11
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -20,20 +21,20 @@ import java.util.*
* Created by minjaesong on 16-01-19.
*/
object MapCamera {
val WORLD: GameWorld = Terrarum.ingame.world
val world: GameWorld = Terrarum.ingame.world
var cameraX = 0
private set
var cameraY = 0
private set
private val TSIZE = MapDrawer.TILE_SIZE
private val TILE_SIZE = MapDrawer.TILE_SIZE
var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TSIZE, TSIZE)
var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TILE_SIZE, TILE_SIZE)
private set
var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TSIZE, TSIZE)
var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TILE_SIZE, TILE_SIZE)
private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here.
var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TSIZE, TSIZE)
var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TILE_SIZE, TILE_SIZE)
private set
var tilesetBook: Array<SpriteSheet> = arrayOf(tilesWall, tilesTerrain, tilesWire)
private set
@@ -238,14 +239,14 @@ object MapCamera {
// position - (WH / 2)
/*cameraX = Math.round(FastMath.clamp(
player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), WORLD.width * TSIZE - renderWidth - TSIZE.toFloat()))
player.hitbox.centeredX.toFloat() - renderWidth / 2, TILE_SIZE.toFloat(), world.width * TILE_SIZE - renderWidth - TILE_SIZE.toFloat()))
cameraY = Math.round(FastMath.clamp(
player.hitbox.centeredY.toFloat() - renderHeight / 2, TSIZE.toFloat(), WORLD.height * TSIZE - renderHeight - TSIZE.toFloat()))
player.hitbox.centeredY.toFloat() - renderHeight / 2, TILE_SIZE.toFloat(), world.height * TILE_SIZE - renderHeight - TILE_SIZE.toFloat()))
*/
cameraX = Math.round( // X only: ROUNDWORLD implementation
player.hitbox.centeredX.toFloat() - renderWidth / 2)
cameraY = Math.round(FastMath.clamp(
player.hitbox.centeredY.toFloat() - renderHeight / 2, TSIZE.toFloat(), WORLD.height * TSIZE - renderHeight - TSIZE.toFloat()))
player.hitbox.centeredY.toFloat() - renderHeight / 2, TILE_SIZE.toFloat(), world.height * TILE_SIZE - renderHeight - TILE_SIZE.toFloat()))
}
@@ -265,11 +266,11 @@ object MapCamera {
}
private fun drawTiles(mode: Int, drawModeTilesBlendMul: Boolean) {
val for_y_start = MapCamera.cameraY / TSIZE
val for_y_end = MapCamera.clampHTile(for_y_start + (MapCamera.renderHeight / TSIZE) + 2)
val for_y_start = MapCamera.cameraY / TILE_SIZE
val for_y_end = MapCamera.clampHTile(for_y_start + (MapCamera.renderHeight / TILE_SIZE) + 2)
val for_x_start = MapCamera.cameraX / TSIZE - 1
val for_x_end = for_x_start + (MapCamera.renderWidth / TSIZE) + 2
val for_x_start = MapCamera.cameraX / TILE_SIZE - 1
val for_x_end = for_x_start + (MapCamera.renderWidth / TILE_SIZE) + 2
// initialise
MapCamera.tilesetBook[mode].startUse()
@@ -280,11 +281,11 @@ object MapCamera {
val thisTile: Int?
if (mode % 3 == WALL)
thisTile = WORLD.getTileFromWall(x, y)
thisTile = world.getTileFromWall(x, y)
else if (mode % 3 == TERRAIN)
thisTile = WORLD.getTileFromTerrain(x, y)
thisTile = world.getTileFromTerrain(x, y)
else if (mode % 3 == WIRE)
thisTile = WORLD.getTileFromWire(x, y)
thisTile = world.getTileFromWire(x, y)
else
throw IllegalArgumentException()
@@ -360,10 +361,10 @@ object MapCamera {
*/
fun getNearbyTilesInfo(x: Int, y: Int, mode: Int, mark: Int?): Int {
val nearbyTiles = IntArray(4)
nearbyTiles[NEARBY_TILE_KEY_LEFT] = WORLD.getTileFrom(mode, x - 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = WORLD.getTileFrom(mode, x + 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_UP] = WORLD.getTileFrom(mode, x , y - 1) ?: 4906
nearbyTiles[NEARBY_TILE_KEY_DOWN] = WORLD.getTileFrom(mode, x , y + 1) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFrom(mode, x , y - 1) ?: 4906
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(mode, x , y + 1) ?: 4096
// try for
var ret = 0
@@ -378,10 +379,10 @@ object MapCamera {
fun getNearbyTilesInfoNonSolid(x: Int, y: Int, mode: Int): Int {
val nearbyTiles = IntArray(4)
nearbyTiles[NEARBY_TILE_KEY_LEFT] = WORLD.getTileFrom(mode, x - 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = WORLD.getTileFrom(mode, x + 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_UP] = WORLD.getTileFrom(mode, x , y - 1) ?: 4906
nearbyTiles[NEARBY_TILE_KEY_DOWN] = WORLD.getTileFrom(mode, x , y + 1) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFrom(mode, x , y - 1) ?: 4906
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(mode, x , y + 1) ?: 4096
// try for
var ret = 0
@@ -402,10 +403,10 @@ object MapCamera {
fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int {
val nearbyTiles = IntArray(4)
val NEARBY_TILE_KEY_BACK = NEARBY_TILE_KEY_UP
nearbyTiles[NEARBY_TILE_KEY_LEFT] = WORLD.getTileFrom(TERRAIN, x - 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = WORLD.getTileFrom(TERRAIN, x + 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_DOWN] = WORLD.getTileFrom(TERRAIN, x , y + 1) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_BACK] = WORLD.getTileFrom(WALL, x , y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(TERRAIN, x + 1, y) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(TERRAIN, x , y + 1) ?: 4096
nearbyTiles[NEARBY_TILE_KEY_BACK] = world.getTileFrom(WALL, x , y) ?: 4096
try {
if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_DOWN]].isSolid)
@@ -436,19 +437,19 @@ object MapCamera {
private fun drawTile(mode: Int, tilewisePosX: Int, tilewisePosY: Int, sheetX: Int, sheetY: Int) {
if (Terrarum.ingame.screenZoom == 1f) {
tilesetBook[mode].renderInUse(
FastMath.floor((tilewisePosX * TSIZE).toFloat()), FastMath.floor((tilewisePosY * TSIZE).toFloat()), sheetX, sheetY)
FastMath.floor((tilewisePosX * TILE_SIZE).toFloat()), FastMath.floor((tilewisePosY * TILE_SIZE).toFloat()), sheetX, sheetY)
} else {
tilesetBook[mode].getSprite(
sheetX, sheetY).drawEmbedded(
Math.round(tilewisePosX.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).toFloat(), Math.round(tilewisePosY.toFloat() * TSIZE.toFloat() * Terrarum.ingame.screenZoom).toFloat(), FastMath.ceil(TSIZE * Terrarum.ingame.screenZoom).toFloat(), FastMath.ceil(TSIZE * Terrarum.ingame.screenZoom).toFloat())
Math.round(tilewisePosX.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).toFloat(), Math.round(tilewisePosY.toFloat() * TILE_SIZE.toFloat() * Terrarum.ingame.screenZoom).toFloat(), FastMath.ceil(TILE_SIZE * Terrarum.ingame.screenZoom).toFloat(), FastMath.ceil(TILE_SIZE * Terrarum.ingame.screenZoom).toFloat())
}
}
fun clampH(x: Int): Int {
if (x < 0) {
return 0
} else if (x > WORLD.height * TSIZE) {
return WORLD.height * TSIZE
} else if (x > world.height * TILE_SIZE) {
return world.height * TILE_SIZE
} else {
return x
}
@@ -457,8 +458,8 @@ object MapCamera {
fun clampWTile(x: Int): Int {
if (x < 0) {
return 0
} else if (x > WORLD.width) {
return WORLD.width
} else if (x > world.width) {
return world.width
} else {
return x
}
@@ -467,18 +468,18 @@ object MapCamera {
fun clampHTile(x: Int): Int {
if (x < 0) {
return 0
} else if (x > WORLD.height) {
return WORLD.height
} else if (x > world.height) {
return world.height
} else {
return x
}
}
fun getRenderStartX(): Int = cameraX / TSIZE
fun getRenderStartY(): Int = cameraY / TSIZE
fun getRenderStartX(): Int = cameraX / TILE_SIZE
fun getRenderStartY(): Int = cameraY / TILE_SIZE
fun getRenderEndX(): Int = clampWTile(getRenderStartX() +(renderWidth / TSIZE) + 2)
fun getRenderEndY(): Int = clampHTile(getRenderStartY() +(renderHeight / TSIZE) + 2)
fun getRenderEndX(): Int = clampWTile(getRenderStartX() + (renderWidth / TILE_SIZE) + 2)
fun getRenderEndY(): Int = clampHTile(getRenderStartY() + (renderHeight / TILE_SIZE) + 2)
fun isConnectSelf(b: Int?): Boolean = TILES_CONNECT_SELF.contains(b)
fun isConnectMutual(b: Int?): Boolean = TILES_CONNECT_MUTUAL.contains(b)
@@ -487,6 +488,6 @@ object MapCamera {
fun isBlendMul(b: Int?): Boolean = TILES_BLEND_MUL.contains(b)
fun tileInCamera(x: Int, y: Int) =
x >= cameraX.div(TSIZE) && y >= cameraY.div(TSIZE) &&
x <= cameraX.plus(renderWidth).div(TSIZE) && y <= cameraY.plus(renderWidth).div(TSIZE)
x >= cameraX.div(TILE_SIZE) && y >= cameraY.div(TILE_SIZE) &&
x <= cameraX.plus(renderWidth).div(TILE_SIZE) && y <= cameraY.plus(renderWidth).div(TILE_SIZE)
}