protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            SetResolution(resolution);

            map = new Map()
            {
                MapCamera = new Camera(GameParameters.Resolutions[resolution])
            };
            map.MapCamera.BoundMap = map;
            obst1        = new SquareObstacle();
            obst2        = new SquareObstacle();
            obst3        = new SquareObstacle();
            obst4        = new SquareObstacle();
            recto        = new Recto(map);
            debugOverlay = new DebugOverlay();

            inputManager           = new InputManager();
            inputManager.BoundHero = recto;
            elapsedMiliseconds     = 0;
            frameCounter           = 0;
            updateCounter          = 0;
            debugInfo = new DebugInfo();

            map.Initialize();
            AddObjectsToMap();
            map.InitializeEntities();
            obst2.SetValues(660, 520, 150, 180);
            obst3.SetValues(810, 650, 50, 50);
            obst4.SetValues(860, 600, 100, 100);
            debugOverlay.Initialize();

            base.Initialize();
        }
Esempio n. 2
0
    /*Credit to Markus Jarderot for this function*/
    static private bool BoxIntersect(Recto a, Recto b)
    {
        foreach (var polygon in new[] { a, b })
        {
            for (int i1 = 0; i1 < polygon.points.Length; i1++)
            {
                int i2 = (i1 + 1) % polygon.points.Length;
                var p1 = polygon.points[i1];
                var p2 = polygon.points[i2];

                var normal = new Vector2(p2.y - p1.y, p1.x - p2.x);

                double?minA = null, maxA = null;
                foreach (var p in a.points)
                {
                    var projected = normal.x * p.x + normal.y * p.y;
                    if (minA == null || projected < minA)
                    {
                        minA = projected;
                    }
                    if (maxA == null || projected > maxA)
                    {
                        maxA = projected;
                    }
                }

                double?minB = null, maxB = null;
                foreach (var p in b.points)
                {
                    var projected = normal.x * p.x + normal.y * p.y;
                    if (minB == null || projected < minB)
                    {
                        minB = projected;
                    }
                    if (maxB == null || projected > maxB)
                    {
                        maxB = projected;
                    }
                }

                if (maxA < minB || maxB < minA)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Esempio n. 3
0
    static public Block WhatHit(Vector2 posP, Vector2 size, float angle)
    {
        foreach (GameObject obj in hitMe)
        {
            Block   blok   = obj.GetComponent <Blocky>().myType;
            Vector2 posB   = obj.transform.position;
            Vector2 scaleB = obj.transform.localScale;
            float   rotB   = obj.transform.eulerAngles.z * Mathf.Deg2Rad;

            Recto rectP = new Recto(posP, size.x, size.y, angle);
            Recto rectB = new Recto(posB, scaleB.y, scaleB.x, rotB);

            if (BoxIntersect(rectP, rectB))
            {
                return(blok);
            }
        }
        return(Block.AIR);
    }
Esempio n. 4
0
    static public Vector2 ContactPoint(Vector2 posP, Vector2 size, float angle)
    {
        foreach (GameObject obj in hitMe)
        {
            Vector2 posB   = obj.transform.position;
            Vector2 scaleB = obj.transform.localScale;
            float   rotB   = obj.transform.eulerAngles.z * Mathf.Deg2Rad;

            Recto rectP = new Recto(posP, size.x, size.y, angle);
            Recto rectB = new Recto(posB, scaleB.x, scaleB.y, rotB);

            if (BoxIntersect(rectP, rectB))
            {
                Vector2 finalPoint = posB;
                float   radius     = rectB.Width / 2 + rectP.Length / 2; // Gets the distance the player should be from the center of the box
                float   aang       = rotB + Mathf.PI;
                finalPoint.x += Mathf.Cos(aang) * radius;
                finalPoint.y += Mathf.Sin(aang) * radius;
                return(finalPoint);
            }
        }
        return(posP);
    }