public SimulationManager(GraphicsDevice device, ContentManager content)
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("Cannot create more than once instance of the simulation manager.");
            }
            Instance = this;

            _sb       = new SpriteBatch(device);
            _blankTex = new Texture2D(device, 1, 1);
            _blankTex.SetData(new Color[] { Color.White });

            _device    = device;
            _world     = new WorldModel(device, (int)Constants.WorldSize.X / 10);
            _uavModel  = new CModel(device, content.Load <Model>("UAV"));
            _tankModel = new CModel(device, content.Load <Model>("tank"));
            _missModel = new CModel(device, content.Load <Model>("sphere_missile"));
            _cone      = new ConeModel(device);
            _ring      = new RingModel(device, Constants.TankFiringRange / 10, 1);

            _font  = content.Load <SpriteFont>("debugfont");
            _lRect = new Rectangle(0, 0, 130, 70);

            Simulation = new Simulation();

            _entityFollow = new EntityFollowBehavior();
        }
Exemple #2
0
        private void BlueUAVButton_Click(object sender, EventArgs e)
        {
            DisableTranslate();
            // Set target to blue uav
            EntityFollowBehavior entityBeh = new EntityFollowBehavior();

            entityBeh.Choice             = "Team2.UAV";
            CameraManager.ActiveBehavior = entityBeh;
            UpdateZoomControlsUAV();
        }
