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

Added sprite animation for movement. Modified game.cs, warrior.cs, unit.cs and mouseHandler.cs

parent 53ca3064
No related branches found
No related tags found
1 merge request!6Animation
Showing with 112 additions and 6 deletions
......@@ -111,6 +111,7 @@
<Content Include="GameThumbnail.png">
<XnaPlatformSpecific>true</XnaPlatformSpecific>
</Content>
<None Include="Resources\warrior.png" />
<None Include="Resources\Warrior_Info.png" />
<None Include="Resources\warrior_stats.png" />
<None Include="Resources\Game_Map.jpg" />
......
......@@ -8,7 +8,8 @@ Content\items.xnb
Content\move.xnb
Content\wait.xnb
Content\warrior_art.xnb
Content\PixelFont.xnb
Content\warrior_stats.xnb
Content\Warrior_Info.xnb
Content\PixelFont.xnb
Content\PixelFontLarge.xnb
Content\warrior.xnb
......@@ -107,9 +107,8 @@ namespace Controller
MenuButton itemButton = new MenuButton(MenuButtonType.Items, unit1Position, Content.Load<Texture2D>("items")); ;
MenuButton waitButton = new MenuButton(MenuButtonType.Wait, unit1Position, Content.Load<Texture2D>("wait")); ;
player1.addUnit(new Warrior(Content.Load<Texture2D>("charSprite"), attackButton, moveButton,
player1.addUnit(new Warrior(Content.Load<Texture2D>("warrior"), attackButton, moveButton,
itemButton, waitButton, Content.Load<Texture2D>("warrior_Info"), unit1Position));
GameState.setPlayerCurrentlyMoving(player1); // set game state
}
......@@ -193,7 +192,7 @@ namespace Controller
for (int i = 0; i < player1.getNumOfUnits(); i++)
{
Unit unit = player1.getUnits().ElementAt(i); //gets unit at i
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f); // redraws char sprite
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f); // redraws char sprite
}
#endregion
......
......@@ -150,12 +150,14 @@ namespace Controller
{
if (unit.getPixelCoordinates().X < nodePixelX)
{
unit.animate(2);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X + 4, unit.getPixelCoordinates().Y));
Game.Instance.Tick();
Thread.Sleep(40);
}
else
{
unit.animate(1);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X - 4, unit.getPixelCoordinates().Y));
Game.Instance.Tick();
Thread.Sleep(40);
......@@ -166,12 +168,14 @@ namespace Controller
{
if (unit.getPixelCoordinates().Y < nodePixelY)
{
unit.animate(0);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X, unit.getPixelCoordinates().Y + 4));
Game.Instance.Tick();
Thread.Sleep(40);
}
else
{
unit.animate(4);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X, unit.getPixelCoordinates().Y - 4));
Game.Instance.Tick();
Thread.Sleep(40);
......
......@@ -150,6 +150,16 @@ namespace Blaze_Brigade {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap warrior {
get {
object obj = ResourceManager.GetObject("warrior", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
......
......@@ -154,4 +154,7 @@
<data name="Warrior_Info" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Warrior_Info.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="warrior" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\warrior.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
\ No newline at end of file
src/Blaze-Brigade/Blaze_Brigade/Resources/warrior.png

8.52 KiB

......@@ -37,6 +37,8 @@ namespace Model
void setEquippedWeapon(Weapon w); // sets the unit's currently equipped weapon
void setMoved(bool a); // on start of players turn, set all units to unmoved (F)
MenuButton[] getMenuButtons(); // returns the dropdown menu buttons of the unit
Rectangle getCurrentFrame(); // returns the current sprite frame in animation sequence
void animate(int direction);
}
enum UnitType { Warrior, Archer, Mage }; //defines the possible classes of a unit
......
......@@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using View;
using System.Diagnostics;
namespace Model
{
......@@ -32,6 +33,8 @@ namespace Model
private Texture2D charInfo;
private Boolean clickedOn = false;
private Boolean menuOpen = false;
private int currentFrame; //the current frame the sprite is on
private int direction; //direction the character is currently facing - 0=down, 1=left, 2=right, up=up
public Warrior(Texture2D spriteImage, MenuButton attackButton, MenuButton moveButton,
MenuButton itemButton, MenuButton waitButton, Texture2D charInfo, Vector2 coordinates)
......@@ -47,7 +50,7 @@ namespace Model
int positionX = (int)Math.Round(coordinates.X / 32);
int positionY = (int)Math.Round(coordinates.Y / 32);
position = new Tuple<int, int>(positionX, positionY);
currentFrame = 1;
setMenuButtonCoordinates(pixelCoordinates);
}
......@@ -224,9 +227,85 @@ namespace Model
}
}
public void Update(GameTime gameTime)
public Rectangle getCurrentFrame() //return current frame the sprite is on
{
Rectangle screenBounds = new Rectangle(currentFrame * 32, 0, 32, 32);
return screenBounds;
}
// animates the sprite by switching to the correct frame sequences
public void animate(int direction)
{
if (direction == 0) // for going down
{
if (currentFrame > 2) // if unit isnt already going down, set the sprite to default facing downwards
{
currentFrame = 1;
}
else
{
if (currentFrame == 2) // if unit has reached end of going down walk cycle, go back to beginning
{
currentFrame = 0;
}
else
{
currentFrame++; // increment through walk cycle
}
}
}else if(direction == 1) // for going left
{
if ((currentFrame < 3) || (currentFrame > 5)) // if unit isnt already going left, set the sprite to default facing left
{
currentFrame = 4;
}
else
{
if (currentFrame == 5) // if unit has reached end of going down walk cycle, go back to beginning
{
currentFrame = 3;
}
else
{
currentFrame++; //increment walk cycle
}
}
}else if (direction == 2) // for going right
{
if ((currentFrame < 6) || (currentFrame > 8)) // if unit isnt already going right, set the sprite to default facing right
{
currentFrame = 7;//increment walk cycle
}
else
{
if (currentFrame == 8)// if unit has reached end of going down walk cycle, go back to beginning
{
currentFrame = 6;
}
else
{
currentFrame++;
}
}
}
else if (direction == 3) // for going up
{
if (currentFrame < 9) // if unit isnt already going up, set the sprite to default facing upwards
{
currentFrame = 10;//increment walk cycle
}
else
{
if (currentFrame == 11)// if unit has reached end of going down walk cycle, go back to beginning
{
currentFrame = 9;//increment walk cycle
}
else
{
currentFrame++;
}
}
}
}
}
}
......@@ -128,6 +128,13 @@
<Processor>FontDescriptionProcessor</Processor>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="warrior.png">
<Name>warrior</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
src/Blaze-Brigade/Blaze_BrigadeContent/warrior.png

8.52 KiB

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