Пример #1
0
    IEnumerator GenerateGrid(int columnCount)
    {
        grid.m_Column = columnCount;
        cellArray = new GameObject[columnCount*columnCount, columnCount*columnCount];
        yield return new WaitForEndOfFrame ();

        for (var i = 0; i < columnCount; i++)
        {
            for(var j = 0; j < columnCount; j++)
            {
                cellArray[i,j] = (GameObject)Instantiate(cell, new Vector3(1, 1, 1), Quaternion.identity);
                cellArray[i,j].transform.SetParent(grid.transform);
                cellArray[i,j].transform.localScale = new Vector3(1, 1, 1);
                cellArray[i,j].name = "Cell[" + i + "][" + j + "]";

                cellList.Add (cellArray[i,j]);

                cellHandler = cellArray[i,j].GetComponent<CellHandler> ();
                cellHandler.CoordX = i;
                cellHandler.CoordY = j;

                // Add color:
                var rand = Random.Range (0,2);

                if (rand == 1) {
                    cellHandler.cellStatus = CellHandler.Status.On;
                    cellArray[i,j].GetComponent<CanvasRenderer> ().SetColor (new Color32 (135, 204, 196, 255));
                } else {
                    cellHandler.cellStatus = CellHandler.Status.Off;
                    cellArray[i,j].GetComponent<CanvasRenderer>().SetColor (new Color32 (128, 128, 128, 128));
                }
            }
        }
    }
Пример #2
0
    /*int GetAliveNeighbours (int _iColumn, int _iRow)
    {
        int iAliveNeighbours = 0;
        //nachbarn für feld 3,8 wäre column 2-4 und row 7-9 (im range 1)
        for (int iColumn = _iColumn -1; iColumn <= _iColumn +1; iColumn++)
        {
            for (int iRow = _iRow -1; iRow <= _iRow -1; iRow++)
            {
                if (iColumn == _iColumn && iRow == _iRow)
                    continue;

                if (iColumn >= 0 && iColumn < m_iSize && iRow >= 0 && iRow < m_iSize &&
                    m_Grid[iColumn, iRow].GetComponent<Renderer>().material.color == Color.blue) //Check Range/Bounce
                    iAliveNeighbours++;
            }
        }
        return iAliveNeighbours;
    }*/
    // Use this for initialization
    void Start()
    {
        m_Grid = new GameObject[m_iSize, m_iSize];

        for (int i = 0; i < m_iSize; i++)
        for (int j = 0; j < m_iSize; j++)
        {
            GameObject kachel = GameObject.CreatePrimitive(PrimitiveType.Quad);
            kachel.name = "Kachel(" + i + "," + j + ")";
            m_Grid[i, j] = kachel;
            kachel.transform.position = new Vector3 (i, j, 0);
            kachel.transform.parent = this.transform;
        }
        Camera.main.transform.position = new Vector3 (m_iSize/2, m_iSize/2, -100);
        Camera.main.orthographicSize = m_iSize;

        transform.position = new Vector3 (0.5f, 0.5f, 0);

        for (int i = 0; i < m_iSize; i++)
        for (int j = 0; j < m_iSize; j++)
        {
            float farben = Random.value;
            if (farben <= 0.5)
                SetAlive (i, j, true);//m_Grid [i, j].GetComponent<Renderer>().material.color = Color.blue;
            else
                SetAlive (i, j, false);//m_Grid [i, j].GetComponent<Renderer>().material.color = Color.white;
        }
        print ("Anzahl Nachbarn: " + GetAliveNeighbours (1, 1));
        Debug.Log (GetAliveNeighbours (9, 9));

        //KillAll ();
    }
Пример #3
0
    void Awake()
    {
        //Get size of sprite
        Renderer rend = (Renderer)Tile.GetComponent(typeof(Renderer));
        tileSize = rend.bounds.size.x;
        //Debug.Log("TileSize: " + tileSize);
        //Create Arrays
        coordinates = new Vector3[4, 4];
        tileGrid = new GameObject[4, 4];

        //Initialize Arrays
        initArrays();

        //Update edges
        BotLeft = coordinates[0, 0];
        BotLeft.x -= (float)tileSize / 2;
        BotLeft.y -= (float)tileSize / 2;

        TopRight = coordinates[3, 3];
        TopRight.x += (float)tileSize / 2;
        TopRight.y += (float)tileSize / 2;

        //The distance between two tile
        tileDistance = tileSize + margin;
        //Debug.Log("tileDistance: " + tileDistance);
    }
Пример #4
0
    void CreateHexGrid() {
        hexes = new GameObject[gridWidthInHexes, gridHeightInHexes];

        //Loop for Hex Rows
        for (int y = 0; y < gridHeightInHexes; y++)
        {
            //Loop for Hex Columns
            for (int x = 0; x < gridWidthInHexes; x++)
            {
                Vector2 gridPosition = new Vector2(x, y);
                
                //Create a clone of the supplied Hex object
                //GameObject hex = (GameObject)Instantiate(Hex);
                hexes[x, y] = (GameObject)Instantiate(hex);
                
                hexes[x, y].GetComponent<GridTile>().myGridPosition = gridPosition;
               
                
                //Get the current x,y of loop to place Hex | column 5, row 3, etc.
                //Vector2 gridPosition = new Vector2(x, y);
                
                //Center of grid is 0,0,0 figure out the pixel coordinates of this hex based on it's x,y
                //hex.transform.position = calculateWorldCoordinates(gridPosition);
                hexes[x, y].transform.position = CalculateWorldCoordinates(gridPosition);
                
                //Add the hex to the parent ojbect
                //hex.transform.parent = gridParent.transform;
                hexes[x, y].transform.parent = gridParent.transform;
                
            }
        }
    }
Пример #5
0
    void Start()
    {

        boxesArray = new GameObject[100, 100];
        for (int i = 0; i < 100; i++)
        {
            for (int j = 0; j < 100; j++)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                boxesArray[i, j] = cube;
                cube.transform.position = new Vector3(i, 30, j);
                cube.AddComponent<BoxCollider>();
                cube.name = i + " " + j;
                cube.layer = 8;
                cube.GetComponent<Renderer>().material.color = Color.gray;
            }
        }

//		fogOfWarColor = new Color (170, 170, 170, 1);
//		transparentColor = new Color (200, 200, 200, 0.5f);
//		// renders the objects
//		var renderer = GetComponent<Renderer> ();
//		// get the material of object
//		Material fogOfWarMat = null;
//		if (renderer != null) {
//			fogOfWarMat = renderer.material;
//		}
//		texture = new Texture2D (100, 100, TextureFormat.RGBA32, false);
//		texture.wrapMode = TextureWrapMode.Clamp;
//		fogOfWarMat.mainTexture = texture;
    }
 void Awake()
 {
     towers = new GameObject[MapData.rows,MapData.columns];
     for (int i = 0; i < MapData.rows; i++)
         for (int a = 0; a < MapData.columns; a++)
             towers[i, a] = null;
 }
Пример #7
0
    // Use this for initialization
    void Start()
    {
        timeToAct += turnTime;

        airplane = new Airplane ();
        grid = new GameObject[numCubesX, numCubesY];

        //setting airplane location
        airplane.x = 0;
        airplane.y = 8;

        //setting cargo info
        airplane.cargo = 0;
        airplane.cargoCapacity = 90;

        //spawn all the grid
        for (int x = 0; x < numCubesX; x++) {
            for (int y = 0; y < numCubesY; y++) {
                grid[x,y] = (GameObject) Instantiate (cubePrefab, new Vector3(x*2 - 14, y*2 - 8, 10), Quaternion.identity);
                grid[x,y].GetComponent<CubeBehavior>().x = x;
                grid[x,y].GetComponent<CubeBehavior>().y = y;
            }
        }

        //set airplane as red
        grid [0, 8].GetComponent<Renderer>().material.color = Color.red;

        //set depot as black
        grid [15, 0].GetComponent<Renderer>().material.color = Color.black;
    }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        Renderer tileRenderer = tileA.GetComponent<Renderer>();
        tileWidth = tileRenderer.bounds.size.x;
        tileHeight = tileRenderer.bounds.size.y;
        float anchorX = anchor.transform.position.x;
        float anchorY = anchor.transform.position.y;
        Debug.Log (anchorX);
        Debug.Log (anchorY);

        tiles = new GameObject[columns, rows];
        for (int i = 0; i < columns; ++i) {
            for (int j = 0; j < rows; j++) {
                float x = ((tileWidth) * i) - (anchorX / 2);
                float y = ((tileHeight) * j) - (anchorY / 2);

                if (i == 0 && j == 0) {
                    //Debug.Log (bgX);
                    //Debug.Log (bgY);
                    Debug.Log (tileWidth);
                    Debug.Log (tileHeight);
                    //Debug.Log (x);
                    //Debug.Log (y);
                }

                // alternating tiles
                var tile = tileA;
                if ((j % 2) == 0) {
                    tile = tileB;
                }

                tiles[i, j] = (GameObject)Instantiate(tile, new Vector3(x, y, tileLayer), Quaternion.identity);
            }
        }
    }
Пример #9
0
        void Start()
        {
            world = WorldControler.Instance.World;
            go_actor = new Dictionary<Actors.Actor, GameObject>();
            if (world == null)
            {
                Debug.LogError("No world?!");
                return;
            }

            go_tiles = new GameObject[world.Width, world.Hight];
            System.Random rnd = new System.Random();
            //Create game objets for each tile
            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Hight; y++)
                {
                    GameObject tile_go = new GameObject();
                    tile_go.name = "Tile_" + x + "_" + y;
                    tile_go.transform.position = new Vector3(world[x, y].X, world[x, y].Y);
                    tile_go.transform.SetParent(this.transform, true);
                    SpriteRenderer tile_sr = tile_go.AddComponent<SpriteRenderer>();
                    tile_sr.sortingLayerName = "Tiles";
                    go_tiles[x, y] = tile_go;
                    SetTileSprite(x, y, tile_go, rnd);
                }
            }
            SetHeroSprite();
            world.TileTypeChanged += w_TileTypeChange;
            world.ActorMoved += MoveActorSprite;
        }
