Player movement seems like back to working, res→assets

Former-commit-id: f91181caee4dabf4cb2e51d8077441c6b0f83757
Former-commit-id: 8b450303698c5c85dea9145a056b290b95a6a7b0
This commit is contained in:
Song Minjae
2016-08-02 17:32:42 +09:00
parent 5e7a95a3b9
commit 17c39c1824
248 changed files with 371 additions and 104 deletions

View File

@@ -7,7 +7,7 @@ import org.newdawn.slick.Image
* Created by minjaesong on 16-07-26.
*/
object ColourTemp {
private var envOverlayColourmap = Image("./res/graphics/colourmap/black_body_col_1000_40000_K.png")
private var envOverlayColourmap = Image("./assets/graphics/colourmap/black_body_col_1000_40000_K.png")
private fun colTempToImagePos(K: Int): Int {
if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)")

View File

@@ -12,50 +12,50 @@ constructor() : GameFontBase() {
init {
GameFontBase.hangulSheet = SpriteSheet(
"./res/graphics/fonts/han_johab.png", GameFontBase.W_CJK, GameFontBase.H_HANGUL)
"./assets/graphics/fonts/han_johab.png", GameFontBase.W_CJK, GameFontBase.H_HANGUL)
GameFontBase.asciiSheet = SpriteSheet(
"./res/graphics/fonts/ascii_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/ascii_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.asciiSheetEF = SpriteSheet(
"./res/graphics/fonts/ascii_special_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
"./assets/graphics/fonts/ascii_special_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.runicSheet = SpriteSheet(
"./res/graphics/fonts/futhark.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/futhark.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.extASheet = SpriteSheet(
"./res/graphics/fonts/LatinExtA_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/LatinExtA_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.extASheetEF = SpriteSheet(
"./res/graphics/fonts/LatinExtA_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
"./assets/graphics/fonts/LatinExtA_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.kanaSheet = SpriteSheet(
"./res/graphics/fonts/kana.png", GameFontBase.W_CJK, GameFontBase.H_KANA)
"./assets/graphics/fonts/kana.png", GameFontBase.W_CJK, GameFontBase.H_KANA)
GameFontBase.cjkPunct = SpriteSheet(
"./res/graphics/fonts/cjkpunct.png", GameFontBase.W_CJK, GameFontBase.H_KANA)
"./assets/graphics/fonts/cjkpunct.png", GameFontBase.W_CJK, GameFontBase.H_KANA)
/*uniHan = new SpriteSheet(
"./res/graphics/fonts/unifont_unihan"
"./assets/graphics/fonts/unifont_unihan"
+ ((!terrarum.gameLocale.contains("zh"))
? "_ja" : "")
+".png"
, W_UNIHAN, H_UNIHAN
);*/
GameFontBase.cyrilic = SpriteSheet(
"./res/graphics/fonts/cyrilic_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/cyrilic_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.cyrilicEF = SpriteSheet(
"./res/graphics/fonts/cyrilic_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
"./assets/graphics/fonts/cyrilic_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.fullwidthForms = SpriteSheet(
"./res/graphics/fonts/fullwidth_forms.png", GameFontBase.W_UNIHAN, GameFontBase.H_UNIHAN)
"./assets/graphics/fonts/fullwidth_forms.png", GameFontBase.W_UNIHAN, GameFontBase.H_UNIHAN)
GameFontBase.uniPunct = SpriteSheet(
"./res/graphics/fonts/unipunct.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/unipunct.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.wenQuanYi_1 = SpriteSheet(
"./res/graphics/fonts/wenquanyi_11pt_part1.png", 16, 18, 2)
"./assets/graphics/fonts/wenquanyi_11pt_part1.png", 16, 18, 2)
GameFontBase.wenQuanYi_2 = SpriteSheet(
"./res/graphics/fonts/wenquanyi_11pt_part2.png", 16, 18, 2)
"./assets/graphics/fonts/wenquanyi_11pt_part2.png", 16, 18, 2)
GameFontBase.greekSheet = SpriteSheet(
"./res/graphics/fonts/greek_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/greek_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.greekSheetEF = SpriteSheet(
"./res/graphics/fonts/greek_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
"./assets/graphics/fonts/greek_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.romanianSheet = SpriteSheet(
"./res/graphics/fonts/romana_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/romana_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.romanianSheetEF = SpriteSheet(
"./res/graphics/fonts/romana_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
"./assets/graphics/fonts/romana_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.thaiSheet = SpriteSheet(
"./res/graphics/fonts/thai_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
"./assets/graphics/fonts/thai_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
val shk = arrayOf(
GameFontBase.asciiSheet,

View File

@@ -28,7 +28,7 @@ class TinyAlphNum : Font {
private val mappingTable = HashMap<Int, Int>()
init {
fontSheet = SpriteSheet("./res/graphics/fonts/alphanumeric_small.png", W, H)
fontSheet = SpriteSheet("./assets/graphics/fonts/alphanumeric_small.png", W, H)
chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
}

View File

@@ -56,7 +56,7 @@ object DefaultConfig {
val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0
jsonObject.add("keyquickbars", keyquickbars)
jsonObject.addProperty("pcgamepadenv", "console")
return jsonObject

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum
import net.torvald.imagefont.GameFontWhite
import org.newdawn.slick.Font
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -17,6 +18,8 @@ class StateFontTester : BasicGameState() {
override fun init(gc: GameContainer, game: StateBasedGame) {
canvas = Graphics(1024, 1024)
gameFont = GameFontWhite()
}
override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) {
@@ -24,7 +27,8 @@ class StateFontTester : BasicGameState() {
}
override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) {
g.font = gameFont
g.drawString(textToPrint, 10f, 10f)
}
override fun getID(): Int = Terrarum.SCENE_ID_TEST_FONT

View File

@@ -94,9 +94,9 @@ constructor() : BasicGameState() {
@Throws(SlickException::class)
override fun init(gameContainer: GameContainer, stateBasedGame: StateBasedGame) {
// load necessary shaders
shader12BitCol = Shader.makeShader("./res/4096.vrt", "./res/4096.frg")
shaderBlurH = Shader.makeShader("./res/blurH.vrt", "./res/blur.frg")
shaderBlurV = Shader.makeShader("./res/blurV.vrt", "./res/blur.frg")
shader12BitCol = Shader.makeShader("./assets/4096.vrt", "./assets/4096.frg")
shaderBlurH = Shader.makeShader("./assets/blurH.vrt", "./assets/blur.frg")
shaderBlurV = Shader.makeShader("./assets/blurV.vrt", "./assets/blur.frg")
// init map as chosen size
world = GameWorld(8192, 2048)

View File

@@ -46,6 +46,17 @@ constructor(gamename: String) : StateBasedGame(gamename) {
gameLocale = gameLocaleFromConfig
println("[terrarum] Locale: " + gameLocale)
try {
Controllers.getController(0)
environment = if (getConfigString("pcgamepadenv") == "console")
RunningEnvironment.CONSOLE
else
RunningEnvironment.PC
}
catch (e: IndexOutOfBoundsException) {
environment = RunningEnvironment.PC
}
}
@Throws(SlickException::class)
@@ -63,8 +74,8 @@ constructor(gamename: String) : StateBasedGame(gamename) {
}
ingame = StateInGame()
addState(ingame)
//addState(StateMonitorCheck())
//addState(ingame)
addState(StateMonitorCheck())
}
companion object {
@@ -111,6 +122,8 @@ constructor(gamename: String) : StateBasedGame(gamename) {
lateinit var defaultSaveDir: String
private set
lateinit var environment: RunningEnvironment
private val localeSimple = arrayOf("de", "en", "es", "it")
var gameLocale = "####" // locale override
set(value) {
@@ -335,9 +348,9 @@ constructor(gamename: String) : StateBasedGame(gamename) {
private fun getConfigMaster(key: String): Any {
var cfg: Any? = null
try { cfg = gameConfig[key]!! }
try { cfg = gameConfig[key.toLowerCase()]!! }
catch (e: NullPointerException) {
try { cfg = DefaultConfig.fetch()[key] }
try { cfg = DefaultConfig.fetch()[key.toLowerCase()] }
catch (e1: NullPointerException) { e.printStackTrace() }
}
return cfg!!
@@ -372,3 +385,7 @@ fun setBlendScreen() {
fun setBlendDisable() {
GL11.glDisable(GL11.GL_BLEND)
}
enum class RunningEnvironment {
PC, CONSOLE, MOBILE
}

View File

@@ -1,9 +1,12 @@
package net.torvald.terrarum.audio
import org.lwjgl.BufferUtils
import org.lwjgl.openal.AL10
import org.newdawn.slick.Music
import org.newdawn.slick.openal.Audio
import org.newdawn.slick.openal.AudioImpl
import org.newdawn.slick.openal.MODSound
import org.newdawn.slick.openal.StreamSound
import java.util.*
/**
@@ -12,10 +15,10 @@ import java.util.*
object AudioMixer {
const val TRACK_COUNT = 32
const val TRACK_AMBIENT_ONE = 0
const val TRACK_AMBIENT_ONE_NEXT = 1
const val TRACK_AMBIENT_TWO = 2
const val TRACK_AMBIENT_TWO_NEXT = 3
const val TRACK_AMBIENT_ONE = 0 // music track one
const val TRACK_AMBIENT_ONE_NEXT = 1 // music track two
const val TRACK_AMBIENT_TWO = 2 // music track three
const val TRACK_AMBIENT_TWO_NEXT = 3 // music track four
const val TRACK_UI_ONE = 8
const val TRACK_UI_TWO = 9
@@ -23,14 +26,18 @@ object AudioMixer {
const val TRACK_SFX_START = 16
const val TRACK_SFX_END = 31
val tracks = ArrayList<MixerTrack>(TRACK_COUNT)
val tracks = ArrayList<Int>(TRACK_COUNT) // stores index of ALSource
init {
tracks[TRACK_AMBIENT_ONE]
}
fun getAudio(track: Int) = tracks[track]
fun play(channel: Int) {
}
/**
* Queue an SFX to any empty SFX track and play it.
*/
@@ -38,11 +45,12 @@ object AudioMixer {
}
fun update() {
fun update(delta: Int) {
}
class MixerTrack(val audio: Audio, var volume: Float, var pan: Float) {
}
}
}

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.audio
import org.newdawn.slick.openal.Audio
import org.newdawn.slick.openal.AudioLoader
import java.io.File
import java.io.FileInputStream
import java.util.*
@@ -10,22 +11,25 @@ import java.util.*
*/
object AudioResourceLibrary {
// will play as music
val ambientsForest = ArrayList<Audio>()
val ambientsMeadow = ArrayList<Audio>()
val ambientsWindy = ArrayList<Audio>()
val ambientsWoods = ArrayList<Audio>()
// will play as sound effect
val crickets = ArrayList<Audio>()
init {
ambientsForest.add(AudioLoader.getAudio("ogg", FileInputStream("./res/sounds/ambient/ambient_forest_01.ogg")))
ambientsForest.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_forest_01.ogg").toURI().toURL()))
ambientsMeadow.add(AudioLoader.getAudio("ogg", FileInputStream("./res/sounds/ambient/ambient_meadow_01.ogg")))
ambientsMeadow.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_meadow_01.ogg").toURI().toURL()))
ambientsWindy.add(AudioLoader.getAudio("ogg", FileInputStream("./res/sounds/ambient/ambient_windy_01.ogg")))
ambientsWindy.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_windy_01.ogg").toURI().toURL()))
ambientsWoods.add(AudioLoader.getAudio("ogg", FileInputStream("./res/sounds/ambient/ambient_woods_01.ogg")))
ambientsWoods.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_woods_01.ogg").toURI().toURL()))
crickets.add(AudioLoader.getAudio("ogg", FileInputStream("./res/sounds/ambient/crickets_01.ogg")))
crickets.add(AudioLoader.getAudio("ogg", FileInputStream("./res/sounds/ambient/crickets_02.ogg")))
crickets.add(AudioLoader.getAudio("OGG", FileInputStream("./assets/sounds/ambient/crickets_01.ogg")))
crickets.add(AudioLoader.getAudio("OGG", FileInputStream("./assets/sounds/ambient/crickets_02.ogg")))
}
}

View File

@@ -43,7 +43,8 @@ object CommandDict {
Pair("bulletintest", SetBulletin()),
Pair("gsontest", GsonTest()),
Pair("tips", PrintRandomTips()),
Pair("langtest", LangTest())
Pair("langtest", LangTest()),
Pair("musictest", MusicTest())
)
operator fun get(commandName: String): ConsoleCommand {

View File

@@ -0,0 +1,45 @@
package net.torvald.terrarum.console
import org.newdawn.slick.Music
import org.newdawn.slick.openal.AudioLoader
import java.io.File
/**
* Created by minjaesong on 16-08-02.
*/
class MusicTest : ConsoleCommand {
var music: Music? = null
/**
* Args 0: command given
* Args 1: first argument
*
* e.g. in ```setav mass 74```, zeroth args will be ```setav```.
*/
override fun execute(args: Array<String>) {
if (args.size < 2) {
printUsage()
return
}
if (args[1] == "stop") {
music!!.stop()
return
}
val type = args[1].substringAfter('.').toUpperCase()
/*AudioLoader.getStreamingAudio(
type,
File("./assets/sounds/test/${args[1]}").absoluteFile.toURI().toURL()
).playAsMusic(1f, 1f, false)*/
music = Music("./assets/sounds/test/${args[1]}")
music!!.play()
}
override fun printUsage() {
Echo().execute("Usage: musictest filename/in/res/sounds/test")
Echo().execute("musictest stop to stop playback")
}
}

View File

@@ -112,6 +112,8 @@ open class ActorWithBody : Actor(), Visible {
set(value) { elasticity = 1.0 - value }
get() = 1.0 - elasticity
@Transient private val CEILING_HIT_ELASTICITY = 0.3
var density = 1000.0
set(value) {
if (value < 0)
@@ -374,7 +376,7 @@ open class ActorWithBody : Actor(), Visible {
* Apply only if not grounded; normal force is precessed separately.
*/
private fun applyGravitation() {
if (!isTouchingSide(hitbox, COLLIDING_BOTTOM)) {//(!isColliding(COLLIDING_BOTTOM)) { // or !grounded
if (!isTouchingSide(hitbox, COLLIDING_BOTTOM)) {
/**
* weight; gravitational force in action
* W = mass * G (9.8 [m/s^2])
@@ -388,7 +390,7 @@ open class ActorWithBody : Actor(), Visible {
* Drag of atmosphere
* D = Cd (drag coefficient) * 0.5 * rho (density) * V^2 (velocity sqr) * A (area)
*/
val D: Vector2 = velocity * DRAG_COEFF * 0.5 * A// * tileDensityFluid.toDouble()
val D: Vector2 = Vector2(veloX.magnSqr(), veloY.magnSqr()) * DRAG_COEFF * 0.5 * A// * tileDensityFluid.toDouble()
val V: Vector2 = (W - D) / mass * SI_TO_GAME_ACC
@@ -398,9 +400,13 @@ open class ActorWithBody : Actor(), Visible {
private fun applyNormalForce() {
if (!isNoCollideWorld) {
// axis Y. Use operand >=
if (moveDelta.y >= 0.0) { // was moving downward?
if (isColliding(nextHitbox)) { // FIXME if standing: standard box, if walking: top-squished box
// axis Y. Using operand >= and hitting the ceiling will lock the player to the position
if (moveDelta.y > 0.0) { // was moving downward?
if (isColliding(nextHitbox, COLLIDING_TOP)) { // hit the ceiling
hitAndForciblyReflectY()
grounded = false
}
else if (isColliding(nextHitbox)) { // FIXME if standing: standard box, if walking: top-squished box
hitAndReflectY()
grounded = true
}
@@ -415,7 +421,7 @@ open class ActorWithBody : Actor(), Visible {
else if (moveDelta.y < 0.0) { // or was moving upward?
grounded = false
if (isTouchingSide(nextHitbox, COLLIDING_TOP)) { // actor hit something on its top
hitAndReflectY()
hitAndForciblyReflectY()
}
else { // the actor is not grounded at all
}
@@ -478,6 +484,13 @@ open class ActorWithBody : Actor(), Visible {
}
}
private fun hitAndForciblyReflectY() {
if (veloY.abs() * CEILING_HIT_ELASTICITY > A_PIXEL)
veloY = -veloY * CEILING_HIT_ELASTICITY
else
veloY = veloY.sign() * -A_PIXEL
}
private fun isColliding(hitbox: Hitbox) = isColliding(hitbox, 0)
private fun isColliding(hitbox: Hitbox, option: Int): Boolean {
@@ -915,33 +928,6 @@ open class ActorWithBody : Actor(), Visible {
private val AUTO_CLIMB_RATE: Int
get() = Math.min(TSIZE / 8 * Math.sqrt(scale), TSIZE.toDouble()).toInt()
fun Double.floorInt() = Math.floor(this).toInt()
fun Double.round() = Math.round(this).toDouble()
fun Double.floor() = Math.floor(this)
fun Double.ceil() = this.floor() + 1.0
fun Double.roundInt(): Int = Math.round(this).toInt()
fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this
fun Int.abs() = if (this < 0) -this else this
fun Double.bipolarClamp(limit: Double) =
if (this > 0 && this > limit) limit
else if (this < 0 && this < -limit) -limit
else this
fun absMax(left: Double, right: Double): Double {
if (left > 0 && right > 0)
if (left > right) return left
else return right
else if (left < 0 && right < 0)
if (left < right) return left
else return right
else {
val absL = left.abs()
val absR = right.abs()
if (absL > absR) return left
else return right
}
}
private fun assertInit() {
// errors
if (baseHitboxW == 0 || baseHitboxH == 0)
@@ -983,3 +969,32 @@ open class ActorWithBody : Actor(), Visible {
}
}
}
fun Double.floorInt() = Math.floor(this).toInt()
fun Double.round() = Math.round(this).toDouble()
fun Double.floor() = Math.floor(this)
fun Double.ceil() = this.floor() + 1.0
fun Double.roundInt(): Int = Math.round(this).toInt()
fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this
fun Int.abs() = if (this < 0) -this else this
fun Double.bipolarClamp(limit: Double) =
if (this > 0 && this > limit) limit
else if (this < 0 && this < -limit) -limit
else this
fun absMax(left: Double, right: Double): Double {
if (left > 0 && right > 0)
if (left > right) return left
else return right
else if (left < 0 && right < 0)
if (left < right) return left
else return right
else {
val absL = left.abs()
val absR = right.abs()
if (absL > absR) return left
else return right
}
}
fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr()
fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0

View File

@@ -0,0 +1,166 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import java.util.*
/**
* Provides MDL interpretation, pre-compilation and stores state of the interpreter
*
* Created by minjaesong on 16-07-30.
*/
class MDLInterpreterState {
val stack = MagicArrayStack(20)
fun interpret(line: String) {
}
fun execute(property: MagicWords, power: MagicWords? = null, arg: Int? = null) {
}
enum class MagicWords {
// properties
ELDR, IS, STORMR, HREYFING, LAEKNING, GLEYPI, TJON,
//fire, ice, storm, kinesis, heal, absorb, harm
// reserved words
LAEKNINGHRADI, HREYFINGHRADI, LAEKNINGAUKI, HREYFINGAUKI, STOEKKAUKI, HEILSASTIG,
// heal rate,movement speed, healratemult,movespeedmult, jump boost, health point
// adjectives (power)
// operators
ITA, POP, PLUS, MINUS, SINNUM, DEILING, LEIFASTOFN, AFRIT, TALASKIPTI, HENDA
// push, pop, +, -, *, /, %, dup, swap, drop
}
class MagicOrInt() {
private var magic: MagicWords? = null
private var number: Int? = null
constructor(kynngi: MagicWords): this() {
magic = kynngi
}
constructor(integer: Int) : this() {
number = integer
}
fun toMagic() = if (magic != null) magic!! else throw TypeCastException("$this: cannot be cast to MagicWord")
fun toInt() = if (number != null) number!! else throw TypeCastException("$this: cannot be cast to MagicWord")
fun isMagic() = (magic != null)
fun isInt() = (number != null)
override fun toString(): String = if (magic != null && number == null) "$magic" else if (magic == null && number != null) "$number" else "INVALID"
}
class MagicArrayStack {
/**
* Number of elements in the stack
*/
var depth: Int = 0
private set
var size: Int
get() = data.size
set(newSize) {
if (newSize > depth) inflate(newSize - data.size)
else deflate(data.size - newSize)
}
private lateinit var data: Array<MagicOrInt?>
constructor(stackSize: Int) {
data = Array(stackSize, { null })
}
constructor(arr: Array<MagicOrInt?>) {
data = arr.copyOf()
depth = size
}
fun push(v: MagicOrInt) {
if (depth >= data.size) throw StackOverflowError()
data[depth++] = v
}
fun pop(): MagicOrInt {
if (depth == 0) throw EmptyStackException()
return data[--depth]!!
}
fun peek(): MagicOrInt? {
if (depth == 0) return null
return data[depth - 1]
}
fun dup() {
if (depth == 0) throw EmptyStackException()
if (depth == data.size) throw StackOverflowError()
push(peek()!!)
}
fun swap() {
if (depth < 2) throw UnsupportedOperationException("Stack is empty or has only one element.")
val up = pop()
val dn = pop()
push(up)
push(dn)
}
fun drop() {
if (depth == 0) throw EmptyStackException()
--depth
}
fun defineFromArray(arr: Array<MagicOrInt?>) { data = arr.copyOf() }
/**
* Increase the stack size by a factor.
*/
fun inflate(sizeToAdd: Int) {
if (sizeToAdd < 0) throw UnsupportedOperationException("$sizeToAdd: Cannot deflate the stack with this function. Use deflate(int) instead.")
size += sizeToAdd
val oldStack = this.asArray()
data = Array(size, { if (it < oldStack.size) oldStack[it] else null })
}
/**
* Decrease the stack size by a factor. Overflowing data will be removed.
*/
fun deflate(sizeToTake: Int) {
if (size - sizeToTake < 1) throw UnsupportedOperationException("$sizeToTake: Cannot deflate the stack to the size of zero or negative.")
size -= sizeToTake
val oldStack = this.asArray()
data = Array(size, { oldStack[it] })
if (depth > data.size) depth = data.size
}
/**
* Convert stack as array. Index zero is the bottommost element.
* @return array of data, with array size equivalent to the stack depth.
*/
fun asArray() = data.copyOfRange(0, depth - 1)
fun equalTo(other: MagicArrayStack) = (this.asArray() == other.asArray())
fun plus() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() + (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun minus() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() - (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun times() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() * (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun div() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() / (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
fun mod() { if (data[depth - 2]!!.isInt() && peek()!!.isInt()) data[depth - 2] = MagicOrInt(data[depth - 2]!!.toInt() % (pop().toInt())) else throw RuntimeException("${data[depth - 2]}: Cannot do arithmetic operation on non-numeric type.") }
}
}

View File

@@ -16,7 +16,7 @@ object PBCynthia {
p.sprite = SpriteAnimation()
p.sprite!!.setDimension(26, 42)
p.sprite!!.setSpriteImage("res/graphics/sprites/test_player_2.png")
p.sprite!!.setSpriteImage("assets/graphics/sprites/test_player_2.png")
p.sprite!!.setDelay(200)
p.sprite!!.setRowsAndFrames(1, 1)
p.sprite!!.setAsVisible()

View File

@@ -20,14 +20,14 @@ object PBSigrid {
p.sprite = SpriteAnimation()
p.sprite!!.setDimension(28, 51)
p.sprite!!.setSpriteImage("res/graphics/sprites/test_player.png")
p.sprite!!.setSpriteImage("assets/graphics/sprites/test_player.png")
p.sprite!!.setDelay(200)
p.sprite!!.setRowsAndFrames(1, 1)
p.sprite!!.setAsVisible()
p.spriteGlow = SpriteAnimation()
p.spriteGlow!!.setDimension(28, 51)
p.spriteGlow!!.setSpriteImage("res/graphics/sprites/test_player_glow.png")
p.spriteGlow!!.setSpriteImage("assets/graphics/sprites/test_player_glow.png")
p.spriteGlow!!.setDelay(200)
p.spriteGlow!!.setRowsAndFrames(1, 1)
p.spriteGlow!!.setAsVisible()

View File

@@ -79,7 +79,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
override val lightBoxList: List<Hitbox>
get() = arrayOf(Hitbox(0.0, 0.0, hitbox.width, hitbox.height)).toList() // use getter; dimension of the player may change by time.
var gamepad: Controller? = Controllers.getController(0)
var gamepad: Controller? = null
var axisX = 0f
var axisY = 0f
var axisRX = 0f
@@ -105,6 +105,13 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
referenceID = PLAYER_REF_ID // forcibly set ID
density = BASE_DENSITY
collisionType = KINEMATIC
try {
gamepad = Controllers.getController(0)
}
catch (e: IndexOutOfBoundsException) {
println("[Player] gamepad not detected.")
}
}
override fun update(gc: GameContainer, delta: Int) {

View File

@@ -7,7 +7,7 @@ import java.io.IOException
* Created by minjaesong on 16-03-15.
*/
object PlayerBuilder {
private val JSONPATH = "./res/raw/"
private val JSONPATH = "./assets/raw/"
private val jsonString = String()
@Throws(IOException::class, SlickException::class)

View File

@@ -10,7 +10,7 @@ import java.io.IOException
*/
object FactionFactory {
const val JSONPATH = "./res/raw/factions/"
const val JSONPATH = "./assets/raw/factions/"
/**
* @param filename with extension

View File

@@ -28,7 +28,7 @@ object Lang {
val languageList: List<String>
private val PATH_TO_LANG = "./res/locales/"
private val PATH_TO_LANG = "./assets/locales/"
val POLYGLOT_VERSION = "100"
private val PREFIX_POLYGLOT = "Polyglot-${POLYGLOT_VERSION}_"
private val PREFIX_NAMESET = "nameset_"

View File

@@ -29,11 +29,11 @@ object MapCamera {
private val TSIZE = MapDrawer.TILE_SIZE
var tilesWall: SpriteSheet = SpriteSheet("./res/graphics/terrain/wall.png", TSIZE, TSIZE)
var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TSIZE, TSIZE)
private set
var tilesTerrain: SpriteSheet = SpriteSheet("./res/graphics/terrain/terrain.png", TSIZE, TSIZE)
var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.png", TSIZE, TSIZE)
private set
var tilesWire: SpriteSheet = SpriteSheet("./res/graphics/terrain/wire.png", TSIZE, TSIZE)
var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TSIZE, TSIZE)
private set
var tilesetBook: Array<SpriteSheet> = arrayOf(tilesWall, tilesTerrain, tilesWire)
private set

View File

@@ -20,11 +20,11 @@ object ItemSlotImageBuilder {
private val colourWhite = Color(0xC0C0C0)
private val numberFont = SpriteSheetFont(
SpriteSheet("./res/graphics/fonts/numeric_small.png", 5, 8),
SpriteSheet("./assets/graphics/fonts/numeric_small.png", 5, 8),
'0'
)
val slotImage = Image("./res/graphics/gui/quickbar/item_slot.png") // must have same w/h as slotLarge
val slotLarge = Image("./res/graphics/gui/quickbar/item_slot_large.png")
val slotImage = Image("./assets/graphics/gui/quickbar/item_slot.png") // must have same w/h as slotLarge
val slotLarge = Image("./assets/graphics/gui/quickbar/item_slot_large.png")
private val canvas = Image(slotImage.width, slotImage.height)
private val canvasLarge = Image(slotLarge.width, slotLarge.height)

View File

@@ -31,14 +31,14 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
init {
if (!isBlackVariant) {
segmentLeft = Image("./res/graphics/gui/message_twoline_white_left.png");
segmentRight = Image("./res/graphics/gui/message_twoline_white_right.png");
segmentBody = Image("./res/graphics/gui/message_twoline_white_body.png");
segmentLeft = Image("./assets/graphics/gui/message_twoline_white_left.png");
segmentRight = Image("./assets/graphics/gui/message_twoline_white_right.png");
segmentBody = Image("./assets/graphics/gui/message_twoline_white_body.png");
}
else {
segmentLeft = Image("./res/graphics/gui/message_twoline_black_left.png")
segmentRight = Image("./res/graphics/gui/message_twoline_black_right.png")
segmentBody = Image("./res/graphics/gui/message_twoline_black_body.png")
segmentLeft = Image("./assets/graphics/gui/message_twoline_black_left.png")
segmentRight = Image("./assets/graphics/gui/message_twoline_black_right.png")
segmentBody = Image("./assets/graphics/gui/message_twoline_black_body.png")
}
uiFont = GameFontWhite()
height = segmentLeft!!.height

View File

@@ -35,12 +35,12 @@ object WeatherMixer {
const val WEATHER_GENERIC = "generic"
// TODO add weather classification indices manually
const val RAW_DIR = "./res/raw/weathers"
const val RAW_DIR = "./assets/raw/weathers"
init {
weatherList = HashMap<String, ArrayList<BaseModularWeather>>()
// read weather descriptions from res/weather (modular weather)
// read weather descriptions from assets/weather (modular weather)
val weatherRawValidList = ArrayList<File>()
val weatherRaws = File(RAW_DIR).listFiles()
weatherRaws.forEach {
@@ -157,7 +157,7 @@ object WeatherMixer {
]
}
*/
val pathToImage = "./res/graphics/weathers"
val pathToImage = "./assets/graphics/weathers"
val JSON = JsonFetcher(path)