GetPosition() public method

public GetPosition ( ) : Vector2
return Vector2
コード例 #1
0
        public static Vector2 GetPosition(Vector2 start, Vector2 toGoal, float radius, Entity source)
        {
            float range = toGoal.Length();
            toGoal.Normalize();

            if(range == 0)
            {
                return start;
            }

            #region Standard method

            Vector2 curGoal = start + toGoal * (range + radius);

            float standardRange = range;

            if (_level.IsPixelAccessible((curGoal)))
            {
                return curGoal - toGoal * radius;
            }
            else
            {
                if (source != null)
                {
                    Entity ent = _level.GetEntityAt(curGoal);
                    if (ent.Equals(source))
                    {
                        return curGoal;
                    }

                    ent.OnCollide(source);

                    if (!start.Equals(source.GetPosition()))
                    {
                        return source.GetPosition();
                    }

                    if (ent.CanBePickedUp())
                    {
                        return curGoal - toGoal * radius;
                    }
                }
            }

            while (!_level.IsPixelAccessible((curGoal)))
            {
                if (standardRange > 1)
                {
                    standardRange -= 1;
                }
                else
                {
                    break;
                }

                curGoal = start + toGoal * (standardRange + radius);

                if (_level.IsPixelAccessible((curGoal)))
                {
                    return curGoal - toGoal * radius;
                }
                else
                {
                    if (source != null)
                    {
                        Entity ent = _level.GetEntityAt(curGoal);

                        ent.OnCollide(source);

                        if (!start.Equals(source.GetPosition()))
                        {
                            return source.GetPosition();
                        }

                        if (ent.CanBePickedUp())
                        {
                            return curGoal - toGoal * radius;
                        }
                    }
                }
            }

            #endregion

            #region "Slide" method

            if (Math.Abs(toGoal.X) > Math.Abs(toGoal.Y))
            {
                toGoal = new Vector2(toGoal.X, 0);
            }
            else
            {
                toGoal = new Vector2(0, toGoal.Y);
            }

            curGoal = start + toGoal * (range + radius);

            while (!_level.IsPixelAccessible((curGoal)))
            {
                if (standardRange > 1)
                {
                    standardRange -= 1;
                }
                else
                {
                    return start;
                }

                curGoal = start + toGoal * (standardRange + radius);
            }

            #endregion

            return curGoal - toGoal * radius;
        }
コード例 #2
0
ファイル: EntityGruselUte.cs プロジェクト: floAr/WarTornLands
        public override void Update(GameTime gameTime)
        {
            _victim = (Game as Game1)._player;
            Vector2 toPlayer = this._position - _victim.GetPosition();

            #region Check state

            if (toPlayer.LengthSquared() < Constants.GruselUte_SightRange * Constants.GruselUte_SightRange)
            {
                _state = AIstate.AGGRO;
            }
            else
            {
                _state = AIstate.IDLE;
            }

            switch (_state)
            {
                case AIstate.IDLE:
                    IdleBehavior(gameTime);
                    break;
                case AIstate.AGGRO:
                    AggroBehavior(gameTime);
                    break;
                default:
                    IdleBehavior(gameTime);
                    break;
            }
            #endregion

            _cm.Update(gameTime);

            base.Update(gameTime);
        }