コード例 #1
0
        private int[] CalcMask(Sprite s, out int width, out int height)
        {
            width = 0;
            height = 0;
            if (s == null)
                return null;
            // Calc # of int32s required.
            int xsize = ((s.PixelWidth + MaskWordWidth-1) / MaskWordWidth);
            int ysize = s.PixelHeight;
            int size = xsize * ysize;
            int[] mask = new int[size];

            for (int y = 0; y < ysize; y++)
            {
                for (int x = 0; x < xsize; x++)
                {
                    int index = y * xsize + x;
                    mask[index] = 0;
                    for (int i = 0; i < MaskWordWidth; i++)
                    {
                        mask[index] <<= 1;
                        if (x * MaskWordWidth + i < s.PixelWidth)
                        {
                            if (s.GetPixel(x * MaskWordWidth + i, y) != 0)
                                mask[index] |= 1;
                        }
                    }
                }
            }
            width = xsize;
            height = ysize;
            return mask;
        }
コード例 #2
0
ファイル: MapForm.cs プロジェクト: jduranmaster/spritely
        public MapForm(ProjectMainForm parent, Map m, Spriteset ss, Sprite s)
        {
            m_parent = parent;

            m_ss = ss;

            InitializeComponent();

            SetMap(m);
            m_toolbox = new Toolbox_Map();
            m_optionbox = new Optionbox_Map();

            MdiParent = parent;
            FormBorderStyle = FormBorderStyle.SizableToolWindow;
            StartPosition = FormStartPosition.Manual;
            Visible = false;
            ControlBox = false;

            // Set to 16x.
            cbZoom.SelectedIndex = (int)ZoomLevel.Zoom_16x;
            cbZoom.Enabled = false;

            m_tileSpriteX = -1;
            m_tileSpriteY = -1;
        }
コード例 #3
0
 private void bNext_Click(object sender, EventArgs e)
 {
     Sprite s = m_ss.NextSprite(m_sprite);
     if (s != null)
     {
         m_sprite = s;
         UpdateSpriteInfo();
     }
 }
コード例 #4
0
ファイル: Tile.cs プロジェクト: jduranmaster/spritely
        public Tile(Sprite s, int nTileId)
        {
            m_sprite = s;
            m_id = nTileId;
            m_data = new UndoData(TileSize);

            // This will be assigned when the spriteset is saved or exported.
            m_nExportId = 0;
        }
コード例 #5
0
        public UndoAction_AddSprite(UndoMgr mgr, Spriteset ss, Sprite sprite, bool fAdd)
        {
            m_mgr = mgr;
            m_ss = ss;
            m_sprite = sprite;
            m_fAdd = fAdd;

            Description = (fAdd ? "AddSprite " : "RemoveSprite ") + sprite.Name;
        }
コード例 #6
0
        public SpriteProperties(Document doc, Spriteset ss)
        {
            InitializeComponent();

            m_doc = doc;
            m_ss = ss;
            m_sprite = m_ss.CurrentSprite;

            UpdateSpriteInfo();
        }
コード例 #7
0
ファイル: SpriteType.cs プロジェクト: jduranmaster/spritely
 public SpriteType(string strName, int nWidth, int nHeight, Sprite.GBASize size, Sprite.GBAShape shape)
 {
     Name = strName;
     Width = nWidth;
     Height = nHeight;
     Size = size;
     Shape = shape;
     Sprites = new List<Sprite>();
     ScrollHeight = 0;
     FirstLine = 0;
 }
コード例 #8
0
        public UndoAction_SpriteEdit(UndoMgr mgr, Spriteset ss, Sprite sprite, Sprite.UndoData before, Sprite.UndoData after, string strDesc)
        {
            m_mgr = mgr;
            m_ss = ss;
            m_sprite = sprite;
            m_before = new Sprite.UndoData(before);
            m_after = new Sprite.UndoData(after);

            Description = "SpriteEdit " + sprite.Name + " " + strDesc;
            if (IsPaletteChange())
                Description += " " + before.subpalette + " to " + after.subpalette;
        }
