/// <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(); }
protected internal MovePoint(Sprite sprite, double totalTime, Rectangle destLoc) { parent = sprite; TotalTicks = (long)(totalTime * (double)HighResTimer.TicksPerSecond); TotalTicksRunning = 0; DestCoord = Sprites.GridCoordinates(sprite, sprite.ParentGrid, destLoc); DestSize = new Size(destLoc.Width, destLoc.Height); }
public void Add(Sprite sprite) { if (_children.Contains(sprite)) return; sprite.Disposing += sprite_Disposing; _children.Add(sprite); }
protected internal MovePoint(Sprite sprite, double totalTime, PointF destCoord, Size destSize) { parent = sprite; TotalTicks = (long)(totalTime * (double)HighResTimer.TicksPerSecond); TotalTicksRunning = 0; DestCoord = destCoord; DestSize = destSize; }
private double _velocityY; // tiles per second #endregion Fields #region Constructors protected internal Movement(Sprite sprite) { _parent = sprite; _lastTick = HighResTimer.GetCurrentTickCount(); _velocityX = 0; _velocityY = 0; _accelerationX = 0; _accelerationY = 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; }
public static Sprite CreateSprite(GridPointMatrix matrix, Frame frame) { Sprite sprite = new Sprite(matrix, frame); SubscribeToSpriteEvents(sprite); return sprite; }
protected internal SpriteMovePointFinishedEventArgs(Sprite _sprite, Movement _movement, MovePoint _movePoint) { sprite = _sprite; movement = _movement; movePoint = _movePoint; }
private void ShuffleNext() { Random random = new Random(); // find all pieces next to open space List<Sprite> sprites = FindSpritesAdjToOpenSpace(); // pick one of the pieces at random Sprite sprite = sprites[random.Next(0, sprites.Count)]; // don't move the same sprite 2 times in a row while (sprite == _lastMoved) sprite = sprites[random.Next(0, sprites.Count)]; // move the piece SlidePiece(sprite, _slideTime); _lastMoved = sprite; if (++_moveNumber >= _totalMoves) _isShuffling = false; }
public static void LoadSprite() { FrameSequence seq = new FrameSequence(); seq.AddFrame(sprtBmp, 0, 0); seq.AddFrame(sprtBmp, 1, 0); seq.AddFrame(sprtBmp, 2, 0); seq.AddFrame(sprtBmp, 3, 0); seq.SequenceCycleType = Gondwana.Common.Enums.CycleType.PingPong; Cycle cycle = new Cycle(seq, 0.03, "groovin"); sprite = Sprites.CreateSprite(matrix, seq[0]); sprite.TileAnimator.CurrentCycle = cycle; sprite.RenderSize = new Size(50, 50); sprite.VertAlign = Gondwana.Common.Enums.VerticalAlignment.Top; sprite.HorizAlign = Gondwana.Common.Enums.HorizontalAlignment.Left; sprite.MoveSprite(3, 3); sprite.Visible = true; sprite.TileAnimator.StartAnimation(); sprite.DetectCollision = CollisionDetection.All; //matrix2[1, 1].EnableAnimator = true; //matrix2[1, 1].TileAnimator.CurrentCycle = Cycles.GetAnimationCycle("groovin"); //matrix2[1, 1].TileAnimator.StartAnimation(); }
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 void Remove(Sprite sprite) { if (!_children.Contains(sprite)) return; sprite.Disposing -= sprite_Disposing; _children.Remove(sprite); }
protected internal SpriteMovedEventArgs(Sprite _sprite, PointF _oldPt, PointF _newPt) { sprite = _sprite; oldPt = _oldPt; newPt = _newPt; }
static void Keyboard_KeyDown(KeyDownEventArgs e) { switch (e.KeyConfig.Key) { case Keys.Up: if (e.IsShift) //matrix.SetSourceGridPoint(new PointF(matrix.SourceGridPoint.X, matrix.SourceGridPoint.Y - (float).1)); matrix.VelocityY = -1; //else // //sprite.MoveSprite(sprite.GridCoordinates.X, sprite.GridCoordinates.Y - .1); // sprite.SpriteMovement.VelocityY = -1; break; case Keys.Down: if (e.IsShift) //matrix.SetSourceGridPoint(new PointF(matrix.SourceGridPoint.X, matrix.SourceGridPoint.Y + (float).1)); matrix.VelocityY = 1; //else // //sprite.MoveSprite(sprite.GridCoordinates.X, sprite.GridCoordinates.Y + .1); // sprite.SpriteMovement.VelocityY = 1; break; case Keys.Left: if (e.IsShift) //matrix.SetSourceGridPoint(new PointF(matrix.SourceGridPoint.X - (float).1, matrix.SourceGridPoint.Y)); matrix.VelocityX = -1; //else // //sprite.MoveSprite(sprite.GridCoordinates.X - 0.1, sprite.GridCoordinates.Y); // sprite.SpriteMovement.VelocityX = -1; break; case Keys.Right: if (e.IsShift) //matrix.SetSourceGridPoint(new PointF(matrix.SourceGridPoint.X + (float).1, matrix.SourceGridPoint.Y)); matrix.VelocityX = 1; //else // //sprite.MoveSprite(sprite.GridCoordinates.X + 0.1, sprite.GridCoordinates.Y); // sprite.SpriteMovement.VelocityX = 1; break; case Keys.A: matrix.Visible = true; break; case Keys.S: matrix.Visible = false; break; case Keys.X: Sprites.PauseAllAnimation(true); break; case Keys.Y: Sprites.PauseAllAnimation(false); break; case Keys.Escape: stopEngine = true; break; case Keys.Q: sprite.TileAnimator.StopAnimation(); break; case Keys.Z: sprite.TileAnimator.StartAnimation(); break; case Keys.D: sprite.Dispose(); sprite = null; DirectDrawing.Clear(); MediaFile.GetMediaFile("boom").Play();; break; case Keys.C: //Sprite cloned = (Sprite)sprite.Clone(); //cloned.TileAnimator.StartAnimation("groovin"); MediaFile.GetMediaFile("chicken").Play(); break; case Keys.V: //MediaFile.FullScreen = !MediaFile.FullScreen; break; case Keys.B: //DirectDrawing.ClearAll(); Text text = new Text(visSurf, "BEWARE THE HORNY CHICKENS", new Font("Times New Roman", 24), new Rectangle(200, 200, 700, 100), Color.Orange, Color.Transparent, TextFormatFlags.WordBreak | TextFormatFlags.HorizontalCenter); break; case Keys.W: matrix.WrapHorizontally = !matrix.WrapHorizontally; //matrix3.WrapHorizontally = !matrix3.WrapHorizontally; break; default: break; } }
public static void Remove(Sprite sprite) { // Dispose method of Sprite adds area to Ref Queue and removes from spriteList sprite.Dispose(); }
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); }
protected internal SpriteDisposingEventArgs(Sprite _sprite) { sprite = _sprite; }
internal static void UnsubscribeFromSpriteEvents(Sprite sprite) { sprite.SpriteMoved -= newCoordinates; sprite.Disposing -= disposing; sprite.movement.Started -= moveStart; sprite.movement.MovePointFinished -= moveFinish; sprite.movement.Stopped -= moveStop; sprite.animator.Started -= animStart; sprite.animator.Stopped -= animStop; sprite.animator.Cycled -= animCycle; }
public void Shuffle(int totalMoves, double slideTime) { _isShuffling = true; _totalMoves = totalMoves; _slideTime = slideTime; _moveNumber = 0; _lastMoved = null; ShuffleNext(); }
/// <summary> /// does not copy the value of the Tag property /// </summary> /// <returns></returns> public object Clone() { Sprite newSprite = new Sprite(this); return newSprite; }
public bool SlidePiece(Sprite sprite, double slideTime) { if (FindSpritesAdjToOpenSpace().IndexOf(sprite) == -1) // sprite not eligible to move return false; else { // capture the starting point of the sprite being moved Point startPt = new Point((int)sprite.GridCoordinates.X, (int)sprite.GridCoordinates.Y); // move the sprite to the open space sprite.SpriteMovement.Start(slideTime, new PointF((float)openSpace.X, (float)openSpace.Y)); // make the openSpace value equal to the original sprite starting point openSpace = startPt; // move was successful return true; } }
/// <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); }
protected internal SpriteMovementEventArgs(Sprite _sprite, Movement _movement) { sprite = _sprite; movement = _movement; }