Skip to content

Commit

Permalink
Merge pull request #495 from CSE3902-Group-3/Fix-Dodongo
Browse files Browse the repository at this point in the history
Hotfix Dodongo
  • Loading branch information
EthanGlenwright775 authored Dec 13, 2023
2 parents ac9b03b + b6bb7e2 commit 6415519
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions Enemies/Dodongo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace LegendOfZelda
public class Dodongo : IEnemy
{
private readonly List<AnimatedSprite> Sprites;
private readonly List<AnimatedSprite> HurtSprites;
private int CurrentSprite;
public AnimatedSprite Sprite { get; set; }
public float Health { get; set; } = 8.0f;
Expand All @@ -27,7 +26,6 @@ public class Dodongo : IEnemy
public float CurrentCooldown { get; set; } = 0.0f;
public double LastSwitch { get; set; } = 0;
private Vector2 Center;
private bool Injured = false;
public Dodongo(Vector2 pos)
{
Position = pos;
Expand All @@ -39,24 +37,11 @@ public Dodongo(Vector2 pos)
SpriteFactory.getInstance().CreateDodongoUpSprite()
};

HurtSprites = new List<AnimatedSprite>
{
SpriteFactory.getInstance().CreateDodongoRightHitSprite(),
SpriteFactory.getInstance().CreateDodongoLeftHitSprite(),
SpriteFactory.getInstance().CreateDodongoDownHitSprite(),
SpriteFactory.getInstance().CreateDodongoUpHitSprite()
};

foreach (AnimatedSprite dodongo in Sprites)
{
dodongo.UnregisterSprite();
}

foreach (AnimatedSprite dodongo in HurtSprites)
{
dodongo.UnregisterSprite();
}

int scale = SpriteFactory.getInstance().scale;
CurrentSprite = 0;
LevelManager.AddUpdateable(this);
Expand Down Expand Up @@ -104,21 +89,11 @@ public void UpdateHealth(float damagePoints)
// Indicate damage, or if health has reached 0, die
if (Health < 0)
{
Sprites[CurrentSprite] = HurtSprites[CurrentSprite];
Die();
}
else
{
if (!Injured)
{
Sprites[CurrentSprite] = HurtSprites[CurrentSprite];
}
else
{
Sprites[CurrentSprite] = Sprites[CurrentSprite];
}
Sprites[CurrentSprite].UpdatePos(Position);
Injured = !Injured;
}
}

Expand Down Expand Up @@ -174,14 +149,18 @@ public void OnCollision(List<CollisionInfo> collisions)
IsColliding = false;
ChangeDirection();
}
else if (collidedWith == CollisionLayer.PlayerWeapon)
else if (collision.CollidedWith.Collidable is Explosion)
{
if (CurrentCooldown <= 0)
{
EnemyUtilities.HandleWeaponCollision(this, GetType(), collision);
CurrentCooldown = EnemyUtilities.DAMAGE_COOLDOWN; // Reset the cooldown timer
Sprites[CurrentSprite].flashing = true;
foreach(IAnimatedSprite sprite in Sprites)
{
sprite.flashing = true;
}
new Timer(1.0f, StopFlashing);
new Timer(CurrentCooldown, EndCooldown);
}
}
}
Expand All @@ -190,8 +169,17 @@ public void OnCollision(List<CollisionInfo> collisions)
public void Stun() { }
public void StopFlashing()
{
Sprites[CurrentSprite].flashing = false;
foreach (IAnimatedSprite sprite in Sprites)
{
sprite.flashing = false;
}
}

private void EndCooldown()
{
CurrentCooldown = -1;
}

public void DropItem()
{
Center = EnemyUtilities.GetCenter(Position, Width, Height);
Expand Down

0 comments on commit 6415519

Please sign in to comment.