Exemple #3
0
        private void RedTankButton_Click(object sender, EventArgs e)
        {
            DisableTranslate();
            // Set target to red tank
            EntityFollowBehavior entityBeh = new EntityFollowBehavior();

            entityBeh.Choice             = "Team1.Tank";
            CameraManager.ActiveBehavior = entityBeh;
            UpdateZoomControlsTank();
        }
        public void Render()
        {
            //Checks to see if Active Camera is going to follow an entity.
            if (CameraManager.ActiveBehavior is EntityFollowBehavior)
            {
                ArcBallCamera        _entityCamera = CameraManager.ActiveCamera as ArcBallCamera;
                EntityFollowBehavior EntityBeh     = CameraManager.ActiveBehavior as EntityFollowBehavior;
                //_entityCamera.Distance = 20f; //Zoom into the entity.
                if (EntityBeh.Choice == "Team1.Tank")
                {
                    _entityFollow.Entity   = Simulation.Team2.Tank;
                    _entityCamera.Distance = 20f;
                }
                else if (EntityBeh.Choice == "Team1.UAV")
                {
                    _entityFollow.Entity   = Simulation.Team2.UAV;
                    _entityCamera.Distance = 80f;
                    _entityCamera.Pitch    = 45f;
                }
                else if (EntityBeh.Choice == "Team2.Tank")
                {
                    _entityFollow.Entity   = Simulation.Team1.Tank;
                    _entityCamera.Distance = 20f;
                }
                else if (EntityBeh.Choice == "Team2.UAV")
                {
                    _entityFollow.Entity   = Simulation.Team1.UAV;
                    _entityCamera.Distance = 80f;
                    _entityCamera.Pitch    = 45f;
                }
                //else { throw new NotSupportedException(); }
                CameraManager.Set(_entityCamera, _entityFollow);
            }

            // Draw the world
            Camera camera = CameraManager.ActiveCamera;

            _world.Draw(_device, camera);
            CheckLogin(teamLogin);

            // Draw the entities
            Position t1  = Simulation.Team1.Tank.Position;
            Position t2  = Simulation.Team2.Tank.Position;
            Position u1  = Simulation.Team1.UAV.Position;
            Position u2  = Simulation.Team2.UAV.Position;
            float    t1h = Simulation.Team1.Tank.CurrentHeading;
            float    t2h = Simulation.Team2.Tank.CurrentHeading;
            float    u1h = Simulation.Team1.UAV.CurrentHeading;
            float    u2h = Simulation.Team2.UAV.CurrentHeading;

            if (id != 0)
            {
                if (id == 1)
                {
                    _tankModel.Render(camera, new Vector3(t1.X / 10, 0, t1.Y / 10), t1h, Color.Blue);
                    _uavModel.TextureRender(camera, new Vector3(u1.X / 10, 20, u1.Y / 10), u1h);

                    _cone.Render(_device, new Vector2(u1.X / 10, u1.Y / 10), camera, 1, Simulation.Team1.UAV.DetectedTankThisTurn);
                    _ring.Render(_device, new Vector2(t1.X / 10, t1.Y / 10), camera, 1);
                }
                else if (id == 2)
                {
                    _tankModel.Render(camera, new Vector3(t2.X / 10, 0, t2.Y / 10), t2h, Color.Red);
                    _uavModel.TextureRender(camera, new Vector3(u2.X / 10, 20, u2.Y / 10), u2h);

                    _cone.Render(_device, new Vector2(u2.X / 10, u2.Y / 10), camera, 2, Simulation.Team2.UAV.DetectedTankThisTurn);
                    _ring.Render(_device, new Vector2(t2.X / 10, t2.Y / 10), camera, 2);
                }
                else if (id == 3)
                {
                    _tankModel.Render(camera, new Vector3(t1.X / 10, 0, t1.Y / 10), t1h, Color.Blue);
                    _uavModel.TextureRender(camera, new Vector3(u1.X / 10, 20, u1.Y / 10), u1h);
                    _tankModel.Render(camera, new Vector3(t2.X / 10, 0, t2.Y / 10), t2h, Color.Red);
                    _uavModel.TextureRender(camera, new Vector3(u2.X / 10, 20, u2.Y / 10), u2h);

                    _cone.Render(_device, new Vector2(u1.X / 10, u1.Y / 10), camera, 1, Simulation.Team1.UAV.DetectedTankThisTurn);
                    _ring.Render(_device, new Vector2(t1.X / 10, t1.Y / 10), camera, 1);
                    _cone.Render(_device, new Vector2(u2.X / 10, u2.Y / 10), camera, 2, Simulation.Team2.UAV.DetectedTankThisTurn);
                    _ring.Render(_device, new Vector2(t2.X / 10, t2.Y / 10), camera, 2);
                }
            }


            //Draw all missiles
            for (int i = 0; i < mposList.Count; i++)
            {
                _missModel.Render(camera, new Vector3(mposList[i].X / 10, 1, mposList[i].Y / 10), mheadingList[i], Color.Black);
            }

            //Derender dead tanks
            if (gameResult == 1)
            {
                _tankModel.Render(camera, new Vector3(t2.X / 10, 0, t2.Y / 10), t1h, Color.Transparent);
            }
            if (gameResult == 2)
            {
                _tankModel.Render(camera, new Vector3(t1.X / 10, 0, t1.Y / 10), t1h, Color.Transparent);
            }
            if (gameResult == 3)
            {
                _tankModel.Render(camera, new Vector3(t1.X / 10, 0, t1.Y / 10), t1h, Color.Transparent);
                _tankModel.Render(camera, new Vector3(t2.X / 10, 0, t2.Y / 10), t1h, Color.Transparent);
            }

            // Draw legend
            _sb.Begin();
            _sb.Draw(_blankTex, _lRect, Color.White);
            _sb.DrawString(_font, "Blue = Team 1 Tank", new Vector2(5, 5), Color.Black, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            _sb.DrawString(_font, "Cyan = Team 1 UAV", new Vector2(5, 18), Color.Black, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            _sb.DrawString(_font, "Red  = Team 2 Tank", new Vector2(5, 31), Color.Black, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            _sb.DrawString(_font, "Pink = Team 2 UAV", new Vector2(5, 44), Color.Black, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            _sb.DrawString(_font, "Black = Missiles", new Vector2(5, 57), Color.Black, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);

            //Draw a message to annouonce the result
            if (gameResult != 0)
            {
                if (gameResult == 3)
                {
                    _sb.DrawString(_font, $"Both tanks destroyed. It's a draw!", new Vector2(100, 200), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                }
                else
                {
                    if (gameResult == 1)
                    {
                        _sb.DrawString(_font, $"Blue Team Wins!", new Vector2(100, 200), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                    }
                    else if (gameResult == 2)
                    {
                        _sb.DrawString(_font, $"Red Team Wins!", new Vector2(100, 200), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                    }
                }
            }
            _sb.End();
        }