Пример #1
0
        /// <summary>
        /// Takes the tile numbers from the array and renders the tiles.
        /// </summary>
        /// <returns>The tile list.</returns>
        /// <param name="levelimporter">Levelimporter.</param>
        public List<AnimationSprite> GetTiles(LevelImporter levelimporter, Player player)
        {
            tiles = new List<AnimationSprite> ();
            game.Add (this);

            //Tile render
            int y = 0;
            Console.WriteLine ("Loading Level");
            //Go trough the lines
            foreach (string s in levelimporter.GetLevel()) {
                int[] csvArray = s.Split (',').Select (int.Parse).ToArray ();
                int x = 0;

                //Go trought the cells
                foreach (int i in csvArray) {
                    Tile tile = new Tile ("Sprites/tiles.png", 2, 3);
                    if (i == 0) {
                        tile.visible = false;

                    }

                    if (i == 1) {
                        //make a coin
                        Coin coin = new Coin ();
                        coin.x = x;
                        coin.y = y;
                        this.AddChild (coin);
                        tile.visible = false;
                    } else if (i == 5) {
                        //Spawn player here
                        player.x = x;
                        player.y = y - 8;
                        tile.SetFrame (i - 1);
                        tile.y = y;
                        tile.x = x;
                    } else {
                        //set the tile to the correct frame
                        tile.SetFrame (i - 1);
                        tile.y = y;
                        tile.x = x;
                        tile.SetColor (1, 1, 1);
                    }

                    //render the tile
                    this.AddChild (tile);
                    tiles.Add (tile);

                    x += 16;
                }
                y += 16;
            }
            return tiles;
        }
Пример #2
0
        public Level(int level, int lives = 3)
            : base()
        {
            game.Add (this);
            _currentLevel = level;

            //set the background color
            Canvas canvas = new Canvas (game.width, game.height);
            canvas.graphics.FillRectangle (new SolidBrush (Color.FromArgb (125, 106, 148)), new Rectangle (0, 0, game.width, game.height));
            AddChild (canvas);

            //level lister to get the level names
            _levelList = new LevelLister ();

            //import the selected level
            _levelImporter = new LevelImporter (level);
            this.AddChild (_levelImporter);

            //create the player
            _player = new Player (lives);

            //render the tiles of the selected level
            _tileRenderer = new TileRenderer ();
            this.AddChild (_tileRenderer);
            _tileRenderer.GetTiles (_levelImporter, _player);
            Console.WriteLine ("Level Loaded");

            //add the player to the level
            this.AddChild (_player);
            Console.WriteLine ("Player Loaded");

            //add the scoreboard
            _hud = new HUD ();
            this.AddChild (_hud);
            Console.WriteLine ("HUD loaded");
        }