コード例 #1
0
    /**
     * Generates single-tile background objects
     * Mushrooms have a 10% chance of spawning. Everything else is 90%
     * @param x - coordinate for row in grid
     * @param y - coordinate for column in grid
     */
    private void genSingle(int x, int y)
    {
        if (chanceSpawn(5))
        {
            int index;

            if (chanceSpawn(10))
            {
                index = (int)SingleCell.mushroom;
            }
            else
            {
                index = (int)Random.Range((float)SingleCell.bgGrass1, (float)SingleCell.bgGrass2 + 1);
            }
            Sprite  spriteToPlace = room.getSpriteAtIndex(index);
            Cell    cellToPlace   = room.getCellAtCoord(x, y + 1);
            Vector3 position      = roomPosition + room.GetWorldPosition(x, y + 1) + new Vector3(room.getCellSize(), room.getCellSize());

            cellToPlace.placeBGTile(position, spriteToPlace);
        }
    }
コード例 #2
0
    /**
     *  Attempt to place enemy. Uses above functions to randomize
     **/
    private void placeEnemy(int x, int y)
    {
        if (shouldPlaceEnemy())
        {
            Enemy   enemyToPlace = pickEnemy();
            Enemy   placedEnemy  = Object.Instantiate(enemyToPlace);
            Vector3 position     = roomPosition + room.GetWorldPosition(x, y + 1) + new Vector3(room.getCellSize(), room.getCellSize());
            placedEnemy.transform.position = position;

            room.setCellType(x, y + 1, CellType.Enemy); //set cell to enemy to block off from other enemies
            room.setCellType(x + 1, y + 1, CellType.Enemy);
            room.setCellType(x - 1, y + 1, CellType.Enemy);
        }
    }