From 01def757e9313132857b62a93044fe1c70a351ec Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Sun, 18 Dec 2016 23:21:51 +0900 Subject: [PATCH] minor edits Former-commit-id: 727c880ff913f72cf17f89155c35966f38224c07 Former-commit-id: 65d4bf1045440de7d23efd3ef43176e1cddfa1e4 --- .../terrarum/gameactors/ActorWithBody.kt | 27 ++++++----- src/net/torvald/terrarum/gameactors/Player.kt | 2 +- .../terrarum/gameactors/ProjectileSimple.kt | 2 +- .../terrarum/mapdrawer/LightmapRenderer.kt | 14 +++++- .../torvald/terrarum/mapdrawer/MapCamera.kt | 46 +++++++++---------- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 15528f8e2..8415a5b9f 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -29,7 +29,7 @@ open class ActorWithBody : Actor() { @Transient internal var sprite: SpriteAnimation? = null @Transient internal var spriteGlow: SpriteAnimation? = null - protected var drawMode: DrawMode = DrawMode.NORMAL + var drawMode = BLEND_NORMAL @Transient private val world: GameWorld = Terrarum.ingame.world @@ -211,10 +211,7 @@ open class ActorWithBody : Actor() { @Transient internal val BASE_FRICTION = 0.3 - @Transient val KINEMATIC = 1 // does not displaced by external forces - @Transient val DYNAMIC = 2 // displaced by external forces - @Transient val STATIC = 3 // does not displaced by external forces, target of collision - var collisionType = DYNAMIC + var collisionType = COLLISION_DYNAMIC @Transient private val CCD_TICK = 1.0 / 16.0 @Transient private val CCD_TRY_MAX = 12800 @@ -935,9 +932,9 @@ open class ActorWithBody : Actor() { open fun drawBody(gc: GameContainer, g: Graphics) { if (isVisible && sprite != null) { when (drawMode) { - DrawMode.NORMAL -> blendNormal() - DrawMode.MULTIPLY -> blendMul() - DrawMode.SCREEN -> blendScreen() + BLEND_NORMAL -> blendNormal() + BLEND_MULTIPLY -> blendMul() + BLEND_SCREEN -> blendScreen() } if (!sprite!!.flippedHorizontal()) { @@ -1080,6 +1077,16 @@ open class ActorWithBody : Actor() { companion object { + /** + * Enumerations that exported to JSON + */ + @Transient const val COLLISION_KINEMATIC = 1 // does not displaced by external forces + @Transient const val COLLISION_DYNAMIC = 2 // displaced by external forces + @Transient const val COLLISION_STATIC = 3 // does not displaced by external forces, target of collision + @Transient const val BLEND_NORMAL = 4 + @Transient const val BLEND_SCREEN = 5 + @Transient const val BLEND_MULTIPLY = 6 + @Transient private val TILE_SIZE = MapDrawer.TILE_SIZE private fun div16TruncateToMapWidth(x: Int): Int { @@ -1140,7 +1147,3 @@ fun absMax(left: Double, right: Double): Double { fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr() fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0 - -enum class DrawMode { - NORMAL, SCREEN, MULTIPLY -} diff --git a/src/net/torvald/terrarum/gameactors/Player.kt b/src/net/torvald/terrarum/gameactors/Player.kt index 22a250fc3..cdefcabe2 100644 --- a/src/net/torvald/terrarum/gameactors/Player.kt +++ b/src/net/torvald/terrarum/gameactors/Player.kt @@ -43,7 +43,7 @@ class Player(born: GameDate) : ActorHumanoid(born) { isVisible = true referenceID = PLAYER_REF_ID // forcibly set ID density = BASE_DENSITY - collisionType = KINEMATIC + collisionType = COLLISION_KINEMATIC try { gamepad = Controllers.getController(0) diff --git a/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt b/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt index 6fb1be1cc..f15f86bbc 100644 --- a/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt +++ b/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt @@ -63,7 +63,7 @@ open class ProjectileSimple( - collisionType = KINEMATIC + collisionType = COLLISION_KINEMATIC } override fun update(gc: GameContainer, delta: Int) { diff --git a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt index 88ed6fa5e..5287b514b 100644 --- a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt @@ -304,10 +304,22 @@ object LightmapRenderer { ambient = darkenColoured(ambient, thisTileOpacity) // get real ambient by appling opacity value - // mix and return lightlevel and ambient + return lightLevelThis maxBlend ambient + // mix and return lightlevel and ambient + /*val retLevel = lightLevelThis maxBlend ambient + // hack: make sure (3,3,3) become 0 + return if (retLevel.rawR() < 4 && retLevel.rawG() < 4 && retLevel.rawB() < 4) + 0 + else + retLevel*/ } else { + // hack: make sure (3,3,3) become 0 + /*return if (lightLevelThis.rawR() < 4 && lightLevelThis.rawG() < 4 && lightLevelThis.rawB() < 4) + 0 + else + lightLevelThis*/ return lightLevelThis } } diff --git a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt index 42a445c6a..f7692e849 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt +++ b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt @@ -11,10 +11,7 @@ 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 -import org.newdawn.slick.SlickException -import org.newdawn.slick.SpriteSheet +import org.newdawn.slick.* import java.util.* /** @@ -255,17 +252,17 @@ object MapCamera { * render to camera */ blendNormal() - drawTiles(WALL, false) - drawTiles(TERRAIN, false) + drawTiles(g, WALL, false) + drawTiles(g, TERRAIN, false) } fun renderFront(gc: GameContainer, g: Graphics) { blendMul() - drawTiles(TERRAIN, true) + drawTiles(g, TERRAIN, true) blendNormal() } - private fun drawTiles(mode: Int, drawModeTilesBlendMul: Boolean) { + private fun drawTiles(g: Graphics, mode: Int, drawModeTilesBlendMul: Boolean) { val for_y_start = MapCamera.cameraY / TILE_SIZE val for_y_end = MapCamera.clampHTile(for_y_start + (MapCamera.renderHeight / TILE_SIZE) + 2) @@ -275,6 +272,8 @@ object MapCamera { // initialise MapCamera.tilesetBook[mode].startUse() + var zeroTileCounter = 0 + // loop for (y in for_y_start..for_y_end) { for (x in for_x_start..for_x_end - 1) { @@ -294,23 +293,19 @@ object MapCamera { // draw try { if ( - - (mode == WALL || mode == TERRAIN) // not an air tile - - && (thisTile ?: 0) > 0 - && + (mode == WALL || mode == TERRAIN) && // not an air tile + (thisTile ?: 0) > 0) //&& // commented out: meh // check if light level of nearby or this tile is illuminated - ( LightmapRenderer.getValueFromMap(x, y) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x - 1, y) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x + 1, y) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x, y - 1) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x, y + 1) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x - 1, y - 1) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x + 1, y + 1) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x + 1, y - 1) ?: 0 > 0 - || LightmapRenderer.getValueFromMap(x - 1, y + 1) ?: 0 > 0) - ) { - + /*( LightmapRenderer.getValueFromMap(x, y) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x - 1, y) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x + 1, y) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x, y - 1) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x, y + 1) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x - 1, y - 1) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x + 1, y + 1) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x + 1, y - 1) ?: 0 > 0 || + LightmapRenderer.getValueFromMap(x - 1, y + 1) ?: 0 > 0) + )*/ { val nearbyTilesInfo: Int if (isPlatform(thisTile)) { nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y) @@ -346,6 +341,9 @@ object MapCamera { // or else they will not look like they should be when backed with wall drawTile(mode, x, y, thisTileX, thisTileY) } + } // end if (not an air and is illuminated) + else { + zeroTileCounter++ } } catch (e: NullPointerException) { // do nothing. WARNING: This exception handling may hide erratic behaviour completely.