Пример #10
0
    void Start()
    {
        //Set up NodeMap
        xOffSet = 1-(Node.minX);
        yOffSet = 1-(Node.minY);
        nodeMap = new GameObject[(Node.maxX+xOffSet+2),(Node.maxY+yOffSet+2)]; //+2 is to create a buffer edge
        //Populate empty map
        for(int x=0;x<(nodeMap.GetLength(0));x++){
            for(int y=0;y<(nodeMap.GetLength(1));y++){
                nodeMap[x,y] = null;
            }
        }

        //Stick nodes in the map
        GameObject[] temp = GameObject.FindGameObjectsWithTag("Node");
        for(int i=0;i<temp.Length;i++){
            Node node = temp[i].GetComponent<Node>();
            node.refactorX(xOffSet);
            node.refactorY(yOffSet);
            nodeMap[node.getX(),node.getY()]=temp[i];
        }

        //Now that they're in the big map, tell them who
        //the neighbours are.
        for(int i=0;i<temp.Length;i++){
            Node node = temp[i].GetComponent<Node>();
            node.mapNeighbours();
        }

        //Identify the Player.
        player = GameObject.FindGameObjectWithTag("Player");
        //PrintDimensions();
        PrintMap();
    }
Пример #11
0
	void Start () {

		BoardCreator bc = gameObject.GetComponent<BoardCreator>();
		int size=bc.getBoardSize();
		print(size);
		tileSheet = new GameObject[size,size];
	}
Пример #12
0
    // Use this for initialization
    void Start()
    {
        var arenaSize = Arena.Instance.GetArenaSize();
        var gridSize = mapSize / arenaSize.y;
        GridMap = new GameObject[(int)arenaSize.x, (int)arenaSize.y];

        // create the minimap grid squares to match arena size
        for(var x = 0; x < arenaSize.x; x++)
        {
            for(var y = 0; y < arenaSize.y; y++)
            {
                var sq = (GameObject)Instantiate(GridSquarePrefab);
                sq.transform.SetParent(transform);
                var rect = sq.GetComponent<RectTransform>();
                rect.sizeDelta = new Vector2(gridSize, gridSize);
                var posx = (x * gridSize) + (x); //<-- leave a gap of 1px for every sq except the first one
                var posy = (y * gridSize) + (y); //<-- leave a gap of 1px for every sq except the first one
                sq.transform.localPosition = new Vector3(posx, posy, 0);

                GridMap[x,y] = sq;

                var info = Arena.Instance.GetGridSquare(x, y);
                GridContentsChanged(info);
            }
        }

        var myrect = GetComponent<RectTransform>();
        myrect.sizeDelta = new Vector2((arenaSize.x * gridSize) + arenaSize.x, (arenaSize.y * gridSize) + arenaSize.y);
        myrect.localPosition = new Vector3(-myrect.sizeDelta.x / 2, myrect.localPosition.y + 16, 0);

        Arena.Instance.OnGridContentsChanged.AddListener(GridContentsChanged);
    }
Пример #13
0
    public void JewelMapCreate(int[,] Map)
    {
		JewelGrib = new GameObject[GameController.WIDTH, GameController.HEIGHT];

		JewelGribScript = new JewelObj[GameController.WIDTH, GameController.HEIGHT];

		for (int x = 0; x < GameController.WIDTH; x++)
        {
            int s = 0;
			for (int y = 0; y < GameController.HEIGHT; y++)
            {
                if (GribManager.cell.GribCellObj[x, y] != null && GribManager.cell.GribCellObj[x, y].cell.CellEffect == 4)
                    s = y;
            }
			for (int y = s; y < GameController.HEIGHT; y++)
            {
                if (Map[x, y] > 0)
                {
                    RJewelInstantiate(x, y);
                }
            }
        }

        while (!Supporter.sp.isNoMoreMove())
        {
            RemakeGrib();
            JewelMapCreate(Map);
        }
    }
Пример #14
0
    // Use this for initialization
    void Start()
    {
        m_Grid = new GameObject[m_iSize, m_iSize];

        for (int i = 0; i <m_iSize; i++)
            for (int j = 0; j <m_iSize; j++) {
                GameObject kachel = GameObject.CreatePrimitive (PrimitiveType.Quad);
                m_Grid [i, j] = kachel;
                kachel.transform.position = new Vector3 (i, j, 0);
                kachel.transform.parent = this.transform;

                kachel.name = "kachel(" + i + "," + j + ")";

                if (Random.value < 0.5) {
                    kachel.GetComponent<Renderer> ().material.color = Color.black;
                }

                Camera.main.transform.position = new Vector3 (m_iSize / 2, m_iSize / 2, -10);
                Camera.main .orthographicSize = m_iSize;

            }

        transform.position = new Vector3 (0.5f, 0.5f, 0);

        int iCol = 3;
        int iRow = 3;
        print ("Anzahl Nachbarn (" + iCol + "," + iRow + "): " + GetAliveN (iCol, iRow));
    }
Пример #15
0
        void Start()
        {
            GameObject tempPar = new GameObject("ElasticLine");
            _lineParts = new GameObject[10, 2];

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < (int)(_elasticLengthInUnits * 0.5f * 10); i++)
                {
                    GameObject temp = _lineParts[i, j];
                    temp.transform.parent = tempPar.transform;
                    temp = GameObject.CreatePrimitive(PrimitiveType.Cube);

                    if (j == 0)
                        temp.transform.position = new Vector3(temp.transform.position.x + i,temp.transform.position.y,temp.transform.position.z);
                    //Set these up on the left
                    else
                        temp.transform.position = new Vector3(temp.transform.position.x + -i,temp.transform.position.y,temp.transform.position.z);
                    //set these up on the right.

                    temp.AddComponent<ElasticBehaviour>();

                    temp.GetComponent<ElasticBehaviour>().MaxElasticLength = 2;
                    temp.GetComponent<ElasticBehaviour>().MinElasticLength = 1;
                    temp.AddComponent<BoxCollider>();

                    _lineParts[i,j] = temp;
                }
            }
        }
 public GameObjectGrid(int rows, int columns, string id = "")
 {
     grid = new GameObject[columns, rows];
     for (int x = 0; x < columns; x++)
         for (int y = 0; y < rows; y++)
             grid[x, y] = null;
 }
Пример #17
0
    // Use this for initialization
    void Start()
    {
        tileViewers = new GameObject[width, height];
        elementViewers = new GameObject[width, height];

        GameObject mapViewer = new GameObject("MapViewer");
        GameObject tiles = new GameObject("Tiles");
        GameObject elements = new GameObject("Elements");

        tiles.transform.parent = mapViewer.transform;
        elements.transform.parent = mapViewer.transform;

        for(int Y = 0; Y < height; Y++) {

            for(int X = 0; X < width; X++) {

                GameObject newTile = Instantiate(Resources.Load ("Tiles/Tile")) as GameObject;
                newTile.transform.position = new Vector3(X, -Y, 0);
                newTile.name = "Tile " + X + ", " + Y;
                newTile.transform.parent = tiles.transform;
                tileViewers[X,Y] = newTile;

                GameObject newElement = Instantiate(Resources.Load ("Tiles/Tile")) as GameObject;
                newElement.transform.position = new Vector3(X, -Y, -1);
                newElement.name = "Element " + X + ", " + Y;
                newElement.transform.parent = elements.transform;
                elementViewers[X,Y] = newElement;
            }
        }

        InvokeRepeating("Refresh", 0, refreshRate);
    }
Пример #18
0
    void createCube()
    {
        cubeTileArray = new GameObject[width, height];

        Vector3 size = cube.GetComponent<Renderer>().bounds.size;

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Vector3 pos = new Vector3(posX, 0, posZ);
                GameObject newTile = Instantiate(cube, pos, cube.transform.rotation) as GameObject;
                newTile.transform.SetParent(this.transform, false);

                cubeTileArray[x, y] = newTile;

                posX += size.x;

            }

            posZ += size.z;
            posX = 0;

        }
    }
Пример #19
0
    private void initLevelData()
    {
        tileEarth = Resources.Load("Sprite_Earth") as GameObject;

        tileBlockade1 = Resources.Load("Blockade_1") as GameObject;
        tileBlockade2 = Resources.Load("Blockade_2") as GameObject;
        tileBlockade3 = Resources.Load("Blockade_3") as GameObject;
        tileStart = Resources.Load("Sprite_Player01_Start") as GameObject;
        tileEvent = Resources.Load("Sprite_Player02_Start") as GameObject;

        levelVisualisation = new GameObject[maxSizeElementsArray,maxSizeElementsArray];
        try
        {
            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y <10; y++)
                {
                    GameObject newtile = Instantiate(selectTile(lvlInformation[x, y]), new Vector3(x + 5, y + 5, 0) + zeroPointLevel, Quaternion.Euler(Vector3.zero)) as GameObject;

                    levelVisualisation[x, y] = newtile;
                }
            }
        }

        catch (System.Exception e)
        {
            Debug.Log(e.Message);

        }
    }
Пример #20
0
    //when player clicks on plane, make the color change/have airplane glow to show it's activated
    //if player clicks active plane it deactivates (changes back to red/stop glowing)
    //if there is no active airplane, don't do anything, no teleportation, nothing
    // Use this for initialization
    void Start()
    {
        allCubes = new GameObject[gridWidth,gridHeight];
        for(int x = 0; x < gridWidth; x++) {
            for (int y = 0; y < gridHeight; y++){
            allCubes[x,y] = (GameObject) Instantiate (Cube, new Vector3 (x*2, y*2, 0), Quaternion.identity);

            allCubes[x,y].GetComponent<CubeBehavior>().x = x;
            allCubes[x,y].GetComponent<CubeBehavior>().y = y;
            }
            print ("Cubes spawned");
            //reaching into CubeBehavior script, which is tracking the plane position
            //uses those coordinates in cubes spawned here (in allCubes)
        }

        airplane = new Aiplane ();

        airplane.x = 0;
        airplane.y = 8;
        if(airplane.x == 0 && airplane.y == 8){
            allCubes[airplane.x,airplane.y].GetComponent<Renderer>().material.color = Color.red;
        }

        print ("load airplane");
    }
Пример #21
0
 public void LoadMap()
 {
    var path =  EditorUtility.OpenFilePanel("Select a Map", @"\Assets\Maps", "map");
    if (path.Length == 0)
        return;
    StreamReader Mapreader = new StreamReader(path);
    Mapreader.ReadLine();
    var htext = Mapreader.ReadLine().Split(' ')[1];
    var wtext = Mapreader.ReadLine().Split(' ')[1];
    Mapreader.ReadLine();
    var height  = Int32.Parse(htext);
    var width = Int32.Parse(wtext);
    Char[] mapline = new char[width];
    Char[,] FinalMap = new char[height,width];
    for (int i = 0; i < height; ++i)
    {
        mapline = Mapreader.ReadLine().ToCharArray();
        for (int j = 0; j < width; ++j)
        {
            FinalMap[i, j] = mapline[j];
        }
    }
    AiMap = FinalMap;
    DrawMap(FinalMap, GameMap = CreateGrid(tilesize, height, width));
 }
