Terraria.Player.HorizontalMovement C# (CSharp) Method

HorizontalMovement() public method

public HorizontalMovement ( ) : void
return void
        public void HorizontalMovement()
        {
            if (this.chilled)
                this.accRunSpeed = this.maxRunSpeed;
            bool flag = (this.itemAnimation == 0 || this.inventory[this.selectedItem].useTurn) && this.mount.AllowDirectionChange;
            if ((double)this.trackBoost != 0.0)
            {
                this.velocity.X += this.trackBoost;
                this.trackBoost = 0.0f;
                if ((double)this.velocity.X < 0.0)
                {
                    if ((double)this.velocity.X < -(double)this.maxRunSpeed)
                        this.velocity.X = -this.maxRunSpeed;
                }
                else if ((double)this.velocity.X > (double)this.maxRunSpeed)
                    this.velocity.X = this.maxRunSpeed;
            }
            if (this.controlLeft && (double)this.velocity.X > -(double)this.maxRunSpeed)
            {
                if (!this.mount.Active || !this.mount.Cart || (double)this.velocity.Y == 0.0)
                {
                    if ((double)this.velocity.X > (double)this.runSlowdown)
                        this.velocity.X -= this.runSlowdown;
                    this.velocity.X -= this.runAcceleration;
                }
                if (this.onWrongGround)
                {
                    if ((double)this.velocity.X < -(double)this.runSlowdown)
                        this.velocity.X += this.runSlowdown;
                    else
                        this.velocity.X = 0.0f;
                }
                if (this.mount.Active && this.mount.Cart && !this.onWrongGround)
                {
                    if ((double)this.velocity.X < 0.0 && flag)
                        this.direction = -1;
                    else if (this.itemAnimation <= 0 && (double)this.velocity.Y == 0.0)
                    {
                        Main.PlaySound(2, (int)this.position.X + this.width / 2, (int)this.position.Y + this.height / 2, 55);
                        DelegateMethods.Minecart.rotation = this.fullRotation;
                        DelegateMethods.Minecart.rotationOrigin = this.fullRotationOrigin;
                        if ((double)Math.Abs(this.velocity.X) > (double)this.maxRunSpeed * 0.66)
                        {
                            if (Main.rand.Next(2) == 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position + this.velocity * 0.66f, this.width, this.height, 1);
                            if (Main.rand.Next(2) == 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position + this.velocity * 0.33f, this.width, this.height, 1);
                            if (Main.rand.Next(2) == 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 1);
                        }
                        else if ((double)Math.Abs(this.velocity.X) > (double)this.maxRunSpeed * 0.33)
                        {
                            if (Main.rand.Next(3) != 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position + this.velocity * 0.5f, this.width, this.height, 1);
                            if (Main.rand.Next(3) != 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 1);
                        }
                        else
                            Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 1);
                    }
                }
                else if (!this.sandStorm && (this.itemAnimation == 0 || this.inventory[this.selectedItem].useTurn) && this.mount.AllowDirectionChange)
                    this.direction = -1;
            }
            else if (this.controlRight && (double)this.velocity.X < (double)this.maxRunSpeed)
            {
                if (!this.mount.Active || !this.mount.Cart || (double)this.velocity.Y == 0.0)
                {
                    if ((double)this.velocity.X < -(double)this.runSlowdown)
                        this.velocity.X += this.runSlowdown;
                    this.velocity.X += this.runAcceleration;
                }
                if (this.onWrongGround)
                {
                    if ((double)this.velocity.X > (double)this.runSlowdown)
                        this.velocity.X -= this.runSlowdown;
                    else
                        this.velocity.X = 0.0f;
                }
                if (this.mount.Active && this.mount.Cart && !this.onWrongGround)
                {
                    if ((double)this.velocity.X > 0.0 && flag)
                        this.direction = 1;
                    else if (this.itemAnimation <= 0 && (double)this.velocity.Y == 0.0)
                    {
                        Main.PlaySound(2, (int)this.position.X + this.width / 2, (int)this.position.Y + this.height / 2, 55);
                        DelegateMethods.Minecart.rotation = this.fullRotation;
                        DelegateMethods.Minecart.rotationOrigin = this.fullRotationOrigin;
                        if ((double)Math.Abs(this.velocity.X) > (double)this.maxRunSpeed * 0.66)
                        {
                            if (Main.rand.Next(2) == 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position + this.velocity * 0.66f, this.width, this.height, 1);
                            if (Main.rand.Next(2) == 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position + this.velocity * 0.33f, this.width, this.height, 1);
                            if (Main.rand.Next(2) == 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 1);
                        }
                        else if ((double)Math.Abs(this.velocity.X) > (double)this.maxRunSpeed * 0.33)
                        {
                            if (Main.rand.Next(3) != 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position + this.velocity * 0.5f, this.width, this.height, 1);
                            if (Main.rand.Next(3) != 0)
                                Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 1);
                        }
                        else
                            Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 1);
                    }
                }
                else if (!this.sandStorm && (this.itemAnimation == 0 || this.inventory[this.selectedItem].useTurn) && this.mount.AllowDirectionChange)
                    this.direction = 1;
            }
            else if (this.controlLeft && (double)this.velocity.X > -(double)this.accRunSpeed && this.dashDelay >= 0)
            {
                if (this.mount.Active && this.mount.Cart)
                {
                    if ((double)this.velocity.X < 0.0)
                        this.direction = -1;
                }
                else if ((this.itemAnimation == 0 || this.inventory[this.selectedItem].useTurn) && this.mount.AllowDirectionChange)
                    this.direction = -1;
                if ((double)this.velocity.Y == 0.0 || this.wingsLogic > 0 || this.mount.CanFly)
                {
                    if ((double)this.velocity.X > (double)this.runSlowdown)
                        this.velocity.X -= this.runSlowdown;
                    this.velocity.X -= this.runAcceleration * 0.2f;
                    if (this.wingsLogic > 0)
                        this.velocity.X -= this.runAcceleration * 0.2f;
                }
                if (this.onWrongGround)
                {
                    if ((double)this.velocity.X < (double)this.runSlowdown)
                        this.velocity.X += this.runSlowdown;
                    else
                        this.velocity.X = 0.0f;
                }
                if ((double)this.velocity.X < -((double)this.accRunSpeed + (double)this.maxRunSpeed) / 2.0 && (double)this.velocity.Y == 0.0 && !this.mount.Active)
                {
                    int num = 0;
                    if ((double)this.gravDir == -1.0)
                        num -= this.height;
                    if (this.runSoundDelay == 0 && (double)this.velocity.Y == 0.0)
                    {
                        Main.PlaySound(17, (int)this.position.X, (int)this.position.Y, 1);
                        this.runSoundDelay = 9;
                    }
                    if (this.wings == 3)
                    {
                        int index1 = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y + (float)this.height + (float)num), this.width + 8, 4, 186, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 50, new Color(), 1.5f);
                        Main.dust[index1].velocity *= 0.025f;
                        Main.dust[index1].shader = GameShaders.Armor.GetSecondaryShader(this.cWings, this);
                        int index2 = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y + (float)this.height + (float)num), this.width + 8, 4, 186, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 50, new Color(), 1.5f);
                        Main.dust[index2].velocity *= 0.2f;
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cWings, this);
                    }
                    else if (this.sailDash)
                    {
                        for (int index1 = 0; index1 < 4; ++index1)
                        {
                            int index2 = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y), this.width + 8, this.height, 253, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 100, new Color(), 1.5f);
                            Main.dust[index2].noGravity = true;
                            Main.dust[index2].velocity.X = Main.dust[index2].velocity.X * 0.2f;
                            Main.dust[index2].velocity.Y = Main.dust[index2].velocity.Y * 0.2f;
                            Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                            Main.dust[index2].scale += (float)Main.rand.Next(-5, 3) * 0.1f;
                            Vector2 vector2 = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101));
                            vector2.Normalize();
                            vector2 *= (float)Main.rand.Next(81) * 0.1f;
                        }
                    }
                    else if (this.coldDash)
                    {
                        for (int index1 = 0; index1 < 2; ++index1)
                        {
                            int index2 = index1 != 0 ? Dust.NewDust(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)this.height + this.gfxOffY), this.width / 2, 6, 76, 0.0f, 0.0f, 0, new Color(), 1.35f) : Dust.NewDust(new Vector2(this.position.X, this.position.Y + (float)this.height + this.gfxOffY), this.width / 2, 6, 76, 0.0f, 0.0f, 0, new Color(), 1.35f);
                            Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20, 40) * 0.00999999977648258);
                            Main.dust[index2].noGravity = true;
                            Main.dust[index2].noLight = true;
                            Main.dust[index2].velocity *= 1.0f / 1000.0f;
                            Main.dust[index2].velocity.Y -= 3.0f / 1000.0f;
                            Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                        }
                    }
                    else
                    {
                        int index = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y + (float)this.height + (float)num), this.width + 8, 4, 16, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 50, new Color(), 1.5f);
                        Main.dust[index].velocity.X = Main.dust[index].velocity.X * 0.2f;
                        Main.dust[index].velocity.Y = Main.dust[index].velocity.Y * 0.2f;
                        Main.dust[index].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                    }
                }
            }
            else if (this.controlRight && (double)this.velocity.X < (double)this.accRunSpeed && this.dashDelay >= 0)
            {
                if (this.mount.Active && this.mount.Cart)
                {
                    if ((double)this.velocity.X > 0.0)
                        this.direction = -1;
                }
                else if ((this.itemAnimation == 0 || this.inventory[this.selectedItem].useTurn) && this.mount.AllowDirectionChange)
                    this.direction = 1;
                if ((double)this.velocity.Y == 0.0 || this.wingsLogic > 0 || this.mount.CanFly)
                {
                    if ((double)this.velocity.X < -(double)this.runSlowdown)
                        this.velocity.X += this.runSlowdown;
                    this.velocity.X += this.runAcceleration * 0.2f;
                    if (this.wingsLogic > 0)
                        this.velocity.X += this.runAcceleration * 0.2f;
                }
                if (this.onWrongGround)
                {
                    if ((double)this.velocity.X > (double)this.runSlowdown)
                        this.velocity.X -= this.runSlowdown;
                    else
                        this.velocity.X = 0.0f;
                }
                if ((double)this.velocity.X > ((double)this.accRunSpeed + (double)this.maxRunSpeed) / 2.0 && (double)this.velocity.Y == 0.0 && !this.mount.Active)
                {
                    int num = 0;
                    if ((double)this.gravDir == -1.0)
                        num -= this.height;
                    if (this.runSoundDelay == 0 && (double)this.velocity.Y == 0.0)
                    {
                        Main.PlaySound(17, (int)this.position.X, (int)this.position.Y, 1);
                        this.runSoundDelay = 9;
                    }
                    if (this.wings == 3)
                    {
                        int index1 = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y + (float)this.height + (float)num), this.width + 8, 4, 186, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 50, new Color(), 1.5f);
                        Main.dust[index1].velocity *= 0.025f;
                        Main.dust[index1].shader = GameShaders.Armor.GetSecondaryShader(this.cWings, this);
                        int index2 = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y + (float)this.height + (float)num), this.width + 8, 4, 186, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 50, new Color(), 1.5f);
                        Main.dust[index2].velocity *= 0.2f;
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cWings, this);
                    }
                    else if (this.sailDash)
                    {
                        for (int index1 = 0; index1 < 4; ++index1)
                        {
                            int index2 = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y), this.width + 8, this.height, 253, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 100, new Color(), 1.5f);
                            Main.dust[index2].noGravity = true;
                            Main.dust[index2].velocity.X = Main.dust[index2].velocity.X * 0.2f;
                            Main.dust[index2].velocity.Y = Main.dust[index2].velocity.Y * 0.2f;
                            Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                            Main.dust[index2].scale += (float)Main.rand.Next(-5, 3) * 0.1f;
                            Vector2 vector2 = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101));
                            vector2.Normalize();
                            vector2 *= (float)Main.rand.Next(81) * 0.1f;
                        }
                    }
                    else if (this.coldDash)
                    {
                        for (int index1 = 0; index1 < 2; ++index1)
                        {
                            int index2 = index1 != 0 ? Dust.NewDust(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)this.height + this.gfxOffY), this.width / 2, 6, 76, 0.0f, 0.0f, 0, new Color(), 1.35f) : Dust.NewDust(new Vector2(this.position.X, this.position.Y + (float)this.height + this.gfxOffY), this.width / 2, 6, 76, 0.0f, 0.0f, 0, new Color(), 1.35f);
                            Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20, 40) * 0.00999999977648258);
                            Main.dust[index2].noGravity = true;
                            Main.dust[index2].noLight = true;
                            Main.dust[index2].velocity *= 1.0f / 1000.0f;
                            Main.dust[index2].velocity.Y -= 3.0f / 1000.0f;
                            Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                        }
                    }
                    else
                    {
                        int index = Dust.NewDust(new Vector2(this.position.X - 4f, this.position.Y + (float)this.height + (float)num), this.width + 8, 4, 16, (float)(-(double)this.velocity.X * 0.5), this.velocity.Y * 0.5f, 50, new Color(), 1.5f);
                        Main.dust[index].velocity.X = Main.dust[index].velocity.X * 0.2f;
                        Main.dust[index].velocity.Y = Main.dust[index].velocity.Y * 0.2f;
                        Main.dust[index].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                    }
                }
            }
            else if (this.mount.Active && this.mount.Cart && (double)Math.Abs(this.velocity.X) >= 1.0)
            {
                if (this.onWrongGround)
                {
                    if ((double)this.velocity.X > 0.0)
                    {
                        if ((double)this.velocity.X > (double)this.runSlowdown)
                            this.velocity.X -= this.runSlowdown;
                        else
                            this.velocity.X = 0.0f;
                    }
                    else if ((double)this.velocity.X < 0.0)
                    {
                        if ((double)this.velocity.X < -(double)this.runSlowdown)
                            this.velocity.X += this.runSlowdown;
                        else
                            this.velocity.X = 0.0f;
                    }
                }
                if ((double)this.velocity.X > (double)this.maxRunSpeed)
                    this.velocity.X = this.maxRunSpeed;
                if ((double)this.velocity.X < -(double)this.maxRunSpeed)
                    this.velocity.X = -this.maxRunSpeed;
            }
            else if ((double)this.velocity.Y == 0.0)
            {
                if ((double)this.velocity.X > (double)this.runSlowdown)
                    this.velocity.X -= this.runSlowdown;
                else if ((double)this.velocity.X < -(double)this.runSlowdown)
                    this.velocity.X += this.runSlowdown;
                else
                    this.velocity.X = 0.0f;
            }
            else if (!this.PortalPhysicsEnabled)
            {
                if ((double)this.velocity.X > (double)this.runSlowdown * 0.5)
                    this.velocity.X -= this.runSlowdown * 0.5f;
                else if ((double)this.velocity.X < -(double)this.runSlowdown * 0.5)
                    this.velocity.X += this.runSlowdown * 0.5f;
                else
                    this.velocity.X = 0.0f;
            }
            if (!this.mount.Active || this.mount.Type != 10 || (double)Math.Abs(this.velocity.X) <= (double)this.mount.DashSpeed - (double)this.mount.RunSpeed / 2.0)
                return;
            Microsoft.Xna.Framework.Rectangle rect1 = this.getRect();
            if (this.direction == 1)
                rect1.Offset(this.width - 1, 0);
            rect1.Width = 2;
            rect1.Inflate(6, 12);
            for (int number = 0; number < 200; ++number)
            {
                NPC npc = Main.npc[number];
                if (npc.active && !npc.dontTakeDamage && (!npc.friendly && npc.immune[this.whoAmI] == 0))
                {
                    Microsoft.Xna.Framework.Rectangle rect2 = npc.getRect();
                    if (rect1.Intersects(rect2) && (npc.noTileCollide || Collision.CanHit(this.position, this.width, this.height, npc.position, npc.width, npc.height)))
                    {
                        float number2 = 80f * this.minionDamage;
                        float num = 10f;
                        int hitDirection = this.direction;
                        if ((double)this.velocity.X < 0.0)
                            hitDirection = -1;
                        if ((double)this.velocity.X > 0.0)
                            hitDirection = 1;
                        if (this.whoAmI == Main.myPlayer)
                        {
                            npc.StrikeNPC((int)number2, num, hitDirection, false, false, false);
                            if (Main.netMode != 0)
                                NetMessage.SendData(28, -1, -1, "", number, number2, num, (float)hitDirection, 0, 0, 0);
                        }
                        npc.immune[this.whoAmI] = 30;
                        this.immune = true;
                        this.immuneTime = 6;
                        break;
                    }
                }
            }
        }
Player