Fixed the animations to occur sequentially rather than all at once
This commit is contained in:
parent
e008892c13
commit
11b03b02d2
@ -29,8 +29,8 @@ class Game extends Application {
|
|||||||
implicit val rng = new scala.util.Random()
|
implicit val rng = new scala.util.Random()
|
||||||
val form1 = Form("Diabolo")
|
val form1 = Form("Diabolo")
|
||||||
val form2 = Form("Chanilla")
|
val form2 = Form("Chanilla")
|
||||||
val movepool1 = IndexedSeq(Move("eruption"), Move("willowisp"), Move("thunderbolt"), Move("thunderwave"), Move("blastburn"))
|
val movepool1 = IndexedSeq(Move("eruption"), Move("willowisp"), Move("thunderbolt"), Move("thunderwave"), Move("thundershock"))
|
||||||
val movepool2 = IndexedSeq(Move("razorwind"))
|
val movepool2 = IndexedSeq(Move("tackle"))
|
||||||
val p1 = TrainerID("Jaeda", Gender.Female, 0)
|
val p1 = TrainerID("Jaeda", Gender.Female, 0)
|
||||||
val p2 = TrainerID("Wild Monster", Gender.Male, 0)
|
val p2 = TrainerID("Wild Monster", Gender.Male, 0)
|
||||||
val party1 = new Party(p1, new MonsterPtr(Monster.generate("Allied Mon", p1, 500, form1, movepool1)), IndexedSeq())
|
val party1 = new Party(p1, new MonsterPtr(Monster.generate("Allied Mon", p1, 500, form1, movepool1)), IndexedSeq())
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package fmon.battle
|
package fmon.battle
|
||||||
|
|
||||||
|
import java.util.concurrent.locks.{Condition, ReentrantLock}
|
||||||
|
|
||||||
|
import javafx.application.Platform
|
||||||
import javafx.fxml.FXML
|
import javafx.fxml.FXML
|
||||||
import javafx.fxml.FXMLLoader
|
import javafx.fxml.FXMLLoader
|
||||||
import javafx.fxml.JavaFXBuilderFactory
|
import javafx.fxml.JavaFXBuilderFactory
|
||||||
@ -8,6 +11,7 @@ import javafx.scene.image.ImageView
|
|||||||
|
|
||||||
import scalafx.Includes._
|
import scalafx.Includes._
|
||||||
import scalafx.animation._
|
import scalafx.animation._
|
||||||
|
import scalafx.concurrent.Task
|
||||||
import scalafx.geometry.{Point2D, Pos}
|
import scalafx.geometry.{Point2D, Pos}
|
||||||
import scalafx.scene.{Group, Parent}
|
import scalafx.scene.{Group, Parent}
|
||||||
import scalafx.scene.control._
|
import scalafx.scene.control._
|
||||||
@ -36,6 +40,10 @@ class BattleUI extends SignalConsumer {
|
|||||||
|
|
||||||
private var engine: BattleEngine = _
|
private var engine: BattleEngine = _
|
||||||
|
|
||||||
|
private var numPlaying = 0
|
||||||
|
private val lock = new ReentrantLock()
|
||||||
|
private val finishedPlaying = lock.newCondition()
|
||||||
|
|
||||||
def setEngine(engine: BattleEngine): Unit = {
|
def setEngine(engine: BattleEngine): Unit = {
|
||||||
this.engine = engine
|
this.engine = engine
|
||||||
updateUI()
|
updateUI()
|
||||||
@ -51,22 +59,43 @@ class BattleUI extends SignalConsumer {
|
|||||||
enemyMonController.update(enemy)
|
enemyMonController.update(enemy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def requestUpdateUI(): Unit = {
|
||||||
|
val task = Task(updateUI)
|
||||||
|
Platform.runLater(task)
|
||||||
|
}
|
||||||
|
|
||||||
def onMove(move: Move): Unit = {
|
def onMove(move: Move): Unit = {
|
||||||
implicit val rng = engine.rng
|
implicit val rng = engine.rng
|
||||||
implicit val reader = engine
|
implicit val reader = engine
|
||||||
val action = Action(engine.player.lead, move, engine.player.pollTarget(move, engine.player.lead, engine.enemy))
|
val action = Action(engine.player.lead, move, engine.player.pollTarget(move, engine.player.lead, engine.enemy))
|
||||||
engine.playTurn(action)
|
val task = Task(engine.playTurn(action))
|
||||||
updateUI()
|
val thread = new Thread(task)
|
||||||
|
thread.setDaemon(true)
|
||||||
|
thread.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
def !(msg: Signal): Unit = {
|
def !(msg: Signal): Unit = {
|
||||||
|
lock.lock()
|
||||||
|
try {
|
||||||
msg match {
|
msg match {
|
||||||
case Message(text) => messages.text = s"${messages.text()}${text}\n"
|
case Message(text) => messages.text = s"${messages.text()}${text}\n"
|
||||||
case DamageMsg(dmg, target, element) => playDamage(dmg, target, element)
|
case DamageMsg(dmg, target, element) => playDamage(dmg, target, element)
|
||||||
}
|
}
|
||||||
|
while (numPlaying > 0) {
|
||||||
|
finishedPlaying.await()
|
||||||
|
}
|
||||||
|
requestUpdateUI()
|
||||||
|
} catch {
|
||||||
|
case e: Exception => e.printStackTrace()
|
||||||
|
} finally {
|
||||||
|
lock.unlock()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def playDamage(damage: Int, target: Monster, element: Element): Unit = {
|
private def playDamage(damage: Int, target: Monster, element: Element): Unit = {
|
||||||
|
numPlaying += 1
|
||||||
|
def helper = {
|
||||||
val r = 25
|
val r = 25
|
||||||
val color = Color.AliceBlue
|
val color = Color.AliceBlue
|
||||||
val center = findCenter(target)
|
val center = findCenter(target)
|
||||||
@ -106,10 +135,25 @@ class BattleUI extends SignalConsumer {
|
|||||||
))
|
))
|
||||||
animation.onFinished = handle{
|
animation.onFinished = handle{
|
||||||
animationPane.children -= group
|
animationPane.children -= group
|
||||||
|
finishPlay()
|
||||||
}
|
}
|
||||||
animation.play()
|
animation.play()
|
||||||
animationPane.children += group
|
animationPane.children += group
|
||||||
}
|
}
|
||||||
|
val task = Task(helper)
|
||||||
|
Platform.runLater(task)
|
||||||
|
}
|
||||||
|
|
||||||
|
private def finishPlay(): Unit = {
|
||||||
|
lock.lock()
|
||||||
|
try {
|
||||||
|
numPlaying -= 1
|
||||||
|
updateUI()
|
||||||
|
finishedPlaying.signal()
|
||||||
|
} finally {
|
||||||
|
lock.unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def findCenter(monster: Monster): Point2D = {
|
private def findCenter(monster: Monster): Point2D = {
|
||||||
if (monster == engine.player.lead.mon) {
|
if (monster == engine.player.lead.mon) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user