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

◆ WaterCollision()

static Vector2 Terraria.Collision.WaterCollision ( Vector2 Position,
Vector2 Velocity,
int Width,
int Height,
bool fallThrough = false,
bool fall2 = false,
bool lavaWalk = true )
inlinestatic

Definition at line 2301 of file Collision.cs.

2302 {
2303 Vector2 result = Velocity;
2304 Vector2 vector = Position + Velocity;
2306 int value = (int)(Position.X / 16f) - 1;
2307 int value2 = (int)((Position.X + (float)Width) / 16f) + 2;
2308 int value3 = (int)(Position.Y / 16f) - 1;
2309 int value4 = (int)((Position.Y + (float)Height) / 16f) + 2;
2310 int num = Utils.Clamp(value, 0, Main.maxTilesX - 1);
2311 value2 = Utils.Clamp(value2, 0, Main.maxTilesX - 1);
2312 value3 = Utils.Clamp(value3, 0, Main.maxTilesY - 1);
2313 value4 = Utils.Clamp(value4, 0, Main.maxTilesY - 1);
2314 Vector2 vector3 = default(Vector2);
2315 for (int i = num; i < value2; i++)
2316 {
2317 for (int j = value3; j < value4; j++)
2318 {
2319 if (Main.tile[i, j] != null && Main.tile[i, j].liquid > 0 && Main.tile[i, j - 1].liquid == 0 && (!Main.tile[i, j].lava() || lavaWalk))
2320 {
2321 int num2 = Main.tile[i, j].liquid / 32 * 2 + 2;
2322 vector3.X = i * 16;
2323 vector3.Y = j * 16 + 16 - num2;
2324 if (vector.X + (float)Width > vector3.X && vector.X < vector3.X + 16f && vector.Y + (float)Height > vector3.Y && vector.Y < vector3.Y + (float)num2 && vector2.Y + (float)Height <= vector3.Y && !fallThrough)
2325 {
2326 result.Y = vector3.Y - (vector2.Y + (float)Height);
2327 }
2328 }
2329 }
2330 }
2331 return result;
2332 }

References Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Main.tile, and System.value.

Referenced by Terraria.Player.DryCollision().