Exemplo n.º 1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (Window.ClientBounds.Width != GraphicsDevice.Viewport.Width
                ||
                Window.ClientBounds.Height != GraphicsDevice.Viewport.Height)
            {
                graphics.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
                graphics.ApplyChanges();
            }
            if (reflectionMap == null)
            {
                reflectionMap = new RenderTarget2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24);
            }

            cam.AspectRatio = GraphicsDevice.Viewport.AspectRatio;
            //GraphicsDevice.Clear(Color.CornflowerBlue);

            GraphicsDevice.SetRenderTarget(reflectionMap);
            GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Red, 1, 0);
            var rCam = cam.CreateReflectionCam();

            var depthState = new DepthStencilState();

            depthState.DepthBufferEnable = false;

            sky.Draw(rCam);

            depthState.DepthBufferEnable = true;
            heli.Draw(rCam);
            foreach (var b in helis.Values)
            {
                b.Draw(rCam);
            }

            island.Draw(rCam);

            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Red, 1, 0);
            heli.Draw(cam);
            foreach (var b in helis.Values)
            {
                b.Draw(cam);
            }
            island.Draw(cam);
            sky.Draw(cam);
            water.Draw(cam, gameTime, reflectionMap);

            spriteBatch.Begin();

            var pos = GraphicsDevice.Viewport.Project(heli.Position, cam.Projection, cam.View, Matrix.Identity);

            spriteBatch.DrawString(font, heli.nickname, new Vector2(pos.X, pos.Y - 100), heli.color);
            foreach (var b in helis)
            {
                var posb = GraphicsDevice.Viewport.Project(b.Value.Position, cam.Projection, cam.View, Matrix.Identity);
                spriteBatch.DrawString(font, b.Value.nickname, new Vector2(posb.X, posb.Y - 100), b.Value.color);
                spriteBatch.DrawString(font, b.Key, new Vector2(posb.X, posb.Y - 80), b.Value.color);
            }


            spriteBatch.DrawString(font, "Collective: " + heli.collective.ToString(), new Vector2(10, 1), heli.color);
            spriteBatch.DrawString(font, "Roll: " + heli.roll.ToString(), new Vector2(10, 25), heli.color);
            spriteBatch.DrawString(font, "Pitch: " + heli.pitch.ToString(), new Vector2(10, 50), heli.color);
            spriteBatch.DrawString(font, "Autohover: " + autoHover, new Vector2(10, 75), heli.color);

            spriteBatch.DrawString(font, heli.Position.X.ToString(), new Vector2(10, 100), heli.color);
            spriteBatch.DrawString(font, (Math.Cos(heli.pitch) * Math.Cos(heli.roll)).ToString(), new Vector2(10, 125), heli.color);
            if (heli.Position.X > 500 || heli.Position.X < -500 || heli.Position.Y > 500 || heli.Position.Y < -500)
            {
                spriteBatch.DrawString(font, "Unauthorized territory! Get back to the islands now!", new Vector2(200, 300), Color.Red);
            }
            if (heli.vertices[5].Pos.Y >= 200)
            {
                spriteBatch.DrawString(font, "Maximum Altitude", new Vector2(400, 300), Color.Red);

                foreach (var v in heli.vertices)
                {
                    v.A     = Vector3.Zero;
                    v.Pos.Y = 200;
                }
            }
            if (heli.vertices[5].Pos.Y < 0)
            {
                spriteBatch.Draw(reflectionMap, new Rectangle(0, 0, 10000, 10000), Color.Black);
                spriteBatch.DrawString(font, "Game Over", new Vector2(400, 300), Color.Red);

                foreach (var v in heli.vertices)
                {
                    v.Pos.Y = -100;
                }
            }
            spriteBatch.End();
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState        = BlendState.Opaque;

            base.Draw(gameTime);
        }