Exemplo n.º 1
0
        public void AddRectangle(Rectangle Box)
        {
            Vector2[] verts =
            {
                new Vector2(Box.x,             Box.y),
                new Vector2(Box.x + Box.width, Box.y),
                new Vector2(Box.x,             Box.y + Box.height),

                new Vector2(Box.x + Box.width, Box.y),
                new Vector2(Box.x + Box.width, Box.y + Box.height),
                new Vector2(Box.x,             Box.y + Box.height),
            };
            AddVertices(verts);
        }
Exemplo n.º 2
0
 public Hitbox(Rectangle Box)
 {
     Triangles = new List <Triangle>();
     AddRectangle(Box);
 }
Exemplo n.º 3
0
        // https://stackoverflow.com/a/49886367
        private void TryPickUpRock()
        {
            List <(int index, int x, int y, float roation, float scale)> rocksToRemove = new List <(int index, int x, int y, float roation, float scale)>()
            {
            };

            foreach (var rock in rocks.rockTypesAndLocations)
            {
                // Old code, couldn't handle rotation of rocks
                //bool matchX = false;
                //bool matchY = false;
                //if (x > (rock.x - (rocks.GetTexture(rock.index).width*rock.scale)))
                //if (x < rock.x)
                // matchX = true;
                //if (y+40 > (rock.y - (rocks.GetTexture(rock.index).height*rock.scale)))
                //if (y+40 < rock.y)
                //matchY = true;
                //if (matchX && matchY)
                //rocksToRemove.Add(rock);

                System.Drawing.RectangleF clientRectangle = new System.Drawing.RectangleF(rock.x, rock.y, (rocks.GetTexture(rock.index).width *rock.scale), (rocks.GetTexture(rock.index).height *rock.scale));

                // Create Matrix and rotate points.
                // Note: requires libgdiplus
                Matrix matrix = new Matrix();
                var    p      = new System.Drawing.PointF[] {
                    clientRectangle.Location,
                    new System.Drawing.PointF(clientRectangle.Right, clientRectangle.Top),
                    new System.Drawing.PointF(clientRectangle.Right, clientRectangle.Bottom),
                    new System.Drawing.PointF(clientRectangle.Left, clientRectangle.Bottom)
                };
                matrix.RotateAt(rock.rotation, new System.Drawing.PointF(clientRectangle.X, clientRectangle.Top));
                matrix.TransformPoints(p);

                var astronautRectangle = new Raylib_cs.Rectangle(x + 50, y + 10, 50, 110);

                // Detect if we're touching the corners of the rocks.
                if (Raylib.CheckCollisionPointRec(new Vector2(p[0].X, p[0].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[1].X, p[1].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[2].X, p[2].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[3].X, p[3].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }

                var sideOneMidpoint   = new ParametricLine(p[0], p[1]);
                var sideTwoMidpoint   = new ParametricLine(p[1], p[2]);
                var sideThreeMidpoint = new ParametricLine(p[2], p[3]);
                var sideFourMidpoint  = new ParametricLine(p[3], p[0]);

                // Detect if touching midpoint of rock edge.
                if (Raylib.CheckCollisionPointRec(new Vector2(sideOneMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideTwoMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideThreeMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideFourMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
            }
            foreach (var rock in rocksToRemove)
            {
                collectRocks.rocksCollected++;
                rocks.rockTypesAndLocations.Remove(rock);
            }
            if (rocksToRemove.Count == 0)
            {
                IsMoving = false;
            }
        }