Beispiel #1
0
        public Level(int width, int height, List <Block> blocks, List <Block> topLayer, List <Block> bottomLayer, Position start, Position finish, Position secret, bool hasSecret, float scale, string name, int next, int snext, EnemyHandler e)
        {
            this.width       = width;
            this.height      = height;
            this.blocks      = blocks;
            this.physBlocks  = new List <Block>();
            this.topLayer    = topLayer;
            this.bottomLayer = bottomLayer;
            this.start       = start;
            this.finish      = finish;
            this.secret      = secret;
            this.hasSecret   = hasSecret;
            this.name        = name;
            this.next        = next;
            this.snext       = snext;
            BlockOffset      = new Vector2f(-0.5f, -0.5f);
            scale           *= 0.5f;
            this.scale       = scale;
            Global.Scale     = scale;
            enemies          = e;

            block               = new Texture("Content/block.png");
            block.Smooth        = true;
            blockSprite         = new Sprite();
            blockSprite.Texture = block;
            blockSprite.Scale   = new SFML.Window.Vector2f(scale, scale);

            coin               = new Texture("Content/Coin.png");
            coin.Smooth        = true;
            coinSprite         = new Sprite();
            coinSprite.Texture = coin;
            coinSprite.Scale   = new SFML.Window.Vector2f(scale * 0.5f, scale * 0.5f);

            ruby               = new Texture("Content/Ruby.png");
            ruby.Smooth        = true;
            rubySprite         = new Sprite();
            rubySprite.Texture = ruby;
            rubySprite.Scale   = new SFML.Window.Vector2f(scale * 0.5f, scale * 0.5f);

            sw    = new Stopwatch();
            Coins = new List <Coin>();
        }
Beispiel #2
0
        public static Level LoadLevel(string path, EnemyHandler e)
        {
            JSONDescription d     = JsonConvert.DeserializeObject <JSONDescription>(File.ReadAllText("Content/Levels/" + path + "level.json"));
            string          name  = d.Name;
            float           scale = Math.Min(Math.Max(d.Scale, 0.5f), 2.0f);
            Position        start = new Position()
            {
                X = d.Start.X, Y = d.Start.Y
            };
            Position finish = new Position()
            {
                X = d.Finish.X, Y = d.Finish.Y
            };
            Position secret = new Position()
            {
                X = d.SecretExit.X, Y = d.SecretExit.Y
            };
            bool hasSecret = d.HasSecretExit;
            int  next      = d.NextLevel;
            int  snext     = d.SecretNextLevel;

            List <Block> block = new List <Block>();
            List <Block> above = new List <Block>();
            List <Block> below = new List <Block>();

            Bitmap cmap = (Bitmap)Bitmap.FromFile("Content/Levels/" + path + "/" + d.CollisionMap);

            cmap.HandlePixels((x, y, color) =>
            {
                if (color.R == color.G && color.G == color.B && color.R == 0)
                {
                    block.Add(new Block()
                    {
                        Position = new Position()
                        {
                            X = x, Y = y
                        }, ID = GetBlockID(color)
                    });
                }
            });

            Level l = new Level(cmap.Width, cmap.Height, block, above, below, start, finish, secret, hasSecret, scale, name, next, snext, e);

            cmap.HandlePixels((x, y, color) =>
            {
                if (color.R == 255 && color.G == 255 && color.B == 0)
                {
                    l.AddCoin(x, y, false);
                }
                if (color.R == 0 && color.G == 255 && color.B == 255)
                {
                    l.AddCoin(x, y, true);
                }
                if (color.R == 0 && color.G == 255 && color.B == 0)
                {
                    l.SpawnEntity(new Position()
                    {
                        X = x, Y = y
                    });
                }
            });

            return(l);
        }