Пример #1
0
        private void UpdateView()
        {
            //Vector2 p1 = pos - new Vector2(resX, resY) / 2f / zoom;
            //Vector2 p2 = pos + new Vector2(resX, resY) / 2f / zoom;

            //float scale = 0.5f;
            float     border = 0;//256
            M_Polygon poly   = new M_Polygon(Vector2.Zero, new List <Vector2>()
            {
                new Vector2(-border, -border),
                new Vector2(resX + border, -border),
                new Vector2(resX + border, resY + border),
                new Vector2(-border, resY + border)
            });

            poly.Transform(Matrix.Invert(matrix));

            float minX = poly.vertices[0].X;
            float maxX = poly.vertices[0].X;
            float minY = poly.vertices[0].Y;
            float maxY = poly.vertices[0].Y;

            for (int i = 1; i < poly.vertices.Count; i++)
            {
                if (poly.vertices[i].X < minX)
                {
                    minX = poly.vertices[i].X;
                }
                if (poly.vertices[i].X > maxX)
                {
                    maxX = poly.vertices[i].X;
                }
                if (poly.vertices[i].Y < minY)
                {
                    minY = poly.vertices[i].Y;
                }
                if (poly.vertices[i].Y > maxY)
                {
                    maxY = poly.vertices[i].Y;
                }
            }

            //minX = Math.Max(0, minX);
            //minY = Math.Max(0, minY);
            //maxX = Math.Min(mapW - 1, maxX);
            //maxY = Math.Min(mapH - 1, maxY);

            view = new M_Rectangle(minX, minY, maxX - minX, maxY - minY);

            //view = new M_Rectangle(p1, p2 - p1);
        }
