vital metre prototype

Former-commit-id: c3f95f7ef280eabc5516ad6885386cb89d6ee35d
Former-commit-id: ab9cd5bd8daf27d37828a5ca4a737a723d76fa1a
This commit is contained in:
Song Minjae
2017-03-04 01:52:30 +09:00
parent 50da7db1ee
commit 97df2ad6e4
10 changed files with 155 additions and 13 deletions

View File

@@ -175,6 +175,14 @@ class StateInGame : BasicGameState() {
// audio test
//AudioResourceLibrary.ambientsWoods[0].play()
val vitalmetre = UIHandler(UIVitalMetre(player, { 100f }, { 100f }, Color(255, 182, 0)))
//vitalmetre.setAsAlwaysVisible()
vitalmetre.isVisible = true
vitalmetre.UI.handler = vitalmetre
uiContainer.add(vitalmetre)
}
var particlesActive = 0

View File

@@ -581,7 +581,7 @@ infix fun Color.screen(other: Color) = Color(
1f - (1f - this.a) * (1f - other.a)
)
infix fun Color.mul(other: Color) = Color(
operator fun Color.times(other: Color) = Color(
this.r * other.r,
this.g * other.g,
this.b * other.b,

View File

@@ -44,10 +44,14 @@ open class ActorWithSprite(renderOrder: ActorOrder, val immobileBody: Boolean =
@Transient private val world: GameWorld = Terrarum.ingame.world
protected var hitboxTranslateX: Double = 0.0// relative to spritePosX
protected var hitboxTranslateY: Double = 0.0// relative to spritePosY
protected var baseHitboxW: Int = 0
protected var baseHitboxH: Int = 0
var hitboxTranslateX: Double = 0.0// relative to spritePosX
protected set
var hitboxTranslateY: Double = 0.0// relative to spritePosY
protected set
var baseHitboxW: Int = 0
protected set
var baseHitboxH: Int = 0
protected set
/**
* * Position: top-left point
* * Unit: pixel

View File

@@ -49,6 +49,28 @@ interface UICanvas {
* Do not modify handler!!.openCloseCounter here.
*/
fun endClosing(gc: GameContainer, delta: Int)
}
const val OPENCLOSE_GENERIC = 200
companion object {
const val OPENCLOSE_GENERIC = 200
fun doOpeningFade(handler: UIHandler?, openCloseTime: Int) {
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
}
fun doClosingFade(handler: UIHandler?, openCloseTime: Int) {
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
}
fun endOpeningFade(handler: UIHandler?) {
handler!!.opacity = 1f
}
fun endClosingFade(handler: UIHandler?) {
handler!!.opacity = 0f
}
// TODO add drawer slide in/out (quadratic)
// TODO add blackboard take in/out (sinusoidal)
}
}

View File

@@ -133,8 +133,8 @@ constructor(val UI: UICanvas) {
}
fun setAsAlwaysVisible() {
alwaysVisible = true
isVisible = true
alwaysVisible = true
isOpened = true
isOpening = false
isClosing = false

View File

@@ -82,22 +82,22 @@ class UIPieMenu : UICanvas {
}
override fun doOpening(gc: GameContainer, delta: Int) {
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
UICanvas.doOpeningFade(handler, openCloseTime)
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun doClosing(gc: GameContainer, delta: Int) {
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
UICanvas.doClosingFade(handler, openCloseTime)
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun endOpening(gc: GameContainer, delta: Int) {
handler!!.opacity = 1f
UICanvas.endOpeningFade(handler)
handler!!.scale = 1f
}
override fun endClosing(gc: GameContainer, delta: Int) {
handler!!.opacity = 0f
UICanvas.endClosingFade(handler)
handler!!.scale = 1f
}
}

View File

@@ -0,0 +1,107 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.floorInt
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.times
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.Input
/**
* Created by SKYHi14 on 2017-03-03.
*/
class UIVitalMetre(
var player: ActorHumanoid,
val vitalGetterVal: () -> Float,
val vitalGetterMax: () -> Float,
val color: Color,
val order: Int = 0
) : UICanvas {
override var width: Int = 84
override var height: Int = player.baseHitboxH * 3 + 2
override var handler: UIHandler? = null
override var openCloseTime: Int = 50
private val relativePX = width / 2f
private val relativePY = player.baseHitboxH * 1.5f
private val circleRadius = player.baseHitboxH * 3f
private val theta = 33f
private val halfTheta = theta / 2f
override fun update(gc: GameContainer, delta: Int) {
handler!!.setPosition(
(Terrarum.HALFW - relativePX).roundInt(),
(Terrarum.HALFH - relativePY).floorInt()
)
}
override fun render(gc: GameContainer, g: Graphics) {
g.lineWidth = 1.8f
val saturation = 2f
// background
g.color = Color(
(color.r * saturation) - (saturation - 1),
(color.g * saturation) - (saturation - 1),
(color.b * saturation) - (saturation - 1),
0.9f
)
g.drawArc(
relativePX - circleRadius,
-circleRadius,
circleRadius * 2f,
circleRadius * 2f,
90f - halfTheta,
90f + halfTheta
)
g.color = color
g.drawArc(
relativePX - circleRadius,
-circleRadius,
circleRadius * 2f,
circleRadius * 2f,
90f + halfTheta - theta * (vitalGetterVal() / vitalGetterMax()),
90f + halfTheta
)
}
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}
override fun doOpening(gc: GameContainer, delta: Int) {
UICanvas.doOpeningFade(handler, openCloseTime)
}
override fun doClosing(gc: GameContainer, delta: Int) {
UICanvas.doClosingFade(handler, openCloseTime)
}
override fun endOpening(gc: GameContainer, delta: Int) {
UICanvas.endOpeningFade(handler)
}
override fun endClosing(gc: GameContainer, delta: Int) {
UICanvas.endClosingFade(handler)
}
}
/*
X-------------+ (84)
| |
| |
| @ |
| @ |
|, ,|
| ''-------'' |
+-------------+
X: UICanvas position
*/

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.virtualcomputer.worldobject.ui
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas.Companion.OPENCLOSE_GENERIC
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics

View File

@@ -133,7 +133,7 @@ object WeatherMixer {
fun Float.clampOne() = if (this > 1) 1f else this
operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f)
private operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f)
/**
* Get a GL of specific time

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 234 KiB