Example #1
0
        public override void Exit()
        {
            AIFighter fighter = (AIFighter)Entity;

            fighter.Path.Waypoints.Clear();
            fighter.Path.DrawPath = false;
        }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            float timeDelta = (float)gameTime.ElapsedGameTime.TotalSeconds;
            float range     = 30.0f;

            timeShot += timeDelta;
            float fov = MathHelper.PiOver4;
            // Can I see the leader?
            Fighter leader = XNAGame.Instance.Leader;

            if ((leader.Position - Entity.Position).Length() > range)
            {
                // Is the leader inside my FOV
                AIFighter fighter = (AIFighter)Entity;
                fighter.SwicthState(new IdleState(fighter));
            }
            else
            {
                float   angle;
                Vector3 toEnemy = (leader.Position - Entity.Position);
                toEnemy.Normalize();
                angle = (float)Math.Acos(Vector3.Dot(toEnemy, Entity.Look));
                if (angle < fov)
                {
                    if (timeShot > 0.25f)
                    {
                        Lazer lazer = new Lazer();
                        lazer.Position = Entity.Position;
                        lazer.Look     = Entity.Look;
                        XNAGame.Instance.Children.Add(lazer);
                        timeShot = 0.0f;
                    }
                }
            }
        }
Example #3
0
        public override void Enter()
        {
            AIFighter fighter = (AIFighter)Entity;

            fighter.SteeringBehaviours.turnOffAll();
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit);
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance);
            fighter.offset = new Vector3(0, 0, 5);
            fighter.Leader = XNAGame.Instance.Leader;
        }
Example #4
0
        public override void Update(GameTime gameTime)
        {
            float range = 30.0f;
            // Can I see the leader?
            Fighter leader = XNAGame.Instance.Leader;

            if ((leader.Position - Entity.Position).Length() < range)
            {
                // Is the leader inside my FOV
                AIFighter fighter = (AIFighter)Entity;
                fighter.SwicthState(new AttackingState(fighter));
            }
        }
Example #5
0
        public override void Enter()
        {
            AIFighter fighter = (AIFighter)Entity;

            if (initialPos == Vector3.Zero)
            {
                initialPos = fighter.Position;
            }
            fighter.Path.Waypoints.Add(initialPos);
            fighter.Path.Waypoints.Add(initialPos + new Vector3(-50, 0, -80));
            fighter.Path.Waypoints.Add(initialPos + new Vector3(0, 0, -160));
            fighter.Path.Waypoints.Add(initialPos + new Vector3(50, 0, -80));
            fighter.Path.Looped   = true;
            fighter.Path.DrawPath = true;
            fighter.SteeringBehaviours.turnOffAll();
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.follow_path);
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance);
        }
        public static void setUpStateMachineDemo()
        {
            List<Entity> children = XNAGame.Instance().Children;
            Ground ground = new Ground();
            children.Add(ground);
            XNAGame.Instance().Ground = ground;
            AIFighter aiFighter = new AIFighter();
            aiFighter.pos = new Vector3(-20, 50, 50);
            aiFighter.maxSpeed = 16.0f;
            aiFighter.SwicthState(new IdleState(aiFighter));
            aiFighter.Path.DrawPath = true;
            children.Add(aiFighter);

            Fighter fighter = new Fighter();
            fighter.ModelName = "ship2";
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.arrive);
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance);
            fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance);
            fighter.pos = new Vector3(10, 50, 0);
            fighter.targetPos = aiFighter.pos + new Vector3(-50, 0, -80);
            children.Add(fighter);

            Fighter camFighter = new Fighter();
            camFighter.Leader = fighter;
            camFighter.offset = new Vector3(0, 5, 10);
            camFighter.pos = fighter.pos + camFighter.offset;
            camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit);
            camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance);
            camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance);
            XNAGame.Instance().CamFighter = camFighter;
            children.Add(camFighter);

            XNAGame.Instance().Leader = fighter;
            Camera camera = XNAGame.Instance().Camera;
            camera.pos = new Vector3(0.0f, 60.0f, 100.0f);
        }