Beispiel #1
0
        protected internal Sprite(GridPointMatrix matrix, Frame frame)
        {
            id = Guid.NewGuid().ToString();
            parentGrid = matrix;
            animator = new Animator(this);
            movement = new Movement(this);
            pauseAnimation = false;
            pauseMovement = false;
            horizAlign = HorizontalAlignment.Center;
            vertAlign = VerticalAlignment.Bottom;
            nudgeX = 0;
            nudgeY = 0;
            CurrentFrame = frame;

            if ((Sprites.SizeNewSpritesToParentGrid) && (parentGrid != null))
                renderSize = new Size(parentGrid.GridPointWidth, parentGrid.GridPointHeight);
            else
                renderSize = CurrentFrame.Tilesheet.TileSize;

            zOrder = 1;

            if (parentGrid != null)
                parentGrid.RefreshQueue.AddPixelRangeToRefreshQueue(this.DrawLocation, true);

            Sprites._spriteList.Add(this);
            CreateChildSprites();
        }
Beispiel #2
0
        public Puzzle(Graphics dc, string imgFile, int columns, int rows, Size size)
        {
            tilesheet = new Tilesheet("picture", imgFile);

            int tileWidth = (int)((float)tilesheet.Bmp.Width / (float)columns);
            int tileHeight = (int)((float)tilesheet.Bmp.Height / (float)rows);
            int adjWidth = tileWidth * columns;
            int adjHeight = tileHeight * rows;

            tilesheet.TileSize = new Size(tileWidth, tileHeight);

            originalSize = tilesheet.Bmp.Size;
            numColumns = columns;
            numRows = rows;
            adjustedSize = new Size(adjWidth, adjHeight);

            GridPointMatrix matrix = new GridPointMatrix(numColumns, numRows, tileWidth, tileHeight);
            matrix.CoordinateSystem = new SquareIsoCoordinates();
            matrixes = new GridPointMatrixes(matrix);

            surface = new VisibleSurface(dc, size.Width, size.Height, matrixes);
            surface.Erase();

            InitializeSprites(tileWidth, tileHeight);
            //Gondwana.Scripting.Parser.WriteToFile("bmpProp_file.gond", System.IO.FileMode.Create, tilesheet);
            //Engine.ScriptEngineState("file.gond", true);

            delMoveStart = new SpriteMovementEventHandler(Sprites_SpriteMovementStarted);
            delMoveStop = new SpriteMovementEventHandler(Sprites_SpriteMovementStopped);

            Sprites.SpriteMovementStarted += delMoveStart;
            Sprites.SpriteMovementStopped += delMoveStop;
        }
        private void _RefreshQueueNewArea(RefreshQueueAreaAddedEventArgs e)
        {
            // set refresh to Queue if no refresh required
            if (refreshNeeded == MatrixesRefreshType.None)
            {
                refreshNeeded = MatrixesRefreshType.Queue;
            }

            // if matrix that added Tile to queue is visible...
            if (e.layer.Visible == true)
            {
                // refresh all other visible matrixes
                for (int i = _visibleLayers.Count - 1; i >= 0; i--)
                {
                    GridPointMatrix otherMatrix = _visibleLayers[i];

                    // refresh other matrixes; no need to do the calling one again
                    if (e.layer != otherMatrix)
                    {
                        // only refresh e.tileAdded.DrawLocationRefresh rectangle; do not raise cascading events
                        otherMatrix.RefreshQueue.AddPixelRangeToRefreshQueue(e.area, false);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Private constructor used when calling the Clone() method on a Sprite.
        /// </summary>
        private Sprite(Sprite sprite)
        {
            id = Guid.NewGuid().ToString();
            animator = new Animator(this);
            movement = new Movement(this);
            Sprites._spriteList.Add(this);

            parentGrid = sprite.parentGrid;
            frame = sprite.frame;
            DetectCollision = sprite.collisionDetection;
            horizAlign = sprite.horizAlign;
            vertAlign = sprite.vertAlign;
            nudgeX = sprite.nudgeX;
            nudgeY = sprite.nudgeY;
            renderSize = sprite.renderSize;
            ZOrder = sprite.zOrder;
            visible = sprite.visible;
            gridCoordinates = sprite.gridCoordinates;
            AdjustCollisionArea = sprite.AdjustCollisionArea;

            if (parentGrid != null)
                parentGrid.RefreshQueue.AddPixelRangeToRefreshQueue(this.DrawLocation, true);

            Sprites.SubscribeToSpriteEvents(this);

            CreateChildSprites();
        }
Beispiel #5
0
        private List<Tile> _tiles; // array of Tile objects to be redrawn

        #endregion Fields

        #region Constructors

        internal RefreshQueue(GridPointMatrix layer)
        {
            isDirty = false;
            _tiles = new List<Tile>();
            _rects = new List<Rectangle>();
            _layer = layer;
        }
 protected internal GridPointMatrixWrappingChangedEventArgs(GridPointMatrix _layer, bool _oldHoriz, bool _newHoriz, bool _oldVerti, bool _newVerti)
 {
     layer = _layer;
     oldHorizWrapping = _oldHoriz;
     newHorizWrapping = _newHoriz;
     oldVertiWrapping = _oldVerti;
     newHorizWrapping = _newVerti;
 }
 protected internal GridPointSizeChangedEventArgs(GridPointMatrix matrix, int oldW, int oldH, int newW, int newH)
 {
     layer = matrix;
     oldWidth = oldW;
     oldHeight = oldH;
     newWidth = newW;
     newHeight = newH;
 }
        public PointF GetGridPtAtPxl(GridPointMatrix matrix, Point pixelPt)
        {
            PointF retPt = new PointF();

            retPt.X = ((float)(pixelPt.X - matrix.GridPointZeroPixel.X)) / (float)matrix.GridPointWidth;
            retPt.Y = ((float)(pixelPt.Y - matrix.GridPointZeroPixel.Y)) / (float)matrix.GridPointHeight;

            return retPt;
        }
        public void ClearLayer(GridPointMatrix matrix)
        {
            _matrixes.Remove(matrix);
            OnGridPointMatrixRemoved(matrix);

            // rediscover the list of visible arrays
            _SetVisibleLayersArray();

            refreshNeeded = MatrixesRefreshType.All;
        }
Beispiel #10
0
        public static Sprite CloneSprite(Sprite sprite, GridPointMatrix destMatrix)
        {
            Sprite newSprite = (Sprite)sprite.Clone();
            if (newSprite.ParentGrid != destMatrix)
            {
                newSprite.MoveSprite(destMatrix);
                newSprite.ParentGrid.RefreshQueue.AddPixelRangeToRefreshQueue(newSprite.DrawLocation, true);
            }

            return newSprite;
        }
Beispiel #11
0
        public void BindScrollingToParentGrid(GridPointMatrix parent, PointF parentAnchor, PointF thisAnchor)
        {
            // remove any previous binding
            UnbindScrolling();

            // create new binding instance
            scrollBinding                       = new GridPointMatrixScrollBinding();
            scrollBinding.ParentGrid            = parent;
            scrollBinding.ChildGrid             = this;
            scrollBinding.ParentAnchorGridPoint = parentAnchor;
            scrollBinding.ChildAnchorGridPoint  = thisAnchor;
        }
Beispiel #12
0
        public void ClearLayer(int matrix)
        {
            GridPointMatrix grid = this[matrix];

            _matrixes.Remove(grid);
            OnGridPointMatrixRemoved(grid);
            grid = null;

            // rediscover the list of visible arrays
            _SetVisibleLayersArray();

            refreshNeeded = MatrixesRefreshType.All;
        }
Beispiel #13
0
        public GridPointMatrix AddLayer(GridPointMatrix matrix)
        {
            _matrixes.Add(matrix);
            int newIdx = _matrixes.Count - 1;

            OnGridPointMatrixAdded(this[newIdx]);

            // rediscover the list of visible arrays
            _SetVisibleLayersArray();

            refreshNeeded = MatrixesRefreshType.All;

            return(this[newIdx]);
        }
Beispiel #14
0
        internal GridPoint(GridPoint gridPoint, Point gridCoord)
        {
            parentGrid               = gridPoint.parentGrid;
            gridCoordinates          = gridCoord;
            disableAddToRefreshQueue = gridPoint.disableAddToRefreshQueue;
            zOrder    = gridPoint.zOrder;
            visible   = gridPoint.visible;
            frame     = gridPoint.frame;
            rasterOp  = gridPoint.rasterOp;
            enableFog = gridPoint.enableFog;
            Tag       = gridPoint.Tag;

            // associate new GridPoint (child, this) with existing GridPoint (parent)
            gridPoint.AddChild(this);
        }
Beispiel #15
0
        internal GridPoint(GridPoint gridPoint, Point gridCoord)
        {
            parentGrid = gridPoint.parentGrid;
            gridCoordinates = gridCoord;
            disableAddToRefreshQueue = gridPoint.disableAddToRefreshQueue;
            zOrder = gridPoint.zOrder;
            visible = gridPoint.visible;
            frame = gridPoint.frame;
            rasterOp = gridPoint.rasterOp;
            enableFog = gridPoint.enableFog;
            Tag = gridPoint.Tag;

            // associate new GridPoint (child, this) with existing GridPoint (parent)
            gridPoint.AddChild(this);
        }
Beispiel #16
0
        protected virtual void OnGridPointMatrixRemoved(GridPointMatrix grid)
        {
            grid._parent = null;

            grid.FirstColRowChanged    -= firstCRDel;
            grid.VisibleChanged        -= visChgDel;
            grid.GridPointSizeChanged  -= gridPtSzDel;
            grid.RefreshQueueAreaAdded -= refQueueDel;
            grid.WrappingChanged       -= wrappingDel;

            if (GridPointMatrixRemoved != null)
            {
                GridPointMatrixRemoved(new GridPointMatrixAddRemoveEventArgs(this, grid));
            }
        }
Beispiel #17
0
        public int GetMatrixPosition(GridPointMatrix matrix)
        {
            int ret = -1;

            for (int i = this.Count - 1; i >= 0; i--)
            {
                if (this[i] == matrix)
                {
                    ret = i;
                    break;
                }
            }

            return(ret);
        }
        public List<GridPoint> GetGridPtListInPxlRange(GridPointMatrix matrix, Rectangle pixelRange, bool includeOverlaps)
        {
            List<GridPoint> retVal = new List<GridPoint>();

            // find upper-left and bottom-right X and Y grid coordinates
            PointF ptUL = this.GetGridPtAtPxl(matrix, new Point(pixelRange.Left, pixelRange.Top));
            PointF ptBR = this.GetGridPtAtPxl(matrix, new Point(pixelRange.Right - 1, pixelRange.Bottom - 1));

            // loop through all coordinates and add to return value
            for (int y = (int)Math.Floor(ptUL.Y); y <= (int)ptBR.Y; y++)
            {
                for (int x = (int)Math.Floor(ptUL.X); x <= (int)ptBR.X; x++)
                {
                    var gPt = matrix[x, y];
                    if (gPt != null)
                        retVal.Add(gPt);
                }
            }

            // check for overlaps if required
            if (includeOverlaps)
            {
                if (Tilesheet.MaxExtraTopSpaceRatio > 0)
                {
                    foreach (GridPoint grPt in this.GetGridPtListInPxlRange(matrix,
                        new Rectangle(pixelRange.Left, pixelRange.Bottom,
                        pixelRange.Width,
                        (int)Math.Ceiling(Tilesheet.MaxExtraTopSpaceRatio * (float)matrix.GridPointHeight)),
                        false))
                    {
                        if (grPt != null)
                        {
                            if (GetPxlRangeAtGridPt(grPt, true).IntersectsWith(pixelRange))
                            {
                                if (retVal.IndexOf(grPt) == -1)
                                    retVal.Add(grPt);
                            }
                        }
                    }
                }
            }

            return retVal;
        }
Beispiel #19
0
 public GridPointMatrixes(GridPointMatrix matrix)
 {
     _matrixes = new List <GridPointMatrix>();
     _matrixes.Add(matrix);
     Init();
 }
Beispiel #20
0
        /// <summary>
        /// private constructor used when generating "child" Sprite objects.  Adds the new Sprite
        /// to the argument Sprite's childTiles List.  Does not add "child" Sprite to Engine-level
        /// Sprite List.  Does not register "child" Sprite events with static Sprites class.
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="gridCoord"></param>
        private Sprite(Sprite sprite, PointF gridCoord)
        {
            id = Guid.NewGuid().ToString();
            parentGrid = sprite.parentGrid;
            //animator = new Animator(this);
            //movement = new Movement(this);
            frame = sprite.frame;
            collisionDetection = sprite.collisionDetection;
            horizAlign = sprite.horizAlign;
            vertAlign = sprite.vertAlign;
            nudgeX = sprite.nudgeX;
            nudgeY = sprite.nudgeY;
            renderSize = sprite.renderSize;
            zOrder = sprite.zOrder;
            visible = sprite.visible;
            gridCoordinates = gridCoord;
            AdjustCollisionArea = sprite.AdjustCollisionArea;

            if (parentGrid != null)
                parentGrid.RefreshQueue.AddPixelRangeToRefreshQueue(this.DrawLocation, true);

            // add new Sprite to passed-in sprite's childTiles list
            sprite.AddChild(this);
        }
Beispiel #21
0
        public void MoveSprite(GridPointMatrix newLayer)
        {
            Rectangle drawLoc = DrawLocation;

            if (parentGrid != null)
                parentGrid.RefreshQueue.AddPixelRangeToRefreshQueue(this.DrawLocation, true);

            parentGrid = newLayer;
            MoveSprite(drawLoc);

            // create new child Sprites on new grid
            CreateChildSprites();
        }
Beispiel #22
0
 public void MoveSprite(GridPointMatrix newLayer, Size newSize)
 {
     MoveSprite(newLayer);
     RenderSize = newSize;
 }
Beispiel #23
0
 public void BindScrollingToParentGrid(GridPointMatrix parent, PointF parentAnchor)
 {
     BindScrollingToParentGrid(parent, parentAnchor, this.SourceGridPoint);
 }
Beispiel #24
0
        public static Sprite CreateSprite(GridPointMatrix matrix, Frame frame, string ID)
        {
            Sprite sprite = CreateSprite(matrix, frame);
            if (sprite != null)
                sprite.ID = ID;

            return sprite;
        }
Beispiel #25
0
        internal static PointF GridCoordinates(Sprite sprite, GridPointMatrix grid, Rectangle drawLocation)
        {
            // if Sprite hasn't been placed on GridPointMatrix, this is moot
            if (grid == null)
                return new PointF();

            // work the Sprites.DrawLocation method backwards...
            drawLocation.X -= sprite.NudgeX;
            drawLocation.Y -= sprite.NudgeY;

            // adjust X coord
            switch (sprite.HorizAlign)
            {
                case HorizontalAlignment.Left:
                    // no adjustment necessary
                    break;
                case HorizontalAlignment.Center:
                    // shift left by half the difference between Tile Width values
                    // if Sprite Width > GridPt Width, Sprite will shift right
                    drawLocation.X -= (grid.GridPointWidth - drawLocation.Width) / 2;
                    break;
                case HorizontalAlignment.Right:
                    // shift left by the entire difference between Tile Width values
                    // if Sprite Width > GridPt Width, Sprite will shift right
                    drawLocation.X -= (grid.GridPointWidth - drawLocation.Width);
                    break;
                default:
                    // shouldn't get here...
                    break;
            }

            // adjust Y coord
            switch (sprite.VertAlign)
            {
                case VerticalAlignment.Top:
                    // no adjustment necessary
                    break;
                case VerticalAlignment.Middle:
                    // shift up by half the difference between Tile Height values
                    // if Sprite Height > GridPt Height, Sprite will shift down
                    drawLocation.Y -= (grid.GridPointHeight - drawLocation.Height) / 2;
                    break;
                case VerticalAlignment.Bottom:
                    // shift up by the entire difference between Tile Height values
                    // if Sprite Height > GridPt Height, Sprite will shift down
                    drawLocation.Y -= (grid.GridPointHeight - drawLocation.Height);
                    break;
                default:
                    // shouldn't get here...
                    break;
            }

            // find and return the grid coordinates after the Sprite adjustments have been considered
            return grid.CoordinateSystem.GetGridPtAtPxl(grid, drawLocation.Location);
        }
 public List<GridPoint> GetGridPtListInPxlRange(GridPointMatrix matrix, Rectangle pixelRange, bool includeOverlaps)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
 internal static void CreateChildSprites(GridPointMatrix grid)
 {
     foreach (Sprite sprite in _spriteList)
     {
         if (sprite.ParentGrid == grid)
             sprite.CreateChildSprites();
     }
 }
Beispiel #28
0
        internal static Rectangle DrawLocation(Sprite sprite, GridPointMatrix grid, PointF coord, Size size)
        {
            // if Sprite hasn't been placed on GridPointMatrix, this is moot
            if (grid == null)
                return new Rectangle();

            // get the "top left" of the Sprite gridCoordinates value
            Point pxlPt = grid.CoordinateSystem.GetSrcPxlAtGridPt(grid, coord);

            // adjust X coord
            switch (sprite.HorizAlign)
            {
                case HorizontalAlignment.Left:
                    // no adjustment necessary
                    break;
                case HorizontalAlignment.Center:
                    // shift right by half the difference between Tile Width values
                    // if Sprite Width > GridPt Width, Sprite will shift left
                    pxlPt.X += (grid.GridPointWidth - size.Width) / 2;
                    break;
                case HorizontalAlignment.Right:
                    // shift right by the entire difference between Tile Width values
                    // if Sprite Width > GridPt Width, Sprite will shift left
                    pxlPt.X += (grid.GridPointWidth - size.Width);
                    break;
                default:
                    // shouldn't get here...
                    break;
            }

            // adjust Y coord
            switch (sprite.VertAlign)
            {
                case VerticalAlignment.Top:
                    // no adjustment necessary
                    break;
                case VerticalAlignment.Middle:
                    // shift down by half the difference between Tile Height values
                    // if Sprite Height > GridPt Height, Sprite will shift up
                    pxlPt.Y += (grid.GridPointHeight - size.Height) / 2;
                    break;
                case VerticalAlignment.Bottom:
                    // shift down by the entire difference between Tile Height values
                    // if Sprite Height > GridPt Height, Sprite will shift up
                    pxlPt.Y += (grid.GridPointHeight - size.Height);
                    break;
                default:
                    // shouldn't get here...
                    break;
            }

            pxlPt.X += sprite.NudgeX;
            pxlPt.Y += sprite.NudgeY;

            return new Rectangle(pxlPt, size);
        }
Beispiel #29
0
        public static List<Sprite> GetSpritesInRange(Rectangle range, GridPointMatrix grid, bool fullEnclosures)
        {
            List<Sprite> retSprites = new List<Sprite>();

            foreach (Sprite sprite in _spriteList)
            {
                if (sprite.ParentGrid == grid)
                {
                    // check if any childTiles in range; if so, return ParentTile
                    if (sprite.childTiles != null)
                    {
                        foreach (Sprite child in sprite.childTiles)
                        {
                            if (fullEnclosures)
                            {
                                if (range.Contains(child.DrawLocation))
                                    retSprites.Add(sprite);
                            }
                            else
                            {
                                if (child.DrawLocation.IntersectsWith(range))
                                    retSprites.Add(sprite);
                            }
                        }
                    }

                    // check if sprite in range
                    if (fullEnclosures)
                    {
                        if (range.Contains(sprite.DrawLocation))
                            retSprites.Add(sprite);
                    }
                    else
                    {
                        if (sprite.DrawLocation.IntersectsWith(range))
                            retSprites.Add(sprite);
                    }
                }
            }

            return retSprites;
        }
Beispiel #30
0
        public void BindScrollingToParentGrid(GridPointMatrix parent, PointF parentAnchor, PointF thisAnchor)
        {
            // remove any previous binding
            UnbindScrolling();

            // create new binding instance
            scrollBinding = new GridPointMatrixScrollBinding();
            scrollBinding.ParentGrid = parent;
            scrollBinding.ChildGrid = this;
            scrollBinding.ParentAnchorGridPoint = parentAnchor;
            scrollBinding.ChildAnchorGridPoint = thisAnchor;
        }
Beispiel #31
0
        public static List<Sprite> GetSpritesAtPoint(Point pxlPt, GridPointMatrix grid)
        {
            List<Sprite> retSprites = new List<Sprite>();

            foreach (Sprite sprite in _spriteList)
            {
                // check if any childTiles at Point; if so, return ParentTile
                if (sprite.childTiles != null)
                {
                    foreach (Sprite child in sprite.childTiles)
                    {
                        if ((sprite.ParentGrid == grid) && (child.DrawLocation.Contains(pxlPt)))
                            retSprites.Add(sprite);
                    }
                }

                // check if sprite at Point
                if ((sprite.ParentGrid == grid) && (sprite.DrawLocation.Contains(pxlPt)))
                    retSprites.Add(sprite);
            }

            return retSprites;
        }
Beispiel #32
0
 public GridPoint(GridPointMatrix matrix)
 {
     zOrder     = 0;
     visible    = true;
     parentGrid = matrix;
 }
Beispiel #33
0
 internal Movement(GridPointMatrix matrix)
 {
     parent      = matrix;
     IsScrolling = false;
 }
 public Point GetSrcPxlAtGridPt(GridPointMatrix matrix, PointF gridCoord)
 {
     throw new NotImplementedException();
 }
 protected internal ShowGridLinesChangedEventArgs(GridPointMatrix matrix, bool oldVal, bool newVal)
 {
     Matrix = matrix;
     oldValue = oldVal;
     newValue = newVal;
 }
Beispiel #36
0
 public void BindScrollingToParentGrid(GridPointMatrix parent)
 {
     BindScrollingToParentGrid(parent, parent.SourceGridPoint);
 }
 public PointF GetGridPtAtPxl(GridPointMatrix matrix, Point pixelPt)
 {
     throw new NotImplementedException();
 }
Beispiel #38
0
 public void BindScrollingToParentGrid(GridPointMatrix parent, PointF parentAnchor)
 {
     BindScrollingToParentGrid(parent, parentAnchor, this.SourceGridPoint);
 }
Beispiel #39
0
 public static Sprite CreateSprite(GridPointMatrix matrix, Frame frame)
 {
     Sprite sprite = new Sprite(matrix, frame);
     SubscribeToSpriteEvents(sprite);
     return sprite;
 }
Beispiel #40
0
 public GridPoint(GridPointMatrix matrix)
 {
     zOrder = 0;
     visible = true;
     parentGrid = matrix;
 }
Beispiel #41
0
        public static Sprite CloneSprite(string ID, GridPointMatrix destMatrix)
        {
            Sprite sprite = GetSpriteByID(ID);
            if (sprite != null)
                return CloneSprite(sprite, destMatrix);

            return null;
        }
Beispiel #42
0
 public static List<Sprite> GetSpritesInRange(Rectangle range, GridPointMatrix grid)
 {
     return GetSpritesInRange(range, grid, false);
 }
Beispiel #43
0
 internal Movement(GridPointMatrix matrix)
 {
     parent = matrix;
     IsScrolling = false;
 }