Example #1
0
        public override void Update(Chunk chunk)
        {
            float dt = Game1.DeltaT;

            Sprite.Update(dt);
            ViewCone.UpdatePosition(Position);
            ViewCone.Update(chunk);
        }
Example #2
0
 public StaticCamera(Vector2 position, float degrees, Game1 game) : base(game)
 {
     Position = position;
     Sprite   = new AnimatedSprite(null, game, new Vector2(Chunk.TileSize, Chunk.TileSize));
     ViewCone = new ConeEntity(game);
     ViewCone.FromDegrees(degrees, 33);
     ViewCone.Radius = Chunk.TileSize * 999;
     ViewCone.UpdatePosition(position);
 }
Example #3
0
 public GroundDrone(Vector2 position, Game1 game) : base(game, new Vector2(Chunk.TileSize / 3, Chunk.TileSize / 2))
 {
     Position    = position;
     Spawn       = position;
     Sprite      = new AnimatedSprite(null, game, new Vector2(32, 32));
     AlertSignal = new AnimatedSprite(null, game, new Vector2(16, 16));
     ViewCone    = new ConeEntity(game)
     {
         Radius = Chunk.TileSize * 6
     };
     ViewCone.FromDegrees(0, 30);
     ViewCone.UpdatePosition(Position);
     Velocity = new Vector2(PatrolSpeed.X, PatrolSpeed.Y);
 }
Example #4
0
        public AerialDrone(Vector2 position, Game1 game) : base(game, new Vector2(Chunk.TileSize / 3, Chunk.TileSize / 6))
        {
            Spawn          = position;
            Position       = position;
            WanderLocation = Position;
            TargetLocation = Position;
            LastTarget     = Position;
            Sprite         = new AnimatedSprite(null, game, new Vector2(32, 32));
            AlertSignal    = new AnimatedSprite(null, game, new Vector2(16, 16));
            ViewCone       = new ConeEntity(game, false);

            Direction = (float)game.RNG.NextDouble() * 2 * (float)Math.PI;

            ViewCone.FromDegrees(0, 50);
            ViewCone.Radius = Chunk.TileSize * 5;
            ViewCone.UpdatePosition(position);
        }
Example #5
0
        public override void Update(Chunk chunk)
        {
            if (FlyingSound == null)
            {
                FlyingSound = Game.SoundEngine.Play("Enemy_DroneFly", Position, 1, true);
            }

            if (PositionKnown > 0)
            {
                --PositionKnown;
            }

            float dt = Game1.DeltaT;

            Velocity = new Vector2();

            switch (State)
            {
            case AIState.Patrolling:
                if (MoveTo(WanderLocation, PatrolSpeed))
                {
                    Wait();
                }
                break;

            case AIState.Searching:
                if (MoveTo(WanderLocation, SearchSpeed))
                {
                    Velocity = new Vector2(0);
                    bool foundSearch = false;
                    for (int i = 0; i < WanderSearchAttempts; ++i)
                    {
                        if (FindWander(TargetLocation, PatrolRange, chunk))
                        {
                            foundSearch = true;
                            break;
                        }
                    }
                    if (!foundSearch)
                    {
                        if (Target(TargetLocation, chunk, AIState.Targeting))
                        {
                            FinishPath = () => { };
                        }
                    }
                }
                break;

            case AIState.CursorySearching:
                if (MoveTo(WanderLocation, PatrolSpeed))
                {
                    Velocity = new Vector2(0);
                    bool foundSearch = false;
                    for (int i = 0; i < WanderSearchAttempts; ++i)
                    {
                        if (FindWander(TargetLocation, PatrolRange, chunk))
                        {
                            foundSearch = true;
                            break;
                        }
                    }
                    if (!foundSearch)
                    {
                        if (Target(TargetLocation, chunk, AIState.Investigating))
                        {
                            FinishPath = () => { };
                        }
                    }
                }

                StateTimer -= dt;
                if (StateTimer <= 0)
                {
                    Return(chunk);
                }
                break;

            case AIState.Waiting:
                StateTimer += dt;
                if (StateTimer <= 0.05F * WaitTime)
                {
                }
                if (StateTimer <= 0.25F * WaitTime)
                {
                    Direction += dt * WaitAngularVelocity;
                }
                else if (StateTimer <= 0.3F * WaitTime)
                {
                }
                else if (StateTimer <= 0.7F * WaitTime)
                {
                    Direction -= dt * WaitAngularVelocity;
                }
                else if (StateTimer <= 0.75F * WaitTime)
                {
                }
                else if (StateTimer <= 0.95F * WaitTime)
                {
                    Direction += dt * WaitAngularVelocity;
                }
                else if (StateTimer <= WaitTime)
                {
                }
                else
                {
                    bool found = false;
                    for (int i = 0; i < WanderSearchAttempts; ++i)
                    {
                        if (FindWander(Spawn, PatrolRange, chunk))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Return(chunk);
                    }
                    else
                    {
                        State = AIState.Patrolling;
                    }
                }
                break;

            case AIState.Targeting:
                Vector2 nextPos = NextNode < Path.Count - 1 ? Path[NextNode] : TargetLocation;
                if (MoveTo(nextPos, TargetSpeed))
                {
                    Velocity = new Vector2();
                    ++NextNode;

                    nextPos = NextNode < Path.Count - 1 ? Path[NextNode] : TargetLocation;

                    if (NextNode >= Path.Count)
                    {
                        Search(nextPos, chunk, float.PositiveInfinity);
                    }
                    else
                    {
                        MoveTo(nextPos, TargetSpeed);
                    }
                }
                break;

            case AIState.Investigating:
                if (MoveTo(Path[NextNode], SearchSpeed))
                {
                    Velocity = new Vector2();
                    ++NextNode;
                    if (NextNode >= Path.Count)
                    {
                        Search(Path[NextNode - 1], chunk, SearchTime, true);
                    }
                    else
                    {
                        MoveTo(Path[NextNode], SearchSpeed);
                    }
                }
                break;

            case AIState.Returning:
                if (MoveTo(Path[NextNode], PatrolSpeed))
                {
                    ++NextNode;
                    if (NextNode >= Path.Count)
                    {
                        Wait();
                    }
                }
                break;
            }

            if (Pathfinding != null)
            {
                if (Pathfinding.IsCompleted)
                {
                    var newPath = Pathfinding.Result;

                    Pathfinding.Dispose();
                    Pathfinding = null;

                    if (newPath.Count > 1)
                    {
                        Path = newPath;

                        TargetLocation = Path.Last();

                        NextNode = 1;
                    }

                    State = NextState;

                    FinishPath.Invoke();
                }
            }

            { // Kill if touched.
                if (!chunk.Level.Player.IsHiding &&
                    chunk.Level.Player.DeathTimer <= 0 &&
                    GetBoundingBox().Intersects(chunk.Level.Player.GetBoundingBox()))
                {
                    chunk.Level.Player.Kill();
                }
            }

            if (State == AIState.Targeting || State == AIState.Searching)
            {
                Sprite.Play("chase");
            }
            else
            {
                Sprite.Play("idle");
            }

            Position += dt * Velocity;
            ViewCone.UpdatePosition(Position);
            ViewCone.Middle = Direction;
            ViewCone.Update(chunk);

            AlertSignal.Update(dt);
            Sprite.Update(dt);

            FlyingSound.Position = Position;

            base.Update(chunk);
        }