コード例 #9
0
        public CollisionTest(Document d)
        {
            m_doc = d;

            InitializeComponent();

            xOffset = 0;
            yOffset = 0;

            ss = d.Owner.ActiveSpriteset();

            s1 = ss.CurrentSprite;
            s2 = ss.NextSprite(s1);

            mask1 = CalcMask(s1, out mask1w, out mask1h);
            mask2 = CalcMask(s2, out mask2w, out mask2h);

            CollisionCheck();
        }
コード例 #10
0
ファイル: MapForm.cs プロジェクト: jduranmaster/spritely
        private void FloodFill_CheckTile(int x, int y, Sprite spriteOld, int subpaletteOld)
        {
            if (x >= 0 && x < m_map.Width
                && y >= 0 && y < m_map.Height)
            {
                int tile, subpalette;
                m_map.GetTile(x, y, out tile, out subpalette);
                Sprite sprite = m_ss.FindSprite(tile);

                if (sprite == spriteOld && subpalette == subpaletteOld)
                {
                    TileCoord t = new TileCoord(x, y);
                    if (!m_tilesDone.ContainsKey(t))
                    {
                        m_stackTiles.Push(t);
                        m_tilesDone.Add(t, true);
                    }
                }
            }
        }
コード例 #11
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
 // Is this the last sprite in the SpriteList?
 public bool IsLastSprite(Sprite sBase)
 {
     bool fIsLast = false;
     foreach (SpriteType st in SpriteTypes)
     {
         foreach (Sprite s in st.Sprites)
         {
             fIsLast = (s == sBase);
         }
     }
     return fIsLast;
 }
コード例 #12
0
ファイル: Tile.cs プロジェクト: jduranmaster/spritely
        public void Duplicate(Tile tileToCopy)
        {
            CopyData(tileToCopy);

            m_sprite = tileToCopy.m_sprite;
        }
コード例 #13
0
ファイル: Map.cs プロジェクト: jduranmaster/spritely
 /// <summary>
 /// Replace all occurences of this sprite in the background map with the
 /// default sprite.
 /// </summary>
 /// <param name="s"></param>
 public void RemoveSpriteTilesFromMap(Sprite sToRemove)
 {
     for (int ix = 0; ix < kMaxMapTilesX; ix++)
     {
         for (int iy = 0; iy < kMaxMapTilesY; iy++)
         {
             int nTile = m_BackgroundMap[ix, iy].nTileIndex;
             int nSpriteTile1 = sToRemove.FirstTileId;
             int nSpriteTileN = sToRemove.FirstTileId + sToRemove.NumTiles-1;
             if (nTile >= nSpriteTile1 && nTile <= nSpriteTileN)
                 m_BackgroundMap[ix, iy].nTileIndex = -1;
         }
     }
 }
コード例 #14
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
 // Remove from the old SpriteType and add it to the new one
 public void MoveToCorrectSpriteType(Sprite sprite)
 {
     SpriteType stRemove = null;
     SpriteType stAdd = null;
     foreach (SpriteType st in SpriteTypes)
     {
         if (st.Sprites.Contains(sprite))
             stRemove = st;
         if (st.Width == sprite.TileWidth && st.Height == sprite.TileHeight)
             stAdd = st;
     }
     if (stRemove != stAdd)
     {
         if (stRemove != null)
             stRemove.Sprites.Remove(sprite);
         if (stAdd != null)
             stAdd.Sprites.Add(sprite);
         m_doc.Owner.HandleSpriteTypeChanged(this);
     }
 }
コード例 #15
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
 // Return the next sprite after the given sprite in the SpriteList.
 // Returns null if the given sprite is the last one, or if the given sprite doesn't exist.
 public Sprite NextSprite(Sprite sBase)
 {
     bool fReturnNextSprite = false;
     foreach (SpriteType st in SpriteTypes)
     {
         foreach (Sprite s in st.Sprites)
         {
             if (fReturnNextSprite)
                 return s;
             if (s == sBase)
                 fReturnNextSprite = true;
         }
     }
     return null;
 }
