private void OnListenerTriggered(Sprite player)
 {
     if (ListenerTriggeredEvent != null)
     {
         ListenerTriggeredEvent(this, new ListenerTriggeredEventArgs(player));
     }
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        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();
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <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()
            };
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
 /// <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;
 }
Exemplo n.º 8
0
 /// <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;
 }
Exemplo n.º 10
0
        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;
            }
        }
Exemplo n.º 11
0
 /// <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();
 }
Exemplo n.º 12
0
 public override bool OnEditorDrop(Sprite sprite)
 {
     hadContainedSprite = true;
     return base.OnEditorDrop(sprite);
 }
Exemplo n.º 13
0
 public SpriteCollisionData(Sprite owner)
 {
     Owner = owner;
     SpriteResolvedMovement = Vector2.Zero;
 }
Exemplo n.º 14
0
 public override bool OnEditorDrop(Sprite sprite)
 {
     ContainedSprite = sprite;
     return true;
 }
Exemplo n.º 15
0
 /// <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));
 }
Exemplo n.º 16
0
 protected virtual void BeginRelease(VerticalDirection releaseDirection)
 {
     releasingSprite = CloneSpriteToRelease();
     IsReleasingSprite = true;
     releasingSpriteDirection = releaseDirection;
 }
Exemplo n.º 17
0
 /// <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);
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
 /// <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();
 }
Exemplo n.º 20
0
 /// <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)
 {
 }
Exemplo n.º 21
0
 /// <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)
 {
 }