A bunch of stuff from a long while ago that I forgot to commit.
This commit is contained in:
parent
f7747346d7
commit
344f71192f
@ -20,6 +20,7 @@ object Game {
|
||||
|
||||
class Game extends Application {
|
||||
override def start(primaryStage: Stage): Unit = {
|
||||
/*
|
||||
val url = getClass.getResource("battle/battle.fxml")
|
||||
val loader = new FXMLLoader(url)
|
||||
val root: Parent = loader.load()
|
||||
@ -43,5 +44,6 @@ class Game extends Application {
|
||||
primaryStage.setTitle(Config.title)
|
||||
primaryStage.setScene(scene)
|
||||
primaryStage.show()
|
||||
*/
|
||||
}
|
||||
}
|
31
FakeMon/src/fmon/GameManager.scala
Normal file
31
FakeMon/src/fmon/GameManager.scala
Normal file
@ -0,0 +1,31 @@
|
||||
package fmon
|
||||
|
||||
import scalafx.scene.Scene
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.scene.Node
|
||||
import scalafx.scene.Parent
|
||||
import scalafx.stage.Stage
|
||||
|
||||
import fmon.world.ui.GameView
|
||||
|
||||
object GameManager {
|
||||
var currLevel: Parent = _
|
||||
var currController: GameView = _
|
||||
|
||||
var currView: Parent = _
|
||||
|
||||
var root: Stage = _
|
||||
|
||||
def setView(view: Parent): Unit = {
|
||||
currController.timer.stop()
|
||||
currView = view
|
||||
root.scene().root = view
|
||||
}
|
||||
|
||||
def restoreMap(): Unit = {
|
||||
currView = currLevel
|
||||
root.scene().root = currView
|
||||
currController.timer.start()
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package fmon.battle
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon._
|
||||
import fmon.battle.msg._
|
||||
import fmon.stat._
|
||||
import fmon.stat.Statistic._
|
||||
@ -39,10 +40,11 @@ class BattleEngine(val player: Party, val enemy: Party)(implicit val reader: Sig
|
||||
|
||||
if (!player.lead.isAlive) {
|
||||
if (player.canFight) {
|
||||
val replace = player.pollReplacement(enemy)
|
||||
player.switchIn(replace)
|
||||
val replace = player.pollReplacement(enemy)
|
||||
player.switchIn(replace)
|
||||
} else {
|
||||
this ! Message(s"${player.trainer} has lost!")
|
||||
GameManager.restoreMap()
|
||||
}
|
||||
}
|
||||
if (!enemy.lead.isAlive) {
|
||||
@ -51,6 +53,7 @@ class BattleEngine(val player: Party, val enemy: Party)(implicit val reader: Sig
|
||||
enemy.switchIn(replace)
|
||||
} else {
|
||||
this ! Message(s"${enemy.trainer} has lost!")
|
||||
GameManager.restoreMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,16 @@ package fmon.battle
|
||||
import java.io._
|
||||
import java.util.concurrent.locks.{Condition, ReentrantLock}
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import javafx.application.Application
|
||||
import javafx.application.Platform
|
||||
import javafx.fxml.FXML
|
||||
import javafx.fxml.FXMLLoader
|
||||
import javafx.fxml.JavaFXBuilderFactory
|
||||
import javafx.scene.{control => jfxsc}
|
||||
import javafx.scene.image.ImageView
|
||||
import javafx.stage.Stage
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.animation._
|
||||
@ -23,6 +27,7 @@ import scalafx.scene.text.Font
|
||||
import scalafx.scene.transform.Rotate
|
||||
import scalafx.util.Duration
|
||||
|
||||
import fmon.GameManager
|
||||
import fmon.battle.msg._
|
||||
import fmon.draw._
|
||||
import fmon.stat._
|
||||
@ -46,7 +51,24 @@ class BattleUI extends SignalConsumer {
|
||||
private val lock = new ReentrantLock()
|
||||
private val finishedPlaying = lock.newCondition()
|
||||
|
||||
def beginWildBattle(player: Party, wild: Monster)(implicit rng: Random) {
|
||||
implicit val consumer = this
|
||||
setEngine(new BattleEngine(
|
||||
player,
|
||||
new Party(BattleUI.WildTrainer, new MonsterPtr(wild), IndexedSeq())
|
||||
))
|
||||
this ! Message(s"A wild ${wild.name} appeared!")
|
||||
}
|
||||
|
||||
def beginTrainerBattle(player: Party, trainer: Party)(implicit rng: Random) {
|
||||
implicit val consumer = this
|
||||
setEngine(new BattleEngine(player, trainer))
|
||||
this ! Message(s"${trainer.trainer} wants to fight!")
|
||||
this ! Message(s"${trainer.trainer} sent out ${trainer.lead}")
|
||||
}
|
||||
|
||||
def setEngine(engine: BattleEngine): Unit = {
|
||||
messages.clear()
|
||||
this.engine = engine
|
||||
updateUI()
|
||||
}
|
||||
@ -204,4 +226,62 @@ class BattleUI extends SignalConsumer {
|
||||
controller.setup(move, onMove)
|
||||
button
|
||||
}
|
||||
}
|
||||
|
||||
import javafx.scene.Scene
|
||||
|
||||
import fmon.Config
|
||||
import fmon.stat.Gender
|
||||
|
||||
object BattleUI {
|
||||
final val WildTrainer = TrainerID("Wild", Gender.Neuter, 0)
|
||||
|
||||
def startWildBattle(): Unit = {
|
||||
val url = getClass.getResource("battle.fxml")
|
||||
val loader = new FXMLLoader(url)
|
||||
val root: javafx.scene.Parent = loader.load()
|
||||
implicit val controller = loader.getController[BattleUI]()
|
||||
|
||||
implicit val rng = new scala.util.Random()
|
||||
val form1 = Form("Diabolo")
|
||||
val form2 = Form("Chanilla")
|
||||
val movepool1 = IndexedSeq(Move("eruption"), Move("willowisp"), Move("thunderbolt"), Move("thunderwave"), Move("thundershock"))
|
||||
val movepool2 = IndexedSeq(Move("tackle"))
|
||||
val p1 = TrainerID("Jaeda", Gender.Female, 0)
|
||||
val party1 = new Party(p1, new MonsterPtr(Monster.generate("Allied Mon", p1, 500, form1, movepool1)), IndexedSeq())
|
||||
val monster = Monster.generate(null, WildTrainer, 500, form2, movepool2)
|
||||
controller.beginWildBattle(party1, monster)
|
||||
GameManager.setView(root)
|
||||
}
|
||||
|
||||
class GameApp extends Application {
|
||||
override def start(primaryStage: Stage): Unit = {
|
||||
val url = getClass.getResource("battle.fxml")
|
||||
val loader = new FXMLLoader(url)
|
||||
val root: javafx.scene.Parent = loader.load()
|
||||
implicit val controller = loader.getController[BattleUI]()
|
||||
val scene: Scene = new Scene(root)
|
||||
|
||||
implicit val rng = new scala.util.Random()
|
||||
val form1 = Form("Diabolo")
|
||||
val form2 = Form("Chanilla")
|
||||
val movepool1 = IndexedSeq(Move("eruption"), Move("willowisp"), Move("thunderbolt"), Move("thunderwave"), Move("thundershock"))
|
||||
val movepool2 = IndexedSeq(Move("tackle"))
|
||||
val p1 = TrainerID("Jaeda", Gender.Female, 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 party2 = new Party(p2, new MonsterPtr(Monster.generate("Wild Mon", p2, 500, form2, movepool2)), IndexedSeq(
|
||||
Monster.generate("Sideboard Mon", p2, 500, form2, movepool2)
|
||||
))
|
||||
controller.beginTrainerBattle(party1, party2)
|
||||
|
||||
primaryStage.setTitle(Config.title)
|
||||
primaryStage.setScene(scene)
|
||||
primaryStage.show()
|
||||
}
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
Application.launch(classOf[GameApp], args: _*)
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.battle.BattleUI">
|
||||
<VBox prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.battle.BattleUI">
|
||||
<children>
|
||||
<MenuBar VBox.vgrow="NEVER">
|
||||
<menus>
|
||||
@ -53,7 +53,7 @@
|
||||
</Menu>
|
||||
</menus>
|
||||
</MenuBar>
|
||||
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
|
||||
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" VBox.vgrow="ALWAYS">
|
||||
<children>
|
||||
<ImageView fx:id="backgroundImg" fitHeight="575.0" fitWidth="856.0" pickOnBounds="true">
|
||||
<image>
|
||||
|
@ -2,15 +2,18 @@ package fmon.stat
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon._
|
||||
|
||||
case class Gene(val gender : Gender, val nature : Nature, val ivs : Map[Stat, Int], ot : TrainerID) {
|
||||
|
||||
}
|
||||
|
||||
object Gene {
|
||||
final val MaxIV = 31
|
||||
def randomGene(ot : TrainerID, form : Form)(implicit rng : Random) = {
|
||||
|
||||
def randomGene(ot : TrainerID, form : Form)(implicit rng : Random): Gene = {
|
||||
val gender = Gender.Neuter // TODO
|
||||
val ivs = Statistic.values.map(s => (s, rng.nextInt(MaxIV + 1))).toMap
|
||||
val ivs = Statistic.values.toSeq.map(s => (s, rng.nextInt(MaxIV + 1))).toMap
|
||||
Gene(gender, Nature.randomNature, ivs, ot)
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<?import javafx.scene.layout.StackPane?>
|
||||
<?import javafx.scene.layout.TilePane?>
|
||||
|
||||
<ScrollPane fx:id="scroller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#onKeyDown" onKeyReleased="#onKeyUp" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.world.ui.GameView">
|
||||
<ScrollPane fx:id="scroller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#onKeyDown" onKeyReleased="#onKeyUp" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.world.ui.GameView">
|
||||
<content>
|
||||
<StackPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
|
||||
<children>
|
||||
|
@ -26,6 +26,7 @@ import scalafx.util.Duration
|
||||
import FileChooser.ExtensionFilter
|
||||
|
||||
import fmon._
|
||||
import fmon.battle.BattleUI
|
||||
import fmon.draw._
|
||||
import fmon.script.action.MessageAction
|
||||
import fmon.util.Direction
|
||||
@ -98,6 +99,7 @@ class GameView {
|
||||
case KeyCode.A | KeyCode.Left => setDir(West)
|
||||
case KeyCode.S | KeyCode.Down => setDir(South)
|
||||
case KeyCode.Space => activate()
|
||||
case KeyCode.BackQuote => beginWildBattle()
|
||||
case _ => ()
|
||||
}
|
||||
}
|
||||
@ -112,6 +114,10 @@ class GameView {
|
||||
}
|
||||
}
|
||||
|
||||
def beginWildBattle(): Unit = {
|
||||
BattleUI.startWildBattle()
|
||||
}
|
||||
|
||||
def activate(): Unit = {
|
||||
if (hero.move.direction == Direction.Stationary) {
|
||||
val dir = Direction.byName(hero.sprite.pose)
|
||||
@ -281,19 +287,20 @@ object GameView {
|
||||
val stageFile = Config.homedir + raw"Progena\Data\outside.map"
|
||||
val level = GameMap.loadFrom(new File(stageFile))
|
||||
controller.loadLevel(level)
|
||||
//val builderLoader = new FXMLLoader(getClass.getResource("ElementBuilder.fxml"))
|
||||
//val builder: Parent = builderLoader.load()
|
||||
//val builderController = builderLoader.getController[ElementBuilder]()
|
||||
|
||||
//controller.pane.children = builder
|
||||
//controller.builder = builderController
|
||||
|
||||
val scene: Scene = new Scene(root)
|
||||
|
||||
GameManager.root = primaryStage
|
||||
GameManager.currLevel = root
|
||||
GameManager.currController = controller
|
||||
GameManager.currView = root
|
||||
|
||||
primaryStage.setScene(scene)
|
||||
primaryStage.width = 1280
|
||||
primaryStage.height = 800
|
||||
//primaryStage.maximized = true
|
||||
primaryStage.show()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user