/// <summary> /// updates the tile /// </summary> public void Update() { Sprite?.Update(); }
/// <summary> /// updates this game object /// </summary> public virtual void Update() { Touching = false; if (Velocity.X != 0 || Velocity.Y != 0) { for (int i = 0; i < Room.GameObjectList.Count; i++) { GameObject obj = Room.GameObjectList[i]; if (obj.GetType().IsEquivalentTo(PEngine.GetTypeFromName("obj_block"))) { //feel like there should be a better way to do collisions but idk that way Rectangle targetRect = obj.GetHitbox(); targetRect.Location += obj.Position.ToPoint(); Rectangle fromRect = PlatformerMath.AddVectorToRect(GetHitbox(), Position, PlatformerMath.VectorCeil(new Vector2(0, Velocity.Y))); while (PlatformerMath.RectangleInRectangle(fromRect, targetRect)) { Touching = true; if (Math.Abs(Velocity.Y) < CollisionPrecision) { Velocity.Y = 0; break; } else { Velocity.Y -= Math.Sign(Velocity.Y) * CollisionPrecision; fromRect = PlatformerMath.AddVectorToRect(GetHitbox(), Position, PlatformerMath.VectorCeil(new Vector2(0, Velocity.Y))); } } fromRect = PlatformerMath.AddVectorToRect(GetHitbox(), Position, PlatformerMath.VectorCeil(new Vector2(Velocity.X, 0))); while (PlatformerMath.RectangleInRectangle(fromRect, targetRect)) { Touching = true; if (Math.Abs(Velocity.X) < CollisionPrecision) { Velocity.X = 0; break; } else { Velocity.X -= Math.Sign(Velocity.X) * CollisionPrecision; fromRect = PlatformerMath.AddVectorToRect(GetHitbox(), Position, PlatformerMath.VectorCeil(new Vector2(Velocity.X, 0))); } } fromRect = PlatformerMath.AddVectorToRect(GetHitbox(), Position, PlatformerMath.VectorCeil(Velocity)); while (PlatformerMath.RectangleInRectangle(fromRect, targetRect)) { Touching = true; if (Math.Abs(Velocity.X) < CollisionPrecision) { Velocity.X = 0; break; } else { Velocity.X -= Math.Sign(Velocity.X) * CollisionPrecision; } if (Math.Abs(Velocity.Y) < CollisionPrecision) { Velocity.Y = 0; break; } else { Velocity.Y -= Math.Sign(Velocity.Y) * CollisionPrecision; } fromRect = PlatformerMath.AddVectorToRect(GetHitbox(), Position, PlatformerMath.VectorCeil(Velocity)); } } } } Position += Velocity; Sprite?.Update(); }