Example #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);
        }
Example #2
0
 public House(M_Rectangle rect) : base(null, rect)
 {
     baseRect = Mask as M_Rectangle;
     basePoly = rect.ToPolygon();
     for (int i = 0; i < basePoly.vertices.Count; i++)
     {
         basePoly.vertices[i] += basePoly.pos;
     }
     basePoly.pos = Vector2.Zero;
     drawPolies   = new M_Polygon[3];
     for (int i = 0; i < drawPolies.Length; i++)
     {
         drawPolies[i] = new M_Rectangle(0, 0, 0, 0).ToPolygon();
     }
     shading[0] = Colors.brightnessTop;
 }
Example #3
0
        public Car(Vector2 pos, float orientation) : base(Textures.car1Color, new M_Rectangle(0, 0, Textures.car1Color.Width, Textures.car1Color.Height - 4).ToPolygon())
        {
            noColorTex       = Textures.car1NoColor;
            Pos              = pos;
            this.orientation = orientation;
            poly             = Mask as M_Polygon;
            for (int i = 0; i < poly.vertices.Count; i++)
            {
                poly.vertices[i] -= Texture.GetSize() / 2f;
            }
            baseVertices = poly.vertices.ToList();

            carColor = G.Rand.NextColor();

            UpdateMask();
        }
Example #4
0
        public Player(Vector2 pos) : base(Textures.player, new M_Circle(pos, radius))
        {
            Pos = pos;

            right = new KeyCollection(Input.d, Input.right);
            up    = new KeyCollection(Input.w, Input.up);
            left  = new KeyCollection(Input.a, Input.left);
            down  = new KeyCollection(Input.s, Input.down);
            keys.AddRange(new List <KeyCollection>()
            {
                right, up, left, down
            });

            kickMask = new M_Polygon(Pos, new List <Vector2>());
            kickMask.vertices.Add(Vector2.Zero);
            kickMask.vertices.Add(Vector2.Zero);
            kickMask.vertices.Add(Vector2.Zero);
            UpdateKickVertices();
        }
Example #5
0
        public Bot(bool control = true)
        {
            this.control = control;
            float w = length / 2f;
            float h = width / 2f;

            maskSourceVertices = new List <Vector2>()
            {
                new Vector2(w, h), new Vector2(-w, h), new Vector2(-w, -h), new Vector2(w, -h)
            };
            mask = new M_Polygon(Vector2.Zero, maskSourceVertices.ToList());

            if (!control)
            {
                positionX += 10;
            }

            name = GetName();
        }
Example #6
0
 public EMS_Polygon(Vector2 pos) : base(null, M_Polygon.GetRandomConvex(pos, G.Rand, 32f))
 {
 }
Example #7
0
        public EnvCarRace(Type[] botTypes)
        {
            Collision.minDist       = 0.01f;
            CollisionResult.minDist = 0;

            goals = new List <Vector2>();

            Vector2 pos;

            int space = 4;

            for (int i = 0; i < goalCount; i++)
            {
                pos = Vector2.Zero;
                bool col;
                do
                {
                    pos = new Vector2(constRand.Next(space, Width - space), constRand.Next(space, Height - space)) + new Vector2(0.5f);

                    col = false;
                    if (i > 1)
                    {
                        M_Polygon line = new M_Polygon(Vector2.Zero, new List <Vector2>()
                        {
                            goals[i - 1], pos
                        }, true);
                        for (int j = 1; j < goals.Count; j++)
                        {
                            M_Polygon line2 = new M_Polygon(Vector2.Zero, new List <Vector2>()
                            {
                                goals[j], goals[j - 1]
                            }, true);
                            if (line.ColPolygon(line2))
                            {
                                col = true;
                                break;
                            }
                        }
                    }
                } while (col || goals.Any(f => Vector2.Distance(pos, f) < 3f));

                goals.Add(pos);
            }

            this.bots = GetBots <Bot>(botTypes);

            firstPlayerView = false;// bots.Length == 1;

            int x, y;

            x   = constRand.Next(Width);
            y   = constRand.Next(Height);
            pos = new Vector2(x + 0.5f, y + 0.5f);

            float orientation = constRand.NextFloat() * MathHelper.TwoPi;

            for (int i = 0; i < this.bots.Length; i++)
            {
                this.bots[i].Initialize(this, pos, orientation, i, goals.ToList());
            }

            for (int i = 0; i < this.bots.Length; i++)
            {
                this.bots[i].InitializeCustomInternal();
            }

            Drawer.roundPositionTo = 0f;
        }
Example #8
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();
        }