Esempio n. 1
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);
        }
Esempio n. 2
0
 internal RefreshQueue(GridPointMatrix layer)
 {
     isDirty = false;
     _tiles  = new List <Tile>();
     _rects  = new List <Rectangle>();
     _layer  = layer;
 }
Esempio n. 3
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;
        }
Esempio n. 4
0
        public GridPoint GetAdjGridPt(GridPoint gridPt, CardinalDirections direction)
        {
            GridPointMatrix matrix = gridPt.ParentGrid;

            switch (direction)
            {
            case CardinalDirections.N:
                return(matrix[gridPt.GridCoordinatesAbs.X, gridPt.GridCoordinatesAbs.Y - 1]);

            case CardinalDirections.NE:
                return(matrix[gridPt.GridCoordinatesAbs.X - 1, gridPt.GridCoordinatesAbs.Y - 1]);

            case CardinalDirections.E:
                return(matrix[gridPt.GridCoordinatesAbs.X + 1, gridPt.GridCoordinatesAbs.Y]);

            case CardinalDirections.SE:
                return(matrix[gridPt.GridCoordinatesAbs.X + 1, gridPt.GridCoordinatesAbs.Y + 1]);

            case CardinalDirections.S:
                return(matrix[gridPt.GridCoordinatesAbs.X, gridPt.GridCoordinatesAbs.Y + 1]);

            case CardinalDirections.SW:
                return(matrix[gridPt.GridCoordinatesAbs.X - 1, gridPt.GridCoordinatesAbs.Y + 1]);

            case CardinalDirections.W:
                return(matrix[gridPt.GridCoordinatesAbs.X - 1, gridPt.GridCoordinatesAbs.Y]);

            case CardinalDirections.NW:
                return(matrix[gridPt.GridCoordinatesAbs.X - 1, gridPt.GridCoordinatesAbs.Y - 1]);

            default:
                return(null);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public static Sprite CreateSprite(GridPointMatrix matrix, Frame frame)
        {
            Sprite sprite = new Sprite(matrix, frame);

            SubscribeToSpriteEvents(sprite);
            return(sprite);
        }
Esempio n. 7
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();
        }
Esempio n. 8
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();
        }
Esempio n. 9
0
 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;
 }
