Example #1
0
 private void UpdateModSettings()
 {
     FKTModSettings.ModSetting setting;
     if (FKTModSettings.ModSettingsAPI.TryGetModSetting(this, out setting))
     {
         CoinPlayer player = CoinPlayer.GetModPlayer(Main.LocalPlayer);
         setting.Get("bounceAmplitude", ref player.amplitude);
         setting.Get("bounceAmpMult", ref player.ampMult);
         setting.Get("bounceSpeed", ref player.speed);
         setting.Get("bounceOffset", ref player.bounceOffset);
         setting.Get("bounceEvenly", ref player.bounceEvenly);
         setting.Get("bounceModItems", ref player.bounceModItems);
         setting.Get("bouncebyCosine", ref player.byCosine);
     }
 }
Example #2
0
        /*
         * Bouncy coin logic here
         */
        public override bool PreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
        {
            CoinPlayer player = CoinPlayer.GetModPlayer(Main.LocalPlayer);

            // Do not bounce if any of these conditions are true
            if ((!player.bounceModItems && item.modItem != null) ||
                !player.bouncyItems.Contains(item.type) ||
                item.velocity.Length() > 0f)
            {
                return(true);
            }

            // Get coin texture
            Texture2D texture = Main.itemTexture[item.type];

            // Get appropiate keyframe
            var keyFrame = (player.keyFrameActions.ContainsKey(item.type) && player.keyFrameActions[item.type] != null)
                                ? player.keyFrameActions[item.type].Invoke(item, whoAmI)
                                : CoinPlayer.coinKeyFrameAction(item, whoAmI);

            // Logic
            Texture2D animTexture = keyFrame.AnimationTexture;

            rotation = keyFrame.Rotation;
            float offsetY     = item.height - texture.Height;
            float offsetX     = item.width * 0.5f - texture.Width * 0.5f;
            int   frameHeight = keyFrame.FrameHeight;
            // What is our angle for bouncing?
            // If we bounce evenly, all coins bounce based on gametime
            // If not, they will bounce based on their spawntime and whoAmI
            int angle =
                player.bounceEvenly
                                ? (int)Main.time
                                : whoAmI % 60 + item.spawnTime;
            //angle += (int)player.universalOffset;

            Rectangle?frameRect = new Rectangle?(
                new Rectangle(
                    0,
                    Main.itemFrame[whoAmI] * frameHeight + 1,
                    texture.Width,
                    frameHeight
                    ));

            // Do we want to bounce by cosine or sine?
            double bounceByAngle =
                player.byCosine
                                        ? Math.Cos(angle * player.speed / 1000)
                                        : Math.Sin(angle * player.speed / 1000);

            bounceByAngle *= player.amplitude * player.ampMult;

            // Drawing
            Vector2 center = new Vector2(0f, frameHeight * 0.5f);
            Vector2 offset = new Vector2(0f, (float)bounceByAngle - (float)player.amplitude + (float)player.bounceOffset);

            Vector2 pos = new Vector2(item.position.X - Main.screenPosition.X + animTexture.Width * 0.5f + offsetX,
                                      item.position.Y - Main.screenPosition.Y + frameHeight * 0.5f + offsetY)
                          - center + offset;

            Vector2 origin = new Vector2(texture.Width * 0.5f, frameHeight * 0.5f);

            Main.spriteBatch.Draw(animTexture, pos, frameRect, alphaColor, rotation, origin, scale, SpriteEffects.None, 0f);
            return(false);
        }