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

◆ AdvancedTileCollision()

static Vector2 Terraria.Collision.AdvancedTileCollision ( bool[] forcedIgnoredTiles,
Vector2 Position,
Vector2 Velocity,
int Width,
int Height,
bool fallThrough = false,
bool fall2 = false,
int gravDir = 1 )
inlinestatic

Definition at line 3569 of file Collision.cs.

3570 {
3571 up = false;
3572 down = false;
3573 Vector2 result = Velocity;
3574 Vector2 vector = Velocity;
3575 Vector2 vector2 = Position + Velocity;
3577 int value = (int)(Position.X / 16f) - 1;
3578 int value2 = (int)((Position.X + (float)Width) / 16f) + 2;
3579 int value3 = (int)(Position.Y / 16f) - 1;
3580 int value4 = (int)((Position.Y + (float)Height) / 16f) + 2;
3581 int num = -1;
3582 int num2 = -1;
3583 int num3 = -1;
3584 int num4 = -1;
3585 int num5 = Utils.Clamp(value, 0, Main.maxTilesX - 1);
3586 value2 = Utils.Clamp(value2, 0, Main.maxTilesX - 1);
3587 value3 = Utils.Clamp(value3, 0, Main.maxTilesY - 1);
3588 value4 = Utils.Clamp(value4, 0, Main.maxTilesY - 1);
3589 float num6 = (value4 + 3) * 16;
3590 Vector2 vector4 = default(Vector2);
3591 for (int i = num5; i < value2; i++)
3592 {
3593 for (int j = value3; j < value4; j++)
3594 {
3595 Tile tile = Main.tile[i, j];
3596 if (tile == null || !tile.active() || tile.inActive() || forcedIgnoredTiles[tile.type] || (!Main.tileSolid[tile.type] && (!Main.tileSolidTop[tile.type] || tile.frameY != 0)))
3597 {
3598 continue;
3599 }
3600 vector4.X = i * 16;
3601 vector4.Y = j * 16;
3602 int num7 = 16;
3603 if (tile.halfBrick())
3604 {
3605 vector4.Y += 8f;
3606 num7 -= 8;
3607 }
3608 if (!(vector2.X + (float)Width > vector4.X) || !(vector2.X < vector4.X + 16f) || !(vector2.Y + (float)Height > vector4.Y) || !(vector2.Y < vector4.Y + (float)num7))
3609 {
3610 continue;
3611 }
3612 bool flag = false;
3613 bool flag2 = false;
3614 if (tile.slope() > 2)
3615 {
3616 if (tile.slope() == 3 && vector3.Y + Math.Abs(Velocity.X) >= vector4.Y && vector3.X >= vector4.X)
3617 {
3618 flag2 = true;
3619 }
3620 if (tile.slope() == 4 && vector3.Y + Math.Abs(Velocity.X) >= vector4.Y && vector3.X + (float)Width <= vector4.X + 16f)
3621 {
3622 flag2 = true;
3623 }
3624 }
3625 else if (tile.slope() > 0)
3626 {
3627 flag = true;
3628 if (tile.slope() == 1 && vector3.Y + (float)Height - Math.Abs(Velocity.X) <= vector4.Y + (float)num7 && vector3.X >= vector4.X)
3629 {
3630 flag2 = true;
3631 }
3632 if (tile.slope() == 2 && vector3.Y + (float)Height - Math.Abs(Velocity.X) <= vector4.Y + (float)num7 && vector3.X + (float)Width <= vector4.X + 16f)
3633 {
3634 flag2 = true;
3635 }
3636 }
3637 if (flag2)
3638 {
3639 continue;
3640 }
3641 if (vector3.Y + (float)Height <= vector4.Y)
3642 {
3643 down = true;
3644 if ((!(Main.tileSolidTop[tile.type] && fallThrough) || !(Velocity.Y <= 1f || fall2)) && num6 > vector4.Y)
3645 {
3646 num3 = i;
3647 num4 = j;
3648 if (num7 < 16)
3649 {
3650 num4++;
3651 }
3652 if (num3 != num && !flag)
3653 {
3654 result.Y = vector4.Y - (vector3.Y + (float)Height) + ((gravDir == -1) ? (-0.01f) : 0f);
3655 num6 = vector4.Y;
3656 }
3657 }
3658 }
3659 else if (vector3.X + (float)Width <= vector4.X && !Main.tileSolidTop[tile.type])
3660 {
3661 if (Main.tile[i - 1, j] == null)
3662 {
3663 Main.tile[i - 1, j] = new Tile();
3664 }
3665 if (Main.tile[i - 1, j].slope() != 2 && Main.tile[i - 1, j].slope() != 4)
3666 {
3667 num = i;
3668 num2 = j;
3669 if (num2 != num4)
3670 {
3671 result.X = vector4.X - (vector3.X + (float)Width);
3672 }
3673 if (num3 == num)
3674 {
3675 result.Y = vector.Y;
3676 }
3677 }
3678 }
3679 else if (vector3.X >= vector4.X + 16f && !Main.tileSolidTop[tile.type])
3680 {
3681 if (Main.tile[i + 1, j] == null)
3682 {
3683 Main.tile[i + 1, j] = new Tile();
3684 }
3685 if (Main.tile[i + 1, j].slope() != 1 && Main.tile[i + 1, j].slope() != 3)
3686 {
3687 num = i;
3688 num2 = j;
3689 if (num2 != num4)
3690 {
3691 result.X = vector4.X + 16f - vector3.X;
3692 }
3693 if (num3 == num)
3694 {
3695 result.Y = vector.Y;
3696 }
3697 }
3698 }
3699 else if (vector3.Y >= vector4.Y + (float)num7 && !Main.tileSolidTop[tile.type])
3700 {
3701 up = true;
3702 num3 = i;
3703 num4 = j;
3704 result.Y = vector4.Y + (float)num7 - vector3.Y + ((gravDir == 1) ? 0.01f : 0f);
3705 if (num4 == num2)
3706 {
3707 result.X = vector.X;
3708 }
3709 }
3710 }
3711 }
3712 return result;
3713 }
static double Abs(double value)
static bool down
Definition Collision.cs:34
static bool up
Definition Collision.cs:32

References System.Math.Abs(), Terraria.Tile.active(), Terraria.Collision.down, Terraria.Tile.halfBrick(), Terraria.Tile.inActive(), Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Tile.slope(), Terraria.DataStructures.Tile, Terraria.Main.tile, Terraria.Main.tileSolid, Terraria.Main.tileSolidTop, Terraria.Tile.type, Terraria.Collision.up, System.value, and Microsoft.Xna.Framework.Vector2.X.

Referenced by Terraria.NPC.Collision_MoveSandshark().