Пример #22
0
    // Use this for initialization
    public GameObject[,] createGameGrid()
    {
        grid = new GameObject[gridWidth,gridHeight];

        for(int i = 0; i < gridWidth; i++)
        {
            for(int j = 0; j < gridHeight; j++)
            {
                GameObject tile = (GameObject)Instantiate(gridTile);
                tile.transform.position = new Vector3(i,0,j);
                tile.tag = "Tile";

                grid[i,j] = tile;
            }
        }

        /*		for(float i = 0.0f; i <= gridWidth*1.1f; i+=2.2f)
        {
            for(float j = 0.0f; j <= gridHeight*1.1f; j+=2.2f)
            {
                GameObject light = (GameObject)Instantiate(edgeLight);
                light.transform.position = new Vector3(i-0.5f,0,j-2f);
            }
        }
        */
        GameObject light = (GameObject)Instantiate(GlobalLight);
        light.transform.position = light.transform.position;

        return grid;
    }
Пример #23
0
    public void generateNewStage(GameObject floorTile,
		                         GameObject wallBlock,
	                             GameObject coin,
	                             GameObject player,
	                             GameObject targetSprite,
	                             GameObject door,
		                         int difficulty,
	                             int maxDifficulty)
    {
        // Grab prefabs from function call
        _floorTile = floorTile;
        _wallBlock = wallBlock;
        _coin = coin;
        _player = player;
        _targetSprite = Instantiate(targetSprite);
        _door = door;
        // Determine size and num coins for this stage
        determineParamsBasedOnDifficulty(difficulty, maxDifficulty);
        // Create our maze
        _maze = new Maze(_size, difficulty, maxDifficulty);
        _maze.generateMap();
        // Allocate our arrays
        _coins = new GameObject[_numCoins];
        _components = new GameObject[(int)_size.x,(int)_size.y];
        // Instantiate our prefabs
        placeComponentsFromMap();
    }
Пример #24
0
    void Start()
    {
        int numQuadX = camera.pixelWidth / quadPixelSize + 1;
        int numQuadY = camera.pixelHeight / quadPixelSize + 1;

        quads = new GameObject[numQuadX + 1, numQuadY + 1];

        Vector3 worldStartPosition = camera.ViewportToWorldPoint(Vector3.zero);
        Vector3 worldOffset = camera.ScreenToWorldPoint(new Vector3(quadPixelSize, quadPixelSize, 2)) - camera.ScreenToWorldPoint(Vector3.zero);

        baseScale = new Vector3(worldOffset.x + overlap, worldOffset.y + overlap, 1);

        for (int xi = 0; xi <= numQuadX; xi++) {
            for (int yi = 0; yi <= numQuadY; yi++) {
                Vector3 position = worldStartPosition + Vector3.Scale(worldOffset, new Vector3(xi, yi, 1));

                quads[xi, yi] = (GameObject)Instantiate(screenTransitionQuad, position, Quaternion.identity);
                quads[xi, yi].name = "Screen Transition Quad (" + xi + ", " + yi + ")";
                quads[xi, yi].transform.parent = transform;

                quads[xi, yi].transform.localScale = baseScale;
            }
        }

        time = domainMin;
        targetTime = domainMax;

        nextSceneName = "";

        instance = this;

        isTransitioning = true;
        StartCoroutine(setTransitioningFalse(0.5f));
    }
 public void criarMapas()
 {
     Mapas = new GameObject[3, 3];
     for (int cont = 0; cont < 3; cont++)
     {
         for (int cont2 = 0; cont2 < 3; cont2++)
         {
             GameObject mapa = GameObject.Instantiate(MapaPadrao) as GameObject;
             mapa.GetComponent<Mapa>().CriarMapa();
             if(cont == 1 && cont2 == 1)
             {
                 mapa.GetComponent<Mapa>().comprado = true;
                 mapa.GetComponent<Mapa>().setComprador(true);
             } else
             {
                 mapa.GetComponent<Mapa>().comprado = false;
                 mapa.GetComponent<Mapa>().setComprador(false);
             }
             //mapa.GetComponent<Mapa>().Save(cont,cont2);
             Mapas[cont, cont2] = mapa;
         }
     }
     saveMapas();
     destroiMapas();
     load(1, 1);
     gerenciadorObjetosCenario.clonesEstruturaEmPosicao();
 }
Пример #26
0
 private void MakeMap(Map map)
 {
     mapped = new GameObject[map.map_w,map.map_h];
     //Create Map
     for (int i=0; i<map.map_h; i++) {
         for (int j=0; j<map.map_w; j++) {
             GameObject hex;
             if (Misc.IsEven (j)) {
                 hex = (GameObject)Instantiate (hexPrefab, new Vector3 (j * Config.hex_x_offset, 0,
                                                -Config.hex_h * i), Quaternion.identity);
             } else {
                 hex = (GameObject)Instantiate (hexPrefab, new Vector3 (j * Config.hex_x_offset, 0,
                                                -(Config.hex_h * i) - Config.hex_y_offset), Quaternion.identity);
             }
             mapped[j,i] = hex;
             //put hex as child of map
             hex.transform.parent = this.gameObject.transform;
             SDL_Surface hexTex;
             //Draw Terrain
             hexTex = map.map_draw_terrain (j, i);
             if (map.map [j, i].g_unit != null || map.map [j, i].a_unit != null) {
                 hexTex = map.map_draw_units (hexTex, j, i, !Engine.Air_mode, false);
             }
             hex.renderer.material = hexTex.BitmapMaterial;
         }
     }
     Engine.status = STATUS.STATUS_NONE;
 }
Пример #27
0
    // Use this for initialization
    void Start()
    {
        _rowSelector = GameObject.Find("PuzzleGrid/RowSelector");
        _currentlySelectedRow = 1;
        _gridVerticalSize = 4;
        //instantiate puzzle grid
        _puzzleGrid = new PuzzleNode[4,GridHorizontalSize];

        //Create array of gameobjects in game where puzzle nodes are placed
        _anchors = new GameObject[_gridVerticalSize,GridHorizontalSize];
        for (int row = 0; row < _anchors.GetLength(0); row++)
        {
            for (int col = 0; col < _anchors.GetLength(1); col++)
            {
                //find current lane's left and right anchors
                var currentLaneLeftAnchor = GameObject.Find("LaneAnchors/Row" + row + "/Left");
                var currentLaneRightAnchor = GameObject.Find("LaneAnchors/Row" + row + "/Right");
                //divide the distance of anchors by amount of anchors to determine spacing between them
                float rowAnchorSpacing = Vector3.Distance(currentLaneLeftAnchor.transform.position,currentLaneRightAnchor.transform.position)/GridHorizontalSize;
                //create new vector3 for where the current anchor will be placed
                var putAnchorAt = new Vector3(currentLaneLeftAnchor.transform.position.x + rowAnchorSpacing * col,0);
                //create game object, name it, make it's parent the parent of the rest of the row elements
                var currentAnchor = (GameObject) Instantiate(Resources.Load<GameObject>("Prefabs/PuzzleNode"));
                currentAnchor.name = row + "_" + col;
                currentAnchor.transform.parent = GameObject.Find("LaneAnchors/Row" + row).transform;
                //change it's position
                currentAnchor.transform.localPosition = putAnchorAt;
                //add game object to array
                _anchors[row, col] = currentAnchor;
            }
        }
    }
Пример #28
0
    //called as constructor
    public void Awake()
    {
        //rows = 10;
        //columns = 10;
        entrance = new Vector2(-1, -1);
        exit = new Vector2(-1, -1);
        cases = new GameObject[columns, rows];
        walls = new Wall[columns, rows];
        deadends = new List<Vector2>();
        visited = new bool[columns, rows];

        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                visited[i, j] = false;
                walls[i, j] = Wall.RD;
            }
        }
        //Instantiate cells
        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                cases[i, j] = (GameObject) Instantiate(cell, new Vector3(i - 4.5f, 0f, j - 4.5f), Quaternion.identity);
            }
        }
    }
Пример #29
0
    public void RealStart(bool[,] blockArray, int direction, int team_id, Color color)
    {
        // blockArray should be 5x5
        blocks = new GameObject[5, 5];
        System.Random rand = new System.Random();

        string[] FileList = Directory.GetFiles(@"C:\temp2\", "*.png");
        byte[] bytes;
        bytes = System.IO.File.ReadAllBytes(FileList[rand.Next(0, FileList.Length -1)]);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                if(blockArray[i, j]){
                    Vector3 newPos = transform.position + new Vector3(direction*j*block.GetComponent<Renderer>().bounds.size.x,
                                                                      -i*block.GetComponent<Renderer>().bounds.size.y, 0);
                    GameObject b = (GameObject)Instantiate(block, newPos, Quaternion.identity);
                    b.GetComponent<Mover>().MoveSpeed = direction * 1.5f;
                    b.GetComponent<Mover>().team_id = team_id;
                    Texture2D tex = new Texture2D(12, 12);
                    ///while(!www.isDone) { }
                    ///www.LoadImageIntoTexture(tex);
                    tex.LoadImage(bytes);
                    TextureScale.Bilinear(tex, 12, 12);
                    Sprite sprite = Sprite.Create(tex, new Rect(0, 0, 12, 12), new Vector2(0, 0));
                    b.GetComponent<SpriteRenderer>().sprite = sprite;
                    b.GetComponent<SpriteRenderer>().color = color;
                    blocks[i, j] = b;
                }
            }
        }
        LastBlocks = BlockAmount();
    }
Пример #30
0
 public void Begin()
 {
     Debug.Log (text.text);
     string[] strs = text.text.Split ('\n');
     row = strs.Length;
     col = strs [0].Length;
     mArray = new int[row, col];
     for (int i=0; i<row; i++)
     for (int j=0; j <col ; j++)
     {
         mArray[j,row-1-i]=(int)strs[i][j]-48;
     //			Debug.Log(i+","+j+","+strs[i][j]+",");
     //			Debug.Log(row-1-i+","+j+","+strs[i][j]+",");
     }
     cellGameObjects=new GameObject[row,col];
     for (int i=0; i<row; i++)
     for (int j=0; j<col; j++) {
         GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
         quad.transform.position=new Vector3(i+spacing*i,j+spacing*j);
         cellGameObjects[i,j]=quad;
     }
     Camera.main.transform.position = new Vector3 ((row-1 + spacing * (row - 1)) / 2, (col-1 + spacing * (col - 1)) / 2,-10);
     Camera.main.orthographicSize = 1f+Mathf.Max ((row-1 + spacing * (row - 1)) / 2, (col-1 + spacing * (col - 1)) / 2);
     //GameOfLife2 (mArray);
     //ShowResult();
     StartCoroutine (Calculate ());
 }
