From a88b9723b25d09548416a9ee76fb74845c40e71e Mon Sep 17 00:00:00 2001 From: Susan Yuen <susan_loves_cheese@hotmail.com> Date: Wed, 2 Nov 2016 01:22:17 -0400 Subject: [PATCH] ANIMATING WORKS!! Game class is now a singleton --- src/Blaze-Brigade/Blaze_Brigade/Game.cs | 9 ++++++++ .../Blaze_Brigade/MouseHandler.cs | 23 +++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Blaze-Brigade/Blaze_Brigade/Game.cs b/src/Blaze-Brigade/Blaze_Brigade/Game.cs index 1c81fe9..c022ec8 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Game.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Game.cs @@ -26,6 +26,13 @@ namespace Controller #region Variables + static Game instance; + + public static Game Instance + { + get { return instance; } + } + GameMenuState currentGameState = GameMenuState.MainMenu; // game starts in main menu screen MainMenu mMenu; // main menu variable HowToPlay tut; // instruction screen variable @@ -44,6 +51,8 @@ namespace Controller // constructor for game public Game() { + instance = this; + graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = GameState.SCREEN_HEIGHT; graphics.PreferredBackBufferHeight = GameState.SCREEN_WIDTH; diff --git a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs index 2ed06be..46b56e0 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs @@ -64,7 +64,11 @@ namespace Controller // if user clicks on a valid end node, move to it if (turnState == TurnState.Move) { - GameState.getSelectedUnit().setMenuOpen(false); // remove drop down menu from screen + // remove drop down menu from screen + GameState.getSelectedUnit().setMenuOpen(false); + Game.Instance.Tick(); + + // set variables for path finding Node startNode = graph.getNode(GameState.getSelectedUnit().getPosition()); Node endNode = graph.getNode(mouseClickCoordinates); LinkedList<Node> path = GameFunction.pathFinder(graph, GameState.getSelectedUnit(), startNode, endNode); @@ -74,6 +78,7 @@ namespace Controller { updateUnitPosition(mouseClickCoordinates, path); } + GameState.getSelectedUnit().setMenuOpen(true); // opens drop down menu on screen again setSelectedUnit(null, false); // unselect the unit turnState = TurnState.Wait; @@ -128,15 +133,13 @@ namespace Controller { Unit unit = GameState.getSelectedUnit(); - // TODO: CALL ANIMATION FUNCTION HERE TO ANIMATE UNIT - // Use path to determine which nodes to move to - //foreach (Node node in path) - //{ - // unit.setPosition(node.getPositionX(), node.getPositionY()); - //} - - // moves the unit to end node - unit.setPosition(path.Last().getPositionX(), path.Last().getPositionY()); + // updates the unit's position to each node in the path (node by node) + foreach (Node node in path) + { + unit.setPosition(node.getPositionX(), node.getPositionY()); + Game.Instance.Tick(); + Thread.Sleep(100); + } } // returns a menu button that was clicked; if no menu button was clicked, returns null -- GitLab