diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index ae39d99ac..c4d5773f1 100644
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -7,9 +7,9 @@
-
+
-
+
diff --git a/res/graphics/fonts/numeric_small.png b/res/graphics/fonts/numeric_small.png
index bb5d30de1..52b9272ac 100644
Binary files a/res/graphics/fonts/numeric_small.png and b/res/graphics/fonts/numeric_small.png differ
diff --git a/res/graphics/gui/quickbar/item_slot.bmp b/res/graphics/gui/quickbar/item_slot.bmp
deleted file mode 100644
index 6fd711a57..000000000
Binary files a/res/graphics/gui/quickbar/item_slot.bmp and /dev/null differ
diff --git a/res/graphics/gui/quickbar/item_slot.png b/res/graphics/gui/quickbar/item_slot.png
index 5476b55f1..b712a7c13 100644
Binary files a/res/graphics/gui/quickbar/item_slot.png and b/res/graphics/gui/quickbar/item_slot.png differ
diff --git a/res/graphics/gui/quickbar/item_slot_large.png b/res/graphics/gui/quickbar/item_slot_large.png
new file mode 100644
index 000000000..e6c9a225e
Binary files /dev/null and b/res/graphics/gui/quickbar/item_slot_large.png differ
diff --git a/res/graphics/weathers/generic_light 복사본.png b/res/graphics/weathers/generic_light 복사본.png
new file mode 100644
index 000000000..da689f918
Binary files /dev/null and b/res/graphics/weathers/generic_light 복사본.png differ
diff --git a/res/graphics/weathers/generic_light.png b/res/graphics/weathers/generic_light.png
index da689f918..4cc174700 100644
Binary files a/res/graphics/weathers/generic_light.png and b/res/graphics/weathers/generic_light.png differ
diff --git a/res/graphics/weathers/generic_skybox.png b/res/graphics/weathers/generic_skybox.png
index 15762dab4..84a2ace64 100644
Binary files a/res/graphics/weathers/generic_skybox.png and b/res/graphics/weathers/generic_skybox.png differ
diff --git a/src/net/torvald/colourutil/ColourTemp.kt b/src/net/torvald/colourutil/ColourTemp.kt
new file mode 100644
index 000000000..d6e6998ac
--- /dev/null
+++ b/src/net/torvald/colourutil/ColourTemp.kt
@@ -0,0 +1,18 @@
+package net.torvald.colourutil
+
+import org.newdawn.slick.Color
+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 fun colTempToImagePos(K: Int): Int {
+ if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)")
+ return (K - 1000) / 10
+ }
+
+ operator fun invoke(temp: Int): Color = envOverlayColourmap.getColor(colTempToImagePos(temp), 0)
+}
\ No newline at end of file
diff --git a/src/net/torvald/colourutil/ColourUtil.kt b/src/net/torvald/colourutil/ColourUtil.kt
new file mode 100644
index 000000000..798fb8d93
--- /dev/null
+++ b/src/net/torvald/colourutil/ColourUtil.kt
@@ -0,0 +1,10 @@
+package net.torvald.colourutil
+
+import org.newdawn.slick.Color
+
+/**
+ * Created by minjaesong on 16-07-26.
+ */
+object ColourUtil {
+ fun toSlickColor(r: Int, g: Int, b: Int) = Color(r.shl(16) or g.shl(8) or b)
+}
\ No newline at end of file
diff --git a/src/net/torvald/serialise/WriteGameMapData.kt b/src/net/torvald/serialise/WriteGameMapData.kt
index b8fa0fcee..053f00a42 100644
--- a/src/net/torvald/serialise/WriteGameMapData.kt
+++ b/src/net/torvald/serialise/WriteGameMapData.kt
@@ -35,7 +35,7 @@ object WriteGameMapData {
// write binary
Files.write(tempPath, MAGIC)
- Files.write(tempPath, byteArrayOf(GameWorld.BITS))
+ Files.write(tempPath, byteArrayOf(GameWorld.SIZEOF))
Files.write(tempPath, byteArrayOf(GameWorld.LAYERS))
Files.write(tempPath, byteArrayOf(BYTE_NULL))
Files.write(tempPath, byteArrayOf(BYTE_NULL))
@@ -44,15 +44,15 @@ object WriteGameMapData {
Files.write(tempPath, toByteArray(map.spawnX))
Files.write(tempPath, toByteArray(map.spawnY))
map.layerTerrain.forEach(
- {b -> Files.write(tempPath, byteArrayOf(b))})
+ { b -> Files.write(tempPath, byteArrayOf(b)) })
map.layerWall.forEach(
- {b -> Files.write(tempPath, byteArrayOf(b))})
+ { b -> Files.write(tempPath, byteArrayOf(b)) })
map.terrainDamage.forEach(
- {b -> Files.write(tempPath, byteArrayOf(b))})
+ { b -> Files.write(tempPath, byteArrayOf(b)) })
map.wallDamage.forEach(
- {b -> Files.write(tempPath, byteArrayOf(b))})
+ { b -> Files.write(tempPath, byteArrayOf(b)) })
map.layerWire.forEach(
- {b -> Files.write(tempPath, byteArrayOf(b))})
+ { b -> Files.write(tempPath, byteArrayOf(b)) })
// replace savemeta with tempfile
try {
diff --git a/src/net/torvald/serialise/WriteMeta.kt b/src/net/torvald/serialise/WriteMeta.kt
index 3b9f642ab..686587af5 100644
--- a/src/net/torvald/serialise/WriteMeta.kt
+++ b/src/net/torvald/serialise/WriteMeta.kt
@@ -3,6 +3,8 @@ package net.torvald.serialise
import net.torvald.terrarum.mapgenerator.MapGenerator
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import net.torvald.terrarum.Terrarum
+import net.torvald.terrarum.itemproperties.ItemPropCodex
+import net.torvald.terrarum.itemproperties.MaterialPropCodex
import net.torvald.terrarum.tileproperties.TilePropCodex
import org.apache.commons.codec.digest.DigestUtils
import java.io.FileInputStream
@@ -43,8 +45,8 @@ object WriteMeta {
// define files to get hash
val fileArray: Array = arrayOf(
File(TilePropCodex.CSV_PATH)
- //, File(ItemPropCodex.CSV_PATH)
- //, File(MaterialPropCodex.CSV_PATH)
+ , File(ItemPropCodex.CSV_PATH)
+ , File(MaterialPropCodex.CSV_PATH)
//,
)
diff --git a/src/net/torvald/terrarum/COPYING.md b/src/net/torvald/terrarum/COPYING.md
index f5bcebe7b..9ae6a91bb 100644
--- a/src/net/torvald/terrarum/COPYING.md
+++ b/src/net/torvald/terrarum/COPYING.md
@@ -1,7 +1,9 @@
*Terrarum* by Torvald
-Copyright (C) 2015-2016 Torvald. All rights reserved.
-mailto: skyhi14 *64* __115875741922660__ *46* __6516589__
+Copyright (C) 2013-2016 Torvald. All rights reserved.
+mailto: alswo9628 *at* __gmail__ *dot* __com__
+
+You can use any assets (sprites, fonts and tiles) for your own goods (e.g. texture pack for Minecraft), provided that you gave necessary credit to this game and me.
----
diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt
index d8acdf035..4c5b2fdd9 100644
--- a/src/net/torvald/terrarum/DefaultConfig.kt
+++ b/src/net/torvald/terrarum/DefaultConfig.kt
@@ -34,7 +34,7 @@ object DefaultConfig {
jsonObject.addProperty("joypadrstickx", 2)
jsonObject.addProperty("joypadrsticky", 3) // logitech indices
- // control-keyboard (Java key index. This is what Minecraft also uses)
+ // control-keyboard (Java key codes. This is what Minecraft also uses)
jsonObject.addProperty("keyup", Key.E)
jsonObject.addProperty("keyleft", Key.S)
jsonObject.addProperty("keydown", Key.D)
diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt
index 3c0a9f904..eb5bb8ce8 100644
--- a/src/net/torvald/terrarum/StateInGame.kt
+++ b/src/net/torvald/terrarum/StateInGame.kt
@@ -137,6 +137,13 @@ constructor() : BasicGameState() {
// queue up game UIs
// lesser UIs
+ // quick bar
+ uiAliases[UI_QUICK_BAR] = UIHandler(UIQuickBar())
+ uiAliases[UI_QUICK_BAR]!!.isVisible = true
+ uiAliases[UI_QUICK_BAR]!!.setPosition(0, 0)
+ uiAliases[UI_QUICK_BAR]!!.UI.handler = uiAliases[UI_QUICK_BAR]
+ uiContainer.add(uiAliases[UI_QUICK_BAR]!!)
+ // pie menu
uiAliases[UI_PIE_MENU] = UIHandler(UIPieMenu())
uiAliases[UI_PIE_MENU]!!.setPosition(
(Terrarum.WIDTH - uiAliases[UI_PIE_MENU]!!.UI.width) / 2,
@@ -284,65 +291,65 @@ constructor() : BasicGameState() {
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|| key == Terrarum.getConfigInt("keyquicksel")) {
- uiAliases[UI_PIE_MENU]!!.setAsOpening()
- // TODO hide quick bar
+ uiAliases[UI_PIE_MENU]!!.setAsOpen()
+ uiAliases[UI_QUICK_BAR]!!.setAsClose()
}
- uiContainer.forEach { it.keyPressed(key, c) }
+ uiContainer.forEach { it.keyPressed(key, c) } // for KeyboardControlled UIcanvases
}
override fun keyReleased(key: Int, c: Char) {
GameController.keyReleased(key, c)
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
- || key == Terrarum.getConfigInt("keyquicksel")) {
- uiAliases[UI_PIE_MENU]!!.setAsClosing()
- // TODO show quick bar
+ || key == Terrarum.getConfigInt("keyquicksel")) {
+ uiAliases[UI_PIE_MENU]!!.setAsClose()
+ uiAliases[UI_QUICK_BAR]!!.setAsOpen()
}
- uiContainer.forEach { it.keyReleased(key, c) }
+ uiContainer.forEach { it.keyReleased(key, c) } // for KeyboardControlled UIcanvases
}
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
GameController.mouseMoved(oldx, oldy, newx, newy)
- uiContainer.forEach { it.mouseMoved(oldx, oldy, newx, newy) }
+ uiContainer.forEach { it.mouseMoved(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases
}
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
GameController.mouseDragged(oldx, oldy, newx, newy)
- uiContainer.forEach { it.mouseDragged(oldx, oldy, newx, newy) }
+ uiContainer.forEach { it.mouseDragged(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases
}
override fun mousePressed(button: Int, x: Int, y: Int) {
GameController.mousePressed(button, x, y)
- uiContainer.forEach { it.mousePressed(button, x, y) }
+ uiContainer.forEach { it.mousePressed(button, x, y) } // for MouseControlled UIcanvases
}
override fun mouseReleased(button: Int, x: Int, y: Int) {
GameController.mouseReleased(button, x, y)
- uiContainer.forEach { it.mouseReleased(button, x, y) }
+ uiContainer.forEach { it.mouseReleased(button, x, y) } // for MouseControlled UIcanvases
}
override fun mouseWheelMoved(change: Int) {
GameController.mouseWheelMoved(change)
- uiContainer.forEach { it.mouseWheelMoved(change) }
+ uiContainer.forEach { it.mouseWheelMoved(change) } // for MouseControlled UIcanvases
}
override fun controllerButtonPressed(controller: Int, button: Int) {
GameController.controllerButtonPressed(controller, button)
- uiContainer.forEach { it.controllerButtonPressed(controller, button) }
+ uiContainer.forEach { it.controllerButtonPressed(controller, button) } // for GamepadControlled UIcanvases
}
override fun controllerButtonReleased(controller: Int, button: Int) {
GameController.controllerButtonReleased(controller, button)
- uiContainer.forEach { it.controllerButtonReleased(controller, button) }
+ uiContainer.forEach { it.controllerButtonReleased(controller, button) } // for GamepadControlled UIcanvases
}
override fun getID(): Int = Terrarum.SCENE_ID_GAME
@@ -352,7 +359,7 @@ constructor() : BasicGameState() {
/** Send message to notifier UI and toggle the UI as opened. */
fun sendNotification(msg: Array) {
(notifier.UI as Notification).sendNotification(Terrarum.appgc, UPDATE_DELTA, msg)
- notifier.setAsOpening()
+ notifier.setAsOpen()
}
fun wakeDormantActors() {
diff --git a/src/net/torvald/terrarum/StateMonitorCheck.kt b/src/net/torvald/terrarum/StateMonitorCheck.kt
index bf9011f04..8596a3680 100644
--- a/src/net/torvald/terrarum/StateMonitorCheck.kt
+++ b/src/net/torvald/terrarum/StateMonitorCheck.kt
@@ -4,7 +4,7 @@ import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.Typesetter
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIHandler
-import net.torvald.terrarum.ui.UITypable
+import net.torvald.terrarum.ui.KeyboardControlled
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -32,7 +32,7 @@ class StateMonitorCheck : BasicGameState() {
}
override fun keyPressed(key: Int, c: Char) {
- //uiMonitorCheck.setAsClosing()
+ //uiMonitorCheck.setAsClose()
}
override fun getID(): Int = Terrarum.SCENE_ID_CONFIG_CALIBRATE
diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt
index 268163705..b187d22c5 100644
--- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt
+++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt
@@ -64,12 +64,11 @@ open class ActorWithBody : Actor(), Visible {
get() = controllerVel!!.x
internal set(value) { controllerVel!!.x = value }
var walkY: Double
- get() = controllerVel!!.x
- internal set(value) { controllerVel!!.x = value }
+ get() = controllerVel!!.y
+ internal set(value) { controllerVel!!.y = value }
/**
* Physical properties.
- * Values derived from ActorValue must be @Transient.
*/
var scale: Double
get() = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0
@@ -212,6 +211,8 @@ open class ActorWithBody : Actor(), Visible {
var ccdCollided = false
+ var isWalking = false
+
init {
// some initialiser goes here...
}
@@ -291,6 +292,7 @@ open class ActorWithBody : Actor(), Visible {
* Actual physics thing (altering velocity) starts from here
*/
+ // Combine velo and walk
applyMovementVelocity()
// applyBuoyancy()
@@ -308,14 +310,13 @@ open class ActorWithBody : Actor(), Visible {
// Set 'next' position (hitbox) from canonical and walking velocity
setNewNextHitbox()
- applyNormalForce()
/**
* solveCollision()?
* If and only if:
* This body is NON-STATIC and the other body is STATIC
*/
- setNewNextHitbox()
displaceByCCD()
+ applyNormalForce()
setHorizontalFriction()
if (isPlayerNoClip) // or hanging on the rope, etc.
@@ -394,21 +395,15 @@ open class ActorWithBody : Actor(), Visible {
}
}
- /**
- * FIXME the culprit!
- * (5566 -> no collision but player does not "sink")
- * (5567 -> collision)
- * How to fix:
- */
private fun applyNormalForce() {
if (!isNoCollideWorld) {
// axis Y. Use operand >=
if (moveDelta.y >= 0.0) { // was moving downward?
- if (isColliding(nextHitbox)) {
+ if (isColliding(nextHitbox)) { // FIXME if standing: standard box, if walking: top-squished box
hitAndReflectY()
grounded = true
}
- else if (isTouchingSide(nextHitbox, COLLIDING_BOTTOM)) { // actor hit something on its bottom
+ else if (isTouchingSide(nextHitbox, COLLIDING_BOTTOM) && !isColliding(nextHitbox)) { // actor hit something on its bottom
grounded = true
}
else { // the actor is not grounded at all
@@ -427,7 +422,7 @@ open class ActorWithBody : Actor(), Visible {
if (isTouchingSide(nextHitbox, COLLIDING_LEFT) && isTouchingSide(nextHitbox, COLLIDING_RIGHT)
&& moveDelta.x != 0.0) { // check right and left
// the actor is hitting the wall
- hitAndReflectX()
+ //hitAndReflectX()
}
}
}
@@ -436,31 +431,32 @@ open class ActorWithBody : Actor(), Visible {
* nextHitbox must NOT be altered before this method is called!
*/
private fun displaceByCCD() {
+ ccdCollided = false
+
if (!isNoCollideWorld){
+ if (!isColliding(nextHitbox, COLLIDING_ALLSIDE))
+ return
+
// do some CCD between hitbox and nextHitbox
- val ccdBox = nextHitbox.clone()//.snapToPixel()
- val ccdDelta = nextHitbox.toVector() to hitbox.toVector()
- val deltaMax = Math.max(ccdDelta.x.abs(), ccdDelta.y.abs())
- // set ccdDelta so that CCD move a pixel per round
- if (deltaMax > 1.0)
- ccdDelta *= (1.0 / deltaMax)
+ val ccdDelta = (nextHitbox.toVector() - hitbox.toVector())
+ if (ccdDelta.x != 0.0 || ccdDelta.y != 0.0)
+ ccdDelta.set(ccdDelta.setMagnitude(CCD_TICK))
+
+ //////TEST//////
+ ccdDelta.x = 0.0
+ //////TEST//////
+ // Result: player CAN WALK with ccdDelta.x of zero, which means previous method is a shit.
//println("deltaMax: $deltaMax")
//println("ccdDelta: $ccdDelta")
- while (!ccdDelta.isZero && isColliding(ccdBox, COLLIDING_ALLSIDE)) {
- nextHitbox.translate(ccdDelta)
+ while (!ccdDelta.isZero && isColliding(nextHitbox, COLLIDING_ALLSIDE)) {
+ nextHitbox.translate(-ccdDelta)
ccdCollided = true
-
- //ccdBox.reassign(nextHitbox).snapToPixel()
- ccdBox.reassign(nextHitbox)
}
//println("ccdCollided: $ccdCollided")
}
- else {
- ccdCollided = false
- }
}
private fun hitAndReflectX() {
@@ -625,7 +621,7 @@ open class ActorWithBody : Actor(), Visible {
}
return false*/
- return if (tyEnd <= 347) false else true
+ return if (tyEnd < 348) false else true
}
private fun getContactingAreaFluid(side: Int, translateX: Int = 0, translateY: Int = 0): Int {
@@ -749,17 +745,23 @@ open class ActorWithBody : Actor(), Visible {
/**
- * Get highest friction value from feet tiles.
+ * Get highest friction value from surrounding tiles
* @return
*/
internal val bodyFriction: Int
get() {
- /*var friction = 0
+ var friction = 0
+ val frictionCalcHitbox = if (isWalking)
+ Hitbox(nextHitbox.posX + 1.0, nextHitbox.posY + 1.0,
+ nextHitbox.width - 2.0, nextHitbox.height - 2.0)
+ else
+ nextHitbox.clone()
// take highest value
- val tilePosXStart = (hitbox.posX / TSIZE).roundInt()
- val tilePosXEnd = (hitbox.hitboxEnd.x / TSIZE).roundInt()
- val tilePosY = (hitbox.pointedY.plus(1) / TSIZE).roundInt()
+ val tilePosXStart = (frictionCalcHitbox.posX / TSIZE).floorInt()
+ val tilePosXEnd = (frictionCalcHitbox.hitboxEnd.x / TSIZE).floorInt()
+ val tilePosY = (frictionCalcHitbox.pointedY / TSIZE).floorInt()
+
for (x in tilePosXStart..tilePosXEnd) {
val tile = world.getTileFromTerrain(x, tilePosY)
val thisFriction = TilePropCodex.getProp(tile).friction
@@ -767,16 +769,10 @@ open class ActorWithBody : Actor(), Visible {
if (thisFriction > friction) friction = thisFriction
}
- return friction*/
- return 1
+ return friction
}
fun Int.tileFrictionToMult(): Double = this / 16.0
- internal val feetFriction: Int
- get() {
- return 16
- }
-
/**
* Get highest tile density from occupying tiles, fluid only
*/
diff --git a/src/net/torvald/terrarum/gameactors/PBSigrid.kt b/src/net/torvald/terrarum/gameactors/PBSigrid.kt
index 144465ff0..bc880c826 100644
--- a/src/net/torvald/terrarum/gameactors/PBSigrid.kt
+++ b/src/net/torvald/terrarum/gameactors/PBSigrid.kt
@@ -54,7 +54,7 @@ object PBSigrid {
p.actorValue[AVKey.INTELLIGENT] = true
- p.actorValue[AVKey.LUMINOSITY] = 95487100
+ p.actorValue[AVKey.LUMINOSITY] = 0//95487100
p.actorValue[AVKey.BASEDEFENCE] = 141
diff --git a/src/net/torvald/terrarum/gameactors/Player.kt b/src/net/torvald/terrarum/gameactors/Player.kt
index 3e79a659b..04ee0530e 100644
--- a/src/net/torvald/terrarum/gameactors/Player.kt
+++ b/src/net/torvald/terrarum/gameactors/Player.kt
@@ -36,8 +36,10 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
/** how long the jump button has down, in frames */
internal var jumpCounter = 0
+ internal var jumpAcc = 0.0
/** how long the walk button has down, in frames */
- internal var walkCounter = 0
+ internal var walkCounterX = 0
+ internal var walkCounterY = 0
@Transient private val MAX_JUMP_LENGTH = 17 // use 17; in internal frames
private var readonly_totalX = 0.0
@@ -134,7 +136,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
* @author minjaesong
*/
private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
- if ((!walledLeft && left) || (!walledRight && !left)) {
+ if (true) {//(!walledLeft && left) || (!walledRight && !left)) {
readonly_totalX = //veloX +
/*actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
@@ -145,7 +147,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
- applyVelo(walkCounter) *
+ applyVelo(walkCounterX) *
(if (left) -1 else 1).toFloat() *
absAxisVal
@@ -153,7 +155,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkX += readonly_totalX
walkX = absClamp(walkX, actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDMULT)!!)
- walkCounter += 1
+ walkCounterX += 1
// Heading flag
if (left)
@@ -162,6 +164,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkHeading = RIGHT
// println("$walkCounter: ${readonly_totalX}")
+ isWalking = true
}
}
@@ -176,13 +179,16 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
- applyVelo(walkCounter) *
+ applyVelo(walkCounterY) *
(if (up) -1 else 1).toFloat() *
absAxisVal
- applyForce(Vector2(0.0, readonly_totalY))
+ walkY += readonly_totalY
+ walkY = absClamp(walkY, actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDMULT)!!)
- if (walkCounter <= WALK_FRAMES_TO_MAX_ACCEL) walkCounter += 1
+ //if (walkCounterY <= WALK_FRAMES_TO_MAX_ACCEL) walkCounterY += 1
+
+ isWalking = true
}
private fun applyAccel(x: Int): Double {
@@ -219,7 +225,8 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
//veloX = 0f
- walkCounter = 0
+ walkCounterX = 0
+ isWalking = false
}
// stops; let the friction kick in by doing nothing to the velocity here
@@ -245,7 +252,8 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
///veloY = 0f
- walkCounter = 0
+ walkCounterY = 0
+ isWalking = false
}
/**
@@ -266,9 +274,11 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
var timedJumpCharge = init - init / len * jumpCounter
if (timedJumpCharge < 0) timedJumpCharge = 0.0
- val jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * Math.sqrt(scale) // positive value
+ jumpAcc = -pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * Math.sqrt(scale) // positive value
- applyForce(Vector2(0.0, -jumpAcc))
+ applyForce(Vector2(0.0, jumpAcc))
+
+ if (jumpAcc != 0.0) println(jumpAcc)
}
// for mob ai:
@@ -359,7 +369,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkHorizontal(true, AXIS_POSMAX)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)
} // ↓F, ↓S
- else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
+ /*else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) {
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
walkHorizontal(false, AXIS_POSMAX)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)
@@ -367,7 +377,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkHorizontal(true, AXIS_POSMAX)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)
}
- }
+ }*/
}
/**
@@ -388,7 +398,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkVertical(true, AXIS_POSMAX)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)
} // ↓E, ↓D
- else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) && isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
+ /*else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) && isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) {
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
walkVertical(false, AXIS_POSMAX)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)
@@ -396,7 +406,7 @@ class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, L
walkVertical(true, AXIS_POSMAX)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)
}
- }
+ }*/
}
}
diff --git a/src/net/torvald/terrarum/gamecontroller/KeyMap.kt b/src/net/torvald/terrarum/gamecontroller/KeyMap.kt
index d20e452ca..6b03c6b0e 100644
--- a/src/net/torvald/terrarum/gamecontroller/KeyMap.kt
+++ b/src/net/torvald/terrarum/gamecontroller/KeyMap.kt
@@ -1,5 +1,6 @@
package net.torvald.terrarum.gamecontroller
+import net.torvald.terrarum.Terrarum
import java.util.Hashtable
/**
@@ -10,11 +11,11 @@ object KeyMap {
var map_code = Hashtable()
init {
- map_code.put(EnumKeyFunc.MOVE_UP, Key.E)
- map_code.put(EnumKeyFunc.MOVE_LEFT, Key.S)
- map_code.put(EnumKeyFunc.MOVE_DOWN, Key.D)
- map_code.put(EnumKeyFunc.MOVE_RIGHT, Key.F)
- map_code.put(EnumKeyFunc.JUMP, Key.SPACE)
+ map_code.put(EnumKeyFunc.MOVE_UP, Terrarum.getConfigInt("keyup"))
+ map_code.put(EnumKeyFunc.MOVE_LEFT, Terrarum.getConfigInt("keyleft"))
+ map_code.put(EnumKeyFunc.MOVE_DOWN, Terrarum.getConfigInt("keydown"))
+ map_code.put(EnumKeyFunc.MOVE_RIGHT, Terrarum.getConfigInt("keyright"))
+ map_code.put(EnumKeyFunc.JUMP, Terrarum.getConfigInt("keyjump"))
map_code.put(EnumKeyFunc.UI_CONSOLE, Key.GRAVE)
map_code.put(EnumKeyFunc.UI_BASIC_INFO, Key.F3)
}
@@ -23,7 +24,7 @@ object KeyMap {
return map_code[fn]!!
}
- operator fun set(func: EnumKeyFunc, key: Int) {
+ fun set(func: EnumKeyFunc, key: Int) {
map_code.put(func, key)
}
diff --git a/src/net/torvald/terrarum/gamemap/GameWorld.kt b/src/net/torvald/terrarum/gamemap/GameWorld.kt
index 3e9327235..ebcc638d2 100644
--- a/src/net/torvald/terrarum/gamemap/GameWorld.kt
+++ b/src/net/torvald/terrarum/gamemap/GameWorld.kt
@@ -219,7 +219,7 @@ constructor(//properties
@Transient val WIRE = 2
@Transient val TILES_SUPPORTED = MapLayer.RANGE * PairedMapLayer.RANGE
- @Transient val BITS: Byte = 1 // 1 for Byte, 2 for Char, 4 for Int, 8 for Long
+ @Transient val SIZEOF: Byte = MapLayer.SIZEOF
@Transient val LAYERS: Byte = 4 // terrain, wall (terrainDamage + wallDamage), wire
}
}
\ 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 3e6469436..ae6599e4c 100644
--- a/src/net/torvald/terrarum/gamemap/MapLayer.kt
+++ b/src/net/torvald/terrarum/gamemap/MapLayer.kt
@@ -51,6 +51,7 @@ class MapLayer(var width: Int, var height: Int) : Iterable {
companion object {
@Transient const val RANGE = 256
+ @Transient const val SIZEOF: Byte = 1 // 1 for 8-bit, 2 for 16-bit, ...
}
}
diff --git a/src/net/torvald/terrarum/gamemap/PairedMapLayer.kt b/src/net/torvald/terrarum/gamemap/PairedMapLayer.kt
index f12973e8f..30a82308d 100644
--- a/src/net/torvald/terrarum/gamemap/PairedMapLayer.kt
+++ b/src/net/torvald/terrarum/gamemap/PairedMapLayer.kt
@@ -80,7 +80,7 @@ class PairedMapLayer(width: Int, var height: Int) : Iterable {
}
companion object {
-
@Transient const val RANGE = 16
+ @Transient const val SIZEOF: Byte = 1 // 1 for 8-bit, 2 for 16-bit, ...
}
}
diff --git a/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt b/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt
index b387be6ea..1e3369187 100644
--- a/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt
+++ b/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt
@@ -5,6 +5,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.tileproperties.TileNameCode
import net.torvald.terrarum.tilestats.TileStats
import com.jme3.math.FastMath
+import net.torvald.colourutil.ColourTemp
import org.newdawn.slick.*
/**
@@ -13,14 +14,13 @@ import org.newdawn.slick.*
object MapDrawer {
const val TILE_SIZE = 16
- private var envOverlayColourmap: Image = Image("./res/graphics/colourmap/black_body_col_1000_40000_K.png")
-
private val ENV_COLTEMP_LOWEST = 5500
private val ENV_COLTEMP_HIGHEST = 7500
val ENV_COLTEMP_NOON = 6500 // 6500 == sRGB White == untouched!
- private var colTemp: Int = 0
+ var colTemp: Int = 0
+ private set
private val TILES_COLD = intArrayOf(
TileNameCode.ICE_MAGICAL
@@ -49,7 +49,7 @@ object MapDrawer {
colTemp = colTemp_warm + colTemp_cold - ENV_COLTEMP_NOON
val zoom = Terrarum.ingame.screenZoom
- g.color = getColourFromMap(colTemp)
+ g.color = ColourTemp(colTemp)
//g.color = getColourFromMap(3022)
g.fillRect(
MapCamera.cameraX * zoom,
@@ -70,18 +70,4 @@ object MapDrawer {
return Math.round((ENV_COLTEMP_HIGHEST - ENV_COLTEMP_LOWEST) / 2 * FastMath.clamp(x, -1f, 1f) + colTempMedian)
}
-
- fun getColourFromMap(K: Int): Color {
- return envOverlayColourmap.getColor(colTempToImagePos(K), 0)
- }
-
- private fun colTempToImagePos(K: Int): Int {
- if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)")
- return (K - 1000) / 10
- }
-
- @JvmStatic
- fun getColTemp(): Int {
- return colTemp
- }
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
index 1daeb3da8..5e782bf04 100644
--- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
+++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
@@ -19,7 +19,7 @@ import java.util.*
/**
* Created by minjaesong on 16-03-14.
*/
-class BasicDebugInfoWindow:UICanvas {
+class BasicDebugInfoWindow : UICanvas {
override var width: Int = Terrarum.WIDTH
override var height: Int = Terrarum.HEIGHT
@@ -101,6 +101,8 @@ class BasicDebugInfoWindow:UICanvas {
printLine(g, 5, "grounded $ccG${player.grounded}")
printLine(g, 6, "noClip $ccG${player.noClip}")
+ printLine(g, 7, "jump $ccG${player.jumpAcc}")
+
val lightVal: String
val mtX = mouseTileX.toString()
val mtY = mouseTileY.toString()
@@ -114,7 +116,7 @@ class BasicDebugInfoWindow:UICanvas {
rawR.toString() + " " +
rawG.toString() + " " +
rawB.toString() + ")"
- printLine(g, 7, "light@cursor $ccG$lightVal")
+ printLine(g, 8, "light@cursor $ccG$lightVal")
val tileNo: String
val tileNumRaw = Terrarum.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
@@ -122,18 +124,22 @@ class BasicDebugInfoWindow:UICanvas {
val tiledmg = tileNumRaw % PairedMapLayer.RANGE
tileNo = if (tileNumRaw == -1) "—" else "$tilenum:$tiledmg"
- printLine(g, 8, "tile@cursor $ccG$tileNo ($mtX, $mtY)")
+ printLine(g, 9, "tile@cursor $ccG$tileNo ($mtX, $mtY)")
/**
* Second column
*/
printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
- printLineColumn(g, 2, 2, "Env colour temp $ccG" + MapDrawer.getColTemp())
+ printLineColumn(g, 2, 2, "Env colour temp $ccG" + MapDrawer.colTemp)
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame.world.time.elapsedSeconds()}" +
" (${Terrarum.ingame.world.time.getFormattedTime()})")
printLineColumn(g, 2, 6, "Mass $ccG${player.mass}")
+ printLineColumn(g, 2, 7, "p_WalkX $ccG${player.walkX}")
+ printLineColumn(g, 2, 8, "p_WalkY $ccG${player.walkY}")
+
+
drawHistogram(g, LightmapRenderer.histogram,
Terrarum.WIDTH - histogramW - 30,
Terrarum.HEIGHT - histogramH - 30
@@ -220,7 +226,7 @@ class BasicDebugInfoWindow:UICanvas {
private fun line(i: Int): Float = i * 10f
- private fun column(i: Int): Float = 250f * (i - 1)
+ private fun column(i: Int): Float = 300f * (i - 1)
override fun doOpening(gc: GameContainer, delta: Int) {
diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt
index 11badfa5a..d25f7848c 100644
--- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt
+++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt
@@ -13,7 +13,7 @@ import org.newdawn.slick.Input
/**
* Created by minjaesong on 15-12-31.
*/
-class ConsoleWindow : UICanvas, UITypable {
+class ConsoleWindow : UICanvas, KeyboardControlled {
internal var UIColour = Color(0xCC000000.toInt())
diff --git a/src/net/torvald/terrarum/ui/GamepadControlled.kt b/src/net/torvald/terrarum/ui/GamepadControlled.kt
new file mode 100644
index 000000000..1ae4e8030
--- /dev/null
+++ b/src/net/torvald/terrarum/ui/GamepadControlled.kt
@@ -0,0 +1,12 @@
+package net.torvald.terrarum.ui
+
+/**
+ * Button pressing only. If you want stick-controls, use processInput()
+ *
+ * Created by minjaesong on 16-07-21.
+ */
+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/ItemSlotImageBuilder.kt b/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt
index 3f98ad59d..8576315d7 100644
--- a/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt
+++ b/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt
@@ -23,10 +23,16 @@ object ItemSlotImageBuilder {
SpriteSheet("./res/graphics/fonts/numeric_small.png", 5, 8),
'0'
)
- private val slotImage = Image("./res/graphics/gui/quickbar/item_slot.png")
+ 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")
private val canvas = Image(slotImage.width, slotImage.height)
+ private val canvasLarge = Image(slotLarge.width, slotLarge.height)
+
+ val slotImageSize = slotImage.width
fun produce(color: Int, number: Int = -1): Image {
+ canvas.graphics.clear()
+
if (color == COLOR_BLACK)
canvas.graphics.drawImage(slotImage, 0f, 0f, colourBlack)
else if (color == COLOR_WHITE)
@@ -41,12 +47,38 @@ object ItemSlotImageBuilder {
canvas.graphics.color = colourBlack
canvas.graphics.drawString(number.mod(UIQuickBar.SLOT_COUNT).toString(),
- slotImage.width - 6f,
- slotImage.height - 10f
+ slotImage.width - 10f,
+ slotImage.height - 13f
)
}
+
return canvas
}
+ fun produceLarge(color: Int, number: Int = -1): Image {
+ canvasLarge.graphics.clear()
+
+ if (color == COLOR_BLACK)
+ canvasLarge.graphics.drawImage(slotLarge, 0f, 0f, colourBlack)
+ else if (color == COLOR_WHITE)
+ canvasLarge.graphics.drawImage(slotLarge, 0f, 0f, colourWhite)
+
+ if (number >= 0) {
+ canvasLarge.graphics.font = numberFont
+
+ if (color == COLOR_BLACK)
+ canvasLarge.graphics.color = colourWhite
+ else if (color == COLOR_WHITE)
+ canvasLarge.graphics.color = colourBlack
+
+ canvasLarge.graphics.drawString(number.mod(UIQuickBar.SLOT_COUNT).toString(),
+ slotLarge.width - 10f,
+ slotLarge.height - 13f
+ )
+ }
+
+ return canvasLarge
+ }
+
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/ui/UITypable.kt b/src/net/torvald/terrarum/ui/KeyboardControlled.kt
similarity index 83%
rename from src/net/torvald/terrarum/ui/UITypable.kt
rename to src/net/torvald/terrarum/ui/KeyboardControlled.kt
index 6502f0cf0..6de72d6e8 100644
--- a/src/net/torvald/terrarum/ui/UITypable.kt
+++ b/src/net/torvald/terrarum/ui/KeyboardControlled.kt
@@ -3,7 +3,7 @@ package net.torvald.terrarum.ui
/**
* Created by minjaesong on 16-03-06.
*/
-interface UITypable {
+interface KeyboardControlled {
fun keyPressed(key: Int, c: Char)
fun keyReleased(key: Int, c: Char)
diff --git a/src/net/torvald/terrarum/ui/UIClickable.kt b/src/net/torvald/terrarum/ui/MouseControlled.kt
similarity index 69%
rename from src/net/torvald/terrarum/ui/UIClickable.kt
rename to src/net/torvald/terrarum/ui/MouseControlled.kt
index a41040e5c..181d6a3b5 100644
--- a/src/net/torvald/terrarum/ui/UIClickable.kt
+++ b/src/net/torvald/terrarum/ui/MouseControlled.kt
@@ -3,7 +3,7 @@ package net.torvald.terrarum.ui
/**
* Created by minjaesong on 16-03-06.
*/
-interface UIClickable {
+interface MouseControlled {
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
@@ -13,9 +13,4 @@ interface UIClickable {
fun mouseReleased(button: Int, x: Int, y: Int)
fun mouseWheelMoved(change: Int)
-
- 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/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt
index ae112a5ff..fab7feb38 100644
--- a/src/net/torvald/terrarum/ui/UICanvas.kt
+++ b/src/net/torvald/terrarum/ui/UICanvas.kt
@@ -11,14 +11,18 @@ interface UICanvas {
var width: Int
var height: Int
+
+ var handler: UIHandler?
+
/**
* In milliseconds
*/
var openCloseTime: Int
+ /**
+ * Usage: get() = handler!!.openCloseCounter
+ */
var openCloseTimer: Int
- var handler: UIHandler?
-
fun update(gc: GameContainer, delta: Int)
fun render(gc: GameContainer, g: Graphics)
diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt
index 34c5bd79c..3713549d2 100644
--- a/src/net/torvald/terrarum/ui/UIHandler.kt
+++ b/src/net/torvald/terrarum/ui/UIHandler.kt
@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.Terrarum
import com.jme3.math.FastMath
+import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
import org.newdawn.slick.state.StateBasedGame
@@ -44,22 +45,25 @@ constructor(val UI: UICanvas) {
set(value) {
if (alwaysVisible)
throw RuntimeException("[UIHandler] Tried to 'set visibility of' constant UI")
-
- field = value
+ if (value == true) {
+ isOpened = true
+ field = value
+ }
+ else {
+ isOpened = false
+ field = value
+ }
}
var opacity = 1f
var scale = 1f
- var openCloseCounter = 0
+ var openCloseCounter: Int = 0
init {
println("[UIHandler] Creating UI '${UI.javaClass.simpleName}'")
- UIDrawnCanvas = Image(
- //FastMath.nearestPowerOfTwo(UI.width), FastMath.nearestPowerOfTwo(UI.height))
- UI.width, UI.height)
- UIDrawnCanvas.filter = Image.FILTER_LINEAR
+ UIDrawnCanvas = Image(UI.width, UI.height)
UIGraphicInstance = UIDrawnCanvas.graphics
}
@@ -84,6 +88,7 @@ constructor(val UI: UICanvas) {
else {
UI.endOpening(gc, delta)
isOpening = false
+ isClosing = false
isOpened = true
openCloseCounter = 0
}
@@ -101,6 +106,7 @@ constructor(val UI: UICanvas) {
else {
UI.endClosing(gc, delta)
isClosing = false
+ isOpening = false
isOpened = false
isVisible = false
openCloseCounter = 0
@@ -113,8 +119,6 @@ constructor(val UI: UICanvas) {
UIGraphicInstance.clear()
UIGraphicInstance.font = Terrarum.gameFont
- UIGraphicInstance.setAntiAlias(true)
-
UI.render(gc, UIGraphicInstance)
if (sbg.currentStateID == Terrarum.SCENE_ID_GAME) {
ingameGraphics.drawImage(UIDrawnCanvas.getScaledCopy(scale),
@@ -151,39 +155,47 @@ constructor(val UI: UICanvas) {
/**
* Send OPEN signal to the attached UI.
*/
- fun setAsOpening() {
+ fun setAsOpen() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'open' constant UI")
}
- if (!isOpened && !isVisible) {
+ if (!isOpened && !isOpening) {
isOpened = false
isOpening = true
+ isClosing = false
+ isVisible = true
}
}
/**
* Send CLOSE signal to the attached UI.
*/
- fun setAsClosing() {
+ fun setAsClose() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'close' constant UI")
}
- isOpened = false
- isClosing = true
+ if ((isOpening || isOpened) && !isClosing && isVisible) {
+ isOpened = false
+ isClosing = true
+ isOpening = false
+ }
}
+ val isClosed: Boolean
+ get() = !isOpened && !isClosing && !isOpening
+
fun toggleOpening() {
if (alwaysVisible) {
throw RuntimeException("[UIHandler] Tried to 'toggle opening of' constant UI")
}
if (isVisible) {
if (!isClosing) {
- setAsClosing()
+ setAsClose()
}
}
else {
if (!isOpening) {
- setAsOpening()
+ setAsOpen()
}
}
}
@@ -195,55 +207,55 @@ constructor(val UI: UICanvas) {
}
fun keyPressed(key: Int, c: Char) {
- if (isVisible && UI is UITypable) {
+ if (isVisible && UI is KeyboardControlled) {
UI.keyPressed(key, c)
}
}
fun keyReleased(key: Int, c: Char) {
- if (isVisible && UI is UITypable) {
+ if (isVisible && UI is KeyboardControlled) {
UI.keyReleased(key, c)
}
}
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is MouseControlled) {
UI.mouseMoved(oldx, oldy, newx, newy)
}
}
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is MouseControlled) {
UI.mouseDragged(oldx, oldy, newx, newy)
}
}
fun mousePressed(button: Int, x: Int, y: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is MouseControlled) {
UI.mousePressed(button, x, y)
}
}
fun mouseReleased(button: Int, x: Int, y: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is MouseControlled) {
UI.mouseReleased(button, x, y)
}
}
fun mouseWheelMoved(change: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is MouseControlled) {
UI.mouseWheelMoved(change)
}
}
fun controllerButtonPressed(controller: Int, button: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is GamepadControlled) {
UI.controllerButtonPressed(controller, button)
}
}
fun controllerButtonReleased(controller: Int, button: Int) {
- if (isVisible && UI is UIClickable) {
+ if (isVisible && UI is GamepadControlled) {
UI.controllerButtonReleased(controller, button)
}
}
diff --git a/src/net/torvald/terrarum/ui/UIPieMenu.kt b/src/net/torvald/terrarum/ui/UIPieMenu.kt
index 03c241a86..16686eba8 100644
--- a/src/net/torvald/terrarum/ui/UIPieMenu.kt
+++ b/src/net/torvald/terrarum/ui/UIPieMenu.kt
@@ -13,29 +13,31 @@ import org.newdawn.slick.Input
* Created by minjaesong on 16-07-20.
*/
class UIPieMenu : UICanvas {
- private val cellSize = 32
+ private val cellSize = UIQuickBar.CELL_SIZE
private val slotCount = UIQuickBar.SLOT_COUNT
- private val roundRectRadius = 6
+ private val slotDistanceFromCentre = cellSize * 2.7
override var width: Int = cellSize * 7
override var height: Int = width
+
+ override var handler: UIHandler? = null
+
/**
* In milliseconds
*/
override var openCloseTime: Int = 160
override var openCloseTimer: Int = 0
-
- override var handler: UIHandler? = null
+ get() = handler!!.openCloseCounter
private val smallenSize = 0.93f
- var menuSelection: Int = -1
+ var selection: Int = -1
override fun update(gc: GameContainer, delta: Int) {
- if (menuSelection >= 0)
+ if (selection >= 0)
Terrarum.ingame.player.actorValue[AVKey._PLAYER_QUICKBARSEL] =
- menuSelection % quickbarSlots
+ selection % slotCount
}
override fun render(gc: GameContainer, g: Graphics) {
@@ -45,17 +47,19 @@ class UIPieMenu : UICanvas {
for (i in 0..slotCount - 1) {
// set position
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
- val slotCentrePoint = Vector2(0.0, cellSize * 3.0).setDirection(angle) + centrePoint
+ val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre.toDouble()).setDirection(angle) + centrePoint
// draw cells
- g.color = if (menuSelection == i) Color(0xC0C0C0) else Color(0x404040)
- g.drawImage(ItemSlotImageBuilder.produce(
- if (menuSelection == i)
- ItemSlotImageBuilder.COLOR_WHITE
+ val color = if (i == selection)
+ ItemSlotImageBuilder.COLOR_WHITE
+ else
+ ItemSlotImageBuilder.COLOR_BLACK
+
+ g.drawImage(
+ if (i == selection)
+ ItemSlotImageBuilder.produceLarge(color, i + 1)
else
- ItemSlotImageBuilder.COLOR_BLACK,
- i + 1
- ),
+ ItemSlotImageBuilder.produce(color, i + 1),
slotCentrePoint.x.toFloat() - (cellSize / 2f),
slotCentrePoint.y.toFloat() - (cellSize / 2f)
)
@@ -70,38 +74,29 @@ class UIPieMenu : UICanvas {
val centre = Vector2(Terrarum.WIDTH / 2.0, Terrarum.HEIGHT / 2.0)
val deg = (centre - cursorPos).direction.toFloat()
- menuSelection = Math.round(deg * slotCount / FastMath.TWO_PI)
- if (menuSelection < 0) menuSelection += 10
+ selection = Math.round(deg * slotCount / FastMath.TWO_PI)
+ if (selection < 0) selection += 10
+
+ // TODO add gamepad support
}
}
override fun doOpening(gc: GameContainer, delta: Int) {
- if (openCloseTimer < openCloseTime) {
- openCloseTimer += delta
-
- handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
- handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
- }
+ handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
+ handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun doClosing(gc: GameContainer, delta: Int) {
- if (openCloseTimer < openCloseTime) {
- openCloseTimer += delta
- handler!!.isOpened = false
-
- handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
- handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
- }
+ handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
+ handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun endOpening(gc: GameContainer, delta: Int) {
- openCloseTimer = 0
handler!!.opacity = 1f
handler!!.scale = 1f
}
override fun endClosing(gc: GameContainer, delta: Int) {
- openCloseTimer = 0
handler!!.opacity = 0f
handler!!.scale = 1f
}
diff --git a/src/net/torvald/terrarum/ui/UIQuickBar.kt b/src/net/torvald/terrarum/ui/UIQuickBar.kt
index 4cf71897c..19753a635 100644
--- a/src/net/torvald/terrarum/ui/UIQuickBar.kt
+++ b/src/net/torvald/terrarum/ui/UIQuickBar.kt
@@ -1,5 +1,7 @@
package net.torvald.terrarum.ui
+import net.torvald.terrarum.Terrarum
+import net.torvald.terrarum.gameactors.AVKey
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.Input
@@ -7,58 +9,87 @@ import org.newdawn.slick.Input
/**
* Created by minjaesong on 16-07-20.
*/
-class UIQuickBar : UICanvas {
- override var width: Int
- get() = throw UnsupportedOperationException()
- set(value) {
- }
- override var height: Int
- get() = throw UnsupportedOperationException()
- set(value) {
- }
+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
/**
* In milliseconds
*/
- override var openCloseTime: Int
- get() = throw UnsupportedOperationException()
- set(value) {
- }
- override var openCloseTimer: Int
- get() = throw UnsupportedOperationException()
- set(value) {
- }
+ override var openCloseTime: Int = 160
+ override var openCloseTimer: Int = 0
+
+ private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
+ private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2
override var handler: UIHandler? = null
+ private var selection: Int
+ get() = Terrarum.ingame.player.actorValue.getAsInt(AVKey._PLAYER_QUICKBARSEL)!!
+ set(value) { Terrarum.ingame.player.actorValue[AVKey._PLAYER_QUICKBARSEL] = value }
+
override fun update(gc: GameContainer, delta: Int) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun render(gc: GameContainer, g: Graphics) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
+ for (i in 0..SLOT_COUNT - 1) {
+ val color = if (i == selection)
+ ItemSlotImageBuilder.COLOR_WHITE
+ else
+ ItemSlotImageBuilder.COLOR_BLACK
+
+ // draw slots
+ g.drawImage(
+ if (i == selection)
+ ItemSlotImageBuilder.produceLarge(color, i + 1)
+ else
+ ItemSlotImageBuilder.produce(color, i + 1),
+ startPointX + (CELL_SIZE + gutter).times(i).toFloat(),
+ startPointY.toFloat()
+ )
+ // draw items
+
+ }
}
override fun processInput(input: Input) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun doOpening(gc: GameContainer, delta: Int) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
+ handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
}
override fun doClosing(gc: GameContainer, delta: Int) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
+ handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
}
override fun endOpening(gc: GameContainer, delta: Int) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
+ handler!!.opacity = 1f
}
override fun endClosing(gc: GameContainer, delta: Int) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
+ handler!!.opacity = 0f
+ }
+
+ override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
+ }
+
+ override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
+ }
+
+ override fun mousePressed(button: Int, x: Int, y: Int) {
+ }
+
+ override fun mouseReleased(button: Int, x: Int, y: Int) {
+ }
+
+ override fun mouseWheelMoved(change: Int) {
+ selection = selection.plus(if (change > 1) 1 else if (change < -1) -1 else 0).mod(SLOT_COUNT)
+ if (selection < 0) selection += SLOT_COUNT
}
companion object {
const val SLOT_COUNT = 10
+ const val CELL_SIZE = 32
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt
index 5c0b4e3c8..952a48e1e 100644
--- a/src/net/torvald/terrarum/weather/WeatherMixer.kt
+++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt
@@ -2,6 +2,7 @@ package net.torvald.terrarum.weather
import com.jme3.math.FastMath
import net.torvald.JsonFetcher
+import net.torvald.colourutil.ColourUtil
import net.torvald.random.HQRNG
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gamemap.WorldTime
@@ -93,24 +94,47 @@ object WeatherMixer {
Light10B(getGradientColour(currentWeather.globalLightColourMap, 0, timeInSec))
fun getGradientColour(image: Image, row: Int, timeInSec: Int): Color {
- val gradMapWidth = image.width
- val phaseThis = Math.round(
- timeInSec.toFloat() / WorldTime.DAY_LENGTH.toFloat() * gradMapWidth
- )
- val phaseNext = (phaseThis + 1) % WorldTime.DAY_LENGTH
val dataPointDistance = WorldTime.DAY_LENGTH / image.width
+ val phaseThis: Int = timeInSec / dataPointDistance // x-coord in gradmap
+ val phaseNext: Int = (phaseThis + 1) % image.width
+
val colourThis = image.getColor(phaseThis, row)
val colourNext = image.getColor(phaseNext, row)
// interpolate R, G and B
- val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance
- val retColour = Color(0)
- retColour.r = FastMath.interpolateLinear(scale, colourThis.r, colourNext.r)
- retColour.g = FastMath.interpolateLinear(scale, colourThis.g, colourNext.g)
- retColour.b = FastMath.interpolateLinear(scale, colourThis.b, colourNext.b)
+ val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance // [0.0, 1.0]
- return retColour
+ val r = interpolateLinear(scale, colourThis.red, colourNext.red)
+ val g = interpolateLinear(scale, colourThis.green, colourNext.green)
+ val b = interpolateLinear(scale, colourThis.blue, colourNext.blue)
+
+ val newCol = ColourUtil.toSlickColor(r, g, b)
+
+ /* // very nice monitor code
+ // 65 -> 66 | 300 | 19623 | RGB8(255, 0, 255) -[41%]-> RGB8(193, 97, 23) | * `230`40`160`
+ // ^ step |width| time | colour from scale colour to | output
+ if (dataPointDistance == 300)
+ println("$phaseThis -> $phaseNext | $dataPointDistance | $timeInSec" +
+ " | ${colourThis.toStringRGB()} -[${scale.times(100).toInt()}%]-> ${colourNext.toStringRGB()}" +
+ " | * `$r`$g`$b`")*/
+
+ return newCol
+ }
+
+ fun Color.toStringRGB() = "RGB8(${this.red}, ${this.green}, ${this.blue})"
+
+ fun interpolateLinear(scale: Float, startValue: Int, endValue: Int): Int {
+ if (startValue == endValue) {
+ return startValue
+ }
+ if (scale <= 0f) {
+ return startValue
+ }
+ if (scale >= 1f) {
+ return endValue
+ }
+ return Math.round((1f - scale) * startValue + scale * endValue)
}
fun getWeatherList(classification: String) = weatherList[classification]!!
diff --git a/work_files/graphics/weathers/.gitattributes b/work_files/graphics/weathers/.gitattributes
new file mode 100644
index 000000000..ca82ef549
--- /dev/null
+++ b/work_files/graphics/weathers/.gitattributes
@@ -0,0 +1 @@
+*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text
\ No newline at end of file