using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using System; using System.Collections.Generic; using System.Text; using Sprint3_actual.Everything_NPC; using Sprint3_actual.SoundManagement; namespace Sprint3_actual { class Stalfos : INPC { private ISprite StalfosSprite; private ISprite SmokeCloud; private ISprite StarEffect; private Rectangle posRect; private int spriteSpeed; private bool moving, spawning, death; private int moveTimer, direction, spawnTimer, deathTimer; private Random r; private bool removed; private const int posrectWH = 48; private float life; private int canTakeDamage; public bool canTakeDirectDamage => true; private room Room; public bool hasMultipleNodes => false; public Stalfos(int spawnX, int spawnY, room room) { this.removed = false; this.Room = room; posRect = new Rectangle(spawnX, spawnY, posrectWH, posrectWH); StalfosSprite = NPCSpriteFactory.Instance.CreateStalfos(posRect.X, posRect.Y, this); SmokeCloud = NPCSpriteFactory.Instance.CreateSmokeCloud(posRect.X, posRect.Y, this); StarEffect = NPCSpriteFactory.Instance.CreateStarEffect(posRect.X, posRect.Y, this); moving = false; spriteSpeed = 115; r = new Random(); spawning = true; spawnTimer = 0; life = 2.0f; death = false; deathTimer = 0; canTakeDamage = 0; } public Rectangle getRect() { return this.posRect; } public void SetPosition(int x, int y) { posRect.X = x; posRect.Y = y; } public void DrawNPC() { if (spawning) { SmokeCloud.draw(); } else if(death) { StarEffect.draw(); } else { StalfosSprite.draw(); } } public void UpdateNPC() { if (spawning) { this.spawnTimer += GlobalVars.gameTime.ElapsedGameTime.Milliseconds; SmokeCloud.update(GlobalVars.gameTime); if (this.spawnTimer > 1000) { spawning = false; spawnTimer = 0; } } else if (death) { if (deathTimer == 0) { SoundEngine.Instance.playEnemyDeath(); } this.deathTimer += GlobalVars.gameTime.ElapsedGameTime.Milliseconds; if(this.deathTimer > 600) { removed = true; } StarEffect.update(GlobalVars.gameTime); } else { if (moveTimer <= 0 || (!moving)) { moving = true; moveTimer = 150; int number = r.Next(1, 101); if (number <= 25) { direction = 1; } else if (number > 25 && number <= 50) { direction = 2; } else if (number > 50 && number <= 75) { direction = 3; } else if (number > 75 && number <= 100) { direction = 4; } } else { moveTimer -= 4; switch (direction) { case 1: posRect.X -= (int)(spriteSpeed * GlobalVars.gameTime.ElapsedGameTime.TotalSeconds); break; case 2: posRect.Y -= (int)(spriteSpeed * GlobalVars.gameTime.ElapsedGameTime.TotalSeconds); break; case 3: posRect.X += (int)(spriteSpeed * GlobalVars.gameTime.ElapsedGameTime.TotalSeconds); break; case 4: posRect.Y += (int)(spriteSpeed * GlobalVars.gameTime.ElapsedGameTime.TotalSeconds); break; } } StalfosSprite.update(GlobalVars.gameTime); } if(canTakeDamage > 0) { canTakeDamage--; } } public void Spawn() { spawning = true; } public void takeDamage(float damage) { if (canTakeDamage <= 0 && !death) { life -= damage; if (life <= 0.0f) { death = true; SoundEngine.Instance.playEnemyDeath(); Inventory.Instance.incrementKills(); Inventory.Instance.dropRank3(posRect, this.Room); } else { SoundEngine.Instance.playDamage(); } canTakeDamage = 30; } } public float Collide() { return 0.5f; } public bool IsRemoved() { return removed; } public bool IsSpawning() { return spawning; } public bool IsDead() { return death; } } }