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

cleaned up sound merge and minor logic fixes

parent 8e661879
No related branches found
No related tags found
No related merge requests found
......@@ -112,7 +112,7 @@ namespace View
Animates unit movement from current unit location to future unit location. Unit moves through the inbetween nodes obtained from pathing algorith by first moving horizontally, then vertically.
For horizontally, the unit will move right if the future position is greater in the x direction, otherwise it will move left. For vertical, the unit will move down if future y position is
greater then current, otherwise it will move up. animate is called to animate the walking from node to node, and the direction parameter in that call is determined by which direction the
unit is moving.
unit is moving. A tracker is kept for walking sounds, which counts up by 1 each time and plays a walking sound everytime it reaches 5.
\b Exception: \n
- Thie function will only execute if the original and new location are different, otherwise nothing will happen
- The function assumes that the the path between original location and new location is valid
......@@ -126,15 +126,24 @@ namespace View
int nodePixelY = node.getPositionY() * 32;
int pixelDifference = 4;
graph.getNode(unit.Position).unitOnNode = (null);
int walkSoundDelayCounter = 5;
#region Horizontal Movement
while (unit.PixelCoordinates.X != nodePixelX)
{
//keep a tracker so that walking sound only plays once every 5 steps (300millieseconds), otherwise sound is repeated too quickly
if(walkSoundDelayCounter == 5)
{
Sounds.walkingSound();
walkSoundDelayCounter = 0;
}else
{
walkSoundDelayCounter++;
}
if (unit.PixelCoordinates.X < nodePixelX)
{
animate(Direction.Right, unit);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X + pixelDifference, unit.PixelCoordinates.Y);
Sounds.walkingSound();
Controller.Game.Instance.Tick();
Thread.Sleep(40);
}
......@@ -142,7 +151,6 @@ namespace View
{
animate(Direction.Left, unit);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X - pixelDifference, unit.PixelCoordinates.Y);
Sounds.walkingSound();
Controller.Game.Instance.Tick();
Thread.Sleep(40);
}
......@@ -152,11 +160,21 @@ namespace View
#region Vertical Movement
while (unit.PixelCoordinates.Y != nodePixelY)
{
//keep a tracker so that walking sound only plays once every 5 steps (300millieseconds), otherwise sound is repeated too quickly
if (walkSoundDelayCounter == 5)
{
Sounds.walkingSound();
walkSoundDelayCounter = 0;
}
else
{
walkSoundDelayCounter++;
}
if (unit.PixelCoordinates.Y < nodePixelY)
{
animate(Direction.Down, unit);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y + pixelDifference);
Sounds.walkingSound();
Controller.Game.Instance.Tick();
Thread.Sleep(40);
}
......@@ -164,7 +182,6 @@ namespace View
{
animate(Direction.Up, unit);
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y - pixelDifference);
Sounds.walkingSound();
Controller.Game.Instance.Tick();
Thread.Sleep(40);
}
......
......@@ -546,7 +546,7 @@ namespace Controller
GameState.CurrentPlayerDamageDealt = damageDealt.ToString();
enemyUnit.Hp = enemyUnit.Hp - damageDealt; // updates hp
GameState.currentPlayerDamagePopup = true;
Sounds.playSound(unit);
Sounds.attackSound(unit);
Animation.attackAnimation(attackDir, unit);
// if enemy unit is still alive, perform a counter attack
......@@ -558,7 +558,7 @@ namespace Controller
GameState.EnemyPlayerDamageDealt = damageTaken.ToString();
unit.Hp = unit.Hp - damageTaken; // update hp
GameState.enemyPlayerDamagePopup = true;
Sounds.playSound(unit);
Sounds.attackSound(enemyUnit);
Animation.attackAnimation(counterAttackDir, enemyUnit);
}
deselectUnit();
......
......@@ -9,14 +9,17 @@ using System.Text;
namespace View
{
/// <summary>
/// Sound class containing methods to play all different sounds to be used in the game
/// </summary>
static class Sounds
{
public static void playSound (Unit unit)
/**
* This method takes in a unit, and plays an attacking sound corresponding to the unit's weapon. The weapon sounds include Sword, Bow, and Magic
* /param unit The unit who's weapon sound will be played
*/
public static void attackSound (Unit unit)
{
if (unit.equippedWeapon.getWeapType() == weaponType.Sword)
{
Controller.Game.Instance.getSounds("Sword").Play();
......@@ -30,16 +33,13 @@ namespace View
Controller.Game.Instance.getSounds("Fire").Play();
}
}
/**
* This method plays a single walking step sound
*/
public static void walkingSound()
{
Controller.Game.Instance.getSounds("Walk").Play();
}
}
}
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