From d5ff070db666acf32da3b9c7442ecb1c6809e49c Mon Sep 17 00:00:00 2001 From: femsci Date: Thu, 27 Apr 2023 22:24:25 +0200 Subject: [PATCH] Base entity --- Mombae.csproj | 3 ++- src/Bottom.cs | 2 ++ src/Entity/IHasArmor.cs | 12 ++++++++++++ src/Entity/IHasHealth.cs | 12 ++++++++++++ src/Entity/Unit.cs | 14 ++++++++++++++ src/Entity/Vehicle/VehicleBase.cs | 30 ++++++++++++++++++++++++++++++ src/Entity/Vehicle/Vidulg.cs | 12 ++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/Entity/IHasArmor.cs create mode 100644 src/Entity/IHasHealth.cs create mode 100644 src/Entity/Unit.cs create mode 100644 src/Entity/Vehicle/VehicleBase.cs create mode 100644 src/Entity/Vehicle/Vidulg.cs diff --git a/Mombae.csproj b/Mombae.csproj index e215484..923af6d 100644 --- a/Mombae.csproj +++ b/Mombae.csproj @@ -2,5 +2,6 @@ net6.0 true + Mombae - \ No newline at end of file + diff --git a/src/Bottom.cs b/src/Bottom.cs index 295efb2..79243e2 100644 --- a/src/Bottom.cs +++ b/src/Bottom.cs @@ -1,6 +1,8 @@ using System; using Godot; +namespace Mombae; + public partial class Bottom : Node { // Called when the node enters the scene tree for the first time. diff --git a/src/Entity/IHasArmor.cs b/src/Entity/IHasArmor.cs new file mode 100644 index 0000000..f34c259 --- /dev/null +++ b/src/Entity/IHasArmor.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Mombae.Entity; + +namespace Mombae.Entity; + +public interface IHasArmor : IHasHealth +{ + public int ArmorPoints { get; } +} diff --git a/src/Entity/IHasHealth.cs b/src/Entity/IHasHealth.cs new file mode 100644 index 0000000..171feb1 --- /dev/null +++ b/src/Entity/IHasHealth.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Mombae.Entity; + +public interface IHasHealth +{ + public int Health { get; } + public void ReceiveDamage(int hp); +} diff --git a/src/Entity/Unit.cs b/src/Entity/Unit.cs new file mode 100644 index 0000000..40dd2a4 --- /dev/null +++ b/src/Entity/Unit.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Godot; + +namespace Mombae.Entity; + +public abstract class Unit +{ + public string Name { get; } + public Transform2D Transform { get; set; } + public Vector2 Position => Transform.Origin; +} diff --git a/src/Entity/Vehicle/VehicleBase.cs b/src/Entity/Vehicle/VehicleBase.cs new file mode 100644 index 0000000..24d42b3 --- /dev/null +++ b/src/Entity/Vehicle/VehicleBase.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using Mombae.Entity; + +namespace Mombae.Entity.Vehicle; + +public abstract class VehicleBase : Unit, IHasArmor +{ + public abstract int ArmorPoints { get; protected set; } + public abstract int Health { get; protected set; } + + public void ReceiveDamage(int hp) + { + if (ArmorPoints > 0) + { + ArmorPoints -= hp; + if (ArmorPoints < 0) + { + Health -= Math.Abs(ArmorPoints); + } + } + else + { + Health -= Math.Max(0, Health - hp); + } + } +} diff --git a/src/Entity/Vehicle/Vidulg.cs b/src/Entity/Vehicle/Vidulg.cs new file mode 100644 index 0000000..40d01e6 --- /dev/null +++ b/src/Entity/Vehicle/Vidulg.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Mombae.Entity.Vehicle; + +public class Vidulg : VehicleBase +{ + public override int ArmorPoints { get; protected set; } = 300; + public override int Health { get; protected set; } = 1200; +}