Exemple #1
0
        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            Vector2 playerCenter = Main.player[projectile.owner].Center;
            Vector2 center       = projectile.Center;
            Vector2 distToProj   = playerCenter - projectile.Center;
            float   rotation     = distToProj.RotatedBy(MathHelper.ToRadians(180f)).ToRotation();
            float   distance     = distToProj.Length();

            Texture2D texture       = Main.projectileTexture[projectile.type];
            Rectangle rectangle     = new Rectangle(0, 0, 10, 22);
            Rectangle hookRectangle = new Rectangle(10, 0, 26, 22);

            while (distance >= hookRectangle.Width * 0.5f && !float.IsNaN(distance))
            {
                distToProj.Normalize();
                distToProj *= rectangle.Width;
                center     += distToProj;
                distToProj  = playerCenter - center;
                distance    = distToProj.Length();
                Color chainColor = PAFMUtils.LightAtPosition(center);

                spriteBatch.Draw(texture, center - Main.screenPosition, rectangle, chainColor, rotation, rectangle.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f);
            }

            spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, hookRectangle, lightColor, rotation, hookRectangle.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f);

            return(false);
        }
        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            Texture2D texture = Main.projectileTexture[projectile.type];
            Color     color   = lightColor;

            // Some rectangle presets for different parts of the chain.
            Rectangle chainHandle  = new Rectangle(0, 2, texture.Width, 40);
            Rectangle chainLinkEnd = new Rectangle(0, 68, texture.Width, 18);
            Rectangle chainLink    = new Rectangle(0, 46, texture.Width, 18);
            Rectangle chainHead    = new Rectangle(0, 90, texture.Width, 48);

            // If the chain isn't moving, stop drawing all of its components.
            if (projectile.velocity == Vector2.Zero)
            {
                return(false);
            }
            float     chainDistance = projectile.velocity.Length() + 16f;
            bool      distanceCheck = chainDistance < 100f;
            Vector2   direction     = Vector2.Normalize(projectile.velocity);
            Rectangle rectangle     = chainHandle;
            Vector2   yOffset       = new Vector2(0f, Main.player[projectile.owner].gfxOffY);
            float     rotation      = direction.ToRotation() + MathHelper.ToRadians(-90f);

            spriteBatch.Draw(texture, projectile.Center - Main.screenPosition + yOffset, rectangle, color, rotation, rectangle.Size() / 2f - Vector2.UnitY * 4f, projectile.scale, SpriteEffects.None, 0f);
            chainDistance -= 40f * projectile.scale;
            Vector2 position = projectile.Center;

            position += direction * projectile.scale * 24f;
            rectangle = chainLinkEnd;
            if (chainDistance > 0f)
            {
                float chains = 0f;
                while (chains + 1f < chainDistance)
                {
                    if (chainDistance - chains < rectangle.Height)
                    {
                        rectangle.Height = (int)(chainDistance - chains);
                    }
                    spriteBatch.Draw(texture, position - Main.screenPosition + yOffset, rectangle, PAFMUtils.LightAtPosition(position), rotation, new Vector2(rectangle.Width / 2, 0f), projectile.scale, SpriteEffects.None, 0f);
                    chains   += rectangle.Height * projectile.scale;
                    position += direction * rectangle.Height * projectile.scale;
                }
            }
            Vector2 chainEnd = position;

            position  = projectile.Center;
            position += direction * projectile.scale * 24f;
            rectangle = chainLink;
            int   offset            = distanceCheck ? 9 : 18;
            float chainLinkDistance = chainDistance;

            if (chainDistance > 0f)
            {
                float chains    = 0f;
                float increment = chainLinkDistance / offset;
                chains   += increment * 0.25f;
                position += direction * increment * 0.25f;
                for (int i = 0; i < offset; i++)
                {
                    float spacing = increment;
                    if (i == 0)
                    {
                        spacing *= 0.75f;
                    }
                    spriteBatch.Draw(texture, position - Main.screenPosition + yOffset, rectangle, PAFMUtils.LightAtPosition(position), rotation, new Vector2(rectangle.Width / 2, 0f), projectile.scale, SpriteEffects.None, 0f);
                    chains   += spacing;
                    position += direction * spacing;
                }
            }
            rectangle = chainHead;
            spriteBatch.Draw(texture, chainEnd - Main.screenPosition + yOffset, rectangle, PAFMUtils.LightAtPosition(chainEnd), rotation, texture.Frame().Top(), projectile.scale, SpriteEffects.None, 0f);
            chainHeadPosition = chainEnd;

            return(false);
        }