public void Load(LevelDef def)
        {
            if (IsLoaded)
            {
                Debug.LogError("trying to load again.");
                return;
            }

            _levelDef          = def;
            _map               = MapGenerator.Generate(def);
            _starsLeft         = new HashSet <Star>(_map.Stars);
            Star.OnGetStar    += OnGetStar;
            _getStarRegistered = true;

            _ball = MapFactory.InstantiateBall(_map.StartPoisition);
            _ball.transform.SetParent(transform, false);
            var ballController = _ball.gameObject.AddComponent <BallController>();

            ballController.Ball = _ball;
        }
Ejemplo n.º 2
0
        public void Load(TiledSharp.Map map)
        {
            foreach (var tile in map.Layers[0].Tiles)
            {
                var        coor = new Coor(tile.X, MapHeight - tile.Y);
                GameObject go   = null;

                switch (tile.Gid)
                {
                case StartGid:
                    StartPoisition = coor;
                    break;

                case StarGid:
                {
                    var star = MapFactory.InstantiateStar(coor);
                    Stars.Add(star);
                    go = star.gameObject;
                    break;
                }

                default:
                {
                    var gid = MapHelper.MapGidToBlockType(tile.Gid);
                    if (gid.HasValue)
                    {
                        var block = MapFactory.Instantiate(gid.Value, coor);
                        go = block.gameObject;
                    }
                    break;
                }
                }

                if (go != null)
                {
                    go.transform.SetParent(transform, false);
                }
            }
        }