Пример #1
0
 private static void ClearCurrentState(StateComponent component)
 {
     if (component.CurrentState == EntityState.Dying || component.CurrentState == EntityState.Dead)
     {
         return;
     }
     component.Clear();
 }
Пример #2
0
        public Entity SetStateComponent()
        {
            StateComponent component = new StateComponent();

            StateComponent = component;
            AddComponent(component);
            return(this);
        }
Пример #3
0
        private void SetMovementStates(MovementComponent movement)
        {
            if (movement.CurrentEntityState == null || !movement.CurrentEntityState.ReadyToChange)
            {
                return;
            }
            StateComponent stateComponent = movement.CurrentEntityState;

            if (movement.IsMoving)
            {
                stateComponent.TryToSetState(EntityState.Moving);

                if (stateComponent.CurrentState == EntityState.Moving)
                {
                    double PI    = Math.PI;
                    double Angle = movement.Speed.Polar.Angle;

                    if (Angle < PI / 2 && Angle > -PI / 2)
                    {
                        stateComponent.Orientation = Direction.Right;
                    }
                    if (Angle >= PI / 2 || Angle <= -PI / 2)
                    {
                        stateComponent.Orientation = Direction.Left;
                    }

                    /*
                     * if (Angle <= PI / 4 && Angle >= -PI / 4) stateComponent.Direction = Direction.Right;
                     * if (Angle > PI / 4 && Angle < 3 * PI / 4) stateComponent.Direction = Direction.Down;
                     * if (Angle < -PI / 4 && Angle > 3 * -PI / 4) stateComponent.Direction = Direction.Up;
                     * if (Angle >= 3 * PI / 4 || Angle <= 3 * -PI / 4) stateComponent.Direction = Direction.Left;
                     */
                }
            }
            else
            {
                if (stateComponent.CurrentState == EntityState.Moving)
                {
                    stateComponent.Clear();
                }
            }
        }
Пример #4
0
        private void SetAttackStates(AttackBehaviorComponent attack)
        {
            if (attack.CurrentEntityState == null || !attack.CurrentEntityState.ReadyToChange)
            {
                return;
            }
            StateComponent stateComponent = attack.CurrentEntityState;

            if (attack.RemainingAttackCooldownMilliseconds > 0 || (attack.DelayedAttack != null && attack.DelayedAttack.RemainingAttackDelayMilliseconds > 0))
            {
                stateComponent.TryToSetState(EntityState.Attacking);

                if (stateComponent.CurrentState == EntityState.Attacking)
                {
                    double  PI          = Math.PI;
                    Vector2 cursorDelta = new Vector2(attack.Cursor.X, attack.Cursor.Y) - attack.SourcePos.Vector2;
                    double  Angle       = new Coord2(cursorDelta).Polar.Angle;

                    if (Angle < PI / 2 && Angle > -PI / 2)
                    {
                        stateComponent.Orientation = Direction.Right;
                    }
                    else if (Angle >= PI / 2 && Angle <= -PI / 2)
                    {
                        stateComponent.Orientation = Direction.Left;
                    }
                }
            }
            else
            {
                if (stateComponent.CurrentState == EntityState.Attacking)
                {
                    stateComponent.Clear();
                }
            }

            /*
             * if(movement.CurrentEntityState == null || !movement.CurrentEntityState.ReadyToChange) return;
             * StateComponent stateComponent = movement.CurrentEntityState;
             * if (movement.IsMoving)
             * {
             *  if (stateComponent.CurrentStatePriority < 1)
             *  {
             *      stateComponent.CurrentState = EntityState.Moving;
             *  }
             *
             *  if (stateComponent.CurrentState == EntityState.Moving)
             *  {
             *      double PI = Math.PI;
             *      double Angle = movement.Speed.Polar.Angle;
             *
             *      if (Angle < PI / 2 && Angle > -PI / 2) stateComponent.Orientation = Direction.Right;
             *      if (Angle >= PI / 2 || Angle <= -PI / 2) stateComponent.Orientation = Direction.Left;
             *
             *
             *      if (Angle <= PI / 4 && Angle >= -PI / 4) stateComponent.Direction = Direction.Right;
             *      if (Angle > PI / 4 && Angle < 3 * PI / 4) stateComponent.Direction = Direction.Down;
             *      if (Angle < -PI / 4 && Angle > 3 * -PI / 4) stateComponent.Direction = Direction.Up;
             *      if (Angle >= 3 * PI / 4 || Angle <= 3 * -PI / 4) stateComponent.Direction = Direction.Left;
             *
             *  }
             * }
             * else
             * {
             *  if (stateComponent.CurrentState == EntityState.Moving)
             *  {
             *      stateComponent.CurrentState = EntityState.Idle;
             *  }
             * }
             */
        }
Пример #5
0
 private void KillEntity(StateComponent component)
 {
     _ecs.KillEntity(component.RootID);
 }
Пример #6
0
 private void SetPreviousState(StateComponent component) //gets called when all computation is finished and it is preparing for the next game update
 {
     component.RecentlyChanged = component.PreviousState != component.CurrentState;
     component.PreviousState   = component.CurrentState;
 }