Пример #31
0
 // Use this for initialization
 void Start()
 {
     Grid = new GameObject[rows, columns];
     BuildGrid();
 }
Пример #32
0
 // Use this for initialization
 void Start()
 {
     grid  = new GameObject[width, height];
     xGrid = width / 2;
     CreateShape();
 }
 // Use this for initialization
 void Start()
 {
     grid = new GameObject[planeSize * 2, planeSize * 2];
 }
    //Generating the field - solution always visible
    void GenerateMineField(int width, int height, int totalMines)
    {
        grid = new GameObject[width, height];
        //Generating the grid
        RectTransform rtPanel = (RectTransform)minesweeperPanel.transform;

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                // --BUTTON CREATION-- //
                GameObject newButton = Instantiate(prefabButtons, minesweeperPanel.transform) as GameObject;

                RectTransform rtButton = (RectTransform)newButton.transform;
                newButton.GetComponent <RectTransform>().sizeDelta = new Vector2(rtPanel.rect.width / width, rtPanel.rect.width / width);
                float startingPos = minesweeperPanel.transform.localPosition.x - (rtPanel.rect.width / 2) + (rtButton.rect.width / 2);

                float buttonXPosition = startingPos + (rtPanel.rect.width / width * x);
                float buttonYPosition = startingPos + (rtPanel.rect.height / height * y);
                newButton.transform.localPosition = new Vector3(buttonXPosition, buttonYPosition, newButton.transform.position.z);
                //         --         //

                //Grid reference
                grid[x, y] = newButton;
                grid[x, y].GetComponent <CellData>().cellType = Cell.EMPTY;
                grid[x, y].GetComponent <CellData>().x        = x;
                grid[x, y].GetComponent <CellData>().y        = y;

                Button button = newButton.GetComponent <Button>();
                button.onClick.AddListener(delegate { TaskOnClick(newButton); });
            }
        }

        //Creating the mines
        for (int index = 0; index < totalMines; index++)
        {
            int x = Random.Range(0, width - 1);
            int y = Random.Range(0, height - 1);

            GameObject mine = grid[x, y];
            mine.GetComponent <CellData>().cellType         = Cell.MINE;
            grid[x, y].GetComponentInChildren <Text>().text = "MINE";

            tilesSurrounding.Add(grid[x, (y < height? y + 1 : y)]);                                                   //up
            tilesSurrounding.Add(grid[x, (y > 0 ? y - 1 : y)]);                                                       //down
            tilesSurrounding.Add(grid[(x > 0 ? x - 1 : x), y]);                                                       //left
            tilesSurrounding.Add(grid[(x < width ? x + 1 : x), y]);                                                   //right
            tilesSurrounding.Add(grid[(x > 0 && y < height ? x - 1 : x), (x > 0 && y < height ? y + 1 : y)]);         //topLeft
            tilesSurrounding.Add(grid[(x < width && y < height ? x + 1 : x), (x < width && y < height ? y + 1 : y)]); //topRight
            tilesSurrounding.Add(grid[(x > 0 && y > 0 ? x - 1 : x), (x > 0 && y > 0 ? y - 1 : y)]);                   //bottomLeft
            tilesSurrounding.Add(grid[(x < width && y > 0 ? x + 1 : x), (x < width && y > 0 ? y - 1 : y)]);           //bottomRight

            for (int index2 = 0; index2 < tilesSurrounding.Count; index2++)
            {
                if (tilesSurrounding[index2].GetComponent <CellData>().cellType != Cell.MINE)
                {
                    AddEnumNumber(tilesSurrounding[index2]);
                }
            }
            tilesSurrounding.Clear();
        }
    }
Пример #35
0
    public void Restore()
    {
        Transform palt = transform.Find("palette");

        if (palt != null)
        {
            GameObject.DestroyImmediate(palt.gameObject);
        }
        GameObject pal = new GameObject("palette");

        pal.hideFlags = HideFlags.HideInHierarchy;
        BoxCollider bc = pal.AddComponent <BoxCollider>();

        bc.size   = new Vector3(palette.Count * gridsize, gridsize, 0f);
        bc.center = new Vector3((palette.Count - 1f) * gridsize * 0.5f, 0f, 0f);

        pal.transform.parent        = this.gameObject.transform;
        pal.transform.localPosition = new Vector3(0f, -gridsize * 2, 0f);
        pal.transform.rotation      = transform.rotation;



        int palette_folder = -1;

        for (int i = 0; i < palette.Count; i++)
        {
            UnityEngine.Object o = palette[i];
            if (IsAssetAFolder(o))
            {
                palette_folder = i;
            }
            else
            {
                if (o != null)
                {
                    GameObject g = CreatePrefab(o, new Vector3(), transform.rotation);
                    g.transform.parent        = pal.transform;
                    g.transform.localPosition = new Vector3(i * gridsize, 0f, 0f);
                }
            }
        }

        if (palette_folder != -1)
        {
            string path = AssetDatabase.GetAssetPath(palette[palette_folder].GetInstanceID());
            path = path.Trim().Replace("Assets/Resources/", "");
            palette.RemoveAt(palette_folder);
            UnityEngine.Object[] contents = (UnityEngine.Object[])Resources.LoadAll(path);
            foreach (UnityEngine.Object o in contents)
            {
                if (!palette.Contains(o))
                {
                    palette.Add(o);
                }
            }
            Restore();
        }

        tileobs = new GameObject[width, height];
        if (tiles == null)
        {
            tiles = new GameObject("tiles");
            tiles.transform.parent        = this.gameObject.transform;
            tiles.transform.localPosition = new Vector3();
        }
        int cnt = tiles.transform.childCount;
        List <GameObject> trash = new List <GameObject>();

        for (int i = 0; i < cnt; i++)
        {
            GameObject tile    = tiles.transform.GetChild(i).gameObject;
            Vector3    tilepos = tile.transform.localPosition;
            int        X       = (int)(tilepos.x / gridsize);
            int        Y       = (int)(tilepos.y / gridsize);
            if (ValidCoords(X, Y))
            {
                tileobs[X, Y] = tile;
            }
            else
            {
                trash.Add(tile);
            }
        }
        for (int i = 0; i < trash.Count; i++)
        {
            if (Application.isPlaying)
            {
                Destroy(trash[i]);
            }
            else
            {
                DestroyImmediate(trash[i]);
            }
        }

        if (color == null)
        {
            if (palette.Count > 0)
            {
                color = palette[0];
            }
        }
    }
Пример #36
0
 // Start is called before the first frame update
 void Start()
 {
     generateBoxes = new GameObject[GeneratePlaces.GetLength(0), GeneratePlaces.GetLength(1)];
 }
Пример #37
0
    // Find Match-3 Tile
    private ArrayList FindMatch(GameObject[,] cells)
    {//creating an arraylist to store the matching tiles
        ArrayList stack = new ArrayList();

        //Checking the vertical tiles
        for (var x = 0; x <= cells.GetUpperBound(0); x++)
        {
            for (var y = 0; y <= cells.GetUpperBound(1); y++)
            {
                var thiscell = cells[x, y];
                //If it's an empty tile continue
                //if (thiscell.name == "Empty(Clone)") continue;
                if (null == thiscell.GetComponent <PoolObject>())
                {
                    continue;
                }
                int matchCount = 0;
                int y2         = cells.GetUpperBound(1);
                int y1;
                //Getting the number of tiles of the same kind
                for (y1 = y + 1; y1 <= y2; y1++)
                {
                    //if (cells[x, y1].name == "Empty(Clone)" || thiscell.name != cells[x, y1].name) break;
                    if (cells[x, y1].GetComponent <PoolObject>() == null || thiscell.name != cells[x, y1].name)
                    {
                        break;
                    }
                    matchCount++;
                }
                //If we found more than 2 tiles close we add them in the array of matching tiles
                if (matchCount >= 2)
                {
                    y1 = Mathf.Min(cells.GetUpperBound(1), y1 - 1);
                    for (var y3 = y; y3 <= y1; y3++)
                    {
                        if (!stack.Contains(cells[x, y3]))
                        {
                            stack.Add(cells[x, y3]);
                        }
                    }
                }
            }
        }
        //Checking the horizontal tiles , in the following loops we will use the same concept as the previous ones
        for (var y = 0; y < cells.GetUpperBound(1) + 1; y++)
        {
            for (var x = 0; x < cells.GetUpperBound(0) + 1; x++)
            {
                var thiscell = cells[x, y];
                if (thiscell.name == "Empty(Clone)")
                {
                    continue;
                }
                int matchCount = 0;
                int x2         = cells.GetUpperBound(0);
                int x1;
                for (x1 = x + 1; x1 <= x2; x1++)
                {
                    if (cells[x1, y].name == "Empty(Clone)" || thiscell.name != cells[x1, y].name)
                    {
                        break;
                    }
                    matchCount++;
                }
                if (matchCount >= 2)
                {
                    x1 = Mathf.Min(cells.GetUpperBound(0), x1 - 1);
                    for (var x3 = x; x3 <= x1; x3++)
                    {
                        if (!stack.Contains(cells[x3, y]))
                        {
                            stack.Add(cells[x3, y]);
                        }
                    }
                }
            }
        }
        return(stack);
    }
Пример #38
0
 public void PlaceUnits()
 {
     UnitManager = UnitManagerGO.GetComponent <UnitManager>();
     TheGrid     = UnitManager.placeUnits(TheGrid, terrain_generator.map_width, terrain_generator.map_height);
 }
Пример #39
0
 // Use this for initialization
 void Start()
 {
     cells = new GameObject[poleRazmer, poleRazmer];
     Generate();
     pointsText.text = string.Format("{0}", points);
 }
