private void OnListenerTriggered(Sprite player) { if (ListenerTriggeredEvent != null) { ListenerTriggeredEvent(this, new ListenerTriggeredEventArgs(player)); } }
public override void HandleSpriteCollision(Sprite sprite, Vector2 resolutionDistance) { if (sprite.IsPlayer) { Owner.HUDInfo.AddCoins(1); Owner.RemoveSpriteOnNextFrame(this); AudioPlaybackEngine.Instance.PlaySound(collectSound, (sender, e) => { }); } base.HandleSpriteCollision(sprite, resolutionDistance); }
public override void HandleCollision(Sprite sprite, Vector2 intersect) { if (!IsEmpty && hadContainedSprite) { base.HandleCollision(sprite, intersect); } else if (IsEmpty && hadContainedSprite) { return; } else { // This brick block is just a normal brick block and thus can be broken. // TODO: this should only break the block iff the player is Super or higher if (sprite.IsPlayer) { Vector2 playerCenter = sprite.Hitbox.Center; float playerYVelocity = sprite.Velocity.Y; float thisBottom = Hitbox.Bounds.Bottom; float thisTop = Hitbox.Bounds.Top; bool isGroundPounding = sprite.HasAttribute("GroundPounding"); if (playerCenter.Y > thisBottom) { BreakBlock(); } else if (playerCenter.Y < thisTop && isGroundPounding) { BreakBlock(); } } else if (sprite.HasAttribute("ShellSpinning")) { Vector2 spriteCenter = sprite.Hitbox.Center; float spriteXVelocity = sprite.Velocity.X; float thisLeft = Hitbox.Bounds.Left; float thisRight = Hitbox.Bounds.Right; if (spriteCenter.X < thisLeft || spriteCenter.X > thisRight) { BreakBlock(); } } } }
/// <summary> /// Gets the objects for serialization for a given sprite. /// </summary> /// <param name="sprite">The sprite to get the objects for.</param> /// <returns>An anonymous object containing the objects for serialization.</returns> public static object GetSpriteObjects(Sprite sprite) { if (sprite == null) { return null; } return new { typeName = sprite.GetType().FullName, position = sprite.InitialPosition.Serialize(), isActive = sprite.IsActive, state = (int)sprite.InitialState, collision = (int)sprite.TileCollisionMode, name = sprite.Name, message = sprite.Message, isHostile = sprite.IsHostile, isMoving = sprite.IsMoving, direction = (int)sprite.Direction, customObjects = sprite.GetCustomSerializableObjects() }; }
public override void HandleCollision(Sprite sprite, Vector2 intersect) { // The question block is triggered if it's not empty, // if the sprite is a player that hits the block from below // (player.Center beneath Bottom, player's Velocity upward) // or player is ground pounding from above // (player.Center above Top) // or if the sprite has attribute ShellSpinning and hits on the side if (IsEmpty) { return; } if (sprite.IsPlayer) { Vector2 playerCenter = sprite.Hitbox.Center; float playerYVelocity = sprite.Velocity.Y; float thisBottom = Hitbox.Bounds.Bottom; float thisTop = Hitbox.Bounds.Top; bool isGroundPounding = sprite.HasAttribute("GroundPounding"); if (playerCenter.Y > thisBottom) { OnBlockHit(VerticalDirection.Up); } else if (playerCenter.Y < thisTop && isGroundPounding) { OnBlockHit(VerticalDirection.Down); } } else if (sprite.HasAttribute("ShellSpinning")) { Vector2 spriteCenter = sprite.Hitbox.Center; float spriteXVelocity = sprite.Velocity.X; float thisLeft = Hitbox.Bounds.Left; float thisRight = Hitbox.Bounds.Right; if (spriteCenter.X < thisLeft || spriteCenter.X > thisRight) { OnBlockHit(VerticalDirection.Up); } } }
/// <summary> /// Returns the distance to resolve a given colliding sprite by so that /// it will be moved out of this tile. /// </summary> /// <param name="sprite">The sprite to resolve.</param> /// <returns>A resolution containing the distance.</returns> /// <remarks> /// This method accounts for the different tile collision types. /// </remarks> internal virtual Vector2 GetCollisionResolution(Sprite sprite) { if (sprite == null) { throw new ArgumentNullException(nameof(sprite), "The provided sprite was null."); } BoundingRectangle spriteHitbox = (TileShape == CollidableShape.Rectangle) ? sprite.Hitbox : sprite.GetSlopeHitbox(SlopedSides); return Hitbox.GetCollisionResolution(spriteHitbox); }
/// <summary> /// Called when the user drops a sprite onto this tile using the level editor. /// </summary> /// <param name="sprite">The sprite dropped on the tile.</param> /// <returns> /// True if the tile accepted the sprite, false if it did not. /// </returns> public virtual bool OnEditorDrop(Sprite sprite) { return false; }
/// <summary> /// Initializes this component. /// </summary> /// <param name="owner">The sprite that owns this component.</param> public virtual void Initialize(Sprite owner) { Owner = owner; }
public ListenerTriggeredEventArgs(Sprite triggeringSprite) { TriggeringSprite = triggeringSprite; }
protected virtual void EndRelease() { IsReleasingSprite = false; Owner.AddSpriteOnNextFrame(releasingSprite); releasingSprite = null; releaseSpriteProgress = 0f; releasingSpriteDirection = VerticalDirection.None; switch (ReleaseType) { case ItemBlockItemReleaseType.FixedQuantity: Quantity--; if (Quantity == 0) { IsEmpty = true; } break; case ItemBlockItemReleaseType.FixedTime: // TODO: implement break; case ItemBlockItemReleaseType.FixedTimeWithMaximumQuantity: Quantity--; if (Quantity == 0) { IsEmpty = true; } break; case ItemBlockItemReleaseType.FixedTimeWithBonusAction: // TODO: implement break; default: break; } }
/// <summary> /// Handles a collision between this sprite and another. /// </summary> /// <param name="sprite">The sprite that has collided with this one.</param> /// <param name="intersect">The depth of the intersection.</param> public override void HandleSpriteCollision(Sprite sprite, Vector2 intersect) { throw new NotImplementedException(); }
public override bool OnEditorDrop(Sprite sprite) { hadContainedSprite = true; return base.OnEditorDrop(sprite); }
public SpriteCollisionData(Sprite owner) { Owner = owner; SpriteResolvedMovement = Vector2.Zero; }
public override bool OnEditorDrop(Sprite sprite) { ContainedSprite = sprite; return true; }
/// <summary> /// An abstract method which is called when a sprite intersects this tile. /// </summary> /// <param name="sprite">The sprite that intersected this tile.</param> public virtual void HandleCollision(Sprite sprite) { HandleCollision(sprite, Hitbox.GetCollisionResolution(sprite.Hitbox)); }
protected virtual void BeginRelease(VerticalDirection releaseDirection) { releasingSprite = CloneSpriteToRelease(); IsReleasingSprite = true; releasingSpriteDirection = releaseDirection; }
/// <summary> /// Handles a collision between this tile and a sprite. /// </summary> /// <param name="sprite">The sprite that has collided with this tile.</param> /// <param name="intersect">The depth of the intersection.</param> public abstract void HandleCollision(Sprite sprite, Vector2 intersect);
protected virtual void OnBlockHit(VerticalDirection releaseDirection) { if (IsEmpty || IsReleasingSprite) { return; } if (ContainedSprite == null) { return; } releaseDirection = ChangeReleaseDirectionIfNeeded(releaseDirection); // Set the visual displacement. Setting visualDisplacementDirection causes UpdateVisualDisplacement to start automatically. visualDisplacementTarget = MaximumVisualDisplacement.Value; visualDisplacementDirection = releaseDirection; // Clone a sprite and set its properties. releasingSprite = CloneSpriteToRelease(); releaseSpriteProgress = 0f; }
/// <summary> /// Determines if a given sprite intersects this tile. /// </summary> /// <param name="sprite">The sprite to check.</param> /// <returns> /// True if the sprite intersects this tile, false if otherwise. /// </returns> /// <remarks> /// This method accounts for the different tile collision types. /// </remarks> public virtual bool Intersects(Sprite sprite) { throw new NotImplementedException(); }
/// <summary> /// Handles a collision between this tile and a sprite. /// </summary> /// <param name="sprite">The sprite that collided with this tile.</param> /// <param name="intersect">The depth of the intersection.</param> public override void HandleCollision(Sprite sprite, Vector2 intersect) { }
/// <summary> /// A method called when the owner sprite collides with another sprite. /// </summary> /// <param name="collidingSprite"> /// The sprite that the owner sprite collided with. /// </param> /// <param name="resolutionDistance"> /// The distance by which the sprite was moved in order to resolve the /// sprite collision. /// </param> public virtual void HandleSpriteCollision(Sprite collidingSprite, Vector2 resolutionDistance) { }