Ejemplo n.º 1
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="copy">The BoundaryMap to be copied from.</param>
 public BoundaryMap(BoundaryMap copy)
 {
     width              = copy.GetWidth();
     height             = copy.GetHeight();
     gridRepresentation = new SingleSpaceType[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             gridRepresentation[i, j] = copy.GetTypeAtPosition(i, j);
         }
     }
     playerSpawnPos_x = copy.GetPlayerSpawnX();
     playerSpawnPos_y = copy.GetPlayerSpawnY();
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Update is called every frame.
    /// </summary>
    void Update()
    {
        if (editable)
        {
            mouseWorldPos = mainCamera.GetComponent <Camera>().ScreenToWorldPoint(Input.mousePosition);
            Vector2Int gridPos = ConvertToGridIndex(mouseWorldPos);
            if (gridPos.x >= 0 && gridPos.x < map.GetWidth() &&
                gridPos.y >= 0 && gridPos.y < map.GetHeight())
            {
                currentPrefabSelection.SetActive(true);
                DisplaySpriteAtPosition(mouseWorldPos);
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    if (currentTypeSelection != SingleSpaceType.VERTICAL_STRAIGHT)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = GameObject.Instantiate(verticalStraightPrefab);
                        currentTypeSelection   = SingleSpaceType.VERTICAL_STRAIGHT;
                    }
                }
                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    if (currentTypeSelection != SingleSpaceType.CORNER_1Q)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = GameObject.Instantiate(corner1QPrefab);
                        currentTypeSelection   = SingleSpaceType.CORNER_1Q;
                    }
                }
                else if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    if (currentTypeSelection != SingleSpaceType.PLAYER_SPAWN)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = GameObject.Instantiate(playerSpawnPrefab);
                        currentTypeSelection   = SingleSpaceType.PLAYER_SPAWN;
                    }
                }
                if (Input.mouseScrollDelta.y < 0)
                {
                    if (currentTypeSelection == SingleSpaceType.CORNER_1Q || currentTypeSelection == SingleSpaceType.CORNER_2Q ||
                        currentTypeSelection == SingleSpaceType.CORNER_3Q || currentTypeSelection == SingleSpaceType.CORNER_4Q)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = NextCornerTypePrefab();
                        currentTypeSelection   = NextCornerType();
                    }
                    else if (currentTypeSelection == SingleSpaceType.VERTICAL_STRAIGHT ||
                             currentTypeSelection == SingleSpaceType.HORIZONTAL_STRAIGHT)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = OtherRegularTypePrefab();
                        currentTypeSelection   = OtherRegularType();
                    }
                }

                if (Input.mouseScrollDelta.y > 0)
                {
                    if (currentTypeSelection == SingleSpaceType.CORNER_1Q || currentTypeSelection == SingleSpaceType.CORNER_2Q ||
                        currentTypeSelection == SingleSpaceType.CORNER_3Q || currentTypeSelection == SingleSpaceType.CORNER_4Q)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = PrevCornerTypePrefab();
                        currentTypeSelection   = PrevCornerType();
                    }
                    else if (currentTypeSelection == SingleSpaceType.VERTICAL_STRAIGHT ||
                             currentTypeSelection == SingleSpaceType.HORIZONTAL_STRAIGHT)
                    {
                        Destroy(currentPrefabSelection);
                        currentPrefabSelection = OtherRegularTypePrefab();
                        currentTypeSelection   = OtherRegularType();
                    }
                }

                if (Input.GetMouseButton(0))
                {
                    SetSpriteAtPosition(mouseWorldPos);
                    DisplayMap();
                }
                else if (Input.GetMouseButton(1))
                {
                    RemoveSpriteAtPosition(mouseWorldPos);
                    DisplayMap();
                }
            }
            else
            {
                currentPrefabSelection.SetActive(false);
            }
        }
        else
        {
            currentPrefabSelection.SetActive(false);
        }
    }