GameTiles class for creating game tile objects (in menus etc.)
Наследование: MonoBehaviour
Пример #1
0
    private void GenerateWorld(bool useRSeed)
    {
        if (useRSeed)
        {
            seed = System.DateTime.Now.ToString();
        }

        GameTiles.BuildTilesDict(groundTilemap);


        Random.InitState(seed.GetHashCode());

        var env = ScriptableObject.CreateInstance <EnvironmentBuilder>();

        env.wallObject = wallObject;
        env.numWalls   = numWalls;
        env.SpawnWalls();

        var spawner = ScriptableObject.CreateInstance <Spawner>();

        spawner.playerObject = playerObject;
        spawner.enemyObject  = enemyObject;
        spawner.numEnemies   = numEnemies;
        spawner.SpawnPlayer();
        spawner.SpawnEnemies();
        PathGrid.BuildGrid();
    }
Пример #2
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Пример #3
0
 private void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
     GetWorldTiles();
 }
Пример #4
0
	private void Awake() 
	{
		if (instance == null) 
		{
			instance = this;
		}
		else if (instance != this)
		{
			Destroy(gameObject);
		}
        
		Invoke("GetWorldTiles", 0.1f);
	}
Пример #5
0
 private void Awake()
 {
     buildingTilemap = this.gameObject.GetComponent <Tilemap>();
     if (instance == null)
     {
         instance = this;
     }
     // else if (instance != this)
     // {
     //     Destroy(gameObject);
     // }
     GetWorldTiles();
 }
Пример #6
0
 /// <summary>
 /// this will draw the board on the bitmap
 /// </summary>
 /// <returns></returns>
 public Bitmap DrawTileBoard()
 {
     // using a simple way to draw the board
     for (int i = 0; i < GameTiles.GetLength(0); i++)
     {
         for (int j = 0; j < GameTiles.GetLength(1); j++)
         {
             //using Graphics for the buffer
             using (Graphics graphics = Graphics.FromImage(_buffer))
             {
                 //if the gameTile[i,j] is not null
                 if (!(GameTiles[i, j].SpriteObject is null))
                 {
                     graphics.DrawImage(GameTiles[i, j].SpriteObject.SpriteImage, i * _BoardSize, j * _BoardSize, _BoardSize, _BoardSize);
                 }
Пример #7
0
    private void InitializeTileMap()
    {
        var obstacles    = new Dictionary <Vector2Int, Obstacle>();
        var allObstacles = GetComponentsInChildren <Obstacle>();

        foreach (var obstacle in allObstacles)
        {
            if (obstacle.initializeSelf)
            {
                continue;
            }

            var position = Vector2Int.FloorToInt(obstacle.transform.position);
            if (!obstacles.ContainsKey(position))
            {
                obstacles.Add(position, obstacle);
            }
            else
            {
                Debug.LogError(
                    $"Obstacle {obstacle.name} cannot be placed on position {position}! This position already contains an obstacle!");
            }
        }

        gameTiles = new GameTiles();
        var allTiles = GetComponentsInChildren <GameTile>();

        foreach (var tile in allTiles)
        {
            var position = Vector2Int.FloorToInt(tile.transform.position);
            gameTiles.Add(position, tile);
            if (obstacles.ContainsKey(position))
            {
                tile.AddObstacle(obstacles[position]);
            }
        }

        tileMapInitialized = true;
        tileMapObservers.ForEach(o => o?.NotifyBegin());
    }