Permalink
Browse files

Added initial design for a state machine handling the games various s…

…tates.
  • Loading branch information...
fversnel committed May 8, 2012
1 parent 75a7e25 commit ff9f06c380e98ecd6e2a13bc6b717d6d60f2ee53
@@ -0,0 +1,16 @@
+Implement a state machine to provide:
+ - Time-based updates bringing new gates and sheperds to the battlefield.
+ - Transition between game-over and playing states.
+
+PoortjesState
+ state: GameOver
+ - press start to go to 'Playing' state
+
+ transition: GameOver -> Playing
+ - reset entities to starting position
+
+ state: Playing
+ - recognize when to go to GameOver state
+ - occasionally spawn new game objects
+
+ state: Spawning
@@ -0,0 +1,30 @@
+package org.frankversnel.poortjes.game
+
+import org.slf4j.scala.Logging;
+
+import org.frankversnel.poortjes.Update
+import org.frankversnel.poortjes.Component
+import org.frankversnel.poortjes.game.gameobjects.Player
+
+class GameStateMachine extends Component with Logging {
+ case class GameState
+ case object Playing extends GameState
+ case object GameOver extends GameState
+
+ private var currentState: GameState = Playing
+
+ override def process(update: Update) {
+ currentState match {
+ case Playing =>
+ val noPlayersLeft = update.gameObjects.filter(_.is[Player]).isEmpty
+ if(noPlayersLeft) {
+ currentState = GameOver
+ }
+ case GameOver =>
+ logger.info("game over")
+ currentState = Playing
+ // Wait for start button to be pressed
+ }
+
+ }
+}
@@ -26,6 +26,7 @@ class Poortjes extends PApplet with Logging {
val resourceLoader = new ProcessingShapeLoader(this)
val renderer = new Processing2DRenderer(g, resourceLoader, backgroundClr)
EntityManager.initialize(renderer)
+ EntityManager().spawn(new GameStateMachine)
val newPlayer = new Player(resourceLoader) with Keyboard {
val keybindings = KeyboardBindings('w', 's', 'a', 'd')

0 comments on commit ff9f06c

Please sign in to comment.