Skip to content
Snippets Groups Projects
Commit 29f1a2ac authored by Susan Yuen's avatar Susan Yuen
Browse files

Added more features in graph

parent 8775aa4f
Branches revert-afb15ea3
No related tags found
No related merge requests found
Showing
with 110 additions and 37 deletions
......@@ -72,6 +72,7 @@
<Compile Include="Graph.cs" />
<Compile Include="Mage.cs" />
<Compile Include="MapFunction.cs" />
<Compile Include="MouseHandler.cs" />
<Compile Include="Node.cs" />
<Compile Include="Player.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
......
......@@ -17,6 +17,7 @@ namespace Controller
/// </summary>
public class Game : Microsoft.Xna.Framework.Game
{
Graph graph;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D backGround;
......@@ -56,7 +57,6 @@ namespace Controller
unit1 = new Warrior(Content.Load<Texture2D>("charSprite"), spritePosition);//load character sprite
backGround = Content.Load<Texture2D>("Game Map"); //load background
graphics.PreferredBackBufferWidth = screenWidth; // width of screen
......@@ -64,7 +64,6 @@ namespace Controller
IsMouseVisible = true; //sets mouse visibility to true
graphics.ApplyChanges(); // load images
}
/// <summary>
......@@ -77,9 +76,7 @@ namespace Controller
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
MouseState mouse = Mouse.GetState(); //create mouse
MouseHandler.updateMouse();
base.Update(gameTime); //repeatedly calls update
}
......@@ -89,16 +86,26 @@ namespace Controller
/// </summary>
protected override void Draw(GameTime gameTime)
{
// begin spriteBatch
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null);
// draws units
spriteBatch.Draw(unit1.getSpriteImage(), unit1.getPixelCoordinates(), Color.White);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null); //being spriteBatch
// draws background
spriteBatch.Draw(backGround, Vector2.Zero, Color.White);
unit1.updateSprite(spriteBatch); //draws characte
spriteBatch.Draw(backGround, Vector2.Zero, Color.White); //draws background
// end spriteBatch
spriteBatch.End();
spriteBatch.End(); //end spriteBatch
// repeatedly calls draw
base.Draw(gameTime);
}
private void initializeGraph()
{
graph = new Graph(10, 10);
base.Draw(gameTime); //repeatedly calls draw
}
}
}
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace Model
{
......@@ -10,17 +11,45 @@ namespace Model
private int numberOfNodes; // total number of nodes in the graph
private int width; // width of the graph (by number of nodes)
private int height; // height of the graph (by number of nodes)
private Node[,] nodes; // list of nodes in the graph
public Graph(int x, int y)
{
this.width = x;
this.height = y;
numberOfNodes = x * y;
// initialize nodes inside the graph
nodes = new Node[x, y];
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
nodes[i, j] = new Node();
}
}
}
public int getNumberOfNodes()
{
return numberOfNodes;
}
public Node getNode(int x, int y)
{
return nodes[x, y];
}
public Node getNode(Vector2 pixelCoordinates)
{
int x = (int) Math.Round(pixelCoordinates.X / 32);
int y = (int) Math.Round(pixelCoordinates.Y / 32);
return nodes[x, y];
}
public void setNode(Node node, int x, int y)
{
nodes[x, y] = node;
}
}
}
......@@ -7,25 +7,31 @@ using Microsoft.Xna.Framework;
namespace Controller
{
class MouseHandler
static class MouseHandler
{
Vector2 position;
public void updateMouse()
public static void updateMouse()
{
MouseState ms = Mouse.GetState();
if (ms.LeftButton == ButtonState.Released)
if (ms.LeftButton == ButtonState.Pressed)
{
position = new Vector2(ms.X, ms.Y);
Vector2 position = new Vector2(ms.X, ms.Y);
// TODO: determine if player has clicked on a menu button
if (GameFunction.isPlayableUnitSelected())
{
// TODO: PATH FINDING - determine the end node being pressed
}
else
{
// TODO: determine the node being pressed and if there is a playable, player-owned unit on it
}
// TODO: need to check if user clicked on menu button
}
}
//public Vector2
}
}
......@@ -7,9 +7,15 @@ namespace Model
{
class Node
{
private int movability; // index of how far a unit can move within the tile
private int movability; // index of how far a unit can move within the tile; 0 = no hindrence
private bool isObstacle; // indicates whether a unit can stand inside the tile
public Node()
{
movability = 0;
isObstacle = false;
}
public void setMovability(int m)
{
movability = m;
......
......@@ -19,11 +19,15 @@ namespace Model
int getResistance(); // returns unit's resistance
int getCriticalRate(); // returns unit's critical rate
Weapon[] getEquipableWeapons(); // returns array of equipable weapons
Weapon getEquippedWeapon();
int getLevel(); // returns unit's level
UnitType getClass(); // returns unit's class (warrior, mage, archer)
Texture2D getSpriteImage(); // returns the sprite image of the unit
Vector2 getCurrentPosition(); // returns the current position (pixel coordinates) of the sprite
void updateSprite(SpriteBatch spriteBatch); // update sprite location
Tuple<int, int> getPosition(); // returns the current position (by node) of the sprite
Vector2 getPixelCoordinates(); // returns the current position (pixel coordinates) of the sprite
void setPixelCoordinates(Vector2 p);
void setPosition(int x, int y);
void setEquippedWeapon(Weapon w);
}
enum UnitType { Warrior, Archer, Mage }; //defines the possible classes of a unit
......
......@@ -20,14 +20,16 @@ namespace Model
private int criticalRate;
private int level;
private Weapon[] equipableWeapons;
private Weapon equippedWeapon;
private Texture2D spriteImage;
private Vector2 position;
private Vector2 pixelCoordinates;
private Tuple<int, int> position;
public Warrior(Texture2D image, Vector2 positionCoordinates)
public Warrior(Texture2D image, Vector2 coordinates)
{
// TODO: setup pre-determined stats for warrior
spriteImage = image;
position = positionCoordinates;
pixelCoordinates = coordinates;
}
public bool isAlive()
......@@ -85,6 +87,11 @@ namespace Model
return equipableWeapons;
}
public Weapon getEquippedWeapon()
{
return equippedWeapon;
}
public UnitType getClass()
{
return UnitType.Warrior;
......@@ -95,14 +102,29 @@ namespace Model
return spriteImage;
}
public Vector2 getCurrentPosition()
public Tuple<int, int> getPosition()
{
return position;
}
public void updateSprite(SpriteBatch spriteBatch)
public Vector2 getPixelCoordinates()
{
return pixelCoordinates;
}
public void setPosition(int x, int y)
{
position = new Tuple<int, int>(x, y);
}
public void setPixelCoordinates(Vector2 p)
{
pixelCoordinates = p;
}
public void setEquippedWeapon(Weapon w)
{
spriteBatch.Draw(spriteImage, position, Color.White);
equippedWeapon = w;
}
}
}
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -50,7 +50,6 @@ C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bi
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Microsoft.Xna.Framework.Storage.xml
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Microsoft.Xna.Framework.Video.xml
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Microsoft.Xna.Framework.Xact.xml
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\Blaze_Brigade.csprojResolveAssemblyReference.cache
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\Microsoft.Xna.Framework.RuntimeProfile.txt
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\Blaze_Brigade.Resource1.resources
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\Blaze_Brigade.csproj.GenerateResource.Cache
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -7,8 +7,8 @@
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
<Options>None</Options>
<Output>C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\Game Map.xnb</Output>
<Time>2016-10-18T15:56:00.3798501-04:00</Time>
<Output>C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\Game Map.xnb</Output>
<Time>2016-10-18T12:43:29.1631294-04:00</Time>
</Item>
<Item>
<Source>charSprite.png</Source>
......@@ -16,8 +16,8 @@
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
<Options>None</Options>
<Output>C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\charSprite.xnb</Output>
<Time>2016-10-18T13:51:08.0660613-04:00</Time>
<Output>C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\charSprite.xnb</Output>
<Time>2016-10-18T14:25:36.1902902-04:00</Time>
</Item>
<BuildSuccessful>true</BuildSuccessful>
<Settings>
......@@ -26,10 +26,10 @@
<TargetProfile>Reach</TargetProfile>
<BuildConfiguration>Debug</BuildConfiguration>
<CompressContent>false</CompressContent>
<RootDirectory>C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_BrigadeContent\</RootDirectory>
<LoggerRootDirectory>C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\</LoggerRootDirectory>
<IntermediateDirectory>C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\</IntermediateDirectory>
<OutputDirectory>C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\</OutputDirectory>
<RootDirectory>C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_BrigadeContent\</RootDirectory>
<LoggerRootDirectory>C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\</LoggerRootDirectory>
<IntermediateDirectory>C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\</IntermediateDirectory>
<OutputDirectory>C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\</OutputDirectory>
</Settings>
<Assemblies>
<Assembly>
......@@ -58,7 +58,7 @@
</Assembly>
<Assembly>
<Key>C:\WINDOWS\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key>
<Value>2016-10-18T10:51:30.2111439-04:00</Value>
<Value>2016-10-18T11:11:33.4375035-04:00</Value>
</Assembly>
</Assemblies>
</Asset>
......
C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_BrigadeContent\obj\x86\Debug\Blaze_BrigadeContent.contentprojResolveAssemblyReference.cache
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_BrigadeContent\obj\x86\Debug\Blaze_BrigadeContent.contentprojResolveAssemblyReference.cache
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