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

Added tile highlight for moving and attacking

parent dfdc133e
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ namespace Controller ...@@ -49,7 +49,7 @@ namespace Controller
GraphicsDeviceManager graphics; GraphicsDeviceManager graphics;
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
Texture2D backGround; Texture2D backGround, moveableNode, attackableNode;
private SpriteFont font; //custom font private SpriteFont font; //custom font
// constructor for game // constructor for game
...@@ -86,8 +86,12 @@ namespace Controller ...@@ -86,8 +86,12 @@ namespace Controller
initializeGame(); initializeGame();
backGround = Content.Load<Texture2D>("Game_Map"); // load background backGround = Content.Load<Texture2D>("Game_Map"); // load background
moveableNode = Content.Load<Texture2D>("moveableNode");
attackableNode = Content.Load<Texture2D>("attackableNode");
font = Content.Load<SpriteFont>("PixelFont"); //loads font PixelFont font = Content.Load<SpriteFont>("PixelFont"); //loads font PixelFont
graphics.PreferredBackBufferWidth = gameFunction.SCREEN_WIDTH; // width of screen graphics.PreferredBackBufferWidth = gameFunction.SCREEN_WIDTH; // width of screen
graphics.PreferredBackBufferHeight = gameFunction.SCREEN_HEIGHT; //height of screen graphics.PreferredBackBufferHeight = gameFunction.SCREEN_HEIGHT; //height of screen
...@@ -213,16 +217,37 @@ namespace Controller ...@@ -213,16 +217,37 @@ namespace Controller
Unit unit = player1.getUnits().ElementAt(i); //gets unit at i Unit unit = player1.getUnits().ElementAt(i); //gets unit at i
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White);//draws sprite spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White);//draws sprite
//if unit is currently clicked on, draw char info screen //if unit is currently clicked on, draw char info screen
if (unit.getClickedOn()) if (unit.getClickedOn())
{ {
//Highlight movable nodes in blue
LinkedList<Node> moveableNodes = gameFunction.getMovableNodes(graph, unit);
foreach(Node move in moveableNodes)
{
spriteBatch.Draw(moveableNode, move.getPosition(), Color.White * 0.3f);
}
//Highlight attackable nodes in red
LinkedList<Node> attackableNodes = gameFunction.getAttackableNodes(graph, unit);
foreach (Node attack in attackableNodes)
{
if (!moveableNodes.Contains(attack))
{
spriteBatch.Draw(attackableNode, attack.getPosition(), Color.White * 0.2f);
}
}
if (unit.getMenuOpen()) //if dropDowMenu should be opened, draw dropDownMenu if (unit.getMenuOpen()) //if dropDowMenu should be opened, draw dropDownMenu
{ {
Vector2 menuIncrement = new Vector2(0, 32); //increment downwards for successive button Vector2 menuIncrement = new Vector2(0, 32); //increment downwards for successive button
Vector2 currentButtonPosition = Vector2.Add(unit.getPixelCoordinates(), menuIncrement); //starting location for button Vector2 initialOffset = new Vector2(32, 0);
Vector2 currentButtonPosition = Vector2.Add(unit.getPixelCoordinates(), initialOffset); //starting location for button
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
spriteBatch.Draw(unit.getButtonImage(j), currentButtonPosition, Color.White); //draws each button spriteBatch.Draw(unit.getButtonImage(j), currentButtonPosition, Color.White); //draws each button
...@@ -256,10 +281,17 @@ namespace Controller ...@@ -256,10 +281,17 @@ namespace Controller
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White); spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White);
} }
//spriteBatch.Draw(backGround, Vector2.Zero, Color.White); // draws background
break; break;
} }
//spriteBatch.Draw(backGround, Vector2.Zero, Color.White); // draws background
spriteBatch.End(); // end spriteBatch spriteBatch.End(); // end spriteBatch
base.Draw(gameTime); // repeatedly calls draw base.Draw(gameTime); // repeatedly calls draw
} }
......
...@@ -109,6 +109,7 @@ namespace Controller ...@@ -109,6 +109,7 @@ namespace Controller
isAnimating = animating; isAnimating = animating;
} }
//which dropdownmenu is selected
void buttonAction(int i) void buttonAction(int i)
{ {
//take action corresponding to which button was clicked //take action corresponding to which button was clicked
......
using System; using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -9,6 +10,8 @@ namespace Model ...@@ -9,6 +10,8 @@ namespace Model
{ {
private int movabilityObstruction; // index for hindrance of the movability of a unit; 0 = no hindrance private int movabilityObstruction; // index for hindrance of the movability of a unit; 0 = no hindrance
private bool isObstacle; // indicates whether a unit can stand inside the tile private bool isObstacle; // indicates whether a unit can stand inside the tile
private bool highlightMove;
private bool highlightAttack;
private int positionX; // position x on the grid private int positionX; // position x on the grid
private int positionY; // position y on the grid private int positionY; // position y on the grid
...@@ -43,6 +46,12 @@ namespace Model ...@@ -43,6 +46,12 @@ namespace Model
return isObstacle; return isObstacle;
} }
public Vector2 getPosition()
{
Vector2 position = new Vector2(getPositionX()*32, getPositionY()*32);
return position;
}
public int getPositionX() public int getPositionX()
{ {
return positionX; return positionX;
...@@ -74,5 +83,6 @@ namespace Model ...@@ -74,5 +83,6 @@ namespace Model
return false; return false;
} }
} }
} }
} }
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