Ejemplo n.º 1
0
 /// <summary>
 /// Start is called before the first frame update.
 /// </summary>
 void Start()
 {
     mainCamera             = GameObject.FindWithTag("MainCamera");
     map                    = new BoundaryMap(MAP_SIZE, MAP_SIZE);
     currentPrefabSelection = GameObject.Instantiate(verticalStraightPrefab);
     currentTypeSelection   = SingleSpaceType.VERTICAL_STRAIGHT;
     editable               = (SceneManager.GetActiveScene().name != "GameScene");
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates the given grid position to the new SingleSpaceType.
 /// </summary>
 /// <param name="x">X-index position of the space to be updated.</param>
 /// <param name="y">Y-index position of the space to be updated.</param>
 /// <param name="newType">The SingleSpaceType that the space will be changed to.</param>
 public void UpdateSpace(int x, int y, SingleSpaceType newType)
 {
     if (newType == SingleSpaceType.PLAYER_SPAWN)
     {
         for (int i = 0; i < width; i++)
         {
             for (int j = 0; j < height; j++)
             {
                 if (gridRepresentation[i, j] == SingleSpaceType.PLAYER_SPAWN)
                 {
                     ResetSpace(i, j);
                 }
             }
         }
         playerSpawnPos_x = x * BoundaryDrawer.SPRITE_UNIT_WIDTH;
         playerSpawnPos_y = y * BoundaryDrawer.SPRITE_UNIT_WIDTH;
     }
     gridRepresentation[x, y] = newType;
 }
Ejemplo n.º 3
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);
        }
    }