Пример #40
0
    public void CreateTilemapMesh(GameObject[,] tiles)
    {
        CombineInstance combine = new CombineInstance();

        List <CombineInstance> lush  = new List <CombineInstance>();
        List <CombineInstance> grass = new List <CombineInstance>();
        List <CombineInstance> mud   = new List <CombineInstance>();
        List <CombineInstance> sand  = new List <CombineInstance>();
        List <CombineInstance> water = new List <CombineInstance>();

        int verticesSoFar   = 0;
        int meshListCounter = 0;

        //for each tile, grab their meshfilter and add according to their material type
        foreach (GameObject go in tiles)
        {
            Tile tile = go.GetComponent <Tile>();
            tile.id = meshListCounter;

            //hide original tile object
            go.SetActive(false);

            MeshFilter mf       = go.GetComponent <MeshFilter>();
            string     material = mf.GetComponent <MeshRenderer>().material.name.Replace(" (Instance)", "");

            combine.mesh      = mf.mesh;
            combine.transform = mf.transform.localToWorldMatrix;

            if (tile.terrainType == Terrain.Lush)
            {
                lush.Add(combine);
            }
            else if (tile.terrainType == Terrain.Grass)
            {
                grass.Add(combine);
            }
            else if (tile.terrainType == Terrain.Mud)
            {
                mud.Add(combine);
            }
            else if (tile.terrainType == Terrain.Sand)
            {
                sand.Add(combine);
            }
            else if (tile.terrainType == Terrain.Water)
            {
                water.Add(combine);
            }

            verticesSoFar += mf.mesh.vertexCount;

            if (verticesSoFar >= vertexLimit)
            {
                CombineMesh(lush, lushMeshPrefab, lushHolder);
                CombineMesh(grass, grassMeshPrefab, grassHolder);
                CombineMesh(mud, mudMeshPrefab, mudHolder);
                CombineMesh(sand, sandMeshPrefab, sandHolder);
                CombineMesh(water, waterMeshPrefab, waterHolder);

                lush.Clear();
                grass.Clear();
                mud.Clear();
                sand.Clear();
                water.Clear();

                verticesSoFar = 0;
                meshListCounter++;
            }
        }

        CombineMesh(lush, lushMeshPrefab, lushHolder);
        CombineMesh(grass, grassMeshPrefab, grassHolder);
        CombineMesh(mud, mudMeshPrefab, mudHolder);
        CombineMesh(sand, sandMeshPrefab, sandHolder);
        CombineMesh(water, waterMeshPrefab, waterHolder);
    }
Пример #41
0
    void Start()
    {
        //Distance of crystal fall
        distanceY = 2;
        //cell width
        colW = 1;
        //cell height
        rowH = 1;
        //number of rows
        rowLen = 8;
        //number of columns
        colLen = 8;
        //declarate an initial background cell
        cellId = 0;
        //Determining the grid size
        CrystalsList = new GameObject[rowLen, colLen];


        //Prefab loader, load all cells prefabs from the Prefab/Crystals folder
        prefabLoader("Prefabs/UI/Cells", Cells);
        //Prefab loader, load all crystals prefabs from the Prefab/Crystals folder
        prefabLoader("Prefabs/Crystals", Crystals);

        //This 'for' bellow instantiate the background cells and the crystals in the canvas preventing a repetitive crystals sequence in the first turn.

        //There we increment lines
        for (int i = 0; i < rowLen; i++)
        {
            //There increment columns
            for (int j = 0; j < colLen; j++)
            {
                if (cellId == 0)
                {
                    Instantiate(Cells[cellId], new Vector3(colW * j, rowH * i, 1), Quaternion.identity);
                    if (j < colLen - 1)
                    {
                        cellId++;
                    }
                }
                else
                {
                    Instantiate(Cells[cellId], new Vector3(colW * j, rowH * i, 1), Quaternion.identity);
                    if (j < colLen - 1)
                    {
                        cellId = 0;
                    }
                }

                //This is a cristalId, this number will be cached for comparsion reasons.
                crystalId = Random.Range(0, 5);

                //The crystal is loaded and positioned in the canvas using a temporary crystalId
                CrystalsList[i, j] = (GameObject)Instantiate(Crystals[crystalId], new Vector3(colW * j, rowH * i + distanceY, 0), Quaternion.identity);

                if (j > 1)
                {
                    //After the second iteration starts a test if exists two left crystals with a same name, never before this iteration because we whould get an 'Out of Bounds Error' in Array.
                    if (CrystalsList[i, j].name == CrystalsList[i, j - 1].name && CrystalsList[i, j].name == CrystalsList[i, j - 2].name)
                    {
                        //If the gameobjects have the same name the gameoobject will be destroyed, the crystalId will be changed and a new crystal will be loaded.
                        Destroy(CrystalsList[i, j]);
                        crystalId          = (crystalId == 0 ? crystalId = Crystals.Count - 1 : crystalId - 1);
                        CrystalsList[i, j] = (GameObject)Instantiate(Crystals[crystalId], new Vector3(colW * j, rowH * i + distanceY, 0), Quaternion.identity);
                    }
                }
                //Now, after the second line interation, we need find the repeated crystals vertically
                if (i > 1)
                {
                    if (CrystalsList[i, j].name == CrystalsList[i - 1, j].name && CrystalsList[i, j].name == CrystalsList[i - 2, j].name)
                    {
                        Destroy(CrystalsList[i, j]);
                        //No chance to sort a same crystal that was destroyed before because I walk in the list step by step from the end to the beginning. Certally, in this case, the destroyed crystal had another index.
                        crystalId          = (crystalId == 0 ? crystalId = Crystals.Count - 1 : crystalId - 1);
                        CrystalsList[i, j] = (GameObject)Instantiate(Crystals[crystalId], new Vector3(colW * j, rowH * i + distanceY, 0), Quaternion.identity);
                    }
                }
            }
        }
    }
Пример #42
0
 // Use this for initialization
 void Start()
 {
     board = new GameObject[boardDimensions, boardDimensions];
 }
Пример #43
0
    //temp
    public void ActivateAroundTile(GameObject[,] grid, int range, Vector2Int start)
    {
        //get origin
        var origin = grid[start.x, start.y];

        float[,] g = new float[gridSize, gridSize];
        for (var x = 0; x < gridSize; x++)
        {
            for (var y = 0; y < gridSize; y++)
            {
                g[x, y] = Mathf.Infinity;
            }
        }
        g[start.x, start.y] = 0;
        //a star get range
        List <GameObject>          closed = new List <GameObject>();
        PriorityQueue <GameObject> open   = new PriorityQueue <GameObject>();

        open.Clear();

        open.Add(origin, 0);


        //for (var t = 0; t < range; t++)
        {
            while (open.Count > 0)
            {
                float currentTileG = open.GetPriorityMin();
                var   currentTile  = open.GetElementPriorityMin();
                open.Sort();
                open.Remove(open.GetElementPriorityMin());


                closed.Add(currentTile);

                //Handle neighbors
                for (var i = 0; i < 4; i++)
                {
                    var neighbor = GetNeighbor(grid, currentTile, i);
                    if (neighbor == null)
                    {
                        continue;
                    }

                    //check if it's in closed
                    if (closed.Contains(neighbor))
                    {
                        continue;
                    }

                    float tentativeG = currentTileG + 1; //can add terrain costs here


                    //attack tiles could be handled here

                    if (tentativeG > range)
                    {
                        continue;
                    }

                    //if neighbor is not in open, add to open queue
                    if (!open.Contains(neighbor))
                    {
                        open.Add(neighbor, tentativeG);
                    }
                    else if (tentativeG >= currentTileG)
                    {
                        continue;
                    }

                    open.SetPriority(neighbor, tentativeG);

                    Vector2Int neighborPos = GetTilePosition(neighbor);
                    g[neighborPos.x, neighborPos.y] = tentativeG;
                }
            }
        }

        //activate
        for (var x = 0; x < gridSize; x++)
        {
            for (var y = 0; y < gridSize; y++)
            {
                if (g[x, y] <= range)
                {
                    ActivateTile(grid[x, y]);
                }
            }
        }
    }
 public GameObjectGrid(int rows, int columns, int layer = 0, string id = "") : base(layer, id)
 {
     grid = new GameObject[columns, rows];
 }
    // Use this for initialization
    void Start()
    {
        n    = 5;      //n x n grid
        grid = new GameObject[n, n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int whichPrefab = 0;                                        //boring spots
                int diff        = Mathf.Abs(i - j);
                if ((diff == 0 || diff == n - 1) && (i == 0 || i == n - 1)) //corners
                {
                    whichPrefab = 3;
                }
                else if (diff == 1 && (i == n / 2 || j == n / 2))                //plus sign not center
                {
                    whichPrefab = 1;
                }
                else if (((diff == 1 || diff == n - 2) && (i <= 1 || i == n - 1 || i == n - 2)) ||
                         (diff == 1 || diff == n - 2) && (j <= 1 || j == n - 1 || j == n - 2))                                //surrounding corners
                {
                    whichPrefab = 2;
                }
                else if (i == n / 2 && j == n / 2)               //mid
                {
                    whichPrefab = 4;
                }
                Vector3 pos = new Vector3(transform.position.x + 1.1f * j * transform.localScale.x - 0.5f,
                                          transform.position.y - 1.1f * i * transform.localScale.y, zDist);
//				Quaternion rot = Quaternion.AngleAxis (180f, transform.up);
                grid[i, j] = (GameObject)Instantiate(cellPrefabs[whichPrefab], pos, transform.rotation);
                cellBehavior cellScript = grid [i, j].GetComponent <cellBehavior> ();
                cellScript.Init();
                cellScript.i = i;
                cellScript.j = j;
            }
        }
        currPlayer = 0;
        foreach (playerBehavior playerScript in players)
        {
            playerScript.grid = grid;
        }
        score = new int[players.Length];
        for (int i = 0; i < score.Length; i++)
        {
            score [i] = 0;
        }
        tutorialMode       = tutorials.Length > 0;
        currTut            = 0;
        tutModeFin         = false;
        needNewTut         = true;
        origScoreColor     = new Color[2];
        origScoreColor [0] = textFields [0].GetComponent <Text> ().color;
        origScoreColor [1] = textFields [1].GetComponent <Text> ().color;

        origTurnLightColors     = new Color[2];
        origTurnLightColors [0] = turnLights [0].GetComponent <Light> ().color;
        origTurnLightColors [1] = turnLights [1].GetComponent <Light> ().color;
        turnLights [1].GetComponent <Light> ().color = Color.black;

        endSpriteSoundPlaying = false;

        showHomeButtonTimer    = 0f;
        showHomeButtonWaitTime = 1f;
    }
Пример #46
0
 public void InitSwap(Board board, Tile[,] tiles, Drop[,] drops, int width, int height, GameObject[,] dropsGameObjects)
 {
     _board                     = board;
     _width                     = width;
     _height                    = height;
     _dropsGameObjects          = dropsGameObjects;
     _activatedTilesForSwapping = new List <Tile>();
     _tiles                     = tiles;
     _drops                     = drops;
 }
