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 Slime : INPC { private ISprite SlimeSprite; 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; public bool canTakeDirectDamage => true; public bool hasMultipleNodes => false; public Slime(int spawnX, int spawnY) { this.removed = false; posRect = new Rectangle(spawnX, spawnY, posrectWH, posrectWH); SlimeSprite = NPCSpriteFactory.Instance.CreateSlime(spawnX, spawnY, this); SmokeCloud = NPCSpriteFactory.Instance.CreateSmokeCloud(posRect.X, posRect.Y, this); StarEffect = NPCSpriteFactory.Instance.CreateStarEffect(posRect.X, posRect.Y, this); moving = false; spriteSpeed = 100; r = new Random(); spawning = true; spawnTimer = 0; life = 0.5f; death = false; deathTimer = 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 { SlimeSprite.draw(); } } public void UpdateNPC() { if (spawning) { this.spawnTimer += GlobalVars.gameTime.ElapsedGameTime.Milliseconds; if (this.spawnTimer > 1000) { spawning = false; spawnTimer = 0; } SmokeCloud.update(GlobalVars.gameTime); } 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 = 200; 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; } } moveTimer -= 4; if (moveTimer > 50) { 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; } } SlimeSprite.update(GlobalVars.gameTime); } } public void Spawn() { spawning = true; } public void takeDamage(float damage) { life -= damage; if(life<=0.0) { death = true; } } public float Collide() { return 0.5f; } public bool IsRemoved() { return removed; } public bool IsSpawning() { return spawning; } public bool IsDead() { return death; } } }