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

◆ TileCollision()

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

Definition at line 1910 of file Collision.cs.

1911 {
1912 up = false;
1913 down = false;
1914 Vector2 result = Velocity;
1915 Vector2 vector = Velocity;
1916 Vector2 vector2 = Position + Velocity;
1918 int value = (int)(Position.X / 16f) - 1;
1919 int value2 = (int)((Position.X + (float)Width) / 16f) + 2;
1920 int value3 = (int)(Position.Y / 16f) - 1;
1921 int value4 = (int)((Position.Y + (float)Height) / 16f) + 2;
1922 int num = -1;
1923 int num2 = -1;
1924 int num3 = -1;
1925 int num4 = -1;
1926 int num5 = Utils.Clamp(value, 0, Main.maxTilesX - 1);
1927 value2 = Utils.Clamp(value2, 0, Main.maxTilesX - 1);
1928 value3 = Utils.Clamp(value3, 0, Main.maxTilesY - 1);
1929 value4 = Utils.Clamp(value4, 0, Main.maxTilesY - 1);
1930 float num6 = (value4 + 3) * 16;
1931 Vector2 vector4 = default(Vector2);
1932 for (int i = num5; i < value2; i++)
1933 {
1934 for (int j = value3; j < value4; j++)
1935 {
1936 if (Main.tile[i, j] == null || !Main.tile[i, j].active() || Main.tile[i, j].inActive() || (!Main.tileSolid[Main.tile[i, j].type] && (!Main.tileSolidTop[Main.tile[i, j].type] || Main.tile[i, j].frameY != 0)))
1937 {
1938 continue;
1939 }
1940 vector4.X = i * 16;
1941 vector4.Y = j * 16;
1942 int num7 = 16;
1943 if (Main.tile[i, j].halfBrick())
1944 {
1945 vector4.Y += 8f;
1946 num7 -= 8;
1947 }
1948 if (!(vector2.X + (float)Width > vector4.X) || !(vector2.X < vector4.X + 16f) || !(vector2.Y + (float)Height > vector4.Y) || !(vector2.Y < vector4.Y + (float)num7))
1949 {
1950 continue;
1951 }
1952 bool flag = false;
1953 bool flag2 = false;
1954 if (Main.tile[i, j].slope() > 2)
1955 {
1956 if (Main.tile[i, j].slope() == 3 && vector3.Y + Math.Abs(Velocity.X) >= vector4.Y && vector3.X >= vector4.X)
1957 {
1958 flag2 = true;
1959 }
1960 if (Main.tile[i, j].slope() == 4 && vector3.Y + Math.Abs(Velocity.X) >= vector4.Y && vector3.X + (float)Width <= vector4.X + 16f)
1961 {
1962 flag2 = true;
1963 }
1964 }
1965 else if (Main.tile[i, j].slope() > 0)
1966 {
1967 flag = true;
1968 if (Main.tile[i, j].slope() == 1 && vector3.Y + (float)Height - Math.Abs(Velocity.X) <= vector4.Y + (float)num7 && vector3.X >= vector4.X)
1969 {
1970 flag2 = true;
1971 }
1972 if (Main.tile[i, j].slope() == 2 && vector3.Y + (float)Height - Math.Abs(Velocity.X) <= vector4.Y + (float)num7 && vector3.X + (float)Width <= vector4.X + 16f)
1973 {
1974 flag2 = true;
1975 }
1976 }
1977 if (flag2)
1978 {
1979 continue;
1980 }
1981 if (vector3.Y + (float)Height <= vector4.Y)
1982 {
1983 down = true;
1984 if ((!(Main.tileSolidTop[Main.tile[i, j].type] && fallThrough) || !(Velocity.Y <= 1f || fall2)) && num6 > vector4.Y)
1985 {
1986 num3 = i;
1987 num4 = j;
1988 if (num7 < 16)
1989 {
1990 num4++;
1991 }
1992 if (num3 != num && !flag)
1993 {
1994 result.Y = vector4.Y - (vector3.Y + (float)Height) + ((gravDir == -1) ? (-0.01f) : 0f);
1995 num6 = vector4.Y;
1996 }
1997 }
1998 }
1999 else if (vector3.X + (float)Width <= vector4.X && !Main.tileSolidTop[Main.tile[i, j].type])
2000 {
2001 if (i >= 1 && Main.tile[i - 1, j] == null)
2002 {
2003 Main.tile[i - 1, j] = new Tile();
2004 }
2005 if (i < 1 || (Main.tile[i - 1, j].slope() != 2 && Main.tile[i - 1, j].slope() != 4))
2006 {
2007 num = i;
2008 num2 = j;
2009 if (num2 != num4)
2010 {
2011 result.X = vector4.X - (vector3.X + (float)Width);
2012 }
2013 if (num3 == num)
2014 {
2015 result.Y = vector.Y;
2016 }
2017 }
2018 }
2019 else if (vector3.X >= vector4.X + 16f && !Main.tileSolidTop[Main.tile[i, j].type])
2020 {
2021 if (Main.tile[i + 1, j] == null)
2022 {
2023 Main.tile[i + 1, j] = new Tile();
2024 }
2025 if (Main.tile[i + 1, j].slope() != 1 && Main.tile[i + 1, j].slope() != 3)
2026 {
2027 num = i;
2028 num2 = j;
2029 if (num2 != num4)
2030 {
2031 result.X = vector4.X + 16f - vector3.X;
2032 }
2033 if (num3 == num)
2034 {
2035 result.Y = vector.Y;
2036 }
2037 }
2038 }
2039 else if (vector3.Y >= vector4.Y + (float)num7 && !Main.tileSolidTop[Main.tile[i, j].type])
2040 {
2041 up = true;
2042 num3 = i;
2043 num4 = j;
2044 result.Y = vector4.Y + (float)num7 - vector3.Y + ((gravDir == 1) ? 0.01f : 0f);
2045 if (num4 == num2)
2046 {
2047 result.X = vector.X;
2048 }
2049 }
2050 }
2051 }
2052 return result;
2053 }
static double Abs(double value)
static bool down
Definition Collision.cs:34
static bool up
Definition Collision.cs:32

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

Referenced by Terraria.Projectile.AI_067_FreakingPirates(), Terraria.Projectile.AI_195_JimsDrone(), Terraria.Player.CanSnapToPosition(), Terraria.Player.CheckForGoodTeleportationSpot(), Terraria.NPC.Collision_MoveNormal(), Terraria.NPC.Collision_MoveSolarSroller(), Terraria.NPC.Collision_MoveStardustCell(), Terraria.Player.DoQueenSlimeHookTeleport(), Terraria.Player.DryCollision(), Terraria.Collision.FindCollisionDirection(), Terraria.Collision.FindCollisionTile(), Terraria.Gore.Gore_UpdateLeaf(), Terraria.Gore.Gore_UpdateSail(), Terraria.Projectile.HandleMovement(), Terraria.Player.HoneyCollision(), Terraria.Mount.Hover(), Terraria.Collision.IsClearSpotTest(), Terraria.GameContent.TeleportHelpers.IsInSolidTilesExtended(), Terraria.Item.MoveInWorld(), Terraria.Player.ShimmerCollision(), Terraria.Collision.SlopeCollision(), Terraria.Collision.StepConveyorBelt(), Terraria.Mount.TryBeginningFlight(), Terraria.GameContent.PortalHelper.TryGoingThroughPortals(), Terraria.Mount.TryLanding(), Terraria.Gore.Update(), and Terraria.Player.WaterCollision().