Exemple #1
0
        public bool canSet(int x, int y, Block block, float deg = 0)
        {
            Vector2 start = new Vector2(x, y);

            if (grid == null)
            {
                clear();
            }

            Vector2 calc = VectorCalculation.revertToOrigin(start, this);

            if (calc.x >= getWidth() || calc.y >= getHeight())
            {
                return(false);
            }


            Vector2 least = getLeast(block, deg);

            foreach (Vector2 col in block.getCollision())
            {
                Vector2 temp = getGridPoint(col, start, least, deg);
                if (temp.x >= getWidth() || temp.y >= getHeight() || getPos(temp) != null)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        private Vector3 revertToOrigin(Vector3 loc)
        {
            Vector2 temp = new Vector2(loc.x, loc.z);

            temp = VectorCalculation.revertToOrigin(temp, GameMode.getCurrentLevel());
            return(makeVector3(temp));
        }
Exemple #3
0
        private Vector2 getLeast(Block block, float deg)
        {
            Vector2 least      = new Vector2();
            bool    calculated = false;

            foreach (Vector2 col in block.getCollision())
            {
                Vector2 temp = VectorCalculation.rotateVector(col, deg);
                if (!calculated)
                {
                    least      = temp;
                    calculated = true;
                }
                if (temp.x < least.x)
                {
                    least.x = temp.x;
                }
                if (temp.y < least.y)
                {
                    least.y = temp.y;
                }
            }
            least.x = Mathf.Abs(least.x);
            least.y = Mathf.Abs(least.y);
            return(least);
        }
Exemple #4
0
        public Vector2 getWidthHeight(float deg)
        {
            if (deg == cachedDeg)
            {
                return((Vector2)cachedWidthHight);
            }
            cachedDeg = deg;

            float width  = 0;
            float height = 0;

            foreach (Vector2 collision in getCollision())
            {
                Vector2 temp = VectorCalculation.rotateVector(collision, deg);
                width  = Mathf.Max(width, Mathf.Abs(temp.x));
                height = Mathf.Max(height, Mathf.Abs(temp.y));
            }
            cachedWidthHight = new Vector2((width + 1), ((height + 1)));
            return((Vector2)cachedWidthHight);
        }
Exemple #5
0
        private void setParent()
        {
            GameObject empty = new GameObject();

            Vector3 dir = new Vector3();

            switch (data [current].flipFrom)
            {
            case Direction.UP:
                dir = new Vector3(0, 0, .5f);
                break;

            case Direction.LEFT:
                dir = new Vector3(-0.5f, 0, 0);
                break;

            case Direction.BOTTOM:
                dir = new Vector3(0, 0, -0.5f);
                break;

            case Direction.RIGHT:
                dir = new Vector3(0.5f, 0, 0);
                break;
            }
            Vector3 lastPos = makeVector3(VectorCalculation.revertToOrigin(data [current].Position, GameMode.getCurrentLevel())) + dir * -1;

            lastPos.y = 0.1f;

            empty.transform.position = lastPos;

            getPrefab().transform.position      = new Vector3(0, 0, 0);
            getPrefab().transform.eulerAngles   = new Vector3(0, data [current].getRotation(), 0);
            getPrefab().transform.parent        = empty.transform;
            getPrefab().transform.localPosition = dir;

            empty.transform.eulerAngles = getRotation() * -180;
        }
Exemple #6
0
        private Vector2 getGridPoint(Vector2 col, Vector2 start, Vector2 least, float deg)
        {
            Vector2 temp = start + VectorCalculation.rotateVector(col, deg) + least;

            return(VectorCalculation.revertToOrigin(temp, this));
        }
Exemple #7
0
 private void displayRoadPoints()
 {
     placeRoad(VectorCalculation.revertToOrigin(level.getFinish(), level));
     placeRoad(VectorCalculation.revertToOrigin(level.getStart(), level));
 }