Пример #2
0
        void MonoMethods.Draw(SpriteBatch spriteBatch)
        {
            float wScale = (float)graphics.PreferredBackBufferWidth / Width;
            float hScale = (float)graphics.PreferredBackBufferHeight / Height;
            float scale  = Math.Min(wScale, hScale);

            if (Input.mbWheel != 0)
            {
                cameraZoom -= Math.Sign(Input.mbWheel);
                if (cameraZoom < 1)
                {
                    cameraZoom = 1f;
                }
            }

            scale *= cameraZoom;

            float realW = graphics.PreferredBackBufferWidth / scale;
            float realH = graphics.PreferredBackBufferHeight / scale;


            if (firstPlayerView)
            {
                if (cameraOrientation == 99)
                {
                    cameraOrientation = -bots[0].orientation - MathHelper.PiOver2;
                }
                else
                {
                    cameraOrientation += (-bots[0].orientation - MathHelper.PiOver2 - cameraOrientation) * 0.1f;// 04f;
                }
                matrix = Matrix.CreateTranslation(new Vector3(-bots[0].positionV, 0f)) * Matrix.CreateRotationZ(cameraOrientation) * Matrix.CreateTranslation(new Vector3(new Vector2(realW, realH) / 2f, 0)) * Matrix.CreateScale(scale);
            }
            else
            {
                Vector2 shift = Vector2.Zero;// new Vector2(realW, realH) / 2f;// - new Vector2(width, height) / 2f;

                if (hScale > wScale)
                {
                    shift.Y += (realH - Height) * 0.5f;
                }
                else if (wScale > hScale)
                {
                    shift.X += (realW - Width) * 0.5f;
                }

                matrix = Matrix.CreateTranslation(new Vector3(shift, 0)) * Matrix.CreateScale(scale);
            }
            //DrawM.basicEffect.SetWorldAndInvTransp(matrix);
            DrawM.basicEffect.World = matrix;
            DrawM.scale             = scale;

            spriteBatch.GraphicsDevice.Clear(new Color(128, 128, 128));
            //spriteBatch.GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, matrix);

            Drawer.depth = new DepthLayer(0f);

            DrawM.Vertex.DrawRectangle(new M_Rectangle(0, 0, Width, Height), Color.CornflowerBlue);


            for (int i = 0; i < goals.Count; i++)
            {
                if (i + 1 < goals.Count)
                {
                    DrawM.Vertex.DrawLine(goals[i], goals[i + 1], Color.DeepSkyBlue, 0.2f);
                }

                DrawGoal(i, goals[i], 1f);
            }

            void DrawGoal(int i, Vector2 pos, float opaque)
            {
                DrawM.Vertex.DrawCircleOutline(pos, goalRadius, Color.DeepSkyBlue, 8f);

                float angle = 0f;
                float fov   = MathHelper.TwoPi / bots.Length;

                for (int j = 0; j < bots.Length; j++)
                {
                    Color color = bots[j].goalIndex > i ? Color.Transparent : bots[j].goalIndex == i ? bots[j].GetInternalColor() : Color.DeepSkyBlue;
                    DrawM.Vertex.DrawCone(pos, goalRadius, angle, fov, color * opaque, color * opaque, 8f);
                    angle += fov;
                }
                //DrawM.Vertex.DrawCircle(goals[i], GOALRADIUS, Color.Lime, 16f);
                //font.Draw(i.ToString(), Anchor.Center(goals[i]), Color.Black, new Vector2(0.2f));
            }

            if (firstPlayerView && bots[0].goalIndex < goals.Count)
            {
                // if goal is outside of screen, show it at the border of the screen


                M_Rectangle rect   = new M_Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                Vector2     center = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight) / 2f;
                M_Polygon   poly   = rect.ToPolygon();
                //rect.pos -= rect.size / 2f;
                Matrix invert = Matrix.Invert(matrix);
                poly.Transform(invert);
                center = Vector2.Transform(center, invert);
                Vector2 onScreenGoalPos = goals[bots[0].goalIndex];// Vector2.Transform(goals[bots[0].goalIndex], matrix);

                //DrawM.Vertex.DrawRectangle(rect, Color.Red * 0.5f);

                if (!poly.ColVector(onScreenGoalPos))
                {
                    Vector2 dir = onScreenGoalPos - center;
                    var     cr  = poly.DistToVector(onScreenGoalPos, dir);

                    onScreenGoalPos -= dir * cr.distance.Value;// + Vector2.Normalize(dir) * 3f;

                    //if (onScreenGoalPos.X < rect.Left)
                    //    onScreenGoalPos.X = rect.Left;
                    //if (onScreenGoalPos.X > rect.Right)
                    //    onScreenGoalPos.X = rect.Right;
                    //if (onScreenGoalPos.Y < rect.Top)
                    //    onScreenGoalPos.Y = rect.Top;
                    //if (onScreenGoalPos.Y > rect.Bottom)
                    //    onScreenGoalPos.Y = rect.Bottom;

                    DrawGoal(bots[0].goalIndex, onScreenGoalPos, 0.5f);
                }

                //camera
                //bots[0].goalIndex
            }

            string text;

            for (int i = 0; i < bots.Length; i++)
            {
                if (bots[i].Alive)
                {
                    bots[i].mask.Draw(bots[i].GetInternalColor());

                    bots[i].Draw();
                }
            }

            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp);

            for (int i = 0; i < goals.Count; i++)
            {
                Vector2 pos = Vector2.Transform(goals[i], matrix);
                font.Draw((i + 1).ToString(), Anchor.Center(pos), Color.Black);
            }

            text = "";

            text += "time: " + Math.Floor(frame / 60f) + " s\n";

            if (gameEnd)
            {
                for (int i = 0; i < bots.Length; i++)
                {
                    text += "______________________\n";
                    text += "Bot " + i + "\n";
                    //text += "Health: " + bots[i].health + "\n";
                    text += "Time: " + bots[i].frameTime + "\n";

                    /*text += "Kills: " + bots[i].kills + "\n";
                     * text += "Damage Dealt: " + bots[i].damageDealt + "\n";*/
                }
            }

            spriteBatch.DrawString(font, text, new Vector2(16, 16), Color.White);


            spriteBatch.End();
        }