From 6a9da1f144f7f506c03f6aeb8a812fe5fdf66191 Mon Sep 17 00:00:00 2001 From: Susan Yuen <susan_loves_cheese@hotmail.com> Date: Wed, 2 Nov 2016 12:42:54 -0400 Subject: [PATCH] Animated unit sliding --- .../Blaze_Brigade/MouseHandler.cs | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs index 3bb9530..c6cf22f 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs @@ -131,9 +131,7 @@ namespace Controller // 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(200); + animateUnitPosition(unit, node); GameState.setMenuOpen(true); } @@ -141,6 +139,46 @@ namespace Controller GameState.setBeforeMove(false); } + // TODO: move this function to animation class + // animates unit to move to node + private static void animateUnitPosition(Unit unit, Node node) + { + int nodePixelX = node.getPositionX() * 32; + int nodePixelY = node.getPositionY() * 32; + + while (unit.getPixelCoordinates().X != nodePixelX) + { + if (unit.getPixelCoordinates().X < nodePixelX) + { + unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X + 4, unit.getPixelCoordinates().Y)); + Game.Instance.Tick(); + Thread.Sleep(40); + } + else + { + unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X - 4, unit.getPixelCoordinates().Y)); + Game.Instance.Tick(); + Thread.Sleep(40); + } + } + + while (unit.getPixelCoordinates().Y != nodePixelY) + { + if (unit.getPixelCoordinates().Y < nodePixelY) + { + unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X, unit.getPixelCoordinates().Y + 4)); + Game.Instance.Tick(); + Thread.Sleep(40); + } + else + { + unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X, unit.getPixelCoordinates().Y - 4)); + Game.Instance.Tick(); + Thread.Sleep(40); + } + } + } + // returns a menu button that was clicked; if no menu button was clicked, returns null private static MenuButton getMenuButtonClicked(Vector2 mouseCoordinates) { -- GitLab