コード例 #16
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
        // Return true if successfully rotated.
        public bool RotateSelectedSprite(Sprite.RotateDirection dir)
        {
            Sprite sToRotate = CurrentSprite;
            if (sToRotate == null)
                return false;

            int tileNewWidth = sToRotate.TileHeight;
            int tileNewHeight = sToRotate.TileWidth;

            if (!sToRotate.Rotate(dir))
                return false;

            MoveToCorrectSpriteType(sToRotate);
            return true;
        }
コード例 #17
0
 /// <summary>
 /// Draw a sample sprite for use in the tutorials.
 /// </summary>
 /// <param name="s"></param>
 private void DrawSample4x1Sprite(Sprite s, int id)
 {
     if (id == 1)
         DrawSampleSprite(s, 32, 8, m_Bat1);
     else
         DrawSampleSprite(s, 32, 8, m_Bat0);
 }
コード例 #18
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
 // Return the previous sprite before the given sprite in the SpriteList.
 // Returns null if the given sprite is the first one, or if the given sprite doesn't exist.
 public Sprite PrevSprite(Sprite sBase)
 {
     Sprite sPrev = null;
     foreach (SpriteType st in SpriteTypes)
     {
         foreach (Sprite s in st.Sprites)
         {
             if (s == sBase)
                 return sPrev;
             sPrev = s;
         }
     }
     return null;
 }
コード例 #19
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
 // Is this the first sprite in the SpriteList?
 public bool IsFirstSprite(Sprite sBase)
 {
     foreach (SpriteType st in SpriteTypes)
     {
         foreach (Sprite s in st.Sprites)
         {
             return s == sBase;
         }
     }
     return false;
 }
コード例 #20
0
ファイル: Sprite.cs プロジェクト: jduranmaster/spritely
        /// <summary>
        /// Copy the tile data from the specified sprite
        /// </summary>
        /// <param name="sToCopy">Sprite to copy</param>
        public void CopyData(Sprite sToCopy)
        {
            // Make sure that the sprites have the same dimensions
            if (TileWidth != sToCopy.TileWidth || TileHeight != sToCopy.TileHeight)
                return;

            // Copy over the tile data
            for (int i = 0; i < NumTiles; i++)
                m_Tiles[i].CopyData(sToCopy.m_Tiles[i]);
        }
コード例 #21
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
        private Sprite AddSprite_2(Sprite s, List<Sprite> slist, UndoMgr undo)
        {
            slist.Add(s);

            m_nSprites++;
            m_nTiles += (s.TileWidth * s.TileHeight);

            if (undo != null)
                undo.Push(new UndoAction_AddSprite(undo, this, s, true));

            if (m_doc.Owner != null)
                m_doc.Owner.HandleSpriteTypeChanged(this);
            return s;
        }
コード例 #22
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
        private Sprite AddSprite_(int nWidth, int nHeight, string strName, int id, string strDesc, int nSubpalette, UndoMgr undo)
        {
            List<Sprite> slist = null;

            // Make sure that the requested size is valid.
            foreach (SpriteType st in SpriteTypes)
            {
                if (st.Width == nWidth && st.Height == nHeight)
                    slist = st.Sprites;
            }

            // Invalid sprite size - return.
            if (slist == null)
                return null;

            Sprite s = new Sprite(m_doc, this, nWidth, nHeight, strName, id, strDesc, nSubpalette);
            return AddSprite_2(s, slist, undo);
        }
