Beispiel #1
0
        public AnimationSource(MekaItem _item)
        {
            if (_item.Contains("Sprites"))
            {
                foreach (MekaItem frame in _item["Sprites"].Children)
                {
                    this.Sprites.Add(GameBase.LoadImageSource(frame.Data));
                    this.Offsets.Add(frame.Contains("Offset") ? frame["Offset"].To <Vector>() : 0);
                }
            }
            else
            {
                ImageSource src = GameBase.LoadImageSource(_item["Spriteset"].Children[0].Data);
                this.Sprites.Add(src.Split(_item["Spriteset"]["Count"].To <int>()));
                for (int i = 0; i < this.Sprites.Count; i++)
                {
                    this.Offsets.Add(0);
                }
            }

            if (_item.Contains("Offset"))
            {
                Vector offset = _item["Offset"].To <Vector>();
                for (int i = 0; i < this.Sprites.Count; i++)
                {
                    this.Offsets[i] = offset;
                }
            }

            this.Speed    = _item["Speed"].To <int>();
            this.Repeated = _item.Contains("Repeated");
        }
Beispiel #2
0
        public PixelFont(string _path)
        {
            MekaItem file = MekaItem.LoadFromFile(_path);

            MekaItem chars = file["Characters"].Children[0];

            ImageSource src = new ImageSource(chars.Data);

            ImageSource[,] cs = src.Split(chars["Count"].To <Point>());

            foreach (ImageSource c in cs)
            {
                for (int x = 0; x < c.Width; x++)
                {
                    for (int y = 0; y < c.Height; y++)
                    {
                        if (c[x, y].A > 0 && c[x, y] != Color.White)
                        {
                            c[x, y] = Color.White;
                        }
                    }
                }
            }

            {
                int y = 0;
                foreach (MekaItem line in file["Characters"].Children.Where(item => item.Name == "Line"))
                {
                    for (int x = 0; x < line.Content.Length; x++)
                    {
                        this.Chars[line.Content[x]] = cs[x, y];
                    }
                    y++;
                }
            }

            if (file.Contains("Character Size"))
            {
                this.CharSize = file["Character Size"].To <Point>();
            }
            else
            {
                this.CharSize = this.Chars.ToArray()[0].Value.Size;
            }

            if (file.Contains("Default"))
            {
                this._DefaultChar = file["Default"].Content[0];
            }
        }
Beispiel #3
0
        public Areaset(MekaItem _file, Point _tilesize, Point _tilecollisionresolution)
        {
            if (_file["Info"]["Tilesize"].To <Point>() != _tilesize || _file["Info"]["Colsize"].To <Point>() != _tilecollisionresolution)
            {
                throw new Exception("Tilesize and/or Colsize don't match up with this game's.");
            }

            ImageSource tileset = GameBase.LoadImageSource(_file["Tileset"].Data);

            ImageSource[,] tiles = tileset.Split(tileset.Size / _tilesize);
            ImageSource colset = GameBase.LoadImageSource(_file["Colset"].Data);

            int pixelcount = Meth.Up(_tilecollisionresolution.X * _tilecollisionresolution.Y / 4.0);

            this.Size = new Point(tiles.GetLength(0), tiles.GetLength(1));

            for (int y = 0; y < this.Size.Y; y++)
            {
                for (int x = 0; x < this.Size.X; x++)
                {
                    this.Tiles.Add(tiles[x, y]);

                    Bunch <Color> cs = new Bunch <Color>();
                    for (int i = 0; i < pixelcount; i++)
                    {
                        cs.Add(colset[x * pixelcount + i, y]);
                    }

                    Bunch <byte> bs = new Bunch <byte>();
                    foreach (Color c in cs)
                    {
                        bs.Add(c.Bytes);
                    }

                    bs           = bs.SubBunch(0, _tilecollisionresolution.X * _tilecollisionresolution.Y);
                    bool[,] cols = new bool[_tilecollisionresolution.X, _tilecollisionresolution.Y];
                    for (int i = 0; i < bs.Count; i++)
                    {
                        cols[i % _tilecollisionresolution.X, Meth.Down(i / _tilecollisionresolution.X)] = bs[i] == 1;
                    }
                    this.Cols.Add(cols);
                }
            }
        }