Exemplo n.º 1
0
 private void LoadLevel(int lvlNumber)
 {
     levelTxt.text = "LEVEL: " + (lvlNumber + 1).ToString();
     currentLvl    = (byte)lvlNumber;
     // SET OBSTACKLES
     gridScript.LoadLevel(GRID_DIMENSION, GRID_DIMENSION, levelScript.GetLevel(GRID_DIMENSION, lvlNumber));
     gameObjects = new List <GameObject>();
     for (int i = 0; i < GRID_DIMENSION; i++)
     {
         for (int j = 0; j < GRID_DIMENSION; j++)
         {
             if (gridScript.IsOccuppied(i, j))
             {
                 gameObjects.Add(guiScript.CreateImage("Obstackle", gamePanel.transform, new Vector2(ImageW, ImageH),
                                                       new Vector2(0, 1), new Vector2(0, 1), new Vector3(1, 1, 1), new Vector2(0.5f, 0.5f),
                                                       gridScript.GetCoordinates(i, j), new Vector3(0, 0, 0), obstackleSprite, Image.Type.Sliced, new Color32(255, 255, 255, 255)));
             }
         }
     }
     // SET EXIT
     int[] xy = levelScript.GetEndPoint(lvlNumber);
     gridScript.SetEndPoint(xy);
     gameObjects.Add(guiScript.CreateImage("EndPoint", gamePanel.transform, new Vector2(ImageW, ImageH),
                                           new Vector2(0, 1), new Vector2(0, 1), new Vector3(1, 1, 1), new Vector2(0.5f, 0.5f),
                                           gridScript.GetCoordinates(xy[0], xy[1]), new Vector3(0, 0, 0), endPointSprite, Image.Type.Sliced, new Color32(255, 255, 255, 255)));
     // SET PLAYER
     xy     = levelScript.GetStartPoint(lvlNumber);
     player = guiScript.CreateImage("Player", gamePanel.transform, new Vector2(ImageW, ImageH),
                                    new Vector2(0, 1), new Vector2(0, 1), new Vector3(1, 1, 1), new Vector2(0.5f, 0.5f),
                                    gridScript.GetCoordinates(xy[0], xy[1]), new Vector3(0, 0, 0), playerSprite, Image.Type.Sliced, new Color32(255, 255, 255, 255));
     player.AddComponent <PlayerControlScript>();
     player.GetComponent <PlayerControlScript>().SetPlayer(xy, 15, this, gridScript);
     gameObjects.Add(player);
 }
    public void Move(int deltaX, int deltaY)
    {
        inMove = true;
        int[]   blocadePos = gridScript.SeekBlocade(posX, posY, deltaX, deltaY);
        Vector2 destination;

        if (blocadePos != null)
        {
            int deltaPos = Mathf.Abs(blocadePos[0] - posX) + Mathf.Abs(blocadePos[1] - posY);
            if (gridScript.IsEndPoint(blocadePos))
            {
                gameController.Win = true;
                destination        = gridScript.GetCoordinates(blocadePos[0], blocadePos[1]);
                StartCoroutine(MoveCoroutine(destination, true));
            }
            else if (deltaPos > 1)
            {
                blocadePos[0] -= deltaX;
                blocadePos[1] -= deltaY;
                posX           = blocadePos[0];
                posY           = blocadePos[1];
                destination    = gridScript.GetCoordinates(blocadePos[0], blocadePos[1]);
                StartCoroutine(MoveCoroutine(destination, false));
            }
            else
            {
                inMove = false;
            }
        }
        else
        {
            gameController.Win = false;
            destination        = OutOfGridPosition(deltaX, deltaY);
            StartCoroutine(MoveCoroutine(destination, true));
        }
    }