diff --git a/src/Fighter.cs b/src/Fighter.cs index 52fb794..05c1421 100644 --- a/src/Fighter.cs +++ b/src/Fighter.cs @@ -7,6 +7,7 @@ internal class Fighter public int power; public int defense; + public bool IsDead { get; set; } public event Action? OnDeath; // Define the OnDeath event public Fighter(int maxHP, int HP, int power, int defense) @@ -15,6 +16,7 @@ public Fighter(int maxHP, int HP, int power, int defense) this.HP = HP; this.power = power; this.defense = defense; + this.IsDead = false; } public void takeDamage(int damage, int power) @@ -47,6 +49,7 @@ public void takeDamage(int damage, int power) if (HP <= 0) { OnDeath?.Invoke(); // Invoke the OnDeath event when HP reaches zero or below + IsDead = true; } } } diff --git a/src/GameObject.cs b/src/GameObject.cs index b15273f..28a6ca5 100644 --- a/src/GameObject.cs +++ b/src/GameObject.cs @@ -13,15 +13,17 @@ internal class GameObject public Fighter? fighter { get; set; } + public Info info { get; set; } + private readonly ColoredGlyph DEAD = new ColoredGlyph(Color.Crimson, Color.Black, '%'); - public GameObject(ColoredGlyph appearance, Point position, IScreenSurface surface, Fighter? Fighter) + public GameObject(ColoredGlyph appearance, Point position, IScreenSurface surface, Fighter? Fighter, Info Info) { Appearance = appearance; Position = position; hostingSurface = surface; - fighter = null; fighter = Fighter; + info = Info; // attach the OnDeath event of the fighter fighter.OnDeath += Death; @@ -29,8 +31,17 @@ public GameObject(ColoredGlyph appearance, Point position, IScreenSurface surfac private void Death() { - System.Console.WriteLine("this thing has died!"); + // check if its was dead before this call + if (fighter.IsDead) + { + System.Console.WriteLine(info.name + " is smashed to bits!"); + this.Appearance = new ColoredGlyph(); + return; + } + + System.Console.WriteLine(info.name + " died!"); Appearance = DEAD; + info.name = info.name + " corpse"; } public void Draw() @@ -70,6 +81,11 @@ public void MoveAndAttack(int dx, int dy, Map map, List objects) continue; } + // if the traget is a corpse, move it + if (obj.fighter.IsDead == true){ + continue; + } + obj.fighter?.takeDamage(2, fighter.power); blockedbyobject = true; break; @@ -97,7 +113,14 @@ public bool IsBlocked(int x, int y, Map map, List objects) { if (obj.Position == new Point(x, y)) { - return true; + // see if the object has a fighter, if yes, see if the fighter is dead + if (obj.fighter != null) + { + return !obj.fighter.IsDead; + } + else{ + return true; + } } } return false; diff --git a/src/Info.cs b/src/Info.cs new file mode 100644 index 0000000..1e363ab --- /dev/null +++ b/src/Info.cs @@ -0,0 +1,20 @@ +namespace MIST +{ + internal class Info + { + public string name; + + public string description; + + public monsterType type; + + public Info(string name, string description, monsterType type) + { + this.name = name; + this.description = description; + this.type = type; + } + + } + +} \ No newline at end of file diff --git a/src/Map.cs b/src/Map.cs index fc4936a..5177b73 100644 --- a/src/Map.cs +++ b/src/Map.cs @@ -166,15 +166,15 @@ private void CreateMonster(Map map, Rectangle room) var monsterY = random.Next(room.Y, room.Y + room.Height); if (map[monsterX, monsterY].TileType == TileType.Floor) { - var monster = new GameObject(new ColoredGlyph(Color.White, Color.Black, '!'), new Point(monsterX, monsterY), map,new Fighter(1, 1, 1, 1)); + var monster = new GameObject(new ColoredGlyph(Color.White, Color.Black, '!'), new Point(monsterX, monsterY), map,new Fighter(1, 1, 1, 1), new Info("Undefined", "Undefined", monsterType.UNDEFINED)); // 20% to be an smile, alse its a spider if (random.Next(20) == 0) { - monster = new GameObject(new ColoredGlyph(Color.LimeGreen, Color.Black, 'S'), new Point(monsterX, monsterY), map, new Fighter(15, 15, 2, 1)); + monster = new GameObject(new ColoredGlyph(Color.LimeGreen, Color.Black, 'S'), new Point(monsterX, monsterY), map, new Fighter(15, 15, 2, 1), new Info("Smile", "a mass of gelatic green goo... that is alive, it digest any food it comes across.", monsterType.smlie)); } else { - monster = new GameObject(new ColoredGlyph(Color.Red, Color.Black, 's'), new Point(monsterX, monsterY), map, new Fighter(5, 5, 1, 1)); + monster = new GameObject(new ColoredGlyph(Color.Red, Color.Black, 's'), new Point(monsterX, monsterY), map, new Fighter(5, 5, 1, 1), new Info("Spider", "a oddly big arachnid. its black and has a big skull-shaped symbol on it's abdomen, that probably means something.", monsterType.insect)); } success = true; // add it to the list @@ -334,18 +334,24 @@ public override bool ProcessKeyboard(Keyboard keyboard) var player = ScreenContainer.Instance.Player; player.MoveAndAttack(dx, dy, this, _objects); UpdateFOV(player.Position.X, player.Position.Y, radius: 5); - Draw(); - // draw objects - foreach (var obj in _objects) + Draw(); + + // make list of objects to draw + var drawList = new List(); + drawList.AddRange(_objects); + + // sort so that dead objects are drawn last + drawList = drawList.OrderBy(obj => obj.fighter?.IsDead).ToList(); + + // draw the list + for (var obj = 0; obj < drawList.Count; obj++) { - // is lit - if (_fov.BooleanResultView[obj.Position.X, obj.Position.Y] == true) - { - obj.Draw(); - } - } + // if not in FOV, don't draw + if (_fov.BooleanResultView[drawList[obj].Position.X, drawList[obj].Position.Y] == false) continue; + drawList[obj].Draw(); + } player.Draw(); _moveTimer = 5; } diff --git a/src/MonsterType.cs b/src/MonsterType.cs new file mode 100644 index 0000000..5026ebc --- /dev/null +++ b/src/MonsterType.cs @@ -0,0 +1,14 @@ +namespace MIST +{ + public enum monsterType + { + UNDEFINED, + player, + smlie, + insect, + humanoid, + human, + undead, + } + +} \ No newline at end of file diff --git a/src/ScreenContainer.cs b/src/ScreenContainer.cs index 8690423..2b5e315 100644 --- a/src/ScreenContainer.cs +++ b/src/ScreenContainer.cs @@ -28,7 +28,7 @@ public ScreenContainer() Map.IsFocused = true; // add the player - Player = new GameObject(new ColoredGlyph(Color.White, Color.Black, '@'), Map.start, Map, new Fighter(10, 10, 3, 3)); + Player = new GameObject(new ColoredGlyph(Color.White, Color.Black, '@'), Map.start, Map, new Fighter(10, 10, 3, 3), new Info("Player", "It's you!", monsterType.player)); Player.Draw();