From 94f12b56763ff29e132ab5393edbced8a58a693a Mon Sep 17 00:00:00 2001 From: dalyjame Date: Tue, 13 Aug 2019 11:07:32 -0400 Subject: [PATCH] Added NPCs that the hero can collide with and started planning on how to make them scriptable --- FakeMon/src/fmon/draw/CharSet.scala | 4 ++-- FakeMon/src/fmon/script/Action.scala | 5 ++++ FakeMon/src/fmon/script/Condition.scala | 5 ++++ .../fmon/script/condition/AndCondition.scala | 7 ++++++ .../fmon/script/condition/OrCondition.scala | 7 ++++++ FakeMon/src/fmon/world/EventPage.scala | 23 +++++++++++++++++++ FakeMon/src/fmon/world/GameEvent.scala | 6 +++++ FakeMon/src/fmon/world/ui/GameView.scala | 19 ++++++++++++++- 8 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 FakeMon/src/fmon/script/Action.scala create mode 100644 FakeMon/src/fmon/script/Condition.scala create mode 100644 FakeMon/src/fmon/script/condition/AndCondition.scala create mode 100644 FakeMon/src/fmon/script/condition/OrCondition.scala create mode 100644 FakeMon/src/fmon/world/EventPage.scala create mode 100644 FakeMon/src/fmon/world/GameEvent.scala diff --git a/FakeMon/src/fmon/draw/CharSet.scala b/FakeMon/src/fmon/draw/CharSet.scala index 4a745d2..b3dcc59 100644 --- a/FakeMon/src/fmon/draw/CharSet.scala +++ b/FakeMon/src/fmon/draw/CharSet.scala @@ -14,9 +14,9 @@ object CharSet { val palette = new Palette(new FileInputStream(file), na, nd) val x = index % NumAcross val y = index / NumAcross - val xx = x * NumAcross + val xx = x * FramesPerPose + 1 def pose(i: Int): AnimatedImage = { - val yy = y * NumDown + i + val yy = y * Poses.size + i val images = IndexedSeq(palette(xx, yy), palette(xx - 1, yy), palette(xx, yy), palette(xx + 1, yy)) new AnimatedImage(images) } diff --git a/FakeMon/src/fmon/script/Action.scala b/FakeMon/src/fmon/script/Action.scala new file mode 100644 index 0000000..81053b3 --- /dev/null +++ b/FakeMon/src/fmon/script/Action.scala @@ -0,0 +1,5 @@ +package fmon.script + +trait Action[A] { + def apply(env: A): Unit +} \ No newline at end of file diff --git a/FakeMon/src/fmon/script/Condition.scala b/FakeMon/src/fmon/script/Condition.scala new file mode 100644 index 0000000..b5089eb --- /dev/null +++ b/FakeMon/src/fmon/script/Condition.scala @@ -0,0 +1,5 @@ +package fmon.script + +trait Condition[A] { + def apply(t: A): Boolean +} \ No newline at end of file diff --git a/FakeMon/src/fmon/script/condition/AndCondition.scala b/FakeMon/src/fmon/script/condition/AndCondition.scala new file mode 100644 index 0000000..4a1e034 --- /dev/null +++ b/FakeMon/src/fmon/script/condition/AndCondition.scala @@ -0,0 +1,7 @@ +package fmon.script.condition + +import fmon.script.Condition + +class AndCondition[A](seq: Seq[Condition[A]]) extends Condition[A] { + def apply(env: A): Boolean = seq.forall(_(env)) +} \ No newline at end of file diff --git a/FakeMon/src/fmon/script/condition/OrCondition.scala b/FakeMon/src/fmon/script/condition/OrCondition.scala new file mode 100644 index 0000000..35ac20e --- /dev/null +++ b/FakeMon/src/fmon/script/condition/OrCondition.scala @@ -0,0 +1,7 @@ +package fmon.script.condition + +import fmon.script.Condition + +class OrCondition[A](seq: Seq[Condition[A]]) extends Condition[A] { + def apply(env: A): Boolean = seq.exists(_(env)) +} \ No newline at end of file diff --git a/FakeMon/src/fmon/world/EventPage.scala b/FakeMon/src/fmon/world/EventPage.scala new file mode 100644 index 0000000..ee240b6 --- /dev/null +++ b/FakeMon/src/fmon/world/EventPage.scala @@ -0,0 +1,23 @@ +package fmon.world + +class EventPage { + // Conditions + // Switch + // Variable + // Self-Switch + // Item + // Actor + // Graphic + // Priority - Above or below + // Trigger - Action button / On contact + // Movement + // Type + // Speed + // Frequency + // Options + // Walking Animation + // Stepping Animation + // Direction Fix + // Pass through (no-collide) + // Contents (event effects) +} \ No newline at end of file diff --git a/FakeMon/src/fmon/world/GameEvent.scala b/FakeMon/src/fmon/world/GameEvent.scala new file mode 100644 index 0000000..e13ec78 --- /dev/null +++ b/FakeMon/src/fmon/world/GameEvent.scala @@ -0,0 +1,6 @@ +package fmon.world + +class GameEvent(val name: String, val pages: IndexedSeq[EventPage]) { + // Event Name + // Event Pages +} \ No newline at end of file diff --git a/FakeMon/src/fmon/world/ui/GameView.scala b/FakeMon/src/fmon/world/ui/GameView.scala index 3471e8b..6749640 100644 --- a/FakeMon/src/fmon/world/ui/GameView.scala +++ b/FakeMon/src/fmon/world/ui/GameView.scala @@ -39,6 +39,9 @@ class GameView { @FXML var characterPane: jfxsl.AnchorPane = _ var hero: Actor = _ + var npcs = Seq[Actor]() + def actors = hero +: npcs + var heroImg: AnimatedImageView = _ var currDir: Option[Direction] = None @@ -74,7 +77,18 @@ class GameView { x = hero.x * Config.tileSize y = hero.y * Config.tileSize + Config.yOffset } + + npcs = (0 until 8).map(i => + new Actor(CharSet(new File(heroFile), i), Position(7 + i, 4), new Movement(Direction.Stationary, 0.0)) + ) + characterPane.children += heroImg + val npcImgs = npcs.map(npc => new AnimatedImageView(npc.sprite, new Duration(600)) { + x = npc.x * Config.tileSize + y = npc.y * Config.tileSize + Config.yOffset + }) + npcImgs.foreach(characterPane.children += _) + timer.start() } @@ -124,10 +138,13 @@ class GameView { if (hero.pose != dir.toString()) { hero.pose = dir.toString() } else { + val dest = hero.pos + dir val info = level.compositeInfo(hero.pos + dir) val canPass = (dir.x < 0 && info.doesPassEast) || (dir.x > 0 && info.doesPassWest) || (dir.y < 0 && info.doesPassSouth) || (dir.y > 0 && info.doesPassNorth) - if (canPass) { + val unoccupied = !actors.exists(a => a.pos == dest && a != hero) + + if (canPass && unoccupied) { hero.pos += dir hero.move = new Movement(dir, 1.0) }