Пример #47
0
    //ステージ初期化
    void initStage()
    {
        GameObject currentScene = ApplicationManagerController.Instance.currentSceneManager;

        this.sceneManager = currentScene.GetComponent <GameSceneManager>();

        //ステージデータ読み込み
        string stageName = "Map/Stage" + this.app.playingStageNumber;

        this.panelData = new MapReader(stageName + "_panel");
        this.itemData  = new MapReader(stageName + "_item");

        //ステージパネルデータ配列
        this.stageMap = new GameObject[this.stageWidth, this.stageHeight];

        //パネルの準備
        for (int y = 0; y < this.stageHeight; y++)
        {
            for (int x = 0; x < this.stageWidth; x++)
            {
                float      delay = Random.Range(0.0f, 1.0f);
                int        idx   = this.panelData.mapData[x, y];
                GameObject p     = this.enterPanel(idx, x, y);
                //落下演出
                Vector3 pos = p.transform.position;
                pos.y += 10.0f;
                p.transform.position = pos;
                p.transform.DOLocalMove(new Vector3(0, -10.0f, 0.0f), 1.0f)
                .SetEase(Ease.OutBounce)
                .SetDelay(delay)
                .SetRelative();
                PanelController pc = p.GetComponent <PanelController>();
                //初期アイテムセットとパネル設定
                int id = this.itemData.mapData[x, y];
                switch (id)
                {
                case 0:
                    break;

                case 1:
                case 2:
                    this.enterItem(id, x, y, 3.0f);
                    pc.isOnItem = true;
                    break;

                //スタートパネル
                case 8:
                    this.startX      = x;
                    this.startY      = y;
                    pc.isStart       = true;
                    pc.isDisableMove = true;
                    break;

                //ゴールパネル
                case 9:
                    this.goalX       = x;
                    this.goalY       = y;
                    pc.isStart       = true;
                    pc.isDisableMove = true;
                    break;
                }
                if (this.itemData.mapData[x, y] != 0)
                {
                    pc.isDisableShaffle = true;
                }
                this.stageMap[x, y] = p;
            }
        }

        //パネルシャッフル
        for (int i = 0; i < 20; i++)
        {
            int x1 = Random.Range(0, 5), y1 = Random.Range(0, 5);
            int x2 = Random.Range(0, 5), y2 = Random.Range(0, 5);
            this.swapPanel(x1, y1, x2, y2);
        }
        this.transform.parent.gameObject.SendMessage("OnAlreadyStartView");

        //ゴールパネル標識
        GameObject canvasText = Instantiate((GameObject)Resources.Load("Prefabs/GoalText"));

        canvasText.transform.SetParent(this.transform);
        canvasText.transform.position = new Vector3(this.goalX + 0.5f, 5.0f, -5.0f);

        DOVirtual.DelayedCall(2.0f, () => {
            canvasText.transform.DOMove(new Vector3(this.goalX + 0.5f, -this.goalY + 0.5f, -5.0f), 2.0f)
            .SetEase(Ease.OutBounce);
            Destroy(canvasText, 7.0f);
        });

        //早送りボタン
        GameObject ffb = Instantiate((GameObject)Resources.Load("Prefabs/FFButton"));

        ffb.transform.SetParent(this.transform);
        ffb.transform.position = new Vector3(2.5f, -6.5f, -5.0f);
    }
Пример #48
0
    // Start is called before the first frame update
    void Start()
    {
        //load savedata
        data = GameController.Instance.data;
        data.Load();

        tiles = new int[mapSizeX, mapSizeY];
        for (int x = 0; x < mapSizeX; x++)
        {
            for (int y = 0; y < mapSizeY; y++)
            {
                tiles[x, y] = 0;
            }
        }

        //initialize as all 0 units
        units = new Character[mapSizeX, mapSizeY];
        for (int i = 0; i < mapSizeX; i++)
        {
            for (int j = 0; j < mapSizeY; j++)
            {
                units[i, j] = new Character(Alignment.Terrain, "", 0, 0, 0, 0, 0, 0);
            }
        }

        if (SceneManager.GetActiveScene().name == "Tutorial")
        {
            //set unit type 1
            //units[0, 0] = data.characters.Find(c => c.name == "Phos"); //human
            units[2, 1] = data.characters.Find(c => c.name == "Tisiphone"); //elf sister
                                                                            //units[3, 5] = data.characters.Find(c => c.name == "Sisyphus"); //elf brother
                                                                            //units[4,0] = data.characters.Find(c => c.name == "Iphi"); //dwarf
                                                                            //units[6,0] = data.characters.Find(c => c.name == "Dartfoot"); //halfling

            //set enemy type 2
            units[2, 4] = new Character(Alignment.Enemy, "Sisyphus", 3, 3, 1, 0, 2, 2); //elf king
                                                                                        //units[5, 7] = new Character(Alignment.Enemy, "Gorb", 2, 2, 2, 0, 2, 1); //goblin
                                                                                        //units[3, 7] = new Character(Alignment.Enemy, "Gorb", 2, 2, 2, 0, 2, 1); //goblin
                                                                                        //units[1, 7] = new Character(Alignment.Enemy, "Gorb", 2, 2, 2, 0, 2, 1); //goblin
        }
        if (SceneManager.GetActiveScene().name == "Fellowship")
        {
            //set unit type 1
            //units[0, 0] = data.characters.Find(c => c.name == "Phos"); //human
            units[1, 1] = data.characters.Find(c => c.name == "Tisiphone"); //elf sister
                                                                            //units[3, 5] = data.characters.Find(c => c.name == "Sisyphus"); //elf brother
                                                                            //units[4,0] = data.characters.Find(c => c.name == "Iphi"); //dwarf
                                                                            //units[6,0] = data.characters.Find(c => c.name == "Dartfoot"); //halfling

            //set enemy type 2
            //units[2, 4] = new Character(Alignment.Enemy, "Sisyphus", 3, 3, 1, 0, 2, 2); //elf king
            units[4, 6] = new Character(Alignment.Enemy, "Gurd", 4, 4, 3, 0, 2, 1); //goblin
            units[2, 6] = new Character(Alignment.Enemy, "Gorb", 4, 4, 2, 1, 2, 1); //goblin
            units[3, 7] = new Character(Alignment.Enemy, "Garb", 6, 6, 2, 0, 2, 1); //goblin

            //tiles[0, 2] = 1;
            //tiles[1, 3] = 1;
            //tiles[4, 3] = 1;
            //tiles[5, 3] = 1;
            //tiles[6, 3] = 1;
        }
        unitObjects = new GameObject[mapSizeX, mapSizeY];
        tileObjects = new GameObject[mapSizeX, mapSizeY];

        GenerateMap();
        GenerateCharacters();
    }
Пример #49
0
    private void Start()
    {
        // if (this.baseTile == null && this.pathTile)
        //  return;

        // if (tiles != null)
        //  foreach (var tile in tiles)
        //      if (tile != null)
        //          UnityEditor.EditorApplication.delayCall += () => StartCoroutine(destroyObject(tile));

        MapGenerator mapGenerator = new MapGenerator(Random.Range(0, 99999999));

        mapGenerator.GenerateMap(mapSize, mapLength, false, 0.0f, 0.3f);

        char[, ] result = mapGenerator.Display();

        int dim = (int)result.GetLength(0);

        tiles = new GameObject[dim, dim];

        for (int x = 0; x < dim; x++)
        {
            for (int y = 0; y < dim; y++)
            {
                GameObject toInstantiate;
                Quaternion quaternion = Quaternion.identity;

                switch (mapGenerator.GetTile(x, y))
                {
                case TileType.EmptySpace:
                    toInstantiate = baseTile;
                    break;

                case TileType.Decor:
                    toInstantiate = baseTile;
                    break;

                case TileType.Decor2:
                    toInstantiate = baseTile;
                    break;

                case TileType.ElbowLeftDown:
                case TileType.ElbowLeftUp:
                case TileType.ElbowRightDown:
                case TileType.ElbowRightUp:
                    toInstantiate = cornerTile;
                    break;

                case TileType.HorizPath:
                    toInstantiate = pathTile;
                    break;

                case TileType.VertPath:
                    quaternion    = Quaternion.Euler(0, 90, 0);
                    toInstantiate = pathTile;
                    break;

                default:
                    toInstantiate = baseTile;
                    break;
                }

                GameObject tile = (GameObject)Instantiate(toInstantiate, buildPos + new Vector3(-x * 4, 0, y * 4), quaternion, parent.transform);
                tiles[x, y] = tile;
            }
        }
    }
Пример #50
0
    void Start()
    {
        // Position the camera
        float tempZ = Camera.main.transform.position.z;

        Camera.main.transform.position = new Vector3((mapWidth - 1) / 2.0f, (mapHeight) / 2.0f, tempZ);

        tileArray   = new GameObject[mapWidth, mapHeight];
        spriteArray = new SpriteRenderer[mapWidth, mapHeight];

        tileLayerMask = LayerMask.GetMask("Tile");

        lineRenderer         = GetComponent <LineRenderer>();
        lineRenderer.enabled = false;

        turnChangeCanvas.SetActive(true);

        // Generate the map
        for (int i = 0; i < mapWidth; i++)
        {
            for (int j = 0; j < mapHeight; j++)
            {
                Vector3 pos = new Vector3(i, j, 0);
                tileArray[i, j]   = (GameObject)Instantiate(tile, pos, Quaternion.identity);
                spriteArray[i, j] = tileArray[i, j].GetComponent <SpriteRenderer>();
            }
        }

        TileDirection tileDir = TileDirection.UpToLeft;

        // By default, make borders on the grid
        for (int i = 1; i < mapWidth - 1; i++)
        {
            GameObject go = (GameObject)Instantiate(bounceTile, new Vector3(i, 0), Quaternion.identity);
            go.GetComponent <BounceTile>().setDirection(tileDir);
            go.GetComponent <BounceTile>().destructible = false;
            bounceTiles.Add(go);

            tileDir = (TileDirection)(((int)tileDir + 1) % 2);             // switch tiledir to get a zigzag

            go = (GameObject)Instantiate(bounceTile, new Vector3(i, mapHeight - 1), Quaternion.identity);
            go.GetComponent <BounceTile>().setDirection(tileDir);
            go.GetComponent <BounceTile>().destructible = false;
            bounceTiles.Add(go);
        }
        for (int i = 1; i < mapHeight - 1; i++)
        {
            GameObject go = (GameObject)Instantiate(bounceTile, new Vector3(0, i), Quaternion.identity);
            go.GetComponent <BounceTile>().setDirection(tileDir);
            go.GetComponent <BounceTile>().destructible = false;
            bounceTiles.Add(go);

            tileDir = (TileDirection)(((int)tileDir + 1) % 2);             // switch tiledir to get a zigzag

            go = (GameObject)Instantiate(bounceTile, new Vector3(mapWidth - 1, i), Quaternion.identity);
            go.GetComponent <BounceTile>().setDirection(tileDir);
            go.GetComponent <BounceTile>().destructible = false;
            bounceTiles.Add(go);
        }

        // Corners
        GameObject go2 = (GameObject)Instantiate(bounceTile, new Vector3(0, 0), Quaternion.identity);

        go2.GetComponent <BounceTile>().setDirection(TileDirection.UpToLeft);
        go2.GetComponent <BounceTile>().destructible = false;
        bounceTiles.Add(go2);

        go2 = (GameObject)Instantiate(bounceTile, new Vector3(0, mapHeight - 1), Quaternion.identity);
        go2.GetComponent <BounceTile>().setDirection(TileDirection.UpToRight);
        go2.GetComponent <BounceTile>().destructible = false;
        bounceTiles.Add(go2);

        go2 = (GameObject)Instantiate(bounceTile, new Vector3(mapWidth - 1, 0), Quaternion.identity);
        go2.GetComponent <BounceTile>().setDirection(TileDirection.UpToRight);
        go2.GetComponent <BounceTile>().destructible = false;
        bounceTiles.Add(go2);

        go2 = (GameObject)Instantiate(bounceTile, new Vector3(mapWidth - 1, mapHeight - 1), Quaternion.identity);
        go2.GetComponent <BounceTile>().setDirection(TileDirection.UpToLeft);
        go2.GetComponent <BounceTile>().destructible = false;
        bounceTiles.Add(go2);


        // Place bounce tiles according to custom position array
        for (int i = 0; i < bounceTilePos.Length; i++)
        {
            // we use the z component to determine the type of bounce tile
            // janky, or efficient? who knows?
            TileDirection dir = (TileDirection)bounceTilePos[i].z;
            bounceTilePos[i].z = 0;
            buildBounceTile(bounceTilePos[i], dir);
            //tileArray[(int)bounceTilePos[i].x, (int)bounceTilePos[i].y] = go;
            spawnedTerrains++;
        }

        Invoke("NextTurn", turnChangeDuration);
    }
