Exemplo n.º 1
0
        public bool GetSpriteAtLoc(string roomId, int x, int y, out BitsyGame.Sprite spr)
        {
            foreach (var s in this.Sprites.Values)
            {
                if (s.x == x && s.y == y && s.RoomId == roomId)
                {
                    spr = s;
                    return(true);
                }
            }

            spr = null;
            return(false);
        }
Exemplo n.º 2
0
        private void ParseSprite(TextReader reader, string header)
        {
            var sprite = new BitsyGame.Sprite()
            {
                Id    = GetLineArg(header, 1),
                Color = 2 //default palette color index is 2
            };

            string line;

            if (reader.Peek() >= 0 && ((char)reader.Peek()) == 'D')
            {
                sprite.DrawId = GetLineArg(reader.ReadLineSafe(), 1);
            }
            else
            {
                sprite.DrawId = "SPR_" + sprite.Id;
                this.ParseDrawingCore(reader, sprite.DrawId);
            }
            sprite.Anim.FrameCount = _environment.ImageStore[sprite.DrawId].frameCount;
            sprite.Anim.FrameIndex = 0;
            sprite.Anim.IsAnimated = sprite.Anim.FrameCount > 1;

            while (!string.IsNullOrEmpty(line = reader.ReadLineSafe()))
            {
                switch (GetLineArg(line, 0))
                {
                case "NAME":
                    sprite.Name = line.Substring(5);
                    break;

                case "COL":
                    sprite.Color = int.Parse(GetLineArg(line, 1));
                    break;

                case "POS":
                {
                    var args   = line.Split(' ');
                    var coords = args[2].Split(',');
                    this._spriteStartLocations[sprite.Id] = new BitsyGame.Loc()
                    {
                        Id = args[1],         //roomid
                        x  = int.Parse(coords[0]),
                        y  = int.Parse(coords[1])
                    };
                }
                break;

                case "DLG":
                    sprite.DialogId = GetLineArg(line, 1);
                    break;

                case "ITM":
                {
                    string item = GetLineArg(line, 1);
                    float  cnt  = float.Parse(GetLineArg(line, 2));
                    sprite.Inventory[item] = cnt;
                }
                break;
                }
            }

            if (string.IsNullOrEmpty(sprite.Id))
            {
                return;
            }
            _environment.Sprites[sprite.Id] = sprite;
            if (!string.IsNullOrEmpty(sprite.Name))
            {
                _environment.Names.sprites[sprite.Name] = sprite.Id;
            }
        }