コード例 #1
0
        public override void MeleeEffects(Player player, Rectangle hitbox)
        {
            if (blade.effect != null)
            {
                blade.effect(hitbox, player);
            }

            if (accent.effect != null)
            {
                accent.effect(hitbox, player);
            }
        }
コード例 #2
0
        // It appears that for this AI, only the ai0 field is used!

        public override void AI()
        {
            try
            {
                // Since we access the owner player instance so much, it's useful to create a helper local variable for this
                // Sadly, Projectile/ModProjectile does not have its own
                Player projOwner = Main.player[projectile.owner];
                // Here we set some of the projectile's owner properties, such as held item and itemtime, along with projectile directio and position based on the player
                //Vector2 ownerMountedCenter = projOwner.RotatedRelativePoint(projOwner.MountedCenter, true);

                if (projectile.velocity.X > 0)
                {
                    projOwner.direction = 1;
                }
                else
                {
                    projOwner.direction = -1;
                }

                projectile.direction       = projOwner.direction;
                projectile.spriteDirection = projectile.direction;
                projOwner.heldProj         = projectile.whoAmI;
                projOwner.itemTime         = projOwner.itemAnimation;
                projectile.position.X      = projOwner.Center.X - (float)(texture.Width / 2) /* + 2f*projOwner.direction*/;
                projectile.position.Y      = projOwner.Center.Y - (float)(texture.Height / 2) /* + 4f*/;
                // As long as the player isn't frozen, the spear can move
                if (!projOwner.frozen)
                {
                    if (movementFactor == 0f) // When intially thrown out, the ai0 will be 0f
                    {
                        movementFactor       = 3f;
                        projectile.netUpdate = true;
                    }
                    if (projOwner.itemAnimation < projOwner.itemAnimationMax / 3)
                    {
                        movementFactor -= 2.4f;
                    }
                    else
                    {
                        movementFactor += 2.1f;
                    }
                }

                projectile.position += projectile.velocity * movementFactor;
                Vector2 unitVelocity = projectile.velocity;
                unitVelocity.Normalize();
                projectile.position += unitVelocity * (blade.origin.Y * 2.8f + 8f);

                if (projOwner.itemAnimation == 1)
                {
                    projectile.Kill();
                }
                // Apply proper rotation, with an offset of 135 degrees due to the sprite's rotation, notice the usage of MathHelper, use this class!
                // MathHelper.ToRadians(xx degrees here)
                projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + MathHelper.ToRadians(45f);
                // Offset by 90 degrees here
                if (projectile.spriteDirection == -1)
                {
                    projectile.rotation += MathHelper.ToRadians(90f);
                }

                Rectangle rect = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, texture.Width, texture.Height);
                if (blade.effect != null)
                {
                    blade.effect(rect, projOwner);
                }
                if (accent.effect != null)
                {
                    accent.effect(rect, projOwner);
                }
            }
            catch (SystemException e)
            {
                Main.NewText(e.ToString());
            }
        }