| | | 1 | | using Godot; |
| | | 2 | | |
| | | 3 | | |
| | | 4 | | namespace Safarimacik.Model; |
| | | 5 | | |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Base class for all ranger states. |
| | | 9 | | /// </summary> |
| | | 10 | | public abstract class RangerState(Ranger ranger) { |
| | | 11 | | protected Ranger _ranger = ranger; |
| | | 12 | | |
| | | 13 | | public abstract void Tick(); |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Represents a state in which the ranger has nothing to do. |
| | | 18 | | /// </summary> |
| | 1 | 19 | | public class IdleRangerState(Ranger ranger) : RangerState(ranger) { |
| | 1 | 20 | | public override void Tick() { } |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Represents a state in which the ranger approaches its destination following its given path. |
| | | 25 | | /// </summary> |
| | | 26 | | public class WalkingRangerState(Ranger ranger, List<Vector2> path) : RangerState(ranger) { |
| | | 27 | | private Vector2 _destination = path.Last(); |
| | | 28 | | private List<Vector2> _path = path; |
| | | 29 | | |
| | | 30 | | public Vector2 Destination => _destination; |
| | | 31 | | |
| | | 32 | | public override void Tick() { |
| | | 33 | | if (!HasReachedDestination()) { |
| | | 34 | | _ranger.Move(_path); |
| | | 35 | | } |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public bool HasReachedDestination() { |
| | | 39 | | return _destination == _ranger.Position; |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Represents a state in which the animal has reached its target, and is now shooting it. |
| | | 45 | | /// </summary> |
| | | 46 | | public class ShootingRangerState(Ranger ranger) : RangerState(ranger) { |
| | | 47 | | public override void Tick() { |
| | | 48 | | _ranger.KillTarget(); |
| | | 49 | | } |
| | | 50 | | } |