more pictogrammes

Former-commit-id: 670df70bbed466e56034dbdd33d7a1da31cd88d7
Former-commit-id: 2b106753155be6080d4651acca1981f10d614421
This commit is contained in:
Song Minjae
2016-08-25 21:46:01 +09:00
parent fa5e95a89d
commit 720df532aa
50 changed files with 589 additions and 265 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 B

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1 @@
*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1 @@
*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 KiB

After

Width:  |  Height:  |  Size: 353 KiB

View File

@@ -2121,7 +2121,7 @@
},
{
"n": "MENU_LABEL_PRESS_START",
"s": "Start drücken"
"s": "Drücke Start"
},
{
"n": "MENU_LABEL_PRESS_START_CONTINUE",

View File

@@ -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 ##

View File

@@ -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,

View File

@@ -1,7 +1,5 @@
package net.torvald
import net.torvald.terrarum.Terrarum
import javax.imageio.ImageIO
import java.awt.*
import java.awt.color.ColorSpace

View File

@@ -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
}
}

View File

@@ -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
/**

View File

@@ -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
}

View File

@@ -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,15 +166,17 @@ 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)
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 {
/////////////////
// 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 {
//////////////////////
// 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,15 +314,19 @@ constructor() : BasicGameState() {
}
}
}
// fluidmap debug
if (KeyToggler.isOn(Key.F4))
WorldSimulator.drawFluidMapDebug(player, g)
// draw UIs
run {
//////////////
// 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) {
GameController.keyPressed(key, c)
@@ -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)

View File

@@ -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<Image>()
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,

View File

@@ -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
}

View File

@@ -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<String>) = 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)
}

View File

@@ -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()),

View File

@@ -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<String>) {
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,6 +42,9 @@ class SetGlobalLightLevel : ConsoleCommand {
}
}
catch (e: NumberFormatException) {
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”]")
}
}

View File

@@ -29,7 +29,7 @@ abstract class Actor : Comparable<Actor>, 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:

View File

@@ -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()

View File

@@ -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<String>, 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

View File

@@ -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")

View File

@@ -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)

View File

@@ -172,14 +172,14 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkCounterX += 1
isWalkingH = true
}
// Heading flag
if (left)
walkHeading = LEFT
else
walkHeading = RIGHT
isWalkingH = true
}
}
/**

View File

@@ -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()
}

View File

@@ -40,7 +40,7 @@ class MapLayer(var width: Int, var height: Int) : Iterable<Byte> {
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<Byte> {
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)

View File

@@ -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<IntArray>(DOUBLE_RADIUS, { IntArray(DOUBLE_RADIUS) })
private val fluidTypeMap = Array<ByteArray>(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,16 +53,183 @@ 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
////////////////////
// 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) ?: 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.isSolid()) {
val drainage = drain(world, x, y, DISPLACE_CAP)
pour(world, x, y + 1, drainage)
}
// left and right both open
else if (!tileLeft.isSolid() && !tileRight.isSolid()) {
// half-breaker
val moreToTheRight = HQRNG().nextBoolean()
val displacement = drain(world, x, y, DISPLACE_CAP)
if (displacement.isEven()) {
pour(world, x - 1, y, displacement shr 1)
pour(world, x + 1, y, displacement shr 1)
}
else {
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
else if (!tileLeft.isSolid()) {
val displacement = drain(world, x, y, DISPLACE_CAP)
pour(world, 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(world, x, y - 1, DISPLACE_CAP)
}
}
}
}
/////////////////////////////////////////////////////
// replace fluids in the map according to fluidMap //
/////////////////////////////////////////////////////
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) {
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() = this.fluidLevel() == FLUID_MAX || TilePropCodex.getProp(this).isSolid
//fun Int.viscosity() = TilePropCodex.getProp(this).
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, fluidType: Byte, amount: Int) {
if (world.layerTerrain.isInBound(x, y)) {
if (amount > 0 && !world.getTileFromTerrain(x, y)!!.isSolid()) {
world.setTileTerrain(x, y, fluidType, amount - 1)
}
else if (amount == 0 && world.getTileFromTerrain(x, y)!!.isFluid()) {
world.setTileTerrain(x, y, TileNameCode.AIR)
}
}
}
/**
* @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
*/
fun drain(x: Int, y: Int, amount: Int): Int {
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
@@ -51,12 +237,21 @@ object WorldSimulator {
return displacement
}
fun pour(x: Int, y: Int, amount: Int) {
fun pourInternal(xpos: Int, ypos: Int, volume: Int): Int {
/**
* @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 = xpos - updateXFrom
val addrY = ypos - updateYFrom
val addrX = worldXpos - updateXFrom
val addrY = worldYPos - updateYFrom
if (addrX >= 0 && addrY >= 0 && addrX < DOUBLE_RADIUS && addrY < DOUBLE_RADIUS) {
fluidMap[addrY][addrX] += volume
@@ -72,7 +267,7 @@ object WorldSimulator {
// pour the fluid
var spillage = pourInternal(x, y, amount)
if (spillage == 0) return
if (spillage <= 0) return
// deal with the spillage
@@ -84,105 +279,8 @@ object WorldSimulator {
spillage = pourInternal(x, y + 1, spillage)
}
// else, try to fill upward. if there is no space, just discard
if (tileUp != null && !tileUp.isSolid()) {
if (spillage >= 0 && tileUp != null && !tileUp.isSolid()) {
pourInternal(x, y - 1, spillage)
}
}
purgeFluidMap()
/////////////////////////////////////////////////////////////
// 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()) {
// move down if not obstructed
if (tileBottom != null && !tileBottom.isSolid()) {
val drainage = drain(x, y, DISPLACE_CAP)
pour(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) {
// half-breaker
val moreToTheRight = HQRNG().nextBoolean()
val displacement = drain(x, y, DISPLACE_CAP)
if (displacement.isEven()) {
pour(x - 1, y, displacement shr 1)
pour(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)
}
}
// 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)
}
// 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)
}
// nowhere open; do default (fill top)
else {
pour(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!
}
}
}
fun drawFluidMapDebug(p: Player, g: Graphics) {
for (y in 0..fluidMap.size - 1) {
for (x in 0..fluidMap[0].size - 1) {
}
}
}
private fun purgeFluidMap() {
for (y in 1..DOUBLE_RADIUS)
for (x in 1..DOUBLE_RADIUS)
fluidMap[y - 1][x - 1] = 0
}
fun Int.isFluid() = TilePropCodex.getProp(this).isFluid
fun Int.isSolid() = TilePropCodex.getProp(this).isSolid
//fun Int.viscosity() = TilePropCodex.getProp(this).
fun Int.fluidLevel() = this % FLUID_MAX
fun Int.isEven() = (this and 0x01) == 0
private fun placeFluid(world: GameWorld, x: Int, y: Int, tileFluid: Int, 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))
}
else if (amount == 0 && world.getTileFromTerrain(x, y)!!.isFluid()) {
world.setTileTerrain(x, y, TileNameCode.AIR)
}
}
}
val LAVA = TileNameCode.LAVA_1
val WATER = TileNameCode.WATER_1
}

View File

@@ -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<SpriteSheet> = 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)
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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<MapGenerator.TaggedJoise>) : Runnable {
val noiseRecords: Array<WorldGenerator.TaggedJoise>) : 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)
}
}
}

View File

@@ -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)

View File

@@ -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"
Can't render this file because it contains an unexpected character in line 1 and column 18.

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -7,6 +7,5 @@ package net.torvald.terrarum.ui
*/
interface GamepadControlled {
fun controllerButtonPressed(controller: Int, button: Int)
fun controllerButtonReleased(controller: Int, button: Int)
}

View File

@@ -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<Image>,
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.
}
}

View File

@@ -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),

View File

@@ -5,6 +5,5 @@ package net.torvald.terrarum.ui
*/
interface KeyboardControlled {
fun keyPressed(key: Int, c: Char)
fun keyReleased(key: Int, c: Char)
}

View File

@@ -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)
}

View File

@@ -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)),

View File

@@ -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)
}

View File

@@ -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) {

View File

@@ -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
*/

Binary file not shown.