Ejemplo n.º 1
0
 public void Render(bool actors, bool props, bool scenery,QuakeCamera cam,float dist)
 {
     if (actors)
     {
         foreach (Actor a in mEntitiesInPlay)
             a.Render(cam,dist);
     }
 }
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            PickedActors = new List<string>();

            textBox = new Rectangle(10, 10, 300, 300);

            this.Window.Title = "Bane XNA demo";
            // create a default world and matrix
            meshRotation = Matrix.Identity;

            currentjump = 0;
            jumping = false;
            falling = false;

            MusicPlaying = false;

            // create the mesh array
            sampleMeshes = new Model[5];

            //set up a ring of meshes
            meshWorlds = new Matrix[8];
            for (int i = 0; i < 8; i++)
            {
                float theta = MathHelper.TwoPi * ((float)i / 8f);
                meshWorlds[i] = Matrix.CreateTranslation(
                    5f * (float)Math.Sin(theta), 0, 5f * (float)Math.Cos(theta));
            }

            // set the initial material assignments to the geometry

            // stretch the cube out to represent a "floor"
            // that will help visualize the light radii
            floorWorld = Matrix.CreateScale(30f, 1f, 30f) *
                Matrix.CreateTranslation(0, -2.2f, 0);
            lightMeshWorld = Matrix.CreateScale(.2f);

            meshWorlds[1] = Matrix.Identity;
            meshWorlds[1] = meshWorlds[1] * Matrix.CreateScale(0.1f,0.2f,0.1f);
            meshWorlds[1] = meshWorlds[1] * Matrix.CreateTranslation(0, 5f, 0);

            float startx, startz;

            startx = Stage.Level.StartLocation.X * 16;
            startz = Stage.Level.StartLocation.Y * 16;

            fpsCam = new QuakeCamera(GraphicsDevice.Viewport, new Vector3(startx+4, 10.0f, startz+4), 0, 0);
            fpsCam.SetFacingDegrees(Stage.Level.StartOrientation);

            fpsCam.LastGridSquareX = (int)Stage.Level.StartLocation.X;
            fpsCam.LastGridSquareY = (int)Stage.Level.StartLocation.Y;

            // Get collision grid data and load into camera class.
            bool[] bg = new bool[Stage.Map.Width * Stage.Map.Height];

            for (int y = 0; y < Stage.Map.Height; y++)
            {
                for (int x = 0; x < Stage.Map.Width; x++)
                {
                    if (Stage.Map.GetSquareAt(x, y).type == MapSquareType.Closed)
                        bg[x + (y * Stage.Map.Width)] = true;
                    else
                        bg[x + (y * Stage.Map.Width)] = false;
                }
            }

            fpsCam.CollisionGrid = bg;
            fpsCam.GridHeight = Stage.Map.Height;
            fpsCam.GridWidth = Stage.Map.Width;
            fpsCam.SquareWidth = 8;
            fpsCam.SquareHeight = 8;

            //Set up the test actor[0](s)

            actor = new Actor[10];

            //actor[0] 1 - obeys a move to order then wanders aimlessly
            actor[0] = new Actor();
            actor[0].CollisionGrid = bg;
            actor[0].GridWidth = Stage.Map.Width;
            actor[0].GridHeight = Stage.Map.Height;
            actor[0].SetFacingDegrees(-90);
            actor[0].SetLocation(160, 10, 72);
            actor[0].FacingOffset = MathHelper.ToRadians(270);
            actor[0].FOV = 60.0f;
            actor[0].UpdateWorldMatrix();
            actor[0].Behaviours = FLAG_Behaviours.WANDERER | FLAG_Behaviours.MONSTER;
            actor[0].ScalingFactor = 0.02f;

            //Set up the order
            Order o = new Order();
            o.Type = ENUM_OrderType.MOVE_TO;
            Stage.Graph.SearchAStarPath(Stage.Graph.GetGridReferenceFromVector(actor[0].CurrentLocation), new Vector2(11, 37));
            o.Vector2Queue = Stage.Graph.GetPathQueue();

            actor[0].OrderQueue.Enqueue(o);

            //actor[0] 2 - stands around and attacks the player when alerted.
            actor[1] = new Actor();
            actor[1].CollisionGrid = bg;
            actor[1].GridWidth = Stage.Map.Width;
            actor[1].GridHeight = Stage.Map.Height;
            actor[1].SetFacingDegrees(-90);
            actor[1].SetLocation(228, 4, 132);
            actor[1].FacingOffset = MathHelper.ToRadians(270);
            actor[1].FOV = 60.0f;
            actor[1].UpdateWorldMatrix();
            actor[1].Behaviours = FLAG_Behaviours.AGGRESSIVE | FLAG_Behaviours.MONSTER;
            actor[1].ScalingFactor = 4.0f;
            actor[1].FightRange = 6.0f;
            actor[1].HearingRadius = 320.0f;

            //actor[0] 3 - patrols waypoints
            actor[2] = new Actor();
            actor[2].CollisionGrid = bg;
            actor[2].GridWidth = Stage.Map.Width;
            actor[2].GridHeight = Stage.Map.Height;
            actor[2].SetFacingDegrees(-90);
            actor[2].SetLocation(20, 10, 70);
            actor[2].FacingOffset = MathHelper.ToRadians(90);
            actor[2].FOV = 60.0f;
            actor[2].UpdateWorldMatrix();
            actor[2].Behaviours = FLAG_Behaviours.MONSTER | FLAG_Behaviours.PATROLLER;
            actor[2].ScalingFactor = 1.0f;

            //Set up patrol list.
            Stage.Graph.SearchAStarPath(new Vector2(1, 4), new Vector2(1, 13));
            actor[2].SimplePatrolList = Stage.Graph.GetPathList();
            //The last node of this list will always be the same as the first node of the next list. This affects the direction in which the actor[0] looks
            //so.
            actor[2].SimplePatrolList.RemoveAt(actor[2].SimplePatrolList.Count - 1);
            Stage.Graph.SearchAStarPath(new Vector2(1,13), new Vector2(5, 13));
            actor[2].SimplePatrolList.AddRange(Stage.Graph.GetPathList());
            actor[2].SimplePatrolList.RemoveAt(actor[2].SimplePatrolList.Count - 1);
            Stage.Graph.SearchAStarPath(new Vector2(5, 13), new Vector2(5, 4));
            actor[2].SimplePatrolList.AddRange(Stage.Graph.GetPathList());
            actor[2].SimplePatrolList.RemoveAt(actor[2].SimplePatrolList.Count - 1);
            Stage.Graph.SearchAStarPath(new Vector2(5, 4), new Vector2(1, 4));
            actor[2].SimplePatrolList.AddRange(Stage.Graph.GetPathList());
            actor[2].SimplePatrolList.RemoveAt(actor[2].SimplePatrolList.Count - 1);

            actor[0].mInstanceName = "Wanderer";
            actor[1].mInstanceName = "Dwarf";
            actor[2].mInstanceName = "Patroller";

            //TODO: Add waypoints and build this list from waypoint data assuming the last step is always a move back from the last waypoint to the first.
            //TODO: Then add a second type of patrol behaviour that goes backwards through the list when it reaches the end.

            // NEW COLLISION/LOS MODEL DATA
            Stage.Map.CalculateWallCollision();

            base.Initialize();
        }