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

◆ FindCollisionTile()

static List< Point > Terraria.Collision.FindCollisionTile ( int Direction,
Vector2 position,
float testMagnitude,
int Width,
int Height,
bool fallThrough = false,
bool fall2 = false,
int gravDir = 1,
bool checkCardinals = true,
bool checkSlopes = false )
inlinestatic

Definition at line 2110 of file Collision.cs.

2111 {
2113 if ((uint)Direction > 1u)
2114 {
2115 if ((uint)(Direction - 2) <= 1u)
2116 {
2117 Vector2 vector = ((Direction == 2) ? (Vector2.UnitY * testMagnitude) : (-Vector2.UnitY * testMagnitude));
2118 Vector4 vec = new Vector4(position, vector.X, vector.Y);
2119 int y = (int)(position.Y + (float)((Direction == 2) ? Height : 0)) / 16;
2120 float num = Math.Min(16f - position.X % 16f, Width);
2121 float num2 = num;
2122 if (checkCardinals && TileCollision(position - vector, vector, (int)num, Height, fallThrough, fall2, gravDir) != vector)
2123 {
2124 list.Add(new Point((int)position.X / 16, y));
2125 }
2126 else if (checkSlopes && SlopeCollision(position, vector, (int)num, Height, gravDir, fallThrough).YZW() != vec.YZW())
2127 {
2128 list.Add(new Point((int)position.X / 16, y));
2129 }
2130 for (; num2 + 16f <= (float)(Width - 16); num2 += 16f)
2131 {
2132 if (checkCardinals && TileCollision(position - vector + Vector2.UnitX * num2, vector, 16, Height, fallThrough, fall2, gravDir) != vector)
2133 {
2134 list.Add(new Point((int)(position.X + num2) / 16, y));
2135 }
2136 else if (checkSlopes && SlopeCollision(position + Vector2.UnitX * num2, vector, 16, Height, gravDir, fallThrough).YZW() != vec.YZW())
2137 {
2138 list.Add(new Point((int)(position.X + num2) / 16, y));
2139 }
2140 }
2141 int width = Width - (int)num2;
2142 if (checkCardinals && TileCollision(position - vector + Vector2.UnitX * num2, vector, width, Height, fallThrough, fall2, gravDir) != vector)
2143 {
2144 list.Add(new Point((int)(position.X + num2) / 16, y));
2145 }
2146 else if (checkSlopes && SlopeCollision(position + Vector2.UnitX * num2, vector, width, Height, gravDir, fallThrough).YZW() != vec.YZW())
2147 {
2148 list.Add(new Point((int)(position.X + num2) / 16, y));
2149 }
2150 }
2151 }
2152 else
2153 {
2154 Vector2 vector = ((Direction == 0) ? (Vector2.UnitX * testMagnitude) : (-Vector2.UnitX * testMagnitude));
2155 Vector4 vec = new Vector4(position, vector.X, vector.Y);
2156 int y = (int)(position.X + (float)((Direction == 0) ? Width : 0)) / 16;
2157 float num3 = Math.Min(16f - position.Y % 16f, Height);
2158 float num4 = num3;
2159 if (checkCardinals && TileCollision(position - vector, vector, Width, (int)num3, fallThrough, fall2, gravDir) != vector)
2160 {
2161 list.Add(new Point(y, (int)position.Y / 16));
2162 }
2163 else if (checkSlopes && SlopeCollision(position, vector, Width, (int)num3, gravDir, fallThrough).XZW() != vec.XZW())
2164 {
2165 list.Add(new Point(y, (int)position.Y / 16));
2166 }
2167 for (; num4 + 16f <= (float)(Height - 16); num4 += 16f)
2168 {
2169 if (checkCardinals && TileCollision(position - vector + Vector2.UnitY * num4, vector, Width, 16, fallThrough, fall2, gravDir) != vector)
2170 {
2171 list.Add(new Point(y, (int)(position.Y + num4) / 16));
2172 }
2173 else if (checkSlopes && SlopeCollision(position + Vector2.UnitY * num4, vector, Width, 16, gravDir, fallThrough).XZW() != vec.XZW())
2174 {
2175 list.Add(new Point(y, (int)(position.Y + num4) / 16));
2176 }
2177 }
2178 int height = Height - (int)num4;
2179 if (checkCardinals && TileCollision(position - vector + Vector2.UnitY * num4, vector, Width, height, fallThrough, fall2, gravDir) != vector)
2180 {
2181 list.Add(new Point(y, (int)(position.Y + num4) / 16));
2182 }
2183 else if (checkSlopes && SlopeCollision(position + Vector2.UnitY * num4, vector, Width, height, gravDir, fallThrough).XZW() != vec.XZW())
2184 {
2185 list.Add(new Point(y, (int)(position.Y + num4) / 16));
2186 }
2187 }
2188 return list;
2189 }
void Add(TKey key, TValue value)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static Vector2 TileCollision(Vector2 Position, Vector2 Velocity, int Width, int Height, bool fallThrough=false, bool fall2=false, int gravDir=1)
static Vector4 SlopeCollision(Vector2 Position, Vector2 Velocity, int Width, int Height, float gravity=0f, bool fall=false)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.list, System.Math.Min(), Terraria.Collision.SlopeCollision(), Terraria.Collision.TileCollision(), Microsoft.Xna.Framework.Vector2.UnitX, Microsoft.Xna.Framework.Vector2.UnitY, Microsoft.Xna.Framework.Vector2.X, and Microsoft.Xna.Framework.Vector2.Y.

Referenced by Terraria.Player.UpdateTouchingTiles().