Exemplo n.º 1
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;
                    }
                }
            }
        }
Exemplo n.º 2
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));
            }
        }
        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);
        }