Esempio n. 11
0
        public Point GetSrcPxlAtGridPt(GridPointMatrix matrix, PointF gridCoord)
        {
            Point retVal = new Point();

            retVal.X = (int)((float)matrix.GridPointWidth * (gridCoord.X - matrix.SourceGridPoint.X));
            retVal.Y = (int)((float)matrix.GridPointHeight * (gridCoord.Y - matrix.SourceGridPoint.Y));

            return(retVal);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 internal static void CreateChildSprites(GridPointMatrix grid)
 {
     foreach (Sprite sprite in _spriteList)
     {
         if (sprite.ParentGrid == grid)
         {
             sprite.CreateChildSprites();
         }
     }
 }
Esempio n. 14
0
        public static Sprite CloneSprite(string ID, GridPointMatrix destMatrix)
        {
            Sprite sprite = GetSpriteByID(ID);

            if (sprite != null)
            {
                return(CloneSprite(sprite, destMatrix));
            }

            return(null);
        }
Esempio n. 15
0
        public static Sprite CreateSprite(GridPointMatrix matrix, Frame frame, string ID)
        {
            Sprite sprite = CreateSprite(matrix, frame);

            if (sprite != null)
            {
                sprite.ID = ID;
            }

            return(sprite);
        }
Esempio n. 16
0
 /// <summary>
 /// Clear all EngineState collection properties associated with the Engine class
 /// </summary>
 public void Clear()
 {
     ValueBag.Clear();
     EngineResourceFile.ClearAll();
     Tilesheet.ClearAllTilesheets();
     Cycle.ClearAllAnimationCycles();
     GridPointMatrixes.ClearAllGridPointMatrixes();
     GridPointMatrix.ClearAllGridPointMatrix();
     Gondwana.Common.Drawing.Sprites.Sprites.Clear();
     MediaFile.DisposeAll();
 }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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();
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        private static void DoBackgroundTasks(long tick)
        {
            if (BeforeBackgroundTasksExecute != null)
            {
                BeforeBackgroundTasksExecute();
            }

            // raise pre-cycle timer events
            Timers.RaiseTimerEvents(TimerType.PreCycle, tick);

            // check for keyboard events
            Keyboard.RaiseKeyEvents(tick);

            // perform any timed GridPointMatrix scrolling
            foreach (GridPointMatrix matrix in GridPointMatrix.GetAllGridPointMatrix())
            {
                matrix.MoveNext(tick);
            }

            // perform any timed DirectDrawing scrolling
            foreach (DirectDrawing drawing in DirectDrawing.AllDirectDrawings)
            {
                drawing.MoveNext(tick);
            }

            // cycle Animator frames
            CycleAnimations(tick);

            // advance Sprite Movement paths
            Sprites.MoveSprites(tick);

            // check for Tile collisions
            RaiseCollisionEvent(tick);

            // refresh all VisibleSurface backbuffers
            DrawRefreshQueues();

            // all attached VisibleSurface backbuffers drawn; clear the refresh queues
            ClearRefreshQueues();

            if (AfterBackgroundTasksExecute != null)
            {
                AfterBackgroundTasksExecute();
            }
        }
Esempio n. 22
0
 public Point GetSrcPxlAtGridPt(GridPointMatrix matrix, PointF gridCoord)
 {
     throw new NotImplementedException();
 }
Esempio n. 23
0
        public PointF GetGridPtAtPxl(GridPointMatrix matrix, Point pixelPt)
        {
            throw new NotImplementedException();

            #region old VB6 code

            /*
             * 'special calculation for FindGridCoordWithPixel when
             * 'g_renderMode is DIAGONAL_ISOMETRIC_SQUARE_MAP
             * Private Function FindCoordOnDiagIsoSquareMap(ByVal Layer As Long, _
             *                               ByVal XPixel As Single, _
             *                               ByVal YPixel As Single) As GridPoint_Long
             *
             * Dim ptReturn As GridPoint_Long
             * Dim ptGrid As GridPoint_Long
             * Dim ptPixelMajor As PixelLocation
             * Dim ptPixelMinor As PixelLocation
             * Dim lngMinorSection As MINOR_SECTION
             * Dim sngIsoSlope As Single
             *
             * With g_layers
             * 'step 1: find closest even-numbered column
             * ptGrid.Layer = Layer
             * ptGrid.X = Int((XPixel / .Layer(Layer).TileWidthFinal) + _
             *  (.Layer(Layer).FirstX / 2)) * 2
             * ptGrid.Y = Int((YPixel / .Layer(Layer).TileHeightFinal) + .Layer(Layer).FirstY)
             *
             * ptReturn.X = ptGrid.X
             * ptReturn.Y = ptGrid.Y
             *
             * 'step 2: find even-numbered column source pixel coordinates ("major" source)
             * ptPixelMajor.X = (CSng(ptGrid.X) - .Layer(Layer).FirstX) * _
             *  (.Layer(Layer).TileWidthFinal / 2)
             * ptPixelMajor.Y = (CSng(ptGrid.Y) - .Layer(Layer).FirstY) * _
             *  .Layer(Layer).TileHeightFinal
             *
             * 'step 3: find "minor" section source (quadrant within "major" section - see enum)
             * '   i.e., we are dividing the "major" section into 4 "minor" sections
             * If ((XPixel - ptPixelMajor.X) < (CSng(.Layer(Layer).TileWidthFinal) / 2)) Then    'left section
             * If ((YPixel - ptPixelMajor.Y) < (CSng(.Layer(Layer).TileHeightFinal) / 2)) Then   'top section
             *  lngMinorSection = UPPER_LEFT
             *  ptPixelMinor = ptPixelMajor
             * Else
             *  lngMinorSection = LOWER_LEFT
             *  ptPixelMinor.X = ptPixelMajor.X
             *  ptPixelMinor.Y = ptPixelMajor.Y + (CSng(.Layer(Layer).TileHeightFinal) / 2)
             * End If
             * Else        'right section
             * If ((YPixel - ptPixelMajor.Y) < (CSng(.Layer(Layer).TileHeightFinal) / 2)) Then   'top section
             *  lngMinorSection = UPPER_RIGHT
             *  ptPixelMinor.X = ptPixelMajor.X + (CSng(.Layer(Layer).TileWidthFinal) / 2)
             *  ptPixelMinor.Y = ptPixelMajor.Y
             * Else
             *  lngMinorSection = LOWER_RIGHT
             *  ptPixelMinor.X = ptPixelMajor.X + (CSng(.Layer(Layer).TileWidthFinal) / 2)
             *  ptPixelMinor.Y = ptPixelMajor.Y + (CSng(.Layer(Layer).TileHeightFinal) / 2)
             * End If
             * End If
             *
             * 'step 4: determine which side of slope within minor section pixel is on
             * '   where m=(y-b)/x  (you do remember your algebra, don't you?)
             * '   m is slope, y is height, x is width, and b is y-intercept
             * sngIsoSlope = CSng(.Layer(Layer).TileHeightFinal) / CSng(.Layer(Layer).TileWidthFinal)
             *
             * '0.001 is included to avoid divide-by-0 errors
             * Select Case lngMinorSection
             * Case MINOR_SECTION.UPPER_LEFT
             *  sngIsoSlope = -1 * sngIsoSlope
             *  If (((YPixel - ptPixelMinor.Y) - (CSng(.Layer(Layer).TileHeightFinal) / 2)) / _
             *          (XPixel - ptPixelMinor.X + 0.001)) < sngIsoSlope Then
             *      ptReturn.X = ptReturn.X - 1
             *      ptReturn.Y = ptReturn.Y - 1
             *  End If
             *
             * Case MINOR_SECTION.LOWER_LEFT
             *  If ((YPixel - ptPixelMinor.Y) / _
             *          (XPixel - ptPixelMinor.X + 0.001)) > sngIsoSlope _
             *          Then ptReturn.X = ptReturn.X - 1
             *
             * Case MINOR_SECTION.UPPER_RIGHT
             *  If ((YPixel - ptPixelMinor.Y) / _
             *          (XPixel - ptPixelMinor.X + 0.001)) < sngIsoSlope Then
             *      ptReturn.X = ptReturn.X + 1
             *      ptReturn.Y = ptReturn.Y - 1
             *  End If
             *
             * Case MINOR_SECTION.LOWER_RIGHT
             *  sngIsoSlope = -1 * sngIsoSlope
             *  If (((YPixel - ptPixelMinor.Y) - (CSng(.Layer(Layer).TileHeightFinal) / 2)) / _
             *          (XPixel - ptPixelMinor.X + 0.001)) > sngIsoSlope _
             *          Then ptReturn.X = ptReturn.X + 1
             * End Select
             * End With
             *
             * FindCoordOnDiagIsoSquareMap = ptReturn
             * End Function
             */
            #endregion
        }
Esempio n. 24
0
        public static void LoadMatrixLayers()
        {
            Gondwana.Common.Timers.Timers.Add("matrix_move", TimerType.PreCycle, TimerCycles.Repeating, 0.01).Tick +=
                new Gondwana.Common.EventArgs.TimerEventHandler(Timers_Tick);

            matrix = new GridPointMatrix(8, 8, 64, 32);
            matrix.WrapHorizontally = false;
            matrix.WrapVertically   = false;
            matrix.CoordinateSystem = new SquareIsoCoordinates();

            layers = new GridPointMatrixes(matrix);

            matrix2 = new GridPointMatrix(12, 12, 64, 32);
            matrix2.CoordinateSystem = new SquareIsoCoordinates();

            matrix2.BindScrollingToParentGrid(matrix);

            layers.AddLayer(matrix2).LayerSyncModifier = (float)0.25;

            //matrix3 = new GridPointMatrix(12, 12, 64, 32);
            //layers.AddLayer(matrix3).LayerSyncModifier = (float)0.5;
            //matrix3.CoordinateSystem = new SquareIsoCoordinates();
            //matrix3.BindScrollingToParentGrid(matrix);

            /*
             * foreach (GridPoint gridPt in matrix)
             * {
             *  if (gridPt.GridCoordinates.X < 2 && gridPt.GridCoordinates.Y < 2)
             *  {
             *      gridPt.EnableFog = false;
             *      gridPt.CurrentFrame = new Frame(tilesheet, 2, 7);
             *  }
             * }
             */

            //matrix[5, 5].CurrentFrame = new Frame(tilesheet, 2, 7);

            foreach (GridPoint gridPt in matrix)
            {
                gridPt.CurrentFrame = new Frame(tilesheet, 0, 0);
            }

            int i = 0;

            foreach (GridPoint gridPt in matrix2)
            {
                switch (i++ % 3)
                {
                case 0:
                    gridPt.CurrentFrame = new Frame(tilesheet, 1, 6);
                    break;

                case 1:
                    gridPt.CurrentFrame = new Frame(tilesheet, 1, 7);
                    break;

                case 2:
                    gridPt.CurrentFrame = new Frame(tilesheet, 1, 8);
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 25
0
 protected internal SourceGridPointChangedEventArgs(GridPointMatrix matrix, PointF oldP, PointF newP)
 {
     layer = matrix;
     oldPt = oldP;
     newPt = newP;
 }
 protected internal ShowGridLinesChangedEventArgs(GridPointMatrix matrix, bool oldVal, bool newVal)
 {
     Matrix   = matrix;
     oldValue = oldVal;
     newValue = newVal;
 }
Esempio n. 27
0
 public List <GridPoint> GetGridPtListInPxlRange(GridPointMatrix matrix, Rectangle pixelRange, bool includeOverlaps)
 {
     throw new NotImplementedException();
 }
Esempio n. 28
0
 public void MoveSprite(GridPointMatrix newLayer, Size newSize)
 {
     MoveSprite(newLayer);
     RenderSize = newSize;
 }
Esempio n. 29
0
 public PointF GetGridPtAtPxl(GridPointMatrix matrix, Point pixelPt)
 {
     throw new NotImplementedException();
 }
 protected internal GridPointMatrixDisposingEventArgs(GridPointMatrix matrix)
 {
     Matrix = matrix;
 }