コード例 #23
0
ファイル: MapForm.cs プロジェクト: jduranmaster/spritely
        private bool FloodFill_Sprite(int nMapX, int nMapY,
            Sprite spriteOld, int subpaletteOld,
            Sprite spriteNew, int tileNew, int subpaletteNew)
        {
            int spriteWidth = spriteNew == null ? 1 : spriteNew.TileWidth;
            int spriteHeight = spriteNew == null ? 1 : spriteNew.TileHeight;

            // Stack of tiles to process.
            m_stackTiles = new Stack<TileCoord>();
            m_tilesDone = new Dictionary<TileCoord, bool>();

            TileCoord t = new TileCoord(nMapX, nMapY);
            m_stackTiles.Push(t);
            m_tilesDone.Add(t, true);

            // Adjust the mapclick origin off the map (negative) so that all of our
            // offset calculations are guaranteed to be positive.
            while (nMapX > 0)
                nMapX -= spriteWidth;
            while (nMapY > 0)
                nMapY -= spriteHeight;

            while (m_stackTiles.Count != 0)
            {
                t = m_stackTiles.Pop();

                // Calc tile within sprite that we're painting:
                //
                //  Current sprite:   abcd
                //                    efgh
                //
                //  Original:    Click:       After:
                //  ___...___    ___...___    ___efg___
                //  __.....__    __.x...__    __dabcd__
                //  __...____    __...____    __hef____
                //  ____.____    ____.____    ____b____
                //
                //  '.' marks the map coords that belong to the same sprite
                //    (regardless of the particular tile within the sprite).
                int dx = (t.X - nMapX) % spriteWidth;
                int dy = (t.Y - nMapY) % spriteHeight;
                int tile = tileNew + dx + dy * spriteWidth;

                m_map.SetTile(t.X, t.Y, tile, subpaletteNew);

                FloodFill_CheckTile(t.X - 1, t.Y, spriteOld, subpaletteOld);
                FloodFill_CheckTile(t.X + 1, t.Y, spriteOld, subpaletteOld);
                FloodFill_CheckTile(t.X, t.Y - 1, spriteOld, subpaletteOld);
                FloodFill_CheckTile(t.X, t.Y + 1, spriteOld, subpaletteOld);
            }

            m_stackTiles = null;
            m_tilesDone = null;
            return true;
        }
コード例 #24
0
 private void DrawSampleSprite(Sprite s, int width, int height, int[,] data)
 {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             s.SetPixel(x, y, data[y, x]);
         }
     }
 }
コード例 #25
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
        /// <summary>
        /// Is this sprite the first/last one in the group of SpriteTypes
        /// </summary>
        /// <param name="sprite">The sprite to check</param>
        /// <param name="fIsFirst">Returns true if this is the first sprite</param>
        /// <param name="fIsLast">Returns true if this is the last sprite</param>
        public void IsFirstLastSpriteOfType(Sprite sprite, out bool fIsFirst, out bool fIsLast)
        {
            fIsFirst = false;
            fIsLast = false;

            foreach (SpriteType st in SpriteTypes)
            {
                if (st.Sprites.Contains(sprite))
                {
                    bool fFirst = true;
                    bool fLast = false;
                    foreach (Sprite s in st.Sprites)
                    {
                        if (s == sprite)
                        {
                            if (fFirst)
                                fIsFirst = true;
                            fLast = true;
                        }
                        else
                            fLast = false;
                        fFirst = false;
                    }
                    if (fLast)
                        fIsLast = true;
                    return;
                }
            }
        }
コード例 #26
0
ファイル: Spriteset.cs プロジェクト: jduranmaster/spritely
        public void RemoveSprite(Sprite sToRemove, UndoMgr undo)
        {
            SpriteType stToRemove = null;
            Sprite sPrev = null, sCurr = null, sNext = null;
            Sprite sNewSelection = null;

            if (sToRemove == null)
                return;

            // Determine which sprite should be selected when this one is removed.
            foreach (SpriteType st in SpriteTypes)
            {
                if (sNewSelection != null)
                    break;

                foreach (Sprite s in st.Sprites)
                {
                    sPrev = sCurr;
                    sCurr = sNext;
                    sNext = s;
                    if (s == sToRemove)
                        stToRemove = st;
                    if (sCurr == sToRemove)
                    {
                        sNewSelection = sNext;
                        break;
                    }
                }
            }
            // If the last sprite is deleted, select the one before it.
            if (sNext == sToRemove)
                sNewSelection = sCurr;

            int nTiles = sToRemove.NumTiles;
            if (stToRemove == null)
                return;

            if (stToRemove.Sprites.Remove(sToRemove))
            {
                CurrentSprite = null;
                if (undo != null)
                    CurrentSprite = undo.FindMostRecentSprite();
                if (CurrentSprite == null)
                    CurrentSprite = sNewSelection;

                m_nSprites--;
                m_nTiles -= nTiles;

                if (undo != null)
                    undo.Push(new UndoAction_AddSprite(undo, this, sToRemove, false));

                if (m_doc.Owner != null)
                    m_doc.Owner.HandleSpriteTypeChanged(this);
            }

            foreach (Map m in m_Maps)
            {
                m.RemoveSpriteTilesFromMap(sToRemove);
            }
        }
