Ejemplo n.º 1
0
    void Update()
    {
        Vector3 newPosition       = NewPosition();
        Vector3 newPositionAfterX = NewPositionAfterX();

        timeBetweenSteps = 1 / speed;
        if (newPositionAfterX != min) //if we did press X:
        {
            TileBase tileOnNewPosition = TileOnPosition(newPositionAfterX);
            if (tileOnNewPosition.Equals(mountains)) // pressed X at a mountain tile :
            {
                StartCoroutine(Example(newPositionAfterX));
            }
            else if (tileOnNewPosition.Equals(grass)) //pressed X at a grass tile:
            {
                transform.position = newPositionAfterX;
            }
        }
        else
        {
            TileBase tileOnNewPosition = TileOnPosition(newPosition);
            if (allowedTiles.Contain(tileOnNewPosition))
            {
                transform.position = newPosition;
            }
            else
            {
                Debug.Log("You cannot walk on " + tileOnNewPosition + "!");
            }
        }
    }
Ejemplo n.º 2
0
    private void BorrowFromHeap(Vector3Int position)
    {
        TileBase tileBase = tilemap.GetTile(position);

        if (tileBase != null && tileBase.Equals(unusableSpace))
        {
            tilemap.SetTile(position, usableSpace);
        }
    }
Ejemplo n.º 3
0
 public Item getItemByTileBase(TileBase tb)
 {
     for (int i = 0; i < itemList.Count; i++)
     {
         if (tb.Equals(itemList[i].assetTile))
         {
             return(itemList[i].getCopy());
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 /// <summary>method <c>findTilePos</c> returns weights of specific tile </summary>
 public int findTilePos(TileBase t)
 {
     for (int i = 0; i < allowedTiles.Length; i++)
     {
         if (t.Equals(allowedTiles[i]))
         {
             return(i);
         }
     }
     return(-1);
 }
Ejemplo n.º 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (framecount % 10 == 0)
        {
            for (int x = tilemap.cellBounds.min.x; x < tilemap.cellBounds.max.x; x++)
            {
                for (int y = tilemap.cellBounds.min.y; y < tilemap.cellBounds.max.y; y++)
                {
                    for (int z = tilemap.cellBounds.min.z; z < tilemap.cellBounds.max.z; z++)
                    {
                        Vector3Int pos  = new Vector3Int(x, y, 0);
                        TileBase   tile = tilemap.GetTile(pos);

                        if (!tile)
                        {
                            continue;
                        }

                        if (tile.Equals(lavaBasic))
                        {
                            tilemap.SetTile(pos, lavaAnim[0]);
                        }
                        else if (tile.Equals(lavaAnim[0]))
                        {
                            tilemap.SetTile(pos, lavaAnim[1]);
                        }
                        else if (tile.Equals(lavaAnim[1]))
                        {
                            tilemap.SetTile(pos, lavaAnim[2]);
                        }
                        else if (tile.Equals(lavaAnim[2]))
                        {
                            tilemap.SetTile(pos, lavaAnim[0]);
                        }
                    }
                }
            }
        }

        framecount++;
    }
    void Update()
    {
        Vector3  newPosition       = NewPosition();
        TileBase tileOnNewPosition = TileOnPosition(newPosition);

        if (allowedTiles.Contain(tileOnNewPosition))
        {
            transform.position = newPosition;
        }
        else if (!allowedTiles.Contain(tileOnNewPosition) && tileOnNewPosition.Equals(oldTile) && Input.GetKey(KeyCode.Space))
        {
            tilemap.SetTile(tilemap.WorldToCell(newPosition), newTile);
        }
        else if (tileOnNewPosition.Equals(PlayerHome) && Input.GetKey(KeyCode.Space))
        {
            Debug.Log("Home Sweet Home " + tileOnNewPosition + "!");
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
        else
        {
            Debug.Log("You cannot walk on " + tileOnNewPosition + "!");
        }
    }
Ejemplo n.º 7
0
    private void AssignSpace(Vector3Int position)
    {
        TileBase tileBase = tilemap.GetTile(position);

        if (tileBase != null && tileBase.Equals(usableSpace))
        {
            Customer customer = queue[0];
            queue.RemoveAt(0);
            haveSpaceCustomers.Add(position, customer);

            tilemap.SetTile(position, OccupiedSpace);
            //print("assigned");
        }
    }
Ejemplo n.º 8
0
    private void ReturnToHeap(Vector3Int position)
    {
        // Customer is using this space, penalty
        TileBase tileBase = tilemap.GetTile(position);

        if (tileBase != null && tileBase.Equals(OccupiedSpace))
        {
            Customer customerToBeKicked = haveSpaceCustomers[position];
            haveSpaceCustomers.Remove(position);
            audioManager.Play("Angry");
            capital -= customerToBeKicked.spending * kickPenalty;
        }

        tilemap.SetTile(position, unusableSpace);
    }
Ejemplo n.º 9
0
    //we choose the tile weight to be the index of the tile in the allpwedYiles array
    public float getWeight(Vector3Int nextNode)
    {
        TileBase nextTile = TileOnPosition(nextNode);
        float    ind      = 0;

        foreach (TileBase tile in allowedTiles)
        {
            if (nextTile.Equals(tile))
            {
                return(ind);
            }
            ind++;
        }

        return(1f);
    }
Ejemplo n.º 10
0
 private void swapTile(Vector3Int point, TileBase[] arr)
 {
     for (int i = 0; i < arr.Length; i++)
     {
         if (currentTile.Equals(arr[i]))
         {
             if (i == arr.Length - 1)
             {
                 map.SetTile(point, arr[0]);
             }
             else
             {
                 map.SetTile(point, arr[i + 1]);
             }
         }
     }
 }
Ejemplo n.º 11
0
    void Update()
    {
        Vector3  newPosition       = NewPosition();
        TileBase tileOnNewPosition = TileOnPosition(newPosition);

        if (allowedTiles.Contain(tileOnNewPosition))
        {
            transform.position = newPosition;
        }
        else if (!allowedTiles.Contain(tileOnNewPosition) && tileOnNewPosition.Equals(oldTile) && Input.GetKey(KeyCode.A))
        {
            tilemap.SetTile(tilemap.WorldToCell(newPosition), newTile);
        }
        else
        {
            Debug.Log("You cannot walk on " + tileOnNewPosition + "!");
        }
    }
Ejemplo n.º 12
0
    void Update()
    {
        Vector3 newPosition = NewPosition();
        TileBase tileOnNewPosition = TileOnPosition(newPosition);
        if (allowedTiles.Contain(tileOnNewPosition))
        {
            transform.position = newPosition;
        }
        else
        {
            /*            Debug.Log("You cannot walk on " + tileOnNewPosition + "!");*/
            if (tileOnNewPosition != null && tileOnNewPosition.Equals(goal))
            {
                // TilemapCaveGenerator.res
                script.restart();
            }
        }

    }
Ejemplo n.º 13
0
    void Update()
    {
        Vector3  newPosition       = NewPosition();
        TileBase tileOnNewPosition = TileOnPosition(newPosition);

        if (allowedTiles.Contain(tileOnNewPosition))
        {
            transform.position = newPosition;
        }
        else
        {
            //if the player is about to touch the goal then restart the game and make it bigger
            if (tileOnNewPosition != null && tileOnNewPosition.Equals(goal))
            {
                script.restart();
            }
        }
        carveMountain();
    }
Ejemplo n.º 14
0
    void Update()
    {
        Vector3  newPosition       = NewPosition();
        TileBase tileOnNewPosition = TileOnPosition(newPosition);

        if (allowedTiles.Contains(tileOnNewPosition))
        {
            transform.position = newPosition;
        }
        else if (Input.GetKey(toQuarry) && tileOnNewPosition.Equals(mountain) && !beingHandled)
        {
            tilemap.SetTile(tilemap.WorldToCell(newPosition), hill);
            StartCoroutine(HandleIt());
            transform.position = newPosition;
        }

        else
        {
            Debug.Log("You cannot walk on " + tileOnNewPosition + "!");
        }
    }
Ejemplo n.º 15
0
    private void Operate()
    {
        if (!started)
        {
            StartCoroutine(ChargeSpaceCost());
            StartCoroutine(RandomNewcomer());
            started = true;
        }

        Impatience();
        VisualisePatient();
        IncrementTimeHaveSpace();

        // Assign space for customer
        if (queue.Count > 0 && Input.GetMouseButtonDown(0))
        {
            Vector3Int position = ClickOnTile();
            TileBase   tileBase = tilemap.GetTile(position);

            if (tileBase != null && tileBase.Equals(OccupiedSpace))
            {
                star -= annoyingPenalty;
                audioManager.Play("Angry");
            }
            else
            {
                AssignSpace(position);
            }
        }

        // Increment time and update the clock
        dayPassed           += Time.deltaTime;
        clockFill.fillAmount = dayPassed / dayLength;

        //end of day
        if (dayPassed >= dayLength)
        {
            EndOfDay();
        }
    }
Ejemplo n.º 16
0
    public bool ExistsBaseTileAt(Vector3Int tilePosition)
    {
        TileBase tileAtPosition = tilemap.GetTile(tilePosition);

        return(tileAtPosition != null && tileAtPosition.Equals(tiles.BaseTile));
    }
Ejemplo n.º 17
0
    //Do the simulation in a coroutine so we can pause and see what's going on
    private IEnumerator SimulateCavePattern()
    {
        for (int i = 0; i < simulationSteps; i++)
        {
            yield return(new WaitForSeconds(pauseTime)); //we dont want to wait in this scenario

            //Calculate the new values
            caveGenerator.SmoothMap();

            //Generate texture and display it on the plane
            GenerateAndDisplayTexture(caveGenerator.GetMap());
        }
        Debug.Log("Simulation completed!");
        bool foundpos           = false;
        int  positionToPlaceObj = 1;

        //Generate all the objects
        //Find a place for the player and place him there
        //Starting from [1,1] and going [2,2],[3,3].....[n,n] until you find a spot
        while (!foundpos && positionToPlaceObj <= gridSize)
        {
            //create a vector with the new potential position
            Vector3 vec = new Vector3(positionToPlaceObj, positionToPlaceObj, 0);
            //get the TileBase from the potential position
            TileBase tileOnNewPosition = TileOnPosition(vec);
            //If the position is a wall keep going up
            if (wallTile.Equals(tileOnNewPosition))
            {
                positionToPlaceObj++;
            }
            //Else we found a "free" spot where we can put the player
            else
            {
                //Scaling the position of the player to fit the grid box
                Vector3 scaletofit = player.transform.localScale * 0.5f;
                scaletofit.z = 0;
                player.transform.position = vec + scaletofit;
                foundpos = true;
            }
        }
        foundpos           = false;
        positionToPlaceObj = gridSize;
        //Try to find a position for the goal tile
        //Go from [gridSize,gridSize],[gridSize-1,gridSize-1]....[0,0]
        //until you find a spot for the goal tile
        while (!foundpos && positionToPlaceObj >= 0)
        {
            Vector3  vec = new Vector3(positionToPlaceObj, positionToPlaceObj, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            if (tileOnNewPosition == null || wallTile.Equals(tileOnNewPosition))
            {
                positionToPlaceObj--;
            }
            else
            {
                //Scaling the position of the goal tile to fit the grid box
                Vector3Int cellPosition = tilemap.WorldToCell(vec);
                tilemap.SetTile(cellPosition, goalTile);
                foundpos = true;
            }
        }
        foundpos = false;
        //Find a spot for 2 enemy players
        //Try to find a spot for first enemy player
        //randomize a spot on the grid if there is no wall there then put the enemy player there
        while (!foundpos)
        {
            int      x1  = Random.Range(1, gridSize);
            int      x2  = Random.Range(1, gridSize);
            Vector3  vec = new Vector3(x1, x2, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            if (tileOnNewPosition == null || wallTile.Equals(tileOnNewPosition))
            {
                continue;
            }
            else
            {
                //Scaling the position of the enemy player to fit the grid box
                Vector3 scaletofit = enemy1.transform.localScale * 0.5f;
                scaletofit.z = 0;
                enemy1.transform.position = vec + scaletofit;
                foundpos = true;
            }
        }
        foundpos = false;
        //Try to find a spot for second enemy player
        //randomize a spot on the grid if there is no wall there then put the enemy player there
        while (!foundpos)
        {
            int      x1  = Random.Range(1, gridSize);
            int      x2  = Random.Range(1, gridSize);
            Vector3  vec = new Vector3(x1, x2, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            if (tileOnNewPosition == null || wallTile.Equals(tileOnNewPosition))
            {
                continue;
            }
            else
            {
                //Scaling the position of the enemy player to fit the grid box
                Vector3 scaletofit = enemy2.transform.localScale * 0.5f;
                scaletofit.z = 0;
                enemy2.transform.position = vec + scaletofit;
                foundpos = true;
            }
        }
    }
Ejemplo n.º 18
0
    //Do the simulation in a coroutine so we can pause and see what's going on
    private IEnumerator SimulateCavePattern()
    {
        for (int i = 0; i < simulationSteps; i++)
        {
            yield return(new WaitForSeconds(pauseTime));

            //Calculate the new values
            caveGenerator.SmoothMap();

            //Generate texture and display it on the plane
            GenerateAndDisplayTexture(caveGenerator.GetMap());
        }
        Debug.Log("Simulation completed!");
        bool foundpos = false;
        int  z        = 1;

        while (!foundpos)
        {
            Vector3  vec = new Vector3(z, z, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            Debug.Log(tileOnNewPosition.name);
            if (wallTile.Equals(tileOnNewPosition))
            {
                z++;
            }
            else
            {
                Vector3 scaletofit = player.transform.localScale * 0.5f;
                scaletofit.z = 0;
                player.transform.position = vec + scaletofit;
                foundpos = true;
                Debug.Log("FOUND");
            }
        }
        bool foundPosForGoal = false;

        z = gridSize;
        while (!foundPosForGoal)
        {
            Vector3  vec = new Vector3(z, z, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            if (tileOnNewPosition == null || wallTile.Equals(tileOnNewPosition))
            {
                z--;
            }
            else
            {
                Vector3Int cellPosition = tilemap.WorldToCell(vec);
                tilemap.SetTile(cellPosition, goalTile);
                foundPosForGoal = true;
                Debug.Log("FOUND spot for goal tile");
            }
        }
        foundpos = false;
        while (!foundpos)
        {
            int      x1  = Random.Range(1, gridSize);
            int      x2  = Random.Range(1, gridSize);
            Vector3  vec = new Vector3(x1, x2, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            if (tileOnNewPosition == null || wallTile.Equals(tileOnNewPosition))
            {
                continue;
            }
            else
            {
                Vector3 scaletofit = enemy1.transform.localScale * 0.5f;
                scaletofit.z = 0;
                enemy1.transform.position = vec + scaletofit;
                foundpos = true;
                Debug.Log("FOUND");
            }
        }
        foundpos = false;
        while (!foundpos)
        {
            int      x1  = Random.Range(1, gridSize);
            int      x2  = Random.Range(1, gridSize);
            Vector3  vec = new Vector3(x1, x2, 0);
            TileBase tileOnNewPosition = TileOnPosition(vec);
            if (tileOnNewPosition == null || wallTile.Equals(tileOnNewPosition))
            {
                continue;
            }
            else
            {
                Vector3 scaletofit = enemy2.transform.localScale * 0.5f;
                scaletofit.z = 0;
                enemy2.transform.position = vec + scaletofit;
                foundpos = true;
                Debug.Log("FOUND");
            }
        }
    }