Ejemplo n.º 1
0
 public ObjectAnimation GetAnimation(int i)
 {
     try {
         return(_animations[i]);
     }
     catch (KeyNotFoundException) {
         var anim = new ObjectAnimation(this, i);
         _animations[i] = anim;
         return(anim);
     }
 }
Ejemplo n.º 2
0
        public ObjectAnimationFrame(ObjectAnimation anim, Data animData)
        {
            _animation = anim;
            _animData  = animData;

            Color[][] palettes = anim.GetPalettes();

            try {
                // Note: this "index" is more like index*2, since it's added directly to the offset
                // without being multiplied first
                int oamIndex = (byte)_animData.NextData.GetIntValue(0);

                // Get entry in oam table for this object
                Data oamPtr = Project.GetData(_animation.OamTableName, oamIndex);
                _oamData = Project.GetData(oamPtr.GetValue(0));

                // Load sprite images
                int  _numSprites = _oamData.GetIntValue(0);
                Data data        = _oamData.NextData;

                for (int i = 0; i < _numSprites; i++)
                {
                    int y = (sbyte)data.GetIntValue(0) - 16;
                    data = data.NextData;
                    int x = (sbyte)data.GetIntValue(0) - 8;
                    data = data.NextData;
                    int tileIndex = data.GetIntValue(0) + _animation.TileIndexBase;
                    data = data.NextData;
                    byte flags = (byte)(data.GetIntValue(0) | _animation.OamFlagsBase);
                    data = data.NextData;

                    ObjectGfxHeaderData gfxHeader = _animation.ObjectGfxHeaderData;
                    int origTileIndex             = tileIndex;

                    while (tileIndex >= 0x20)
                    {
                        if (gfxHeader.ShouldHaveNext)
                        {
                            gfxHeader  = gfxHeader.NextGfxHeader;
                            tileIndex -= 0x20;
                        }
                        else
                        {
                            throw new InvalidAnimationException("Tileindex out of range (" + tileIndex + ")");
                        }
                    }

                    int    tileOffset = (tileIndex & 0xfe) * 16;
                    Stream gfxStream  = gfxHeader.GfxStream;

                    if (gfxStream.Length - tileOffset < 0x20)
                    {
                        throw new InvalidAnimationException("Sprite not defined in gfx data");
                    }

                    gfxStream.Seek(tileOffset, SeekOrigin.Begin);
                    byte[] gfxData = new byte[0x20];
                    gfxStream.Read(gfxData, 0, 0x20);

                    Bitmap bitmap = GbGraphics.TileToBitmap(gfxData, palettes[flags & 7], flags);
                    bitmaps.Add(new Tuple <Bitmap, int, int>(bitmap, x, y));
                }
            }
            catch (InvalidLookupException e) {
                bitmaps = null;
                throw new InvalidAnimationException(e);
            }
            catch (FormatException e) {
                bitmaps = null;
                throw new InvalidAnimationException(e);
            }
        }