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

◆ WalkDownSlope()

static Vector4 Terraria.Collision.WalkDownSlope ( Vector2 Position,
Vector2 Velocity,
int Width,
int Height,
float gravity = 0f )
inlinestatic

Definition at line 1475 of file Collision.cs.

1476 {
1477 if (Velocity.Y != gravity)
1478 {
1479 return new Vector4(Position, Velocity.X, Velocity.Y);
1480 }
1482 int value = (int)(vector.X / 16f);
1483 int value2 = (int)((vector.X + (float)Width) / 16f);
1484 int value3 = (int)((Position.Y + (float)Height + 4f) / 16f);
1485 value = Utils.Clamp(value, 0, Main.maxTilesX - 1);
1486 value2 = Utils.Clamp(value2, 0, Main.maxTilesX - 1);
1487 value3 = Utils.Clamp(value3, 0, Main.maxTilesY - 3);
1488 float num = (value3 + 3) * 16;
1489 int num2 = -1;
1490 int num3 = -1;
1491 int num4 = 1;
1492 if (Velocity.X < 0f)
1493 {
1494 num4 = 2;
1495 }
1496 for (int i = value; i <= value2; i++)
1497 {
1498 for (int j = value3; j <= value3 + 1; j++)
1499 {
1500 if (Main.tile[i, j] == null)
1501 {
1502 Main.tile[i, j] = new Tile();
1503 }
1504 if (!Main.tile[i, j].nactive() || (!Main.tileSolid[Main.tile[i, j].type] && !Main.tileSolidTop[Main.tile[i, j].type]))
1505 {
1506 continue;
1507 }
1508 int num5 = j * 16;
1509 if (Main.tile[i, j].halfBrick())
1510 {
1511 num5 += 8;
1512 }
1513 if (!new Rectangle(i * 16, j * 16 - 17, 16, 16).Intersects(new Rectangle((int)Position.X, (int)Position.Y, Width, Height)) || !((float)num5 <= num))
1514 {
1515 continue;
1516 }
1517 if (num == (float)num5)
1518 {
1519 if (Main.tile[i, j].slope() == 0)
1520 {
1521 continue;
1522 }
1523 if (num2 != -1 && num3 != -1 && Main.tile[num2, num3] != null && Main.tile[num2, num3].slope() != 0)
1524 {
1525 if (Main.tile[i, j].slope() == num4)
1526 {
1527 num = num5;
1528 num2 = i;
1529 num3 = j;
1530 }
1531 }
1532 else
1533 {
1534 num = num5;
1535 num2 = i;
1536 num3 = j;
1537 }
1538 }
1539 else
1540 {
1541 num = num5;
1542 num2 = i;
1543 num3 = j;
1544 }
1545 }
1546 }
1547 int num6 = num2;
1548 int num7 = num3;
1549 if (num2 != -1 && num3 != -1 && Main.tile[num6, num7] != null && Main.tile[num6, num7].slope() > 0)
1550 {
1551 int num8 = Main.tile[num6, num7].slope();
1552 Vector2 vector2 = default(Vector2);
1553 vector2.X = num6 * 16;
1554 vector2.Y = num7 * 16;
1555 switch (num8)
1556 {
1557 case 2:
1558 {
1559 float num9 = vector2.X + 16f - (Position.X + (float)Width);
1560 if (Position.Y + (float)Height >= vector2.Y + num9 && Velocity.X < 0f)
1561 {
1562 Velocity.Y += Math.Abs(Velocity.X);
1563 }
1564 break;
1565 }
1566 case 1:
1567 {
1568 float num9 = Position.X - vector2.X;
1569 if (Position.Y + (float)Height >= vector2.Y + num9 && Velocity.X > 0f)
1570 {
1571 Velocity.Y += Math.Abs(Velocity.X);
1572 }
1573 break;
1574 }
1575 }
1576 }
1577 return new Vector4(Position, Velocity.X, Velocity.Y);
1578 }
static double Abs(double value)

References System.Math.Abs(), Microsoft.Xna.Framework.Intersects, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.DataStructures.Tile, Terraria.Main.tile, Terraria.Main.tileSolid, Terraria.Main.tileSolidTop, System.value, Microsoft.Xna.Framework.Vector2.X, and Microsoft.Xna.Framework.Vector2.Y.

Referenced by Terraria.NPC.Collision_WalkDownSlopes(), and Terraria.Player.SlopeDownMovement().