Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ HorizontalMovement()

void Terraria.Player.HorizontalMovement ( )
inline

Definition at line 19152 of file Player.cs.

19153 {
19154 if (chilled)
19155 {
19157 }
19159 bool flag2 = controlLeft || controlRight;
19160 float num = (accRunSpeed + maxRunSpeed) / 2f;
19161 float num2 = 0f;
19162 bool flag3 = false;
19163 if (flag2 && mount.Active && mount.Type == 43 && velocity.Y == 0f && !controlJump)
19164 {
19166 float num3 = jumpSpeed * gravDir * 0.5f;
19167 if (num3 < 2f)
19168 {
19169 num3 = 2f;
19170 }
19171 num3 += 0.01f;
19172 velocity.Y = 0f - num3;
19173 jump = jumpHeight;
19174 fullRotation = 0f;
19175 return;
19176 }
19177 if (windPushed && !isLockedToATile && !(mount.Active && velocity.Y == 0f && flag2))
19178 {
19179 num2 = (float)Math.Sign(Main.windSpeedCurrent) * 0.06f;
19180 if (Math.Abs(Main.windSpeedCurrent) > 0.5f)
19181 {
19182 num2 *= 1.37f;
19183 }
19184 if (velocity.Y != 0f)
19185 {
19186 num2 *= 1.5f;
19187 }
19188 if (flag2)
19189 {
19190 num2 *= 0.8f;
19191 float num4 = 0.072f;
19192 num2 = MathHelper.Clamp(num2, 0f - num4, num4);
19193 }
19194 flag3 = true;
19195 if (Math.Sign(direction) != Math.Sign(num2))
19196 {
19197 num -= Math.Abs(num2) * 40f;
19198 }
19199 }
19200 if (trackBoost != 0f)
19201 {
19202 velocity.X += trackBoost;
19203 trackBoost = 0f;
19204 if (velocity.X < 0f)
19205 {
19206 if (velocity.X < 0f - maxRunSpeed)
19207 {
19208 velocity.X = 0f - maxRunSpeed;
19209 }
19210 }
19211 else if (velocity.X > maxRunSpeed)
19212 {
19213 velocity.X = maxRunSpeed;
19214 }
19215 }
19216 if (controlLeft && velocity.X > 0f - maxRunSpeed)
19217 {
19218 if (!mount.Active || !mount.Cart || velocity.Y == 0f)
19219 {
19220 if (velocity.X > runSlowdown)
19221 {
19222 velocity.X -= runSlowdown;
19223 }
19224 velocity.X -= runAcceleration;
19225 }
19226 if (onWrongGround)
19227 {
19228 if (velocity.X < 0f - runSlowdown)
19229 {
19230 velocity.X += runSlowdown;
19231 }
19232 else
19233 {
19234 velocity.X = 0f;
19235 }
19236 }
19237 if (mount.Active && mount.Cart && !onWrongGround)
19238 {
19239 if (velocity.X < 0f && flag)
19240 {
19241 direction = -1;
19242 }
19243 else if (itemAnimation <= 0 && velocity.Y == 0f)
19244 {
19245 SoundEngine.PlaySound(SoundID.Item55, (int)position.X + width / 2, (int)position.Y + height / 2);
19246 DelegateMethods.Minecart.rotation = fullRotation;
19247 DelegateMethods.Minecart.rotationOrigin = fullRotationOrigin;
19248 if ((double)Math.Abs(velocity.X) > (double)maxRunSpeed * 0.66)
19249 {
19250 if (Main.rand.Next(2) == 0)
19251 {
19252 Minecart.WheelSparks(mount.Delegations.MinecartDust, position + velocity * 0.66f, width, height, 1);
19253 }
19254 if (Main.rand.Next(2) == 0)
19255 {
19256 Minecart.WheelSparks(mount.Delegations.MinecartDust, position + velocity * 0.33f, width, height, 1);
19257 }
19258 if (Main.rand.Next(2) == 0)
19259 {
19260 Minecart.WheelSparks(mount.Delegations.MinecartDust, position, width, height, 1);
19261 }
19262 }
19263 else if ((double)Math.Abs(velocity.X) > (double)maxRunSpeed * 0.33)
19264 {
19265 if (Main.rand.Next(3) != 0)
19266 {
19267 Minecart.WheelSparks(mount.Delegations.MinecartDust, position + velocity * 0.5f, width, height, 1);
19268 }
19269 if (Main.rand.Next(3) != 0)
19270 {
19271 Minecart.WheelSparks(mount.Delegations.MinecartDust, position, width, height, 1);
19272 }
19273 }
19274 else
19275 {
19276 Minecart.WheelSparks(mount.Delegations.MinecartDust, position, width, height, 1);
19277 }
19278 }
19279 }
19280 else if (!sandStorm && (itemAnimation == 0 || inventory[selectedItem].useTurn) && mount.AllowDirectionChange)
19281 {
19282 direction = -1;
19283 }
19284 }
19285 else if (controlRight && velocity.X < maxRunSpeed)
19286 {
19287 if (!mount.Active || !mount.Cart || velocity.Y == 0f)
19288 {
19289 if (velocity.X < 0f - runSlowdown)
19290 {
19291 velocity.X += runSlowdown;
19292 }
19293 velocity.X += runAcceleration;
19294 }
19295 if (onWrongGround)
19296 {
19297 if (velocity.X > runSlowdown)
19298 {
19299 velocity.X -= runSlowdown;
19300 }
19301 else
19302 {
19303 velocity.X = 0f;
19304 }
19305 }
19306 if (mount.Active && mount.Cart && !onWrongGround)
19307 {
19308 if (velocity.X > 0f && flag)
19309 {
19310 direction = 1;
19311 }
19312 else if (itemAnimation <= 0 && velocity.Y == 0f)
19313 {
19314 SoundEngine.PlaySound(SoundID.Item55, (int)position.X + width / 2, (int)position.Y + height / 2);
19315 DelegateMethods.Minecart.rotation = fullRotation;
19316 DelegateMethods.Minecart.rotationOrigin = fullRotationOrigin;
19317 if ((double)Math.Abs(velocity.X) > (double)maxRunSpeed * 0.66)
19318 {
19319 if (Main.rand.Next(2) == 0)
19320 {
19321 Minecart.WheelSparks(mount.Delegations.MinecartDust, position + velocity * 0.66f, width, height, 1);
19322 }
19323 if (Main.rand.Next(2) == 0)
19324 {
19325 Minecart.WheelSparks(mount.Delegations.MinecartDust, position + velocity * 0.33f, width, height, 1);
19326 }
19327 if (Main.rand.Next(2) == 0)
19328 {
19329 Minecart.WheelSparks(mount.Delegations.MinecartDust, position, width, height, 1);
19330 }
19331 }
19332 else if ((double)Math.Abs(velocity.X) > (double)maxRunSpeed * 0.33)
19333 {
19334 if (Main.rand.Next(3) != 0)
19335 {
19336 Minecart.WheelSparks(mount.Delegations.MinecartDust, position + velocity * 0.5f, width, height, 1);
19337 }
19338 if (Main.rand.Next(3) != 0)
19339 {
19340 Minecart.WheelSparks(mount.Delegations.MinecartDust, position, width, height, 1);
19341 }
19342 }
19343 else
19344 {
19345 Minecart.WheelSparks(mount.Delegations.MinecartDust, position, width, height, 1);
19346 }
19347 }
19348 }
19349 else if (!sandStorm && (itemAnimation == 0 || inventory[selectedItem].useTurn) && mount.AllowDirectionChange)
19350 {
19351 direction = 1;
19352 }
19353 }
19354 else if (controlLeft && velocity.X > 0f - accRunSpeed && dashDelay >= 0)
19355 {
19356 if (mount.Active && mount.Cart)
19357 {
19358 if (velocity.X < 0f)
19359 {
19360 direction = -1;
19361 }
19362 }
19363 else if ((itemAnimation == 0 || inventory[selectedItem].useTurn) && mount.AllowDirectionChange)
19364 {
19365 direction = -1;
19366 }
19367 if (velocity.Y == 0f || wingsLogic > 0 || mount.CanFly())
19368 {
19369 if (velocity.X > runSlowdown)
19370 {
19371 velocity.X -= runSlowdown;
19372 }
19373 velocity.X -= runAcceleration * 0.2f;
19374 if (wingsLogic > 0)
19375 {
19376 velocity.X -= runAcceleration * 0.2f;
19377 }
19378 }
19379 if (onWrongGround)
19380 {
19381 if (velocity.X < runSlowdown)
19382 {
19383 velocity.X += runSlowdown;
19384 }
19385 else
19386 {
19387 velocity.X = 0f;
19388 }
19389 }
19390 if (velocity.X < 0f - num && velocity.Y == 0f && !mount.Active)
19391 {
19393 }
19394 }
19395 else if (controlRight && velocity.X < accRunSpeed && dashDelay >= 0)
19396 {
19397 if (mount.Active && mount.Cart)
19398 {
19399 if (velocity.X > 0f)
19400 {
19401 direction = -1;
19402 }
19403 }
19404 else if ((itemAnimation == 0 || inventory[selectedItem].useTurn) && mount.AllowDirectionChange)
19405 {
19406 direction = 1;
19407 }
19408 if (velocity.Y == 0f || wingsLogic > 0 || mount.CanFly())
19409 {
19410 if (velocity.X < 0f - runSlowdown)
19411 {
19412 velocity.X += runSlowdown;
19413 }
19414 velocity.X += runAcceleration * 0.2f;
19415 if (wingsLogic > 0)
19416 {
19417 velocity.X += runAcceleration * 0.2f;
19418 }
19419 }
19420 if (onWrongGround)
19421 {
19422 if (velocity.X > runSlowdown)
19423 {
19424 velocity.X -= runSlowdown;
19425 }
19426 else
19427 {
19428 velocity.X = 0f;
19429 }
19430 }
19431 if (velocity.X > num && velocity.Y == 0f && !mount.Active)
19432 {
19434 }
19435 }
19436 else if (mount.Active && mount.Cart && Math.Abs(velocity.X) >= 1f)
19437 {
19438 if (onWrongGround)
19439 {
19440 if (velocity.X > 0f)
19441 {
19442 if (velocity.X > runSlowdown)
19443 {
19444 velocity.X -= runSlowdown;
19445 }
19446 else
19447 {
19448 velocity.X = 0f;
19449 }
19450 }
19451 else if (velocity.X < 0f)
19452 {
19453 if (velocity.X < 0f - runSlowdown)
19454 {
19455 velocity.X += runSlowdown;
19456 }
19457 else
19458 {
19459 velocity.X = 0f;
19460 }
19461 }
19462 }
19463 if (velocity.X > maxRunSpeed)
19464 {
19465 velocity.X = maxRunSpeed;
19466 }
19467 if (velocity.X < 0f - maxRunSpeed)
19468 {
19469 velocity.X = 0f - maxRunSpeed;
19470 }
19471 }
19472 else if (velocity.Y == 0f)
19473 {
19474 if (velocity.X > runSlowdown)
19475 {
19476 velocity.X -= runSlowdown;
19477 }
19478 else if (velocity.X < 0f - runSlowdown)
19479 {
19480 velocity.X += runSlowdown;
19481 }
19482 else
19483 {
19484 velocity.X = 0f;
19485 }
19486 }
19487 else if (!PortalPhysicsEnabled)
19488 {
19489 if ((double)velocity.X > (double)runSlowdown * 0.5)
19490 {
19491 velocity.X -= runSlowdown * 0.5f;
19492 }
19493 else if ((double)velocity.X < (double)(0f - runSlowdown) * 0.5)
19494 {
19495 velocity.X += runSlowdown * 0.5f;
19496 }
19497 else
19498 {
19499 velocity.X = 0f;
19500 }
19501 }
19502 if (flag3)
19503 {
19505 {
19506 velocity.X += num2;
19507 if (velocity.X < num2)
19508 {
19509 velocity.X = num2;
19510 }
19511 }
19512 if (num2 > 0f && velocity.X < num2)
19513 {
19514 velocity.X += num2;
19515 if (velocity.X > num2)
19516 {
19517 velocity.X = num2;
19518 }
19519 }
19520 }
19521 bool flag4 = mount.Type == 40 || mount.Type == 41 || mount.Type == 42;
19522 if (mount.Active && (mount.Type == 10 || mount.Type == 47 || flag4) && Math.Abs(velocity.X) > mount.DashSpeed - mount.RunSpeed / 2f)
19523 {
19525 if (direction == 1)
19526 {
19527 rect.Offset(width - 1, 0);
19528 }
19529 rect.Width = 2;
19530 rect.Inflate(6, 12);
19531 int num5 = 60;
19532 if (flag4)
19533 {
19534 num5 = 30;
19535 }
19536 float damage = (float)num5 * minionDamage;
19537 float knockback = 10f;
19538 if (flag4)
19539 {
19540 knockback = 7f;
19541 }
19542 int nPCImmuneTime = 30;
19543 int playerImmuneTime = 6;
19545 }
19546 if (mount.Active && mount.Type == 44 && Math.Abs(velocity.X) > mount.DashSpeed - mount.RunSpeed / 4f)
19547 {
19549 if (direction == 1)
19550 {
19551 rect2.Offset(width - 1, 0);
19552 }
19553 rect2.Width = 2;
19554 rect2.Inflate(6, 12);
19555 float damage2 = 100f * minionDamage;
19556 float knockback2 = 12f;
19557 int nPCImmuneTime2 = 30;
19558 int playerImmuneTime2 = 6;
19560 }
19561 if (mount.Active && mount.Type == 45 && Math.Abs(velocity.X) > mount.DashSpeed * 0.9f)
19562 {
19564 if (direction == 1)
19565 {
19566 rect3.Offset(width - 1, 0);
19567 }
19568 rect3.Width = 2;
19569 rect3.Inflate(6, 12);
19570 float damage3 = 120f * minionDamage;
19571 float knockback3 = 12f;
19572 int nPCImmuneTime3 = 30;
19573 int playerImmuneTime3 = 6;
19575 }
19576 if (mount.Active && mount.Type == 14 && Math.Abs(velocity.X) > mount.RunSpeed / 2f)
19577 {
19579 if (direction == 1)
19580 {
19581 rect4.Offset(width - 1, 0);
19582 }
19583 rect4.Width = 2;
19584 rect4.Inflate(6, 12);
19585 float damage4 = 90f * minionDamage;
19586 float knockback4 = 10f;
19587 int nPCImmuneTime4 = 30;
19588 int playerImmuneTime4 = 6;
19590 }
19591 if (mount.Active && mount.Type == 17 && Math.Abs(velocity.X) > mount.RunSpeed / 2f)
19592 {
19594 if (direction == 1)
19595 {
19596 rect5.Offset(width - 1, 0);
19597 }
19598 rect5.Width = 2;
19599 rect5.Inflate(6, 12);
19600 float damage5 = 40f * minionDamage;
19601 float knockback5 = 10f;
19602 int nPCImmuneTime5 = 30;
19603 int playerImmuneTime5 = 12;
19605 }
19607 if (HeldItem.type == 4049 && whoAmI == Main.myPlayer)
19608 {
19609 MowTheLawn();
19610 }
19611 }
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static double Abs(double value)
static int Sign(decimal value)
Definition Math.cs:1202
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
static readonly LegacySoundStyle Item55
Definition SoundID.cs:524
static readonly LegacySoundStyle Item168
Definition SoundID.cs:750
bool useTurn
Definition Item.cs:181
Action< Vector2 > MinecartDust
Definition Mount.cs:85
MountDelegatesData Delegations
Definition Mount.cs:507
bool Active
Definition Mount.cs:345
bool CanFly()
Definition Mount.cs:2371
float RunSpeed
Definition Mount.cs:404
bool AllowDirectionChange
Definition Mount.cs:527
float DashSpeed
Definition Mount.cs:441
bool controlRight
Definition Player.cs:1383
bool PortalPhysicsEnabled
Definition Player.cs:3494
static float jumpSpeed
Definition Player.cs:2091
void SpawnFastRunParticles()
Definition Player.cs:19636
float accRunSpeed
Definition Player.cs:821
float runAcceleration
Definition Player.cs:2099
void MowTheLawn()
Definition Player.cs:19732
float trackBoost
Definition Player.cs:1731
int CollideWithNPCs(Rectangle myRect, float Damage, float Knockback, int NPCImmuneTime, int PlayerImmuneTime)
Definition Player.cs:19810
Rectangle getRect()
Definition Player.cs:40162
void TryUsingDiggerCart()
Definition Player.cs:19613
float minionDamage
Definition Player.cs:2039
static int jumpHeight
Definition Player.cs:2089
float maxRunSpeed
Definition Player.cs:2097
float runSlowdown
Definition Player.cs:2101
bool isLockedToATile
Definition Player.cs:3482
float fullRotation
Definition Player.cs:1291
bool onWrongGround
Definition Player.cs:1723
Vector2 fullRotationOrigin
Definition Player.cs:1293
Item[] inventory
Definition Player.cs:1257

References System.Math.Abs(), Microsoft.Xna.Framework.MathHelper.Clamp(), Terraria.ID.SoundID.Item168, Terraria.ID.SoundID.Item55, Terraria.Main.myPlayer, Terraria.Audio.SoundEngine.PlaySound(), Terraria.Main.rand, System.Math.Sign(), Terraria.Item.type, Terraria.Item.useTurn, Terraria.Minecart.WheelSparks(), and Terraria.Main.windSpeedCurrent.