Fries
604d79e654
i added a GameArea class which makes it easier to operate on in coordinates bounds with the GameCoordinate struct wrapper which does calculations for me. the GameArea class also has a normalization system which is how the ScalingManager can teleport items in bounds to relatively the same place when resized. it took quite a while to get the paddle to teleport. looks like im supposed to modify the position inside IntegrateForces instead of PhysicsProcess which is my mistake.
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
namespace Pong.Scripts.Data;
|
|
|
|
public record GameArea
|
|
{
|
|
/// <summary>
|
|
/// the X coordinate of the GameArea wrapped in a struct that makes operating on it easier. this is divided
|
|
/// by 2 in the constructor to represent both sides of the screen by either negative or positive of the number.
|
|
/// </summary>
|
|
public GameCoordinate X { get; }
|
|
|
|
/// <summary>
|
|
/// the Y coordinate of the GameArea wrapped in a struct that makes operating on it easier. this is divided
|
|
/// by 2 in the constructor to represent both sides of the screen by either negative or positive of the number.
|
|
/// </summary>
|
|
public GameCoordinate Y { get; }
|
|
|
|
public Vector2 NormalizePosition(Vector2 globalPosition)
|
|
{
|
|
var normalizedX = Mathf.InverseLerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, globalPosition.X);
|
|
var normalizedY = Mathf.InverseLerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, globalPosition.Y);
|
|
return new Vector2(normalizedX, normalizedY);
|
|
}
|
|
|
|
|
|
public Vector2 GlobalizePosition(Vector2 normalizedPosition)
|
|
{
|
|
var globalizedX = Mathf.Lerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, normalizedPosition.X);
|
|
var globalizedY = Mathf.Lerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, normalizedPosition.Y);
|
|
return new Vector2(globalizedX, globalizedY);
|
|
}
|
|
|
|
public GameArea(Vector2 area)
|
|
{
|
|
X = new GameCoordinate(area.X / 2);
|
|
Y = new GameCoordinate(area.Y / 2);
|
|
}
|
|
}
|