Пример #51
0
        private void SpawnTiles()
        {
            mapTiles = new GameObject[mapSize, mapSize];
            for (int i = 0; i < mapSize; i++)
            {
                for (int j = 0; j < mapSize; j++)
                {
                    if (map[i, j] != (int)Tiles.none)
                    {
                        Vector3 angle = new Vector3(0, 0, 0);
                        //Debug.Log(map[i, j]);
                        if (map[i, j] == (int)Tiles.end || map[i, j] == (int)Tiles.spawn)
                        {
                            if ((int)i - 1 >= 0 && map[i - 1, j] != (int)Tiles.border && map[i - 1, j] != (int)Tiles.none)
                            {
                                angle = new Vector3(0, -90f, 0);
                            }
                            if (i + 1 < mapSize && map[i + 1, j] != (int)Tiles.border && map[i + 1, j] != (int)Tiles.none)
                            {
                                angle = new Vector3(0, 90f, 0);
                            }
                            if (j - 1 >= 0 && map[i, j - 1] != (int)Tiles.border && map[i, j - 1] != (int)Tiles.none)
                            {
                                angle = new Vector3(0, 180f, 0);
                            }
                        }
                        else
                        {
                            angle = new Vector3(0, Random.Range(0, 5) * 90f, 0);
                        }

                        GameObject tile = Instantiate(tiles[map[i, j]], new Vector3(
                                                          tiles[(int)Tiles.basic].transform.localScale.x * i,
                                                          0,
                                                          tiles[(int)Tiles.basic].transform.localScale.z * j),
                                                      Quaternion.Euler(angle));
                        tile.transform.SetParent(this.transform);
                        tile.name      = (((Tiles)map[i, j]).ToString());
                        mapTiles[i, j] = tile;

                        if (map[i, j] == (int)Tiles.spawn)
                        {
                            spawnObject = tile;
                        }
                        if (map[i, j] == (int)Tiles.end)
                        {
                            endObject = tile;
                        }
                    }
                }
            }
            endPointNeighbours = new List <GameObject>();
            for (int i = endPoint.x - 10; i <= endPoint.x + 10; i++)
            {
                for (int j = endPoint.y - 10; j <= endPoint.y + 10; j++)
                {
                    if (i >= 0 && i < mapSize && j >= 0 && j < mapSize)
                    {
                        if (map[i, j] == (int)Tiles.border)
                        {
                            endPointNeighbours.Add(mapTiles[i, j]);
                        }
                    }
                }
            }
        }
    public void generateLevel(string seed)
    {
        // string seed = "112433abcc120b474d189a6979247624";

        Random.InitState(seed.GetHashCode());

        map = new GameObject[levelYSize, levelXSize];

        for (int ii = 0; ii < levelYSize; ii++)
        {
            int[] tilesLocationsCoordX = NumberSpread(Random.Range((int)(levelXSize * minRowFill), levelXSize), levelXSize);

            foreach (int locationX in tilesLocationsCoordX)
            {
                GameObject obj = Instantiate(levelObj, environment);
                obj.name               = "Tile " + locationX + ", " + ii;
                map[ii, locationX]     = obj;
                obj.transform.position = new Vector3(locationX * squaredOffset, 0, ii * squaredOffset);
                Tile tile = obj.GetComponent <Tile>();
                tile.Position = new Vector2Int(locationX, ii);
            }
        }

        for (int iii = 0; iii < smoothingPasses; iii++)
        {
            int c = 0;
            for (int i = 0; i < levelYSize; i++)
            {
                for (int ii = 0; ii < levelXSize; ii++)
                {
                    if (map[i, ii] == null)
                    {
                        continue;
                    }

                    int        totalNeighbouringTiles = 0;
                    Vector2Int pos = new Vector2Int(ii, i);

                    foreach (Vector2Int neighbourTile in neighbouringTiles)
                    {
                        Vector2Int checkPos = pos + neighbourTile;

                        if (checkPos.x < 0 || checkPos.y < 0 || checkPos.x >= levelXSize || checkPos.y >= levelYSize)
                        {
                            continue;
                        }

                        bool tileExists = map[checkPos.y, checkPos.x] != null;
                        totalNeighbouringTiles += tileExists  ? 1 : 0;
                        map[i, ii].GetComponent <Tile>().setDirectionTile(neighbourTile, tileExists);
                    }

                    if (totalNeighbouringTiles <= smoothIntensity)
                    {
                        c++;
                        Destroy(map[i, ii]);
                        map[i, ii] = null;
                    }
                }
            }
        }

        Vector3 max = Vector3.zero;
        Vector3 min = Vector3.zero;

        for (int i = 0; i < levelYSize; i++)
        {
            for (int ii = 0; ii < levelXSize; ii++)
            {
                GameObject obj = map[i, ii];
                if (obj != null)
                {
                    spawnLocations.Add(obj.transform.position + new Vector3(0, 5, 0));

                    if (Random.value > 1.0f - barrelSpawnProbability)
                    {
                        // Put a barrel in the middle of the tile.
                        GameObject barrel = Instantiate(sciFiBarrel, environment);
                        barrel.transform.position = new Vector3(obj.transform.position.x, -0.7f, obj.transform.position.z);
                        barrel.transform.Translate(Random.insideUnitCircle * squaredOffset * new Vector3(1, 0, 1));
                    }



                    if (obj.transform.position.z > max.z)
                    {
                        max.z = obj.transform.position.z;
                    }

                    if (obj.transform.position.z < min.z)
                    {
                        min.z = obj.transform.position.z;
                    }
                }
            }
        }

        Vector3 cameraMove = (max - min) / 2;

        mainCamera.transform.position = cameraMove - new Vector3(12.5F, -22, 0);
    }
Пример #53
0
 void Start()
 {
     grid = new GameObject[gridSize, gridSize];
 }
        void Start()
        {
            //1.起点
            //2.终点
            //3.障碍
            //4.道具(必走)

            //构建数字地图
            //通过代码生成,这里手动生成。
            //这里的11和6对应地图的宽度和高度
            numberMap = new int[11, 6]
            {
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 1, 0, 0 },
                { 0, 3, 4, 0, 3, 0 },
                { 0, 3, 0, 0, 3, 0 },
                { 0, 3, 3, 3, 3, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 2, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 }
            };

            int mapWidth  = 11;
            int mapHeight = 6;

            map = new GameObject[mapWidth, mapHeight];
            Transform mapBG = GameObject.Find("Map").transform;

            Color[] colors = new Color[5]
            {
                Color.white,
                Color.green,
                Color.red,
                Color.blue,
                Color.gray
            };

            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    GameObject temp = Instantiate(MapTiled, mapBG);
                    temp.transform.localPosition = new Vector3(i, j, 0);
                    temp.GetComponent <SpriteRenderer>().color = colors[numberMap[i, j]];
                    map[i, j] = temp;
                }
            }



            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    GameObject temp = Instantiate(MapTiled, mapBG);
                    temp.transform.localPosition = new Vector3(i, j, 0);
                    temp.GetComponent <SpriteRenderer>().color = colors[numberMap[i, j]];
                    map[i, j] = temp;
                }
            }


            BFSTest();
            DFSTest();
        }
