/// <summary> /// Grabs a block from the currently selected stack. /// </summary> /// <param name="stack"></param> private void Grab() { // We only care if we can grab something if (currentStack == null || !CanGrab()) { return; } // Move everything up in the stack. Block topBlock = currentStack.TopBlock; for (int i = Constants.MaximumGrabCount - 1; i > 0; i--) { grabStack[i] = grabStack[i - 1]; } // Grab the top block and change its position grabStack[0] = topBlock; topBlock.IsMoving = false; topBlock.Vector = 0; topBlock.Mass = 0; // Remove the stack for processing currentStack.Remove(topBlock); // Fire the sound event BlockStackEventArgs args = new BlockStackEventArgs(); args.Stack = currentStack; args.Block = topBlock; Game.Sound.BlockGrabbed(this, args); // Save the last grab stack lastGrabStack = currentStack; }
/// <summary> /// This is called when a block stops moving, we use that to /// determine when to pull out the dropped blocks. /// </summary> private void OnBlockMovingChanged( object sender, BlockStackEventArgs args) { // Remove the block from our internal lists stacks.Remove(args.Block); blocks.Remove(args.Block); }
/// <summary> /// This triggers the sounds for when the block lands on the ground. /// </summary> /// <param name="stack"></param> /// <param name="block"></param> public void BlockLanded(object sender, BlockStackEventArgs args) { // Ignore blanks if (args.Block == null || args.Block.Sprite == null || args.Block.Sprite.ID == null) { return; } // Make sure we don't have a character if (args.Block.Sprite.ID.Contains("Character")) { return; } // Play a sound if (Board.IsGroundBlock(args.Block)) { PlaySound("Block Landed"); } /* * String.Format("{0} - {1}", args.Block.DrawableName), * String.Format("{0} - {1} - {2}", args.Block.DrawableName)); */ }
private void OnBlockMovingChanged( object sender, BlockStackEventArgs args) { // Figure out the point Block b = args.Block; BlockStack bs = args.Stack; PointF p1 = blockViewport.ToPoint(bs.X, bs.Y, b.Height); PointF p = new PointF( p1.X + blockViewport.Point.X + 31 + Viewport.Point.X, p1.Y + blockViewport.Point.Y + 90 + Viewport.Point.Y); // Swarm the stars and hearts Game.PlayMode .SwarmStars(Constants.StarsPerPrayerBlock, p); Game.PlayMode .SwarmHearts(Constants.HeartsPerPrayerBlock, p); // Mark the block as unmovable b.Data = false; // Add the chance of a chest int random = Entropy.Next(Constants.ChestChance); chestChance++; if (random <= chestChance) { chestChance = 0; ChestCounter++; } }
/// <summary> /// Triggered when an entire block stack stops moving. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnMovingChanged(object sender, BlockStackEventArgs args) { // Check the board, but only if we dropped a block if (Board.IsGroundBlock(args.Stack.TopBlock)) { Game.State.Board.CheckLayout(args.Stack.X, args.Stack.Y); } }
private void OnMovingChanged(object sender, BlockStackEventArgs args) { // See if we are completely done if (!Prayer.Board.IsMoving) { // Start the countdown timer SecondsRemaining = Constants.PrayerCompletedTimeout; CountingDown = true; } }
/// <summary> /// Triggered when the mouse enters a specific stack /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnStackMouseEnter(object sender, BlockStackEventArgs args) { // Ignore if we have a minor mode if (minorMode != null) { return; } // Add the selector to the current position and set it on top currentStack = args.Stack; // Remove the stack, just in case bool isValidTarget = IsValidTarget(); // See if we have a valid target if (!isValidTarget) { // Change the selector so it shows an incorrect selection selector.Sprite = AssetLoader.Instance .CreateSprite(Constants.InvalidSelectorName); vertViewport.Visible = false; // We are done return; } // Change the selector to show a valid selector. selector.Sprite = AssetLoader.Instance .CreateSprite(Constants.SelectorName); // Move the vertical stack display to the currently // selected stack and make it visible PointF vertPoint = blockViewport.ToPoint( currentStack.X, currentStack.Y, currentStack.TopPosition); vertViewport.Visible = true; vertViewport.BlockStackX = currentStack.X; vertViewport.BlockStackY = currentStack.Y; vertViewport.Point = new PointF( vertPoint.X + blockViewport.BlockWidth / 2 - vertViewport.Size.Width / 2, vertPoint.Y); // We are going to be grabbing or dropping Game.GuiManager.MouseUpListeners.Add(this); }
/// <summary> /// Triggered when a block stops moving. /// </summary> private void OnBlockMovingChanged( object sender, BlockStackEventArgs args) { // Only bother if we are dropping a ground block if (!Board.IsGroundBlock(args.Block) || !droppingBlocks.Contains(args.Block)) { return; } // First check for bugs foreach (Block block in args.Stack) { // Ignore processing ourselves if (args.Block == block) { continue; } // Ignore if the position isn't close if ((int)args.Block.BottomPosition != (int)block.TopPosition) { continue; } // Check for the drawable if (block.Sprite.ID == Constants.BugBlockName) { // Remove the bug (block as Bug).Remove(); // Start falling again args.Block.BottomPosition -= 1f; args.Block.Vector = Constants.DroppedVector; // Finish processing return; } } // Remove it droppingBlocks.Remove(args.Block); }
/// <summary> /// This triggers the sounds for when the block lands on the ground. /// </summary> /// <param name="stack"></param> /// <param name="block"></param> public void BlockLanded(object sender, BlockStackEventArgs args) { // Ignore blanks if (args.Block == null || args.Block.Sprite == null || args.Block.Sprite.ID == null) return; // Make sure we don't have a character if (args.Block.Sprite.ID.Contains("Character")) return; // Play a sound if (Board.IsGroundBlock(args.Block)) PlaySound("Block Landed"); /* String.Format("{0} - {1}", args.Block.DrawableName), String.Format("{0} - {1} - {2}", args.Block.DrawableName)); */ }
/// <summary> /// Triggered when a mouse leaves a stack. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnStackMouseExit(object sender, BlockStackEventArgs args) { // Ignore if we have a minor mode if (minorMode != null) { return; } // If we don't have a current stack, don't bother if (currentStack == null) { return; } // Remove the selectors // We use RemoveAll() because of a duplication bug currentStack = null; vertViewport.Visible = false; // Since we won't be listening to down, remove it Game.GuiManager.MouseUpListeners.Remove(this); }
/// <summary> /// This triggers the sound for when a block is grabbed from /// the ground. /// </summary> /// <param name="stack"></param> /// <param name="block"></param> public void BlockGrabbed(object sender, BlockStackEventArgs args) { PlaySound("Block Grabbed"); }
/// <summary> /// Triggered when a mouse leaves a stack. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnStackMouseExit(object sender, BlockStackEventArgs args) { // Ignore if we have a minor mode if (minorMode != null) return; // If we don't have a current stack, don't bother if (currentStack == null) return; // Remove the selectors // We use RemoveAll() because of a duplication bug currentStack = null; vertViewport.Visible = false; // Since we won't be listening to down, remove it Game.GuiManager.MouseUpListeners.Remove(this); }
/// <summary> /// Triggered when the mouse enters a specific stack /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnStackMouseEnter(object sender, BlockStackEventArgs args) { // Ignore if we have a minor mode if (minorMode != null) return; // Add the selector to the current position and set it on top currentStack = args.Stack; // Remove the stack, just in case bool isValidTarget = IsValidTarget(); // See if we have a valid target if (!isValidTarget) { // Change the selector so it shows an incorrect selection selector.Sprite = AssetLoader.Instance .CreateSprite(Constants.InvalidSelectorName); vertViewport.Visible = false; // We are done return; } // Change the selector to show a valid selector. selector.Sprite = AssetLoader.Instance .CreateSprite(Constants.SelectorName); // Move the vertical stack display to the currently // selected stack and make it visible PointF vertPoint = blockViewport.ToPoint( currentStack.X, currentStack.Y, currentStack.TopPosition); vertViewport.Visible = true; vertViewport.BlockStackX = currentStack.X; vertViewport.BlockStackY = currentStack.Y; vertViewport.Point = new PointF( vertPoint.X + blockViewport.BlockWidth / 2 - vertViewport.Size.Width / 2, vertPoint.Y); // We are going to be grabbing or dropping Game.GuiManager.MouseUpListeners.Add(this); }
/// <summary> /// Triggered when an entire block stack stops moving. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnMovingChanged(object sender, BlockStackEventArgs args) { // Check the board, but only if we dropped a block if (Board.IsGroundBlock(args.Stack.TopBlock)) Game.State.Board.CheckLayout(args.Stack.X, args.Stack.Y); }
/// <summary> /// Triggered when a block stops moving. /// </summary> private void OnBlockMovingChanged( object sender, BlockStackEventArgs args) { // Only bother if we are dropping a ground block if (!Board.IsGroundBlock(args.Block) || !droppingBlocks.Contains(args.Block)) return; // First check for bugs foreach (Block block in args.Stack) { // Ignore processing ourselves if (args.Block == block) continue; // Ignore if the position isn't close if ((int) args.Block.BottomPosition != (int) block.TopPosition) continue; // Check for the drawable if (block.Sprite.ID == Constants.BugBlockName) { // Remove the bug (block as Bug).Remove(); // Start falling again args.Block.BottomPosition -= 1f; args.Block.Vector = Constants.DroppedVector; // Finish processing return; } } // Remove it droppingBlocks.Remove(args.Block); }
/// <summary> /// Grabs a block from the currently selected stack. /// </summary> /// <param name="stack"></param> private void Grab() { // We only care if we can grab something if (currentStack == null || !CanGrab()) return; // Move everything up in the stack. Block topBlock = currentStack.TopBlock; for (int i = Constants.MaximumGrabCount - 1; i > 0; i--) grabStack[i] = grabStack[i - 1]; // Grab the top block and change its position grabStack[0] = topBlock; topBlock.IsMoving = false; topBlock.Vector = 0; topBlock.Mass = 0; // Remove the stack for processing currentStack.Remove(topBlock); // Fire the sound event BlockStackEventArgs args = new BlockStackEventArgs(); args.Stack = currentStack; args.Block = topBlock; Game.Sound.BlockGrabbed(this, args); // Save the last grab stack lastGrabStack = currentStack; }
/// <summary> /// This event is used to handle jumping from one block to /// another. /// </summary> private void OnDirectionChanged( object sender, BlockStackEventArgs args) { // At the apex, we change our direction by moving to the // next stack as appropriate. Start by ignoring direction // 0 since that is an inplace jumping. if (direction == 0) { return; } // Get the destination stack Board board = Game.State.Board; BlockStack srcStack = board[X, Y]; BlockStack destStack = null; if (direction == 1) { destStack = board[X, Y - 1]; } else if (direction == 2) { destStack = board[X + 1, Y]; } else if (direction == 3) { destStack = board[X, Y + 1]; } else if (direction == 4) { destStack = board[X - 1, Y]; } // Make sure we are still a valid destination if (IsInvalidTarget(srcStack, destStack)) { // We want to reverse the direction, but stay in the // same stack because our destination became // invalid. This works because the code will show them // "bouncing" back. if (direction == 1) { direction = 3; } else if (direction == 2) { direction = 4; } else if (direction == 3) { direction = 1; } else if (direction == 4) { direction = 2; } // We are done srcStack.Add(this); return; } // Move this block to the next one srcStack.Remove(this); destStack.Add(this); // Change our coordinates if (direction == 1) { BottomPosition -= 4; Y--; } else if (direction == 2) { OffsetX -= 101; X++; } else if (direction == 3) { BottomPosition += 1; Y++; } else if (direction == 4) { OffsetX += 101; X--; } }
/// <summary> /// This event is used to handle jumping from one block to /// another. /// </summary> private void OnDirectionChanged( object sender, BlockStackEventArgs args) { // At the apex, we change our direction by moving to the // next stack as appropriate. Start by ignoring direction // 0 since that is an inplace jumping. if (direction == 0) return; // Get the destination stack Board board = Game.State.Board; BlockStack srcStack = board[X, Y]; BlockStack destStack = null; if (direction == 1) destStack = board[X, Y - 1]; else if (direction == 2) destStack = board[X + 1, Y]; else if (direction == 3) destStack = board[X, Y + 1]; else if (direction == 4) destStack = board[X - 1, Y]; // Make sure we are still a valid destination if (IsInvalidTarget(srcStack, destStack)) { // We want to reverse the direction, but stay in the // same stack because our destination became // invalid. This works because the code will show them // "bouncing" back. if (direction == 1) direction = 3; else if (direction == 2) direction = 4; else if (direction == 3) direction = 1; else if (direction == 4) direction = 2; // We are done srcStack.Add(this); return; } // Move this block to the next one srcStack.Remove(this); destStack.Add(this); // Change our coordinates if (direction == 1) { BottomPosition -= 4; Y--; } else if (direction == 2) { OffsetX -= 101; X++; } else if (direction == 3) { BottomPosition += 1; Y++; } else if (direction == 4) { OffsetX += 101; X--; } }