Ejemplo n.º 1
0
        private void StartLevel()
        {
            var generator = GameObj.ParentScene.FindComponent <MapGenerator> ();

            generator.GenerateMap(prefs.Map);

            var emptyTiles = generator.GeneratedMap.TilesOfType(TileType.Empty).ToList();

            var playerStartPos = generator.GeneratedMap.TilesOfType(TileType.Empty).First();

            emptyTiles.Remove(playerStartPos);
            GameObj.ParentScene.FindGameObject <PlayerMovement> ().GetComponent <DiscreteTransform> ().MoveTo(playerStartPos);
            SceneCache.Get <TilemapController> ().SetupTilemap(prefs.Map);

            InstantiatePrefabs(emptyTiles);
        }
Ejemplo n.º 2
0
        public void UpdateTilemap()
        {
            var tileGrid = tilemap.BeginUpdateTiles();

            var generatedMap = SceneCache.Get <MapGenerator> ().GeneratedMap;

            var playerPos    = SceneCache.Player.GetComponent <DiscreteTransform> ().Position;
            var halfRectSide = MapExtensions.MaxVisibilityDst;

            var xMin = Math.Max(0, playerPos.X - halfRectSide);
            var yMin = Math.Max(0, playerPos.Y - halfRectSide);
            var xMax = Math.Min(playerPos.X + halfRectSide, generatedMap.Width - 1);
            var yMax = Math.Min(playerPos.Y + halfRectSide, generatedMap.Height - 1);

            for (var y = yMin; y <= yMax; y++)
            {
                for (var x = xMin; x <= xMax; x++)
                {
                    if (generatedMap.IsVisible(playerPos, new Point2(x, y)))
                    {
                        var tileIndex = 0;
                        if (generatedMap[x, y] == TileType.Empty)
                        {
                            tileIndex = EmptyTileIndex;
                        }
                        else
                        {
                            if (x % 2 == 0)
                            {
                                tileIndex++;
                            }
                            if (y % 2 == 0)
                            {
                                tileIndex += 2;
                            }
                        }
                        tileGrid[x, y] = new Tile(tileIndex);
                    }
                }
            }

            tilemap.EndUpdateTiles();
        }
Ejemplo n.º 3
0
 protected override void OnGameStarting()
 {
     SceneCache.AttachToSceneEntered();
     PrefLoader.LoadYamlDocument();
     AudioPlayer.PlayMusic();
 }
Ejemplo n.º 4
0
 protected override void OnGameEnded()
 {
     SceneCache.DetachFromSceneEntered();
 }