Пример #55
0
    void CreateGrid()
    {
        positions = new Vector3[gridWidth, gridHeigth];
        testGrid  = new GameObject[gridWidth, gridHeigth];

        //CALCULATE CENTER OFFSET
        //float centerOffsetX = ((gridWidth * gridHeigth)/4 * tileWidth )/ 2;
        float centerOffsetX = 10;
        float centerOffsetY = 0;

        //CREATE GRID ITSELF
        for (int x = 0; x < gridWidth; x++)
        {
            for (int y = 0; y < gridHeigth; y++)
            {
                positions[x, y] = new Vector3(transform.position.x - centerOffsetX + (tileWidth * x) + (tileWidth * y), transform.position.y - centerOffsetY + (tileHeight * x) - (tileHeight * y), 0);
            }
        }

        //"REMOVE" CORNER POSITIONS
        rockFolder      = Instantiate(new GameObject(), transform.position, transform.rotation);
        rockFolder.name = "Rock Folder";
        if (roundCorners)
        {
            for (int i1 = 0; i1 < roundCornerBy; i1++)
            {
                for (int i2 = 0; i2 < roundCornerBy; i2++)
                {
                    if (!(i1 == i2 && i1 == roundCornerBy - 1) || (i1 == 0 && i2 == 0))
                    {
                        positions[i1, i2] = new Vector3(positions[i1, i2].x, positions[i1, i2].y, 2);
                        PlaceRockToPlace(positions[i1, i2], new Vector2(i1, i2));

                        positions[i1, positions.GetLength(1) - 1 - i2] = new Vector3(positions[i1, positions.GetLength(1) - 1 - i2].x, positions[i1, positions.GetLength(1) - 1 - i2].y, 2);
                        PlaceRockToPlace(positions[i1, positions.GetLength(1) - 1 - i2], new Vector2(i1, positions.GetLength(1) - 1 - i2));

                        positions[positions.GetLength(0) - 1 - i1, i2] = new Vector3(positions[positions.GetLength(0) - 1 - i1, i2].x, positions[positions.GetLength(0) - 1 - i1, i2].y, 2);
                        PlaceRockToPlace(positions[positions.GetLength(0) - 1 - i1, i2], new Vector2(positions.GetLength(0) - 1 - i1, i2));

                        positions[positions.GetLength(0) - 1 - i1, positions.GetLength(1) - 1 - i2] = new Vector3(positions[positions.GetLength(0) - 1 - i1, positions.GetLength(1) - 1 - i2].x, positions[positions.GetLength(0) - 1 - i1, positions.GetLength(1) - 1 - i2].y, 2);
                        PlaceRockToPlace(positions[positions.GetLength(0) - 1 - i1, positions.GetLength(1) - 1 - i2], new Vector2(positions.GetLength(0) - 1 - i1, positions.GetLength(1) - 1 - i2));
                    }
                }
            }
        }

        //CREATE TEST GRID
        testGridFolder      = Instantiate(new GameObject(), Vector3.zero, transform.rotation);
        testGridFolder.name = "Test Grid";

        for (int x = 0; x < gridWidth; x++)
        {
            for (int y = 0; y < gridHeigth; y++)
            {
                if (positions[x, y].z == 3)
                {
                    testGrid[x, y] = null;
                }
                else
                {
                    Vector3 newPos = new Vector3(positions[x, y].x, positions[x, y].y, transform.position.z);
                    testGrid[x, y] = Instantiate(emptyPre, newPos, Quaternion.identity);
                    testGrid[x, y].transform.parent = testGridFolder.transform;
                    testGrid[x, y].name             = x + " , " + y;
                    //testGrid[x, y].transform.localScale = new Vector3(tileWidth * 0.35f, (tileHeight * 2) * 0.35f, testGrid[x, y].transform.localScale.z);
                }
            }
        }

        //PLACE SURRONDING ROCKS
        //Place on top width alinged lines
        for (int rowNo = 0; rowNo < borderHeight; rowNo++)
        {
            for (int i = 0; i < gridWidth; i++)
            {
                if (!(positions[i, rowNo].z == 2))
                {
                    PlaceRockToPlace(new Vector3(positions[i, rowNo].x, positions[i, rowNo].y, transform.position.z), new Vector2(i, rowNo));
                }
            }
        }

        //Place on right height alinged lines
        for (int rowNo = 0; rowNo < borderWidth; rowNo++)
        {
            for (int i = 0; i < gridHeigth; i++)
            {
                if (!(positions[rowNo, i].z == 2))
                {
                    PlaceRockToPlace(new Vector3(positions[rowNo, i].x, positions[rowNo, i].y, transform.position.z), new Vector2(rowNo, i));
                }
            }
        }

        //Place on left height alinged lines
        for (int rowNo = gridWidth - 1; rowNo > (gridWidth - borderWidth - 1); rowNo--)
        {
            for (int i = 0; i < gridHeigth; i++)
            {
                if (!(positions[rowNo, i].z == 2))
                {
                    PlaceRockToPlace(new Vector3(positions[rowNo, i].x, positions[rowNo, i].y, transform.position.z), new Vector2(rowNo, i));
                }
            }
        }

        //Place on bottom width alinged lines
        for (int rowNo = gridHeigth - 1; rowNo > (gridHeigth - borderHeight - 1); rowNo--)
        {
            for (int i = 0; i < gridWidth; i++)
            {
                if (!(positions[i, rowNo].z == 2))
                {
                    PlaceRockToPlace(new Vector3(positions[i, rowNo].x, positions[i, rowNo].y, transform.position.z), new Vector2(i, rowNo));
                }
            }
        }
        List <Vector2> temp = new List <Vector2>()
        {
            new Vector2(gridWidth / 2, gridHeigth / 2), new Vector2(gridWidth / 2 + 1, gridHeigth / 2), new Vector2(gridWidth / 2, gridHeigth / 2 + 1), new Vector2(gridWidth / 2 + 1, gridHeigth / 2 + 1)
        };

        SpawnStructure(mysticPlace, temp, new Vector2(2, 2));

        SetTestGridActive(false);
        RandomGen();
        PlaceGrass();
        gridDone = true;
    }
Пример #56
0
 public GameObject(GameObject[,] map, Point location, bool isEnemy)
     : this(map, location, isEnemy, Textures.Floor)
 {
 }
Пример #57
0
 public void setGridArray(GameObject[,] gridarray)
 {
     gridArray = gridarray;
 }
Пример #58
0
 private void Draw(ref List <ItemObject> content, int height = 4, int width = 6)
 {
     Generator.GetComponent <Generator>().MenuOpened = true;
     Height = height; Width = width;
     Items  = new GameObject[Height, Width];
     for (int y = 0; y < Height; ++y)
     {
         for (int x = 0; x < Width; ++x)
         {
             int Xpos = 0, Ypos = 0;
             if (Width % 2 == 1)
             {
                 Xpos = 100 * (x - Width / 2);
             }
             else
             {
                 Xpos = 50 + 100 * (x - Width / 2);
             }
             if (Height % 2 == 1)
             {
                 Ypos = 100 * ((Height - y - 1) - Height / 2);
             }
             else
             {
                 Ypos = 50 + 100 * ((Height - y - 1) - Height / 2);
             }
             Items[y, x] = Instantiate(InventoryCellPrefab, transform.position, Quaternion.identity);
             Items[y, x].transform.SetParent(transform);
             Items[y, x].GetComponent <RectTransform>().anchoredPosition = new Vector2(Xpos, Ypos);
             Items[y, x].GetComponent <RectTransform>().localScale       = SampleB.GetComponent <RectTransform>().localScale;
             if (y == 0)
             {
                 if (x == 0)
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[0];
                 }
                 else if (x == Width - 1)
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[2];
                     GameObject CI = Instantiate(CloseInventory, transform.position, Quaternion.identity);
                     CI.transform.SetParent(Items[y, x].transform);
                     CI.GetComponent <RectTransform>().anchoredPosition = new Vector2(32F, 32F);
                     CI.GetComponent <RectTransform>().localScale       = SampleB.GetComponent <RectTransform>().localScale;
                     Generator.GetComponent <Generator>().SetCloseButton(CI);
                 }
                 else
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[1];
                 }
             }
             else if (y == Height - 1)
             {
                 if (x == 0)
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[6];
                 }
                 else if (x == Width - 1)
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[8];
                 }
                 else
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[7];
                 }
             }
             else
             {
                 if (x == 0)
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[3];
                 }
                 else if (x == Width - 1)
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[5];
                 }
                 else
                 {
                     Items[y, x].GetComponent <Image>().sprite = MenuCellSprite[4];
                 }
             }
         }
     }
     for (int i = 0; i < Mathf.Min(Width * Height, content.Count); ++i)
     {
         Items[i / Width, i % Width].GetComponent <InventoryCell>().Content = content[i];
     }
 }
Пример #59
0
    public void ActivateFrontierTiles(GameObject[,] referenceGrid, GameObject[,] attackGrid, int moveRange)//, int attackRange)
    {
        //if (attackRange < 1)
        //    return;

        List <GameObject> open   = new List <GameObject>();
        List <GameObject> closed = new List <GameObject>();

        //Range 1
        //check activated tiles
        for (var x = 0; x < gridSize; x++)
        {
            for (var y = 0; y < gridSize; y++)
            {
                if (referenceGrid[x, y].activeSelf)
                {
                    closed.Add(referenceGrid[x, y]);
                    for (var i = 0; i < 4; i++)
                    {
                        var neighbor = GetNeighbor(referenceGrid, referenceGrid[x, y], i);
                        if (neighbor == null)
                        {
                            continue;
                        }
                        var neighborPos = GetTilePosition(neighbor);
                        //if (neighborPos == null)
                        //    continue;

                        if (!neighbor.activeSelf && !attackGrid[neighborPos.x, neighborPos.y].activeSelf)
                        {
                            open.Add(ActivateTile(attackGrid[neighborPos.x, neighborPos.y]));
                        }
                    }
                }
            }
        }
        #region trash code

        /*
         * //Range > 1 --- Currently don't need that, doesn't work for range > 2 yet
         * if (attackRange>1)
         * {
         *  for (var r = 0; r < attackRange - 1; r++)
         *  {
         *      for (var x = 0; x < gridSize; x++)
         *      {
         *          for (var y = 0; y < gridSize; y++)
         *          {
         *              if (closed.Contains(attackGrid[x, y]))
         *                  continue;
         *              if (attackGrid[x, y].activeSelf && open.Contains(attackGrid[x, y]))
         *              {
         *                  closed.Add(attackGrid[x, y]);
         *                  open.Remove(attackGrid[x, y]);
         *                  for (var i = 0; i < 4; i++)
         *                  {
         *                      var neighbor = GetNeighbor(attackGrid, attackGrid[x, y], i);
         *                      if (neighbor == null)
         *                          continue;
         *                      var neighborPos = GetTilePosition(neighbor);
         *                      if (neighborPos == null)
         *                          continue;
         *                      if (!neighbor.activeSelf && !referenceGrid[neighborPos.x, neighborPos.y].activeSelf && !closed.Contains(attackGrid[neighborPos.x, neighborPos.y]))
         *                      {
         *                          ActivateTile(attackGrid[neighborPos.x, neighborPos.y]);
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *
         *      //foreach closed tile
         *      foreach (var t in closed)
         *      {
         *          if (open.Contains(t))
         *              continue;
         *
         *          for (var i = 0; i < 4; i++)
         *          {
         *              var neighbor = GetNeighbor(attackGrid, attackGrid[GetTilePosition(t).x, GetTilePosition(t).y], i);
         *              if (neighbor == null)
         *                  continue;
         *
         *              var neighborPos = GetTilePosition(neighbor);
         *              if (neighborPos == null)
         *                  continue;
         *
         *              //if neighbor is empty
         *              if (!neighbor.activeSelf)
         *              {
         *                  if (!referenceGrid[neighborPos.x, neighborPos.y].activeSelf)
         *                  {
         *                      //re add to open list
         *                      open.Add(t);
         *                      Debug.Log("added tile to open " + GetTilePosition(t).x + ", " + GetTilePosition(t).y);
         *                  }
         *              }
         *
         *          }
         *      }
         *
         *      foreach (var t in open)
         *      {
         *          if (closed.Contains(t))
         *              closed.Remove(t);
         *      }
         *  }
         * }*/
        #endregion
    }
 void Start()
 {
     tokens = new GameObject[numberOfGridColumns, numberOfGridRows];
 }