namespace Otter { /// /// Class representing one piece of a Snake. /// public class Vertebra : Component { #region Public Fields /// /// The distance from the previous Vertabra in the Snake. /// public int Distance; /// /// The slot that contains the final transformation of the Vertebra. /// public VertebraSlot Slot; /// /// The Snake that this Vertebra belongs to. /// public Snake Snake; /// /// The total distance from the head of the Snake for this Vertebra. /// public int TotalDistance; /// /// Determines if the Vertebra will automatically add its Entity to the Scene. /// public bool AutoAddEntities; #endregion Public Fields #region Private Fields private float rotation; private float slotRotation; #endregion Private Fields #region Public Properties /// /// The local rotation of the Vertebra. /// public float LocalRotation { get; private set; } /// /// The rotation of the Vertebra. When setting this the LocalRotation will be set. /// public float Rotation { get { return rotation + LocalRotation; } set { LocalRotation = value; } } #endregion Public Properties #region Public Methods /// /// Sets the Entity of the Vertebra (another way to add this component to an Entity.) /// /// The Entity to assign to this Vertebra. public void SetEntity(Entity e) { e.AddComponent(this); } public override void Update() { Entity.SetPosition(Snake.GetPosition(TotalDistance)); var lookFrom = Snake.GetPosition(TotalDistance + 1); rotation = Util.Angle(lookFrom.X, lookFrom.Y, Entity.X, Entity.Y); slotRotation = Rotation; Slot = new VertebraSlot() { Rotation = slotRotation }; if (!Entity.IsInScene && AutoAddEntities) { if (Snake.Entity.IsInScene) { Snake.Entity.Scene.Add(Entity); } } } #endregion Public Methods #region Public Structs /// /// A struct containing the final transformation of the Vertebra from the Snake. /// public struct VertebraSlot { /// /// The final transformed rotation of the Vertebra. /// public float Rotation; } #endregion Public Structs } }