コード例 #27
0
ファイル: Sprite.cs プロジェクト: jduranmaster/spritely
 public void Duplicate(Sprite sToCopy)
 {
     CopyData(sToCopy);
     SubpaletteID = sToCopy.SubpaletteID;
 }
コード例 #28
0
 /// <summary>
 /// Draw a sample sprite for use in the tutorials.
 /// </summary>
 /// <param name="s"></param>
 private void DrawSample1x1Sprite(Sprite s, int id)
 {
     DrawSampleSprite(s, 8, 8, m_Ball);
 }
コード例 #29
0
        private bool LoadXML_OLD_sprite(Sprite s, XmlNodeList xnl)
        {
            int nNumTiles = s.NumTiles;
            int nTileIndex = 0;

            foreach (XmlNode xn in xnl)
            {
                if (xn.Name == "tile")
                {
                    if (nTileIndex >= nNumTiles)
                    {
                        // too many tiles in sprite
                        m_doc.ErrorString("Too many tiles specified for sprite '{0}' (expected {1})", s.Name, nNumTiles);
                        return false;
                    }
                    uint[] bTile = new uint[32];
                    int nCurrByte = 0;

                    Regex rxTile = new Regex(@"\s*0x([0-9A-Fa-f]{2})\s*,");
                    Match mxTile = rxTile.Match(xn.InnerText);
                    if (mxTile.Success)
                    {
                        while (mxTile.Success)
                        {
                            GroupCollection matchGroups = mxTile.Groups;

                            if (nCurrByte >= 32)
                            {
                                // too many data bytes in tile
                                m_doc.ErrorString("Too many data bytes in tile #{0} of sprite '{0}'", nTileIndex, s.Name);
                                return false;
                            }
                            bTile[nCurrByte] = Convert.ToUInt32(matchGroups[1].Value, 16);
                            nCurrByte++;
                            if (nCurrByte == 32)
                            {
                                // After we've read 32 bytes, import the tile into the sprite.
                                if (!s.ImportTile32(nTileIndex, bTile))
                                {
                                    // Warning/Error message already displayed.
                                    return false;
                                }
                                nTileIndex++;
                            }

                            // Get the next match.
                            mxTile = mxTile.NextMatch();
                        }
                    }

                    if (nCurrByte != 32)
                    {
                        // too few data bytes for tile
                        m_doc.ErrorString("Too few data bytes in tile #{0} of sprite '{0}'", nTileIndex, s.Name);
                        return false;
                    }
                }
            }

            if (nTileIndex != s.NumTiles)
            {
                // incorrect number of tiles for this sprite - too few
                m_doc.ErrorString("Too few tiles specified for sprite '{0}' (expected {1})", s.Name, nNumTiles);
                return false;
            }
            return true;
        }
コード例 #30
0
 /// <summary>
 /// Draw a sample sprite for use in the tutorials.
 /// </summary>
 /// <param name="s"></param>
 private void DrawSample2x2Sprite(Sprite s, int id)
 {
     if (id == 2)
         DrawSampleSprite(s, 16, 16, m_Blobber2);
     else if (id == 1)
         DrawSampleSprite(s, 16, 16, m_Blobber1);
     else
         DrawSampleSprite(s, 16, 16, m_Blobber0);
 }