diff --git a/assets/graphics/gui/health_take_a_break.png b/assets/graphics/gui/health_take_a_break.png index c72e02eaa..b795eab8e 100644 Binary files a/assets/graphics/gui/health_take_a_break.png and b/assets/graphics/gui/health_take_a_break.png differ diff --git a/assets/graphics/gui/monitor_bad.png b/assets/graphics/gui/monitor_bad.png new file mode 100644 index 000000000..661fb77d6 Binary files /dev/null and b/assets/graphics/gui/monitor_bad.png differ diff --git a/assets/graphics/gui/monitor_good.png b/assets/graphics/gui/monitor_good.png new file mode 100644 index 000000000..dba316135 Binary files /dev/null and b/assets/graphics/gui/monitor_good.png differ diff --git a/assets/graphics/gui/monitor_good_alt_maru.png b/assets/graphics/gui/monitor_good_alt_maru.png new file mode 100644 index 000000000..440187b1c Binary files /dev/null and b/assets/graphics/gui/monitor_good_alt_maru.png differ diff --git a/assets/graphics/gui/quickbar/.gitattributes b/assets/graphics/gui/quickbar/.gitattributes new file mode 100644 index 000000000..ca82ef549 --- /dev/null +++ b/assets/graphics/gui/quickbar/.gitattributes @@ -0,0 +1 @@ +*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/assets/graphics/sprites/test_player_2_testa.png b/assets/graphics/sprites/test_player_2_testa.png new file mode 100644 index 000000000..17e2360f4 Binary files /dev/null and b/assets/graphics/sprites/test_player_2_testa.png differ diff --git a/assets/graphics/terrain/.gitattributes b/assets/graphics/terrain/.gitattributes new file mode 100644 index 000000000..ca82ef549 --- /dev/null +++ b/assets/graphics/terrain/.gitattributes @@ -0,0 +1 @@ +*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/assets/graphics/terrain/terrain.png b/assets/graphics/terrain/terrain.png index 7d4c06439..87003e373 100644 Binary files a/assets/graphics/terrain/terrain.png and b/assets/graphics/terrain/terrain.png differ diff --git a/assets/locales/de/Polyglot-100_de.json b/assets/locales/de/Polyglot-100_de.json index 75dc09556..0fc81a0b4 100644 --- a/assets/locales/de/Polyglot-100_de.json +++ b/assets/locales/de/Polyglot-100_de.json @@ -2121,7 +2121,7 @@ }, { "n": "MENU_LABEL_PRESS_START", - "s": "Start drücken" + "s": "Drücke Start" }, { "n": "MENU_LABEL_PRESS_START_CONTINUE", diff --git a/assets/raw/Creature_raw_doc.md b/assets/raw/Creature_raw_doc.md index 3412e1aa5..4c72a1597 100644 --- a/assets/raw/Creature_raw_doc.md +++ b/assets/raw/Creature_raw_doc.md @@ -3,7 +3,7 @@ Creature raw documentation ## Physical properties ## * 1 m = 24 px -* mult: Multiplier. e.g. 1.0, 0.85, 1.25, ... +* mult: Multiplier in pencentage. e.g. 100, 85, 125, ... |name|unit|description| |----|----|-----------| @@ -15,7 +15,7 @@ Creature raw documentation |scale|unit|Creature body scale. Mass/strength/accel/etc. will be changed accordingly, hence the prefix “base” for some raw tokens| |dragcoeff|unit|Drag coefficient| |speedmult, accelmult, jumppowermult|array of percentiles (Int)|Variability factor| -|physiquemult|mult|Breadth variation for mobs| +|scalemult|mult|Breadth variation for mobs| ## Creature properties ## diff --git a/assets/raw/creatures/CreatureHuman.json b/assets/raw/creatures/CreatureHuman.json index e5ff88986..935731693 100644 --- a/assets/raw/creatures/CreatureHuman.json +++ b/assets/raw/creatures/CreatureHuman.json @@ -16,7 +16,7 @@ "jumppowermult": [100,100,100,100,100,100,100], "scale": 1.0, - "physiquemult": [100,100,100,100,100,100,100], + "scalemult": [100,100,100,100,100,100,100], "encumbrance": 1000, "basedefence": 100, diff --git a/src/net/torvald/RasterWriter.kt b/src/net/torvald/RasterWriter.kt index 905cddd2f..65b375485 100644 --- a/src/net/torvald/RasterWriter.kt +++ b/src/net/torvald/RasterWriter.kt @@ -1,7 +1,5 @@ package net.torvald -import net.torvald.terrarum.Terrarum - import javax.imageio.ImageIO import java.awt.* import java.awt.color.ColorSpace diff --git a/src/net/torvald/serialise/ReadGameMapData.kt b/src/net/torvald/serialise/ReadGameMapData.kt new file mode 100644 index 000000000..fa9975fe5 --- /dev/null +++ b/src/net/torvald/serialise/ReadGameMapData.kt @@ -0,0 +1,38 @@ +package net.torvald.serialise + +/** + * Created by minjaesong on 16-08-24. + */ +object ReadGameMapData { + + fun InputStream.readRelative(b: ByteArray, off: Int, len: Int): Int { + if (b == null) { + throw NullPointerException() + } else if (off < 0 || len < 0 || len > b.size) { + throw IndexOutOfBoundsException() + } else if (len == 0) { + return 0 + } + + var c = read() + if (c == -1) { + return -1 + } + b[0] = c.toByte() + + var i = 1 + try { + while (i < len) { + c = read() + if (c == -1) { + break + } + b[i] = c.toByte() + i++ + } + } catch (ee: IOException) { + } + + return i + } +} \ No newline at end of file diff --git a/src/net/torvald/serialise/WriteMeta.kt b/src/net/torvald/serialise/WriteMeta.kt index 686587af5..a02356485 100644 --- a/src/net/torvald/serialise/WriteMeta.kt +++ b/src/net/torvald/serialise/WriteMeta.kt @@ -1,6 +1,6 @@ package net.torvald.serialise -import net.torvald.terrarum.mapgenerator.MapGenerator +import net.torvald.terrarum.mapgenerator.WorldGenerator import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser import net.torvald.terrarum.Terrarum import net.torvald.terrarum.itemproperties.ItemPropCodex @@ -29,7 +29,7 @@ object WriteMeta { val BYTE_NULL: Byte = 0 - val terraseed: Long = MapGenerator.SEED + val terraseed: Long = WorldGenerator.SEED val rogueseed: Long = RoguelikeRandomiser.seed /** diff --git a/src/net/torvald/terrarum/StateFontTester.kt b/src/net/torvald/terrarum/StateFontTester.kt index 8be5f5ff7..91a3b2f07 100644 --- a/src/net/torvald/terrarum/StateFontTester.kt +++ b/src/net/torvald/terrarum/StateFontTester.kt @@ -48,5 +48,5 @@ class StateFontTester : BasicGameState() { } } - override fun getID(): Int = Terrarum.SCENE_ID_TEST_FONT + override fun getID(): Int = Terrarum.STATE_ID_TEST_FONT } \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index c51894eb8..9306995a3 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -5,6 +5,8 @@ import net.torvald.terrarum.audio.AudioResourceLibrary import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.console.Authenticator +import net.torvald.terrarum.console.CommandDict +import net.torvald.terrarum.console.SetGlobalLightOverride import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.Key @@ -16,7 +18,7 @@ import net.torvald.terrarum.gamemap.WorldTime import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapDrawer -import net.torvald.terrarum.mapgenerator.MapGenerator +import net.torvald.terrarum.mapgenerator.WorldGenerator import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser import net.torvald.terrarum.tileproperties.TilePropCodex import net.torvald.terrarum.tilestats.TileStats @@ -94,6 +96,11 @@ constructor() : BasicGameState() { @Throws(SlickException::class) override fun init(gameContainer: GameContainer, stateBasedGame: StateBasedGame) { + // state init code. Executed before the game goes into any "state" in states in StateBasedGame.java + } + + override fun enter(gc: GameContainer, sbg: StateBasedGame) { + // load things when the game entered this "state" // load necessary shaders shader12BitCol = Shader.makeShader("./assets/4096.vrt", "./assets/4096.frg") shaderBlurH = Shader.makeShader("./assets/blurH.vrt", "./assets/blur.frg") @@ -103,10 +110,10 @@ constructor() : BasicGameState() { world = GameWorld(8192, 2048) // generate terrain for the map - MapGenerator.attachMap(world) - MapGenerator.SEED = 0x51621D2 + WorldGenerator.attachMap(world) + WorldGenerator.SEED = 0x51621D2 //mapgenerator.setSeed(new HQRNG().nextLong()); - MapGenerator.generateMap() + WorldGenerator.generateMap() RoguelikeRandomiser.seed = 0x540198 @@ -114,8 +121,8 @@ constructor() : BasicGameState() { // add new player and put it to actorContainer - player = PBSigrid.create() - //player = PFCynthia.create() + //player = PBSigrid.create() + player = PBCynthia.create() //player.setNoClip(true); addActor(player) @@ -159,16 +166,18 @@ constructor() : BasicGameState() { override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { UPDATE_DELTA = delta - setAppTitle() + /////////////////////////// // world-related updates // /////////////////////////// world.updateWorldTime(delta) WorldSimulator(world, player, delta) WeatherMixer.update(gc, delta) - world.globalLight = globalLightByTime.toInt() + TileStats.update() + if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride) + world.globalLight = globalLightByTime.toInt() /////////////////////////// @@ -178,9 +187,6 @@ constructor() : BasicGameState() { uiContainer.forEach { it.processInput(gc.input) } - TileStats.update() - - //////////////////////////// // camera-related updates // //////////////////////////// @@ -213,6 +219,9 @@ constructor() : BasicGameState() { // app-related updates // ///////////////////////// Terrarum.appgc.setVSync(Terrarum.appgc.fps >= Terrarum.VSYNC_TRIGGER_THRESHOLD) + + // determine if lightmap blending should be done + Terrarum.gameConfig["smoothlighting"] = KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH) } private fun setAppTitle() { @@ -225,34 +234,41 @@ constructor() : BasicGameState() { override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) { setBlendNormal() - // determine if lightmap blending should be done - Terrarum.gameConfig["smoothlighting"] = KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH) - - // set antialias as on - if (!g.isAntiAlias) g.isAntiAlias = true drawSkybox(g) + + // make camara work // // compensate for zoom. UIs have to be treated specially! (see UIHandler) g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom) + + ///////////////////////////// + // draw map related stuffs // + ///////////////////////////// MapCamera.renderBehind(gc, g) - // draw actors - run { - actorContainer.forEach { actor -> - if (actor is Visible && actor.inScreen() && actor !is Player) { // if visible and within screen - actor.drawBody(gc, g) - } - } - player.drawBody(gc, g) - } + ///////////////// + // draw actors // + ///////////////// + actorContainer.forEach { actor -> + if (actor is Visible && actor.inScreen() && actor !is Player) { // if visible and within screen + actor.drawBody(gc, g) + } + } + player.drawBody(gc, g) + + + ///////////////////////////// + // draw map related stuffs // + ///////////////////////////// LightmapRenderer.renderLightMap() MapCamera.renderFront(gc, g) MapDrawer.render(gc, g) + setBlendMul() MapDrawer.drawEnvOverlay(g) @@ -260,22 +276,27 @@ constructor() : BasicGameState() { LightmapRenderer.draw(g) setBlendNormal() - // draw actor glows - run { - actorContainer.forEach { actor -> - if (actor is Visible && actor.inScreen() && actor !is Player) { // if visible and within screen - actor.drawGlow(gc, g) - } - } - player.drawGlow(gc, g) - } + ////////////////////// + // draw actor glows // + ////////////////////// + actorContainer.forEach { actor -> + if (actor is Visible && actor.inScreen() && actor !is Player) { // if visible and within screen + actor.drawGlow(gc, g) + } + } + player.drawGlow(gc, g) + + + //////////////////////// + // debug informations // + //////////////////////// // draw reference ID if debugWindow is open if (debugWindow.isVisible) { actorContainer.forEachIndexed { i, actor -> if (actor is Visible) { g.color = Color.white - g.font = Terrarum.smallNumbers + g.font = Terrarum.fontSmallNumbers g.drawString( actor.referenceID.toString(), actor.hitbox.posX.toFloat(), @@ -293,14 +314,18 @@ constructor() : BasicGameState() { } } } + // fluidmap debug + if (KeyToggler.isOn(Key.F4)) + WorldSimulator.drawFluidMapDebug(player, g) - // draw UIs - run { - uiContainer.forEach { ui -> ui.render(gc, sbg, g) } - debugWindow.render(gc, sbg, g) - consoleHandler.render(gc, sbg, g) - notifier.render(gc, sbg, g) - } + + ////////////// + // draw UIs // + ////////////// + uiContainer.forEach { ui -> ui.render(gc, sbg, g) } + debugWindow.render(gc, sbg, g) + consoleHandler.render(gc, sbg, g) + notifier.render(gc, sbg, g) } override fun keyPressed(key: Int, c: Char) { @@ -369,7 +394,7 @@ constructor() : BasicGameState() { uiContainer.forEach { it.controllerButtonReleased(controller, button) } // for GamepadControlled UIcanvases } - override fun getID(): Int = Terrarum.SCENE_ID_GAME + override fun getID(): Int = Terrarum.STATE_ID_GAME private fun drawSkybox(g: Graphics) = WeatherMixer.render(g) diff --git a/src/net/torvald/terrarum/StateMonitorCheck.kt b/src/net/torvald/terrarum/StateMonitorCheck.kt index 18055aff4..3f6901bfc 100644 --- a/src/net/torvald/terrarum/StateMonitorCheck.kt +++ b/src/net/torvald/terrarum/StateMonitorCheck.kt @@ -1,16 +1,11 @@ package net.torvald.terrarum import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.ui.Typography -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIHandler -import net.torvald.terrarum.ui.KeyboardControlled -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Input +import net.torvald.terrarum.ui.* +import org.newdawn.slick.* import org.newdawn.slick.state.BasicGameState import org.newdawn.slick.state.StateBasedGame +import java.util.* /** * Created by minjaesong on 16-07-06. @@ -35,7 +30,7 @@ class StateMonitorCheck : BasicGameState() { //uiMonitorCheck.setAsClose() } - override fun getID(): Int = Terrarum.SCENE_ID_CONFIG_CALIBRATE + override fun getID(): Int = Terrarum.STATE_ID_CONFIG_CALIBRATE class MonitorCheckUI : UICanvas { override var width = Terrarum.WIDTH @@ -44,6 +39,8 @@ class StateMonitorCheck : BasicGameState() { override var handler: UIHandler? = null + private val backgroundCol = Color(0x404040) + private val colourLUT = arrayOf( 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78, 0x80, @@ -51,13 +48,29 @@ class StateMonitorCheck : BasicGameState() { 0xC8, 0xD0, 0xD8, 0xE0, 0xE8, 0xF0, 0xF8, 0xFF ) + val pictograms = ArrayList() + lateinit var imageGallery: ItemImageGallery + + val instructionY = Terrarum.HEIGHT / 2//Terrarum.HEIGHT * 9 / 16 + val anykeyY = Terrarum.HEIGHT * 15 / 16 + + val maru_alt = Regex("CN|JP|K[RP]|TW") + + init { + if (Terrarum.gameLocale.length >= 4 && Terrarum.gameLocale.contains(maru_alt)) + pictograms.add(Image("./assets/graphics/gui/monitor_good_alt_maru.png")) + else + pictograms.add(Image("./assets/graphics/gui/monitor_good.png")) + pictograms.add(Image("./assets/graphics/gui/monitor_bad.png")) + + imageGallery = ItemImageGallery(0, instructionY, Terrarum.WIDTH, anykeyY - instructionY, pictograms) + } + override fun update(gc: GameContainer, delta: Int) { } override fun render(gc: GameContainer, g: Graphics) { val titleY = Terrarum.HEIGHT * 7 / 16 - val instructionY = Terrarum.HEIGHT * 9 / 16 - val anykeyY = Terrarum.HEIGHT * 15 / 16 val barWidthAll = Terrarum.WIDTH.div(100).times(100) * 9 / 10 val barWidth: Int = barWidthAll / 32 + 1 @@ -77,7 +90,7 @@ class StateMonitorCheck : BasicGameState() { // bar start point indicator if (i == 0) { - g.color = Color(0x404040) + g.color = backgroundCol g.drawLine( barXstart.toFloat(), barYstart - barNumberGap - labelH.toFloat(), barXstart.toFloat(), barYstart - barNumberGap.toFloat() @@ -105,7 +118,7 @@ class StateMonitorCheck : BasicGameState() { } // messages background - g.color = Color(0x404040) + g.color = backgroundCol g.fillRect( 0f, Terrarum.HEIGHT.shr(1).toFloat(), Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.shr(1).plus(1).toFloat() @@ -119,14 +132,20 @@ class StateMonitorCheck : BasicGameState() { this ) - (1..12).forEach { + // message text + /*(1..12).forEach { Typography.printCentered( g, Lang["MENU_MONITOR_CALI_LABEL_$it"], instructionY + it.minus(2).times(g.font.lineHeight), this ) - } + }*/ + // message pictogram + imageGallery.render(gc, g) + + + // anykey Typography.printCentered( g, Lang["MENU_LABEL_PRESS_ANYKEY_CONTINUE"], anykeyY, diff --git a/src/net/torvald/terrarum/StateSplash.kt b/src/net/torvald/terrarum/StateSplash.kt index a1e57980c..b561dc7ca 100644 --- a/src/net/torvald/terrarum/StateSplash.kt +++ b/src/net/torvald/terrarum/StateSplash.kt @@ -5,6 +5,7 @@ import net.torvald.terrarum.gameactors.roundInt import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.ui.DrawUtil +import net.torvald.terrarum.ui.ItemImageGallery import net.torvald.terrarum.ui.Typography import org.newdawn.slick.Color import org.newdawn.slick.GameContainer @@ -37,13 +38,16 @@ class StateSplash : BasicGameState() { val backgroundColour = Color(0x303030) - var delta = 0 val deltathre = 500 - val auto_dismiss = 5000 + val auto_dismiss = 6500 var opened = false + var init = false + + lateinit var imageGallery: ItemImageGallery + override fun init(container: GameContainer?, game: StateBasedGame?) { // pre-load lang Lang["MENU_LANGUAGE_THIS"] @@ -53,19 +57,24 @@ class StateSplash : BasicGameState() { fadeSheet = Image(Terrarum.WIDTH, Terrarum.HEIGHT) thisG = fadeSheet.graphics - thisG.font = Terrarum.gameFont + thisG.font = Terrarum.fontGame + + imageBoardHeight = Terrarum.HEIGHT - thisG.font.lineHeight.times(6) + imageBoardOffset = thisG.font.lineHeight.times(3) + + imageGallery = ItemImageGallery(0, imageBoardOffset, Terrarum.WIDTH, imageBoardHeight, pictogramCollection) } override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { - this.delta = delta - // next splash or load next scene - if (anykey_hit && opacity == 0f) { - System.exit(0) + if (anykey_hit && opened) { + game.enterState(Terrarum.STATE_ID_GAME) } // fade-in if (delta < deltathre) { + init = true + if (opacity < 1f && !anykey_hit) { opacity = FastMath.interpolateLinear( fadeTimer.toFloat() / fadeTime, 0f, 1f @@ -85,18 +94,15 @@ class StateSplash : BasicGameState() { // auto dismiss if (opened && fadeTimer >= auto_dismiss) - doAnykeyThingy() + //doAnykeyThingy() fadeTimer += delta + println(fadeTimer) } - override fun getID(): Int = Terrarum.SCENE_ID_SPLASH - - override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics) { - - imageBoardHeight = Terrarum.HEIGHT - thisG.font.lineHeight.times(6) - imageBoardOffset = thisG.font.lineHeight.times(3) + override fun getID(): Int = Terrarum.STATE_ID_SPLASH + override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { thisG.color = backgroundColour thisG.fillRect(0f, 0f, fadeSheet.width.toFloat(), fadeSheet.height.toFloat()) @@ -108,9 +114,7 @@ class StateSplash : BasicGameState() { Typography.printCentered(thisG, Lang["MENU_LABEL_PRESS_ANYKEY_CONTINUE"], Terrarum.HEIGHT - thisG.font.lineHeight.times(3)) - pictogramCollection.forEachIndexed { i, image -> - DrawUtil.drawCentered(thisG, image, knowYourPlace(i) + imageBoardOffset) - } + imageGallery.render(container, thisG) g.drawImage(fadeSheet, 0f, 0f, Color(1f, 1f, 1f, opacity)) } @@ -131,7 +135,7 @@ class StateSplash : BasicGameState() { } private fun doAnykeyThingy() { - if (delta < deltathre && !anykey_hit) { + if (!anykey_hit) { anykey_hit = true fadeTimer = 0 } diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 006b296dd..63f386818 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -26,6 +26,10 @@ import java.util.logging.SimpleFormatter class Terrarum @Throws(SlickException::class) constructor(gamename: String) : StateBasedGame(gamename) { + // these properties goes into the GameContainer + + var previousState: Int? = null // to be used with temporary states like StateMonitorCheck + init { gameConfig = GameConfig() @@ -63,8 +67,8 @@ constructor(gamename: String) : StateBasedGame(gamename) { override fun initStatesList(gc: GameContainer) { gc.input.enableKeyRepeat() - gameFont = GameFontWhite() - smallNumbers = TinyAlphNum() + fontGame = GameFontWhite() + fontSmallNumbers = TinyAlphNum() hasController = gc.input.controllerCount > 0 if (hasController) { @@ -75,11 +79,11 @@ constructor(gamename: String) : StateBasedGame(gamename) { gc.graphics.clear() // clean up any 'dust' in the buffer - ingame = StateInGame() - //addState(ingame) - //addState(StateMonitorCheck()) + //addState(StateSplash()) + addState(StateMonitorCheck()) //addState(StateFontTester()) - addState(StateSplash()) + ingame = StateInGame() + addState(ingame) } companion object { @@ -137,20 +141,20 @@ constructor(gamename: String) : StateBasedGame(gamename) { field = value } - lateinit var gameFont: Font + lateinit var fontGame: Font private set - lateinit var smallNumbers: Font + lateinit var fontSmallNumbers: Font private set // 0x0 - 0xF: Game-related // 0x10 - 0x1F: Config // 0x100 and onward: unit tests for dev - val SCENE_ID_SPLASH = 0x0 - val SCENE_ID_HOME = 0x1 - val SCENE_ID_GAME = 0x3 - val SCENE_ID_CONFIG_CALIBRATE = 0x11 + val STATE_ID_SPLASH = 0x0 + val STATE_ID_HOME = 0x1 + val STATE_ID_GAME = 0x3 + val STATE_ID_CONFIG_CALIBRATE = 0x11 - val SCENE_ID_TEST_FONT = 0x100 + val STATE_ID_TEST_FONT = 0x100 var hasController = false val CONTROLLER_DEADZONE = 0.1f @@ -367,7 +371,7 @@ fun main(args: Array) = Terrarum.main(args) fun setBlendMul() { GL11.glEnable(GL11.GL_BLEND) - GL11.glColorMask(true, true, true, false) + GL11.glColorMask(true, true, true, true) GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA) } diff --git a/src/net/torvald/terrarum/console/CommandDict.kt b/src/net/torvald/terrarum/console/CommandDict.kt index bd24e2a21..e06063a1b 100644 --- a/src/net/torvald/terrarum/console/CommandDict.kt +++ b/src/net/torvald/terrarum/console/CommandDict.kt @@ -27,7 +27,7 @@ object CommandDict { Pair("tp", TeleportPlayer()), Pair("cat", CatStdout()), Pair("exportav", ExportAV()), - Pair("setgl", SetGlobalLightLevel()), + Pair("setgl", SetGlobalLightOverride()), Pair("getfaction", GetFactioning()), Pair("auth", Terrarum.ingame.auth), Pair("spawnball", SpawnPhysTestBall()), diff --git a/src/net/torvald/terrarum/console/SetGlobalLightLevel.kt b/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt similarity index 78% rename from src/net/torvald/terrarum/console/SetGlobalLightLevel.kt rename to src/net/torvald/terrarum/console/SetGlobalLightOverride.kt index 7dfe6a42e..a5a1b25f7 100644 --- a/src/net/torvald/terrarum/console/SetGlobalLightLevel.kt +++ b/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt @@ -6,7 +6,11 @@ import net.torvald.terrarum.Terrarum /** * Created by minjaesong on 16-02-17. */ -class SetGlobalLightLevel : ConsoleCommand { +class SetGlobalLightOverride : ConsoleCommand { + + var lightOverride = false + private set + override fun execute(args: Array) { if (args.size == 4) { try { @@ -15,6 +19,7 @@ class SetGlobalLightLevel : ConsoleCommand { val b = args[3].toInt() val GL = LightmapRenderer.constructRGBFromInt(r, g, b) + lightOverride = true Terrarum.ingame.world.globalLight = GL } catch (e: NumberFormatException) { @@ -37,7 +42,10 @@ class SetGlobalLightLevel : ConsoleCommand { } } catch (e: NumberFormatException) { - Echo().execute("Wrong number input.") + if (args[1].toLowerCase() == "none") + lightOverride = false + else + Echo().execute("Wrong number input.") } } @@ -47,6 +55,6 @@ class SetGlobalLightLevel : ConsoleCommand { } override fun printUsage() { - Echo().execute("Usage: setgl [raw_value|r g b]") + Echo().execute("Usage: setgl [raw_value|r g b|“none”]") } } diff --git a/src/net/torvald/terrarum/gameactors/Actor.kt b/src/net/torvald/terrarum/gameactors/Actor.kt index 1b4916951..537efeb31 100644 --- a/src/net/torvald/terrarum/gameactors/Actor.kt +++ b/src/net/torvald/terrarum/gameactors/Actor.kt @@ -29,7 +29,7 @@ abstract class Actor : Comparable, Runnable { "ID: ${hashCode()} (${actorValue.getAsString(AVKey.NAME)})" override fun compareTo(other: Actor): Int = (this.referenceID - other.referenceID).sign() - fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else this + fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0 /** * Usage: diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index be3b4421b..cd82204c6 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -769,7 +769,7 @@ open class ActorWithBody : Actor(), Visible { Hitbox(nextHitbox.posX, nextHitbox.posY, nextHitbox.width + 2.0, nextHitbox.height + 2.0) // when not walking, enlarge the hitbox for calculation so that - // feet tiles are to be taken into calculation + // feet tiles are also counted else nextHitbox.clone() diff --git a/src/net/torvald/terrarum/gameactors/CreatureRawInjector.kt b/src/net/torvald/terrarum/gameactors/CreatureRawInjector.kt index 7f151ba66..53a57d441 100644 --- a/src/net/torvald/terrarum/gameactors/CreatureRawInjector.kt +++ b/src/net/torvald/terrarum/gameactors/CreatureRawInjector.kt @@ -13,7 +13,7 @@ import java.security.SecureRandom */ object CreatureRawInjector { - const val JSONPATH = "./res/raw/creatures/" + const val JSONPATH = "./assets/raw/creatures/" private const val MULTIPLIER_RAW_ELEM_SUFFIX = AVKey.MULT /** @@ -26,12 +26,14 @@ object CreatureRawInjector { fun inject(actorValueRef: ActorValue, jsonFileName: String) { val jsonObj = JsonFetcher(JSONPATH + jsonFileName) + val elementsInt = arrayOf(AVKey.BASEHEIGHT, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE) val elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL) - val elementsDouble = arrayOf(AVKey.BASEHEIGHT, AVKey.BASEMASS, AVKey.ACCEL, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE) - val elementsDoubleVariable = arrayOf(AVKey.STRENGTH, AVKey.SPEED, AVKey.JUMPPOWER, AVKey.SCALE, AVKey.SPEED) + val elementsDouble = arrayOf(AVKey.BASEMASS, AVKey.ACCEL) + val elementsDoubleVariable = arrayOf(AVKey.STRENGTH, AVKey.SPEED, AVKey.JUMPPOWER, AVKey.SCALE) val elementsBoolean = arrayOf(AVKey.INTELLIGENT) // val elementsMultiplyFromOne = arrayOf() + setAVInts(actorValueRef, elementsInt, jsonObj) setAVStrings(actorValueRef, elementsString, jsonObj) setAVDoubles(actorValueRef, elementsDouble, jsonObj) setAVDoublesVariable(actorValueRef, elementsDoubleVariable, jsonObj) @@ -93,6 +95,20 @@ object CreatureRawInjector { } } + /** + * Fetch and set int actor values + * @param avRef + * * + * @param elemSet + * * + * @param jsonObject + */ + private fun setAVInts(avRef: ActorValue, elemSet: Array, jsonObject: JsonObject) { + for (s in elemSet) { + avRef[s] = jsonObject.get(s).asInt + } + } + /** * Fetch and set actor values that should multiplier be applied to the base value of 1. * E.g. physiquemult diff --git a/src/net/torvald/terrarum/gameactors/PBCynthia.kt b/src/net/torvald/terrarum/gameactors/PBCynthia.kt index bfae41fad..ae1f797b9 100644 --- a/src/net/torvald/terrarum/gameactors/PBCynthia.kt +++ b/src/net/torvald/terrarum/gameactors/PBCynthia.kt @@ -12,8 +12,10 @@ object PBCynthia { val p: Player = Player() CreatureRawInjector.inject(p.actorValue, "CreatureHuman.json") + p.actorValue[AVKey._PLAYER_QUICKBARSEL] = 0 p.actorValue["selectedtile"] = 16 + p.sprite = SpriteAnimation() p.sprite!!.setDimension(26, 42) p.sprite!!.setSpriteImage("assets/graphics/sprites/test_player_2.png") diff --git a/src/net/torvald/terrarum/gameactors/PBSigrid.kt b/src/net/torvald/terrarum/gameactors/PBSigrid.kt index 93aa73f98..4812c9441 100644 --- a/src/net/torvald/terrarum/gameactors/PBSigrid.kt +++ b/src/net/torvald/terrarum/gameactors/PBSigrid.kt @@ -59,7 +59,6 @@ object PBSigrid { p.actorValue[AVKey.BASEDEFENCE] = 141 p.actorValue["selectedtile"] = 16 - p.actorValue[AVKey._PLAYER_QUICKBARSEL] = 0 p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 10, 0) diff --git a/src/net/torvald/terrarum/gameactors/Player.kt b/src/net/torvald/terrarum/gameactors/Player.kt index 5f12434d5..f465091fa 100644 --- a/src/net/torvald/terrarum/gameactors/Player.kt +++ b/src/net/torvald/terrarum/gameactors/Player.kt @@ -172,14 +172,14 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L walkCounterX += 1 - // Heading flag - if (left) - walkHeading = LEFT - else - walkHeading = RIGHT - isWalkingH = true } + + // Heading flag + if (left) + walkHeading = LEFT + else + walkHeading = RIGHT } /** diff --git a/src/net/torvald/terrarum/gamemap/FluidCodex.kt b/src/net/torvald/terrarum/gamemap/FluidCodex.kt new file mode 100644 index 000000000..d9d7e3c1b --- /dev/null +++ b/src/net/torvald/terrarum/gamemap/FluidCodex.kt @@ -0,0 +1,9 @@ +package net.torvald.terrarum.gamemap + +/** + * Created by minjaesong on 16-08-06. + */ +object FluidCodex { + const val FLUID_LAVA = 0xFE.toByte() + const val FLUID_WATER = 0xFF.toByte() +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gamemap/MapLayer.kt b/src/net/torvald/terrarum/gamemap/MapLayer.kt index ab3883243..a619c8e1a 100644 --- a/src/net/torvald/terrarum/gamemap/MapLayer.kt +++ b/src/net/torvald/terrarum/gamemap/MapLayer.kt @@ -40,7 +40,7 @@ class MapLayer(var width: Int, var height: Int) : Iterable { return if (x !in 0..width - 1 || y !in 0..height - 1) null else - uint8ToInt32(data[y][x]) + data[y][x].toUint() } internal fun setTile(x: Int, y: Int, tile: Byte) { @@ -49,11 +49,10 @@ class MapLayer(var width: Int, var height: Int) : Iterable { fun isInBound(x: Int, y: Int) = (x >= 0 && y >= 0 && x < width && y < height) - private fun uint8ToInt32(x: Byte): Int = java.lang.Byte.toUnsignedInt(x) - companion object { @Transient const val RANGE = 256 @Transient const val SIZEOF: Byte = 1 // 1 for 8-bit, 2 for 16-bit, ... } } +fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this) diff --git a/src/net/torvald/terrarum/gamemap/WorldSimulator.kt b/src/net/torvald/terrarum/gamemap/WorldSimulator.kt index 26b27028f..48d9274e3 100644 --- a/src/net/torvald/terrarum/gamemap/WorldSimulator.kt +++ b/src/net/torvald/terrarum/gamemap/WorldSimulator.kt @@ -1,11 +1,15 @@ package net.torvald.terrarum.gamemap import net.torvald.random.HQRNG +import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.Player import net.torvald.terrarum.gameactors.roundInt +import net.torvald.terrarum.gamemap.WorldSimulator.isSolid +import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapDrawer import net.torvald.terrarum.tileproperties.TileNameCode import net.torvald.terrarum.tileproperties.TilePropCodex +import org.newdawn.slick.Color import org.newdawn.slick.Graphics /** @@ -16,16 +20,31 @@ object WorldSimulator { * In tiles; * square width/height = field * 2 */ - const val FLUID_UPDATING_SQUARE_RADIUS = 128 + const val FLUID_UPDATING_SQUARE_RADIUS = 64 // larger value will have dramatic impact on performance const private val DOUBLE_RADIUS = FLUID_UPDATING_SQUARE_RADIUS * 2 private val fluidMap = Array(DOUBLE_RADIUS, { IntArray(DOUBLE_RADIUS) }) + private val fluidTypeMap = Array(DOUBLE_RADIUS, { ByteArray(DOUBLE_RADIUS) }) const val DISPLACE_CAP = 4 const val FLUID_MAX = 16 + var updateXFrom = 0 + var updateXTo = 0 + var updateYFrom = 0 + var updateYTo = 0 + + val colourNone = Color(0x808080) + val colourWater = Color(0x66BBFF) + operator fun invoke(world: GameWorld, p: Player, delta: Int) { + updateXFrom = p.hitbox.centeredX.div(MapDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt() + updateYFrom = p.hitbox.centeredY.div(MapDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt() + updateXTo = updateXFrom + DOUBLE_RADIUS + updateYTo = updateYFrom + DOUBLE_RADIUS + moveFluids(world, p, delta) + displaceFallables(world, p, delta) } /** @@ -34,148 +53,169 @@ object WorldSimulator { * reverse-gravity. */ fun moveFluids(world: GameWorld, p: Player, delta: Int) { - val updateXFrom = p.hitbox.centeredX.div(MapDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt() - val updateYFrom = p.hitbox.centeredY.div(MapDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt() - val updateXTo = updateXFrom + 1 * FLUID_UPDATING_SQUARE_RADIUS - val updateYTo = updateYFrom + 1 * FLUID_UPDATING_SQUARE_RADIUS - - /** - * @return amount of fluid actually drained. - * (intended drainage - this) will give you how much fluid is not yet drained. - */ - fun drain(x: Int, y: Int, amount: Int): Int { - val displacement = Math.min(fluidMap[y - updateYFrom][x - updateXFrom], amount) - - fluidMap[y - updateYFrom][x - updateXFrom] -= displacement - - return displacement - } - - fun pour(x: Int, y: Int, amount: Int) { - fun pourInternal(xpos: Int, ypos: Int, volume: Int): Int { - var spil = 0 - - val addrX = xpos - updateXFrom - val addrY = ypos - updateYFrom - - if (addrX >= 0 && addrY >= 0 && addrX < DOUBLE_RADIUS && addrY < DOUBLE_RADIUS) { - fluidMap[addrY][addrX] += volume - if (fluidMap[addrY][addrX] > FLUID_MAX) { - spil = fluidMap[addrY][addrX] - FLUID_MAX - fluidMap[addrY][addrX] = FLUID_MAX - } - } - - return spil - } - - // pour the fluid - var spillage = pourInternal(x, y, amount) - - if (spillage == 0) return - - // deal with the spillage - - val tileUp = world.getTileFromTerrain(x - updateXFrom, y - updateYFrom - 1) - val tileDown = world.getTileFromTerrain(x - updateXFrom, y - updateYFrom + 1) - - // try to fill downward - if (tileDown != null && !tileDown.isSolid()) { - spillage = pourInternal(x, y + 1, spillage) - } - // else, try to fill upward. if there is no space, just discard - if (tileUp != null && !tileUp.isSolid()) { - pourInternal(x, y - 1, spillage) - } - } - + //////////////////// + // build fluidmap // + //////////////////// purgeFluidMap() + worldToFluidMap(world) + ///////////////////////////////////////////////////////////// // displace fluids. Record displacements into the fluidMap // ///////////////////////////////////////////////////////////// for (y in updateYFrom..updateYTo) { for (x in updateXFrom..updateXTo) { - val tile = world.getTileFromTerrain(x, y) - val tileBottom = world.getTileFromTerrain(x, y + 1) - val tileLeft = world.getTileFromTerrain(x - 1, y) - val tileRight = world.getTileFromTerrain(x + 1, y) - if (tile != null && tile.isFluid()) { + val tile = world.getTileFromTerrain(x, y) ?: TileNameCode.STONE + val tileBottom = world.getTileFromTerrain(x, y + 1) ?: TileNameCode.STONE + val tileLeft = world.getTileFromTerrain(x - 1, y) ?: TileNameCode.STONE + val tileRight = world.getTileFromTerrain(x + 1, y) ?: TileNameCode.STONE + if (tile.isFluid()) { // move down if not obstructed - if (tileBottom != null && !tileBottom.isSolid()) { - val drainage = drain(x, y, DISPLACE_CAP) - pour(x, y + 1, drainage) + if (!tileBottom.isSolid()) { + val drainage = drain(world, x, y, DISPLACE_CAP) + pour(world, x, y + 1, drainage) } - // left and right both open (null is considered as open) - else if ((tileLeft != null && tileRight != null && !tileLeft.isSolid() && !tileRight.isSolid()) || - tileLeft == null && tileRight == null) { + // left and right both open + else if (!tileLeft.isSolid() && !tileRight.isSolid()) { // half-breaker val moreToTheRight = HQRNG().nextBoolean() - val displacement = drain(x, y, DISPLACE_CAP) + val displacement = drain(world, x, y, DISPLACE_CAP) if (displacement.isEven()) { - pour(x - 1, y, displacement shr 1) - pour(x + 1, y, displacement shr 1) + pour(world, x - 1, y, displacement shr 1) + pour(world, x + 1, y, displacement shr 1) } else { - pour(x - 1, y, (displacement shr 1) + if (moreToTheRight) 0 else 1) - pour(x + 1, y, (displacement shr 1) + if (moreToTheRight) 1 else 0) + pour(world, x - 1, y, (displacement shr 1) + if (moreToTheRight) 0 else 1) + pour(world, x + 1, y, (displacement shr 1) + if (moreToTheRight) 1 else 0) } } - // left open (null is considered as open) - else if ((tileLeft != null && !tileLeft.isSolid()) || tileLeft == null) { - val displacement = drain(x, y, DISPLACE_CAP) - pour(x - 1, y, displacement) + // left open + else if (!tileLeft.isSolid()) { + val displacement = drain(world, x, y, DISPLACE_CAP) + pour(world, x - 1, y, displacement) } - // right open (null is considered as open) - else if ((tileRight != null && !tileRight.isSolid()) || tileRight == null) { - val displacement = drain(x, y, DISPLACE_CAP) - pour(x + 1, y, displacement) + // right open + else if (!tileRight.isSolid()) { + val displacement = drain(world, x, y, DISPLACE_CAP) + pour(world, x + 1, y, displacement) } // nowhere open; do default (fill top) else { - pour(x, y - 1, DISPLACE_CAP) + pour(world, x, y - 1, DISPLACE_CAP) } } } } + + ///////////////////////////////////////////////////// // replace fluids in the map according to fluidMap // ///////////////////////////////////////////////////// - for (y in 0..fluidMap.size - 1) { - for (x in 0..fluidMap[0].size - 1) { - placeFluid(world, updateXFrom + x, updateYFrom + y, WATER, fluidMap[y][x].minus(1)) - // FIXME test code: deals with water only! - } - } + fluidMapToWorld(world) } + /** + * displace fallable tiles. It is scanned bottom-left first. To achieve the sens ofreal + * falling, each tiles are displaced by ONLY ONE TILE below. + */ + fun displaceFallables(world: GameWorld, p: Player, delta: Int) { + for (y in updateYFrom..updateYTo) { + for (x in updateXFrom..updateXTo) { + val tile = world.getTileFromTerrain(x, y) ?: TileNameCode.STONE + val tileBelow = world.getTileFromTerrain(x, y + 1) ?: TileNameCode.STONE + + if (tile.isFallable()) { + // displace fluid. This statement must precede isSolid() + if (tileBelow.isFluid()) { + // remove tileThis to create air pocket + world.setTileTerrain(x, y, TileNameCode.AIR) + + pour(world, x, y, drain(world, x, y, tileBelow.fluidLevel())) + // place our tile + world.setTileTerrain(x, y + 1, tile) + } + else if (!tileBelow.isSolid()) { + world.setTileTerrain(x, y, TileNameCode.AIR) + world.setTileTerrain(x, y + 1, tile) + } + } + } + } + } + fun drawFluidMapDebug(p: Player, g: Graphics) { + g.font = Terrarum.fontSmallNumbers + g.color = colourWater + for (y in 0..fluidMap.size - 1) { for (x in 0..fluidMap[0].size - 1) { + val data = fluidMap[y][x] + if (MapCamera.tileInCamera(x + updateXFrom, y + updateYFrom)) { + if (data == 0) + g.color = colourNone + else + g.color = colourWater + g.drawString(data.toString(), + updateXFrom.plus(x).times(MapDrawer.TILE_SIZE).toFloat() + + if (data < 10) 4f else 0f, + updateYFrom.plus(y).times(MapDrawer.TILE_SIZE) + 4f + ) + } + + + //if (data > 0) println(data) } } } private fun purgeFluidMap() { - for (y in 1..DOUBLE_RADIUS) - for (x in 1..DOUBLE_RADIUS) + for (y in 1..DOUBLE_RADIUS) { + for (x in 1..DOUBLE_RADIUS) { fluidMap[y - 1][x - 1] = 0 + fluidTypeMap[y - 1][x - 1] = 0 + } + } + } + + private fun worldToFluidMap(world: GameWorld) { + for (y in updateYFrom..updateYTo) { + for (x in updateXFrom..updateXTo) { + val tile = world.getTileFromTerrain(x, y) ?: TileNameCode.STONE + if (tile.isFluid()) { + fluidMap[y - updateYFrom][x - updateXFrom] = tile.fluidLevel() + fluidTypeMap[y - updateYFrom][x - updateXFrom] = tile.fluidType().toByte() + } + } + } + } + + private fun fluidMapToWorld(world: GameWorld) { + for (y in 0..fluidMap.size - 1) { + for (x in 0..fluidMap[0].size - 1) { + placeFluid(world, updateXFrom + x, updateYFrom + y + , FluidCodex.FLUID_WATER, fluidMap[y][x] - 1 + ) + // FIXME test code: deals with water only! + } + } } fun Int.isFluid() = TilePropCodex.getProp(this).isFluid - fun Int.isSolid() = TilePropCodex.getProp(this).isSolid + fun Int.isSolid() = this.fluidLevel() == FLUID_MAX || TilePropCodex.getProp(this).isSolid //fun Int.viscosity() = TilePropCodex.getProp(this). - fun Int.fluidLevel() = this % FLUID_MAX + fun Int.fluidLevel() = if (!this.isFluid()) 0 else (this % FLUID_MAX) + 1 + fun Int.fluidType() = this / FLUID_MAX fun Int.isEven() = (this and 0x01) == 0 + fun Int.isFallable() = TilePropCodex.getProp(this).isFallable - private fun placeFluid(world: GameWorld, x: Int, y: Int, tileFluid: Int, amount: Int) { + private fun placeFluid(world: GameWorld, x: Int, y: Int, fluidType: Byte, amount: Int) { if (world.layerTerrain.isInBound(x, y)) { if (amount > 0 && !world.getTileFromTerrain(x, y)!!.isSolid()) { - world.setTileTerrain(x, y, amount.minus(1).plus(tileFluid)) + world.setTileTerrain(x, y, fluidType, amount - 1) } else if (amount == 0 && world.getTileFromTerrain(x, y)!!.isFluid()) { world.setTileTerrain(x, y, TileNameCode.AIR) @@ -183,6 +223,64 @@ object WorldSimulator { } } - val LAVA = TileNameCode.LAVA_1 - val WATER = TileNameCode.WATER_1 + /** + * @param x and y: world tile coord + * @return amount of fluid actually drained. + * (intended drainage - this) will give you how much fluid is not yet drained. + * TODO add fluidType support + */ + private fun drain(world: GameWorld, x: Int, y: Int, amount: Int): Int { + val displacement = Math.min(fluidMap[y - updateYFrom][x - updateXFrom], amount) + + fluidMap[y - updateYFrom][x - updateXFrom] -= displacement + + return displacement + } + + /** + * @param x and y: world tile coord + * TODO add fluidType support + */ + private fun pour(world: GameWorld, x: Int, y: Int, amount: Int) { + /** + * @param x and y: world tile coord + * @return spillage + * TODO add fluidType support + */ + fun pourInternal(worldXpos: Int, worldYPos: Int, volume: Int): Int { + var spil = 0 + + val addrX = worldXpos - updateXFrom + val addrY = worldYPos - updateYFrom + + if (addrX >= 0 && addrY >= 0 && addrX < DOUBLE_RADIUS && addrY < DOUBLE_RADIUS) { + fluidMap[addrY][addrX] += volume + if (fluidMap[addrY][addrX] > FLUID_MAX) { + spil = fluidMap[addrY][addrX] - FLUID_MAX + fluidMap[addrY][addrX] = FLUID_MAX + } + } + + return spil + } + + // pour the fluid + var spillage = pourInternal(x, y, amount) + + if (spillage <= 0) return + + // deal with the spillage + + val tileUp = world.getTileFromTerrain(x - updateXFrom, y - updateYFrom - 1) + val tileDown = world.getTileFromTerrain(x - updateXFrom, y - updateYFrom + 1) + + // try to fill downward + if (tileDown != null && !tileDown.isSolid()) { + spillage = pourInternal(x, y + 1, spillage) + } + // else, try to fill upward. if there is no space, just discard + if (spillage >= 0 && tileUp != null && !tileUp.isSolid()) { + pourInternal(x, y - 1, spillage) + } + } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt index 581d19b02..40b84f2be 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt +++ b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt @@ -31,8 +31,8 @@ object MapCamera { var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TSIZE, TSIZE) private set - var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.png", TSIZE, TSIZE) - private set + var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TSIZE, TSIZE) + 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) private set var tilesetBook: Array = arrayOf(tilesWall, tilesTerrain, tilesWire) @@ -494,4 +494,7 @@ object MapCamera { fun isPlatform(b: Int?): Boolean = TILES_WALL_STICKER_CONNECT_SELF.contains(b) 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) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/mapgenerator/NoiseFilterCubic.kt b/src/net/torvald/terrarum/mapgenerator/NoiseFilterCubic.kt index 28397e2cd..bec042a76 100644 --- a/src/net/torvald/terrarum/mapgenerator/NoiseFilterCubic.kt +++ b/src/net/torvald/terrarum/mapgenerator/NoiseFilterCubic.kt @@ -31,13 +31,13 @@ import com.jme3.math.FastMath */ object NoiseFilterCubic : NoiseFilter { override fun getGrad(func_argX: Int, start: Float, end: Float): Float { - val graph_gradient = -FastMath.pow(FastMath.pow((1 - MapGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat(), 3f), -1f) * // 1/4 -> 3/4 -> 9/16 -> 16/9 - (start - end) / FastMath.pow(MapGenerator.HEIGHT.toFloat(), 3f) * - FastMath.pow((func_argX - MapGenerator.HEIGHT).toFloat(), 3f) + end + val graph_gradient = -FastMath.pow(FastMath.pow((1 - WorldGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat(), 3f), -1f) * // 1/4 -> 3/4 -> 9/16 -> 16/9 + (start - end) / FastMath.pow(WorldGenerator.HEIGHT.toFloat(), 3f) * + FastMath.pow((func_argX - WorldGenerator.HEIGHT).toFloat(), 3f) + end - if (func_argX < MapGenerator.TERRAIN_AVERAGE_HEIGHT) { + if (func_argX < WorldGenerator.TERRAIN_AVERAGE_HEIGHT) { return start - } else if (func_argX >= MapGenerator.HEIGHT) { + } else if (func_argX >= WorldGenerator.HEIGHT) { return end } else { return graph_gradient diff --git a/src/net/torvald/terrarum/mapgenerator/NoiseFilterMinusQuadratic.kt b/src/net/torvald/terrarum/mapgenerator/NoiseFilterMinusQuadratic.kt index 8c3292834..cd01f4736 100644 --- a/src/net/torvald/terrarum/mapgenerator/NoiseFilterMinusQuadratic.kt +++ b/src/net/torvald/terrarum/mapgenerator/NoiseFilterMinusQuadratic.kt @@ -31,13 +31,13 @@ import com.jme3.math.FastMath */ object NoiseFilterMinusQuadratic : NoiseFilter { override fun getGrad(func_argX: Int, start: Float, end: Float): Float { - val graph_gradient = -FastMath.pow(FastMath.sqr((1 - MapGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()), -1f) * // 1/4 -> 3/4 -> 9/16 -> 16/9 - (start - end) / FastMath.sqr(MapGenerator.HEIGHT.toFloat()) * - FastMath.sqr((func_argX - MapGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()) + start + val graph_gradient = -FastMath.pow(FastMath.sqr((1 - WorldGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()), -1f) * // 1/4 -> 3/4 -> 9/16 -> 16/9 + (start - end) / FastMath.sqr(WorldGenerator.HEIGHT.toFloat()) * + FastMath.sqr((func_argX - WorldGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()) + start - if (func_argX < MapGenerator.TERRAIN_AVERAGE_HEIGHT) { + if (func_argX < WorldGenerator.TERRAIN_AVERAGE_HEIGHT) { return start - } else if (func_argX >= MapGenerator.HEIGHT) { + } else if (func_argX >= WorldGenerator.HEIGHT) { return end } else { return graph_gradient diff --git a/src/net/torvald/terrarum/mapgenerator/NoiseFilterQuadratic.kt b/src/net/torvald/terrarum/mapgenerator/NoiseFilterQuadratic.kt index c2ffbb410..1616755b8 100644 --- a/src/net/torvald/terrarum/mapgenerator/NoiseFilterQuadratic.kt +++ b/src/net/torvald/terrarum/mapgenerator/NoiseFilterQuadratic.kt @@ -32,13 +32,13 @@ import com.jme3.math.FastMath */ object NoiseFilterQuadratic : NoiseFilter { override fun getGrad(func_argX: Int, start: Float, end: Float): Float { - val graph_gradient = FastMath.pow(FastMath.sqr((1 - MapGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()), -1f) * // 1/4 -> 3/4 -> 9/16 -> 16/9 - (start - end) / FastMath.sqr(MapGenerator.HEIGHT.toFloat()) * - FastMath.sqr((func_argX - MapGenerator.HEIGHT).toFloat()) + end + val graph_gradient = FastMath.pow(FastMath.sqr((1 - WorldGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()), -1f) * // 1/4 -> 3/4 -> 9/16 -> 16/9 + (start - end) / FastMath.sqr(WorldGenerator.HEIGHT.toFloat()) * + FastMath.sqr((func_argX - WorldGenerator.HEIGHT).toFloat()) + end - if (func_argX < MapGenerator.TERRAIN_AVERAGE_HEIGHT) { + if (func_argX < WorldGenerator.TERRAIN_AVERAGE_HEIGHT) { return start - } else if (func_argX >= MapGenerator.HEIGHT) { + } else if (func_argX >= WorldGenerator.HEIGHT) { return end } else { return graph_gradient diff --git a/src/net/torvald/terrarum/mapgenerator/NoiseFilterSqrt.kt b/src/net/torvald/terrarum/mapgenerator/NoiseFilterSqrt.kt index 2e46593cc..fd58f03d4 100644 --- a/src/net/torvald/terrarum/mapgenerator/NoiseFilterSqrt.kt +++ b/src/net/torvald/terrarum/mapgenerator/NoiseFilterSqrt.kt @@ -7,11 +7,11 @@ import com.jme3.math.FastMath */ object NoiseFilterSqrt : NoiseFilter { override fun getGrad(func_argX: Int, start: Float, end: Float): Float { - val graph_gradient = (end - start) / FastMath.sqrt((MapGenerator.HEIGHT - MapGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()) * FastMath.sqrt((func_argX - MapGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()) + start + val graph_gradient = (end - start) / FastMath.sqrt((WorldGenerator.HEIGHT - WorldGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()) * FastMath.sqrt((func_argX - WorldGenerator.TERRAIN_AVERAGE_HEIGHT).toFloat()) + start - if (func_argX < MapGenerator.TERRAIN_AVERAGE_HEIGHT) { + if (func_argX < WorldGenerator.TERRAIN_AVERAGE_HEIGHT) { return start - } else if (func_argX >= MapGenerator.HEIGHT) { + } else if (func_argX >= WorldGenerator.HEIGHT) { return end } else { return graph_gradient diff --git a/src/net/torvald/terrarum/mapgenerator/ThreadProcessNoiseLayers.kt b/src/net/torvald/terrarum/mapgenerator/ThreadProcessNoiseLayers.kt index 62836b36f..c1680a71f 100644 --- a/src/net/torvald/terrarum/mapgenerator/ThreadProcessNoiseLayers.kt +++ b/src/net/torvald/terrarum/mapgenerator/ThreadProcessNoiseLayers.kt @@ -4,14 +4,14 @@ package net.torvald.terrarum.mapgenerator * Created by minjaesong on 16-06-13. */ class ThreadProcessNoiseLayers(val startIndex: Int, val endIndex: Int, - val noiseRecords: Array) : Runnable { + val noiseRecords: Array) : Runnable { override fun run() { for (record in noiseRecords) { println("[mapgenerator] ${record.message}...") for (y in startIndex..endIndex) { - for (x in 0..MapGenerator.WIDTH - 1) { + for (x in 0..WorldGenerator.WIDTH - 1) { val noise: Float = record.noiseModule.get( x.toDouble() / 48.0, // 48: Fixed value y.toDouble() / 48.0 @@ -24,11 +24,11 @@ class ThreadProcessNoiseLayers(val startIndex: Int, val endIndex: Int, // replace to designated tile is Int -> record.replaceTo as Int // replace to randomly selected tile from given array of tile IDs - is IntArray -> (record.replaceTo as IntArray)[MapGenerator.random.nextInt((record.replaceTo as IntArray).size)] + is IntArray -> (record.replaceTo as IntArray)[WorldGenerator.random.nextInt((record.replaceTo as IntArray).size)] else -> throw IllegalArgumentException("[mapgenerator] Unknown replaceTo tile type '${record.replaceTo.javaClass.canonicalName}': Only 'kotlin.Int' and 'kotlin.IntArray' is valid.") } // replace to ALL? this is bullshit - if (to == MapGenerator.TILE_MACRO_ALL) throw IllegalArgumentException("[mapgenerator] Invalid replaceTo: TILE_MACRO_ALL") + if (to == WorldGenerator.TILE_MACRO_ALL) throw IllegalArgumentException("[mapgenerator] Invalid replaceTo: TILE_MACRO_ALL") // filtered threshold val threshold = record.filter.getGrad(y, record.filterArg1, record.filterArg2) @@ -38,15 +38,15 @@ class ThreadProcessNoiseLayers(val startIndex: Int, val endIndex: Int, for (i in 0..fromTerr.size - 1) { val fromTerrVariable = fromTerr[i] - if ((MapGenerator.world.getTileFromTerrain(x, y) == fromTerrVariable || fromTerrVariable == MapGenerator.TILE_MACRO_ALL) - && (MapGenerator.world.getTileFromWall(x, y) == fromWall || fromWall == MapGenerator.TILE_MACRO_ALL)) { - MapGenerator.world.setTileTerrain(x, y, to) + if ((WorldGenerator.world.getTileFromTerrain(x, y) == fromTerrVariable || fromTerrVariable == WorldGenerator.TILE_MACRO_ALL) + && (WorldGenerator.world.getTileFromWall(x, y) == fromWall || fromWall == WorldGenerator.TILE_MACRO_ALL)) { + WorldGenerator.world.setTileTerrain(x, y, to) } } } - else if ((MapGenerator.world.getTileFromTerrain(x, y) == fromTerr || fromTerr == MapGenerator.TILE_MACRO_ALL) - && (MapGenerator.world.getTileFromWall(x, y) == fromWall || fromWall == MapGenerator.TILE_MACRO_ALL)) { - MapGenerator.world.setTileTerrain(x, y, to) + else if ((WorldGenerator.world.getTileFromTerrain(x, y) == fromTerr || fromTerr == WorldGenerator.TILE_MACRO_ALL) + && (WorldGenerator.world.getTileFromWall(x, y) == fromWall || fromWall == WorldGenerator.TILE_MACRO_ALL)) { + WorldGenerator.world.setTileTerrain(x, y, to) } } } diff --git a/src/net/torvald/terrarum/mapgenerator/MapGenerator.kt b/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt similarity index 99% rename from src/net/torvald/terrarum/mapgenerator/MapGenerator.kt rename to src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt index ee6433f66..88a87c653 100644 --- a/src/net/torvald/terrarum/mapgenerator/MapGenerator.kt +++ b/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt @@ -11,7 +11,7 @@ import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.gameactors.ThreadActorUpdate import java.util.* -object MapGenerator { +object WorldGenerator { internal lateinit var world: GameWorld internal lateinit var random: Random @@ -74,7 +74,7 @@ object MapGenerator { DIRT_LAYER_DEPTH = (100 * HEIGHT / 1024f).toInt() minimumFloatingIsleHeight = (25 * (HEIGHT / 1024f)).toInt() - TERRAIN_AVERAGE_HEIGHT = HEIGHT / 4 + TERRAIN_AVERAGE_HEIGHT = HEIGHT / 3 OCEAN_WIDTH = Math.round(OCEAN_WIDTH * widthMulFactor) SHORE_WIDTH = Math.round(SHORE_WIDTH * widthMulFactor) diff --git a/src/net/torvald/terrarum/tileproperties/tileprop.csv b/src/net/torvald/terrarum/tileproperties/tileprop.csv index 02bea2db9..67cdd2220 100644 --- a/src/net/torvald/terrarum/tileproperties/tileprop.csv +++ b/src/net/torvald/terrarum/tileproperties/tileprop.csv @@ -50,14 +50,14 @@ "12"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "11"; "0"; "0"; "0";"16" "12"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "11"; "1"; "0"; "0";"16" "13"; "0";"TILE_ILLUMINATOR_WHITE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "239319274"; "13"; "0"; "0"; "0";"16" - "13"; "1";"TILE_ILLUMINATOR_YELLOW" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "246656000"; "13"; "1"; "0"; "0";"16" - "13"; "2";"TILE_ILLUMINATOR_ORANGE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "246602752"; "13"; "2"; "0"; "0";"16" + "13"; "1";"TILE_ILLUMINATOR_YELLOW" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "267607040"; "13"; "1"; "0"; "0";"16" + "13"; "2";"TILE_ILLUMINATOR_ORANGE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "267546624"; "13"; "2"; "0"; "0";"16" "13"; "3";"TILE_ILLUMINATOR_RED" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "246415360"; "13"; "3"; "0"; "0";"16" "13"; "4";"TILE_ILLUMINATOR_FUCHSIA" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "246415543"; "13"; "4"; "0"; "0";"16" "13"; "5";"TILE_ILLUMINATOR_PURPLE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "191889643"; "13"; "5"; "0"; "0";"16" - "13"; "6";"TILE_ILLUMINATOR_BLUE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "235"; "13"; "6"; "0"; "0";"16" - "13"; "7";"TILE_ILLUMINATOR_CYAN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "207083"; "13"; "7"; "0"; "0";"16" - "13"; "8";"TILE_ILLUMINATOR_GREEN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "68364288"; "13"; "8"; "0"; "0";"16" + "13"; "6";"TILE_ILLUMINATOR_BLUE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "52479"; "13"; "6"; "0"; "0";"16" + "13"; "7";"TILE_ILLUMINATOR_CYAN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "219391"; "13"; "7"; "0"; "0";"16" + "13"; "8";"TILE_ILLUMINATOR_GREEN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "56884224"; "13"; "8"; "0"; "0";"16" "13"; "9";"TILE_ILLUMINATOR_GREEN_DARK";"8396808"; "0"; "N/A"; "0"; "1"; "1"; "33660928"; "13"; "9"; "0"; "0";"16" "13"; "10";"TILE_ILLUMINATOR_BROWN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "89161728"; "13"; "10"; "0"; "0";"16" "13"; "11";"TILE_ILLUMINATOR_TAN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "157392948"; "13"; "11"; "0"; "0";"16" diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index f196c0949..59d009ebe 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -68,7 +68,7 @@ class BasicDebugInfoWindow : UICanvas { val mouseTileX = ((MapCamera.cameraX + gc.input.mouseX / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt() val mouseTileY = ((MapCamera.cameraY + gc.input.mouseY / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt() - g.font = Terrarum.smallNumbers + g.font = Terrarum.fontSmallNumbers g.color = GameFontBase.codeToCol["y"] val hitbox = player.hitbox diff --git a/src/net/torvald/terrarum/ui/DrawUtil.kt b/src/net/torvald/terrarum/ui/DrawUtil.kt index 09b2018a5..d59c2044a 100644 --- a/src/net/torvald/terrarum/ui/DrawUtil.kt +++ b/src/net/torvald/terrarum/ui/DrawUtil.kt @@ -14,4 +14,9 @@ object DrawUtil { g.drawImage(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat()) } + + fun drawCentered(g: Graphics, image: Image, screenPosY: Int, targetW: Int, offsetX: Int = 0, offsetY: Int = 0) { + val imageW = image.width + g.drawImage(image, targetW.minus(imageW).ushr(1).toFloat() + offsetX, screenPosY.toFloat() + offsetY) + } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/GamepadControlled.kt b/src/net/torvald/terrarum/ui/GamepadControlled.kt index 1ae4e8030..f50e21098 100644 --- a/src/net/torvald/terrarum/ui/GamepadControlled.kt +++ b/src/net/torvald/terrarum/ui/GamepadControlled.kt @@ -7,6 +7,5 @@ package net.torvald.terrarum.ui */ interface GamepadControlled { fun controllerButtonPressed(controller: Int, button: Int) - fun controllerButtonReleased(controller: Int, button: Int) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/ItemImageGallery.kt b/src/net/torvald/terrarum/ui/ItemImageGallery.kt new file mode 100644 index 000000000..7cf0b3fe7 --- /dev/null +++ b/src/net/torvald/terrarum/ui/ItemImageGallery.kt @@ -0,0 +1,80 @@ +package net.torvald.terrarum.ui + +import net.torvald.terrarum.gameactors.roundInt +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Image +import java.util.* + +/** + * Image gallery. Images will be equally spaced, counted from top-left to bottom-right. + * Created by minjaesong on 16-08-08. + */ +class ItemImageGallery( + override var posX: Int, + override var posY: Int, + val width: Int, + val height: Int, + val imageList: ArrayList, + val column: Int = 1 +) : UIItem { + + override fun update(gc: GameContainer, delta: Int) { + } + + override fun render(gc: GameContainer, g: Graphics) { + fun column(i: Int) = i % column + fun row(i: Int) = i / column + + fun imagePosY(i: Int): Int { + val gutter = (height - imageList[i].height.times(imageList.size)).toFloat().div( + imageList.size + 1f + ) + return row((gutter * i.plus(1) + imageList[i].height * i).roundInt()) + } + + imageList.forEachIndexed { i, image -> + DrawUtil.drawCentered(g, image, + imagePosY(i), + width.toFloat().div(column).times(column(i).plus(1)).roundInt(), + posX, posY + ) + } + } + + override fun keyPressed(key: Int, c: Char) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun keyReleased(key: Int, c: Char) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun mousePressed(button: Int, x: Int, y: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun mouseReleased(button: Int, x: Int, y: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun mouseWheelMoved(change: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun controllerButtonPressed(controller: Int, button: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun controllerButtonReleased(controller: Int, button: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt b/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt index 19190cbda..6c447e9b0 100644 --- a/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt +++ b/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt @@ -16,8 +16,8 @@ object ItemSlotImageBuilder { const val COLOR_BLACK = 1 const val COLOR_WHITE = 2 - private val colourBlack = Color(0x404040) - private val colourWhite = Color(0xC0C0C0) + private val colourBlack = Color(0x40, 0x40, 0x40, 0xEE) + private val colourWhite = Color(0xC0, 0xC0, 0xC0, 0xEE) private val numberFont = SpriteSheetFont( SpriteSheet("./assets/graphics/fonts/numeric_small.png", 5, 8), diff --git a/src/net/torvald/terrarum/ui/KeyboardControlled.kt b/src/net/torvald/terrarum/ui/KeyboardControlled.kt index 6de72d6e8..360884f09 100644 --- a/src/net/torvald/terrarum/ui/KeyboardControlled.kt +++ b/src/net/torvald/terrarum/ui/KeyboardControlled.kt @@ -5,6 +5,5 @@ package net.torvald.terrarum.ui */ interface KeyboardControlled { fun keyPressed(key: Int, c: Char) - fun keyReleased(key: Int, c: Char) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/MouseControlled.kt b/src/net/torvald/terrarum/ui/MouseControlled.kt index 181d6a3b5..80e04a378 100644 --- a/src/net/torvald/terrarum/ui/MouseControlled.kt +++ b/src/net/torvald/terrarum/ui/MouseControlled.kt @@ -5,12 +5,8 @@ package net.torvald.terrarum.ui */ interface MouseControlled { fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) - fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) - fun mousePressed(button: Int, x: Int, y: Int) - fun mouseReleased(button: Int, x: Int, y: Int) - fun mouseWheelMoved(change: Int) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index 3713549d2..e185e576d 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -117,10 +117,10 @@ constructor(val UI: UICanvas) { fun render(gc: GameContainer, sbg: StateBasedGame, ingameGraphics: Graphics) { if (isVisible || alwaysVisible) { UIGraphicInstance.clear() - UIGraphicInstance.font = Terrarum.gameFont + UIGraphicInstance.font = Terrarum.fontGame UI.render(gc, UIGraphicInstance) - if (sbg.currentStateID == Terrarum.SCENE_ID_GAME) { + if (sbg.currentStateID == Terrarum.STATE_ID_GAME) { ingameGraphics.drawImage(UIDrawnCanvas.getScaledCopy(scale), posX + MapCamera.cameraX * Terrarum.ingame.screenZoom - (UI.width / 2f * scale.minus(1)), posY + MapCamera.cameraY * Terrarum.ingame.screenZoom - (UI.height / 2f * scale.minus(1)), diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt index 7e26e68fc..2fdc801bd 100644 --- a/src/net/torvald/terrarum/ui/UIItem.kt +++ b/src/net/torvald/terrarum/ui/UIItem.kt @@ -1,13 +1,32 @@ package net.torvald.terrarum.ui +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics + /** * Created by minjaesong on 15-12-31. */ -class UIItem { +interface UIItem { // X/Y Position relative to the containing canvas - internal var posX: Int = 0 - internal var posY: Int = 0 + var posX: Int + var posY: Int + fun update(gc: GameContainer, delta: Int) + fun render(gc: GameContainer, g: Graphics) + // keyboard controlled + fun keyPressed(key: Int, c: Char) + fun keyReleased(key: Int, c: Char) + + // mouse controlled + fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) + fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) + fun mousePressed(button: Int, x: Int, y: Int) + fun mouseReleased(button: Int, x: Int, y: Int) + fun mouseWheelMoved(change: Int) + + // gamepad controlled + fun controllerButtonPressed(controller: Int, button: Int) + fun controllerButtonReleased(controller: Int, button: Int) } diff --git a/src/net/torvald/terrarum/ui/UIPieMenu.kt b/src/net/torvald/terrarum/ui/UIPieMenu.kt index 245872dbb..38c28f8b1 100644 --- a/src/net/torvald/terrarum/ui/UIPieMenu.kt +++ b/src/net/torvald/terrarum/ui/UIPieMenu.kt @@ -36,6 +36,8 @@ class UIPieMenu : UICanvas { if (selection >= 0) Terrarum.ingame.player.actorValue[AVKey._PLAYER_QUICKBARSEL] = selection % slotCount + + } override fun render(gc: GameContainer, g: Graphics) { diff --git a/src/net/torvald/terrarum/ui/UIQuickBar.kt b/src/net/torvald/terrarum/ui/UIQuickBar.kt index 799a2e957..6ec66cecc 100644 --- a/src/net/torvald/terrarum/ui/UIQuickBar.kt +++ b/src/net/torvald/terrarum/ui/UIQuickBar.kt @@ -12,7 +12,7 @@ import org.newdawn.slick.Input class UIQuickBar : UICanvas, MouseControlled { private val gutter = 8 override var width: Int = (ItemSlotImageBuilder.slotImageSize + gutter) * SLOT_COUNT - override var height: Int = ItemSlotImageBuilder.slotImageSize + 4 + Terrarum.gameFont.lineHeight + override var height: Int = ItemSlotImageBuilder.slotImageSize + 4 + Terrarum.fontGame.lineHeight /** * In milliseconds */ diff --git a/work_files/health_and_safety_2.tiff b/work_files/health_and_safety_2.tiff new file mode 100644 index 000000000..8c5f7585e Binary files /dev/null and b/work_files/health_and_safety_2.tiff differ