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

◆ UpdatePlayerPosition()

static void Terraria.GameContent.PressurePlateHelper.UpdatePlayerPosition ( Player player)
inlinestatic

Definition at line 51 of file PressurePlateHelper.cs.

52 {
53 Point p = new Point(1, 1);
54 Vector2 vector = p.ToVector2();
55 List<Point> tilesIn = Collision.GetTilesIn(PlayerLastPosition[player.whoAmI] + vector, PlayerLastPosition[player.whoAmI] + player.Size - vector * 2f);
56 List<Point> tilesIn2 = Collision.GetTilesIn(player.TopLeft + vector, player.BottomRight - vector * 2f);
57 Rectangle hitbox = player.Hitbox;
58 Rectangle hitbox2 = player.Hitbox;
59 hitbox.Inflate(-p.X, -p.Y);
60 hitbox2.Inflate(-p.X, -p.Y);
61 hitbox2.X = (int)PlayerLastPosition[player.whoAmI].X;
62 hitbox2.Y = (int)PlayerLastPosition[player.whoAmI].Y;
63 for (int i = 0; i < tilesIn.Count; i++)
64 {
65 Point point = tilesIn[i];
66 Tile tile = Main.tile[point.X, point.Y];
67 if (tile.active() && tile.type == 428)
68 {
69 pressurePlateBounds.X = point.X * 16;
70 pressurePlateBounds.Y = point.Y * 16 + 16 - pressurePlateBounds.Height;
71 if (!hitbox.Intersects(pressurePlateBounds) && !tilesIn2.Contains(point))
72 {
73 MoveAwayFrom(point, player.whoAmI);
74 }
75 }
76 }
77 for (int j = 0; j < tilesIn2.Count; j++)
78 {
80 Tile tile2 = Main.tile[point2.X, point2.Y];
81 if (tile2.active() && tile2.type == 428)
82 {
83 pressurePlateBounds.X = point2.X * 16;
84 pressurePlateBounds.Y = point2.Y * 16 + 16 - pressurePlateBounds.Height;
85 if (hitbox.Intersects(pressurePlateBounds) && (!tilesIn.Contains(point2) || !hitbox2.Intersects(pressurePlateBounds)))
86 {
87 MoveInto(point2, player.whoAmI);
88 }
89 }
90 }
91 PlayerLastPosition[player.whoAmI] = player.position;
92 }
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
static void MoveAwayFrom(Point location, int player)
static void MoveInto(Point location, int player)

References Terraria.Tile.active(), Terraria.Entity.BottomRight, System.Collections.Generic.Dictionary< TKey, TValue >.Contains(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, Terraria.Collision.GetTilesIn(), Terraria.Entity.Hitbox, Terraria.GameContent.PressurePlateHelper.MoveAwayFrom(), Terraria.GameContent.PressurePlateHelper.MoveInto(), Terraria.GameContent.PressurePlateHelper.PlayerLastPosition, Terraria.Entity.position, Terraria.GameContent.PressurePlateHelper.pressurePlateBounds, Terraria.Entity.Size, Terraria.Main.tile, Terraria.Entity.TopLeft, Terraria.Tile.type, Terraria.Entity.whoAmI, Microsoft.Xna.Framework.Point.X, and Microsoft.Xna.Framework.Point.Y.

Referenced by Terraria.Player.Teleport(), and Terraria.Player.Update().