Skip to content
Snippets Groups Projects
Commit 6b9de933 authored by Trandinh Thien's avatar Trandinh Thien
Browse files

Clicking attack now leads to a new state, where a user can select a unit to...

Clicking attack now leads to a new state, where a user can select a unit to attack. Added attack confirmation button in this state, where an attack will only execute after confirming
parent 55a838ec
No related branches found
No related tags found
No related merge requests found
......@@ -6,10 +6,10 @@ Content\attack.xnb
Content\items.xnb
Content\move.xnb
Content\wait.xnb
Content\warrior_stats.xnb
Content\warrior.xnb
Content\PixelFont.xnb
Content\warrior_stats.xnb
Content\PixelFontLarge.xnb
Content\warrior.xnb
Content\instructions1.xnb
Content\instructions2.xnb
Content\instructions3.xnb
......
......@@ -304,6 +304,11 @@ namespace Controller
}
}
}
MenuButton confirmButton = unit.getAttackConfirmButton();
if (GameState.attackConfirmOpen)
{
spriteBatch.Draw(confirmButton.getImage(), confirmButton.getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f);
}
#endregion
}
......@@ -361,14 +366,14 @@ namespace Controller
MenuButton moveButton = new MenuButton(MenuButtonType.Move, unitPosition, Content.Load<Texture2D>("move"));
MenuButton itemButton = new MenuButton(MenuButtonType.Items, unitPosition, Content.Load<Texture2D>("items")); ;
MenuButton waitButton = new MenuButton(MenuButtonType.Wait, unitPosition, Content.Load<Texture2D>("wait")); ;
MenuButton attackConfirmButton = new MenuButton(MenuButtonType.Attack, unitPosition, Content.Load<Texture2D>("attack"));
MenuButton attackConfirmButton = new MenuButton(MenuButtonType.AttackConfirm, unitPosition, Content.Load<Texture2D>("attack"));
if (player == 1)
{
if (unitType == UnitType.Warrior)
{
Unit unit = new Warrior(Content.Load<Texture2D>("warrior"), attackButton, moveButton,
itemButton, waitButton, Content.Load<Texture2D>("warrior_stats"), unitPosition, 1);
itemButton, waitButton, attackConfirmButton, Content.Load<Texture2D>("warrior_stats"), unitPosition, 1);
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......@@ -378,7 +383,7 @@ namespace Controller
if (unitType == UnitType.Warrior)
{
Unit unit = new Warrior(Content.Load<Texture2D>("2warrior"), attackButton, moveButton,
itemButton, waitButton, Content.Load<Texture2D>("2warrior_stats"), unitPosition, 2);
itemButton, waitButton, attackConfirmButton, Content.Load<Texture2D>("2warrior_stats"), unitPosition, 2);
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......
......@@ -17,6 +17,7 @@ namespace Model
public static Player currentPlayer { get; set; } // indicates player 1
public static Player enemyPlayer { get; set; } // indicates enemy player (player 2)
public static bool dropDownMenuOpen { get; set; } // indicates whether drop down menu should be open
public static bool attackConfirmOpen { get; set; } //indicates whether player has selected a unit to attack
public static bool beforeMove { get; set; } // true before unit moves, false after it moves. Used to determine what tiles are highlighted
public static bool isAnimating { get; set; } // indicates whether an animation sequence is on screen
public static LinkedList<Node> moveableNodes { get; set; } // holds moveable nodes that can be retreived without calling path finding
......
......@@ -58,12 +58,11 @@ namespace Controller
if (getMenuButtonClicked(mouseClickCoordinates) != null)
{
MenuButton menuButton = getMenuButtonClicked(mouseClickCoordinates);
Debug.WriteLine(getMenuButtonClicked(mouseClickCoordinates).getButtonType());
buttonAction(menuButton);
return;
}
// if user clicks on a valid end node, move to it
if (turnState == TurnState.Move)
{
......@@ -89,12 +88,10 @@ namespace Controller
if (unit != null)
{
setAttackedUnit(unit, true);
attackAnimation(graph, 0);
//GameState.dropDownMenuOpen = (true);
GameState.attackConfirmOpen = true; //opens attack confirm button
}
}
}
}
......@@ -165,7 +162,7 @@ namespace Controller
GameState.beforeMove = (false);
}
private static void attackAnimation(Graph graph, int direction)
private static void attackAnimation(int direction)
{
Unit unit = GameState.selectedUnit;
GameState.isAnimating = true;
......@@ -181,12 +178,13 @@ namespace Controller
Thread.Sleep(10);
}
for (float i = unit.PixelCoordinates.X; i >= originalLocationX; i--)
for (float i = unit.PixelCoordinates.X; i > originalLocationX; i--)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X - 1, unit.PixelCoordinates.Y);
Game.Instance.Tick();
Thread.Sleep(10);
}
Debug.WriteLine(unit.PixelCoordinates.X);
}
#endregion
#region Attack Left
......@@ -194,30 +192,30 @@ namespace Controller
{
for (float i = originalLocationX; i >= originalLocationX - 8; i--)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X + 1, unit.PixelCoordinates.Y);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X - 1, unit.PixelCoordinates.Y);
Game.Instance.Tick();
Thread.Sleep(10);
}
for (float i = unit.PixelCoordinates.X; i <= originalLocationX; i++)
for (float i = unit.PixelCoordinates.X; i < originalLocationX; i++)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X - 1, unit.PixelCoordinates.Y);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X + 1, unit.PixelCoordinates.Y);
Game.Instance.Tick();
Thread.Sleep(10);
}
}
#endregion
#region Attack Up
else if (direction == 2) //attack up
#region Attack Down
else if (direction == 2) //attack down
{
for (float i = originalLocationY; i >= originalLocationY - 8; i--)
for (float i = originalLocationY; i <= originalLocationY + 8; i++)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X , unit.PixelCoordinates.Y +1);
Game.Instance.Tick();
Thread.Sleep(10);
}
for (float i = unit.PixelCoordinates.X; i <= originalLocationX; i++)
for (float i = unit.PixelCoordinates.Y; i > originalLocationY; i++)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X , unit.PixelCoordinates.Y - 1);
Game.Instance.Tick();
......@@ -225,19 +223,19 @@ namespace Controller
}
}
#endregion
#region Attack Down
else if (direction == 3) //attack down
#region Attack Up
else if (direction == 3) //attack up
{
for (float i = originalLocationY; i >= originalLocationY - 8; i--)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y + 1);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y - 1);
Game.Instance.Tick();
Thread.Sleep(10);
}
for (float i = unit.PixelCoordinates.X; i <= originalLocationX; i++)
for (float i = unit.PixelCoordinates.Y; i < originalLocationY; i++)
{
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y - 1);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y + 1);
Game.Instance.Tick();
Thread.Sleep(10);
}
......@@ -311,6 +309,15 @@ namespace Controller
}
}
}
int ButtonX = (int)unit.getAttackConfirmButton().getPixelCoordinates().X;
int ButtonY = (int)unit.getAttackConfirmButton().getPixelCoordinates().Y;
if (ButtonX <= clickX && clickX < ButtonX + 128 && ButtonY <= clickY && clickY < ButtonY + 32)
{
if (GameState.attackConfirmOpen)
{
return unit.getAttackConfirmButton();
}
}
return null;
}
......@@ -318,32 +325,54 @@ namespace Controller
private static void buttonAction(MenuButton button)
{
// take action corresponding to which button was clicked
Unit unit = GameState.selectedUnit;
Unit unit2 = GameState.unitToAttack;
switch (button.getButtonType())
{
case MenuButtonType.Attack: // if attackMenu clicked
turnState = TurnState.AttackMenu;
GameState.dropDownMenuOpen = (false); // close the dropdownmenu when selecting who to attack
button.setActive(false);
case MenuButtonType.Attack: // if attack clicked
turnState = TurnState.Attack;
GameState.dropDownMenuOpen = false; // close the dropdownmenu when selecting who to attack
button.setActive(false);
break;
case MenuButtonType.AttackConfirm: // if confirm attack clicked
turnState = TurnState.Attack;
turnState = TurnState.AttackMenu;
button.setActive(false);
Unit unit = GameState.selectedUnit;
MenuButton moveButtons = unit.getMenuButtonAt(1);
unit.getMenuButtonAt(1).setActive(false);
int attackDirection=0;
if (unit.Position.Item1 < unit2.Position.Item1)
{
attackDirection = 0;
}
else if (unit.Position.Item1 > unit2.Position.Item1)
{
attackDirection = 1;
}
else if (unit.Position.Item2 < unit2.Position.Item2)
{
attackDirection = 2;
}
else if (unit.Position.Item2 > unit2.Position.Item2)
{
attackDirection = 3;
}
Debug.WriteLine(attackDirection);
attackAnimation(attackDirection);
GameState.attackConfirmOpen = false;
GameState.dropDownMenuOpen = true;
break;
case MenuButtonType.Move: // if moved is clicked
turnState = TurnState.Move;
GameState.dropDownMenuOpen = (false); // close the dropdownmenu when selecting where to move
GameState.dropDownMenuOpen = false; // close the dropdownmenu when selecting where to move
button.setActive(false);
break;
case MenuButtonType.Items: // if item is clicked
turnState = TurnState.Items;
GameState.dropDownMenuOpen = (false);
GameState.dropDownMenuOpen = false;
break;
case MenuButtonType.Wait: // if wait is clicked
turnState = TurnState.Wait;
GameState.dropDownMenuOpen = (false);
GameState.dropDownMenuOpen = false;
GameState.playableUnitSelected = false;
button.setActive(false);
break;
......
......@@ -40,6 +40,7 @@ namespace Model
Tuple<int, int> Position { get; set;} // gets and sets unit's position by tile
Vector2 PixelCoordinates { get; set; }
MenuButton getMenuButtonAt(int i);
MenuButton getAttackConfirmButton();
MenuButton[] getMenuButtons(); // returns the dropdown menu buttons of the unit
Rectangle getCurrentFrame(); // returns the current sprite frame in animation sequence
......
......@@ -34,13 +34,14 @@ namespace Model
private int player; // which player this unit belongs to
public Warrior(Texture2D spriteImage, MenuButton attackButton, MenuButton moveButton,
MenuButton itemButton, MenuButton waitButton, Texture2D charInfo, Vector2 coordinates, int player)
MenuButton itemButton, MenuButton waitButton, MenuButton confirmButton, Texture2D charInfo, Vector2 coordinates, int player)
{
this.spriteImage = spriteImage;
menuButtons[0] = attackButton;
menuButtons[1] = moveButton;
menuButtons[2] = itemButton;
menuButtons[3] = waitButton;
attackConfirm = confirmButton;
this.charInfo = charInfo;
this.player = player;
pixelCoordinates = coordinates;
......@@ -192,6 +193,11 @@ namespace Model
{
return menuButtons[i];
}
public MenuButton getAttackConfirmButton()
{
return attackConfirm;
}
// updates menu button positions
public void setMenuButtonCoordinates(Vector2 pixelCoordinates)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment