Class: TonMath

ゲーム開発に役立つ数学・乱数などのユーティリティ関数群です。

Enums

EasingType

イージング関数の種類を表す列挙体です。

値 説明
Linear等速の直線運動
Quad2次方程式補間(なめらか)
Cubic3次方程式補間(少し急な加減速)
Quart4次方程式補間(急な加減速)
Quint5次方程式補間(非常に急な加減速)
Sineサイン波(きわめて自然な加減速)
Expo指数関数(動き出しが遅く、後半一気に加速)
Back少し後ろに沈み込んでから前に飛び出す動き
Circ円形補間(硬質で機械的な加減速)
Elastic弾性のあるバネ振動のような動き
Bounceボールが跳ね返るようなバウンド運動

EasingMode

イージングの方向(モード)を表す列挙体です。

値 説明
In開始時にイージング(最初はゆっくり、徐々に加速)
Out終了時にイージング(最初は速く、徐々に減速)
InOut開始と終了の両方でイージング

Methods

int Rand(int min, int max)

指定範囲の整数の乱数を返します。

float RandF(float min, float max)

指定範囲の浮動小数点の乱数を返します。

float GetDistance(float x1, float y1, float x2, float y2)

二点間の距離を計算します。

float GetAngle(float x1, float y1, float x2, float y2)

二点間の角度(ラジアン)を計算します。

bool HitCheckRect(Rectangle rect1, Rectangle rect2)

二つの矩形の当たり判定(交差判定)を行います。

bool HitCheckCircle(Vector2 pos1, float r1, Vector2 pos2, float r2)

二つの円の当たり判定(交差判定)を行います。

bool IsPointInRect(float x, float y, Rectangle rect)

点が矩形内に含まれているかを判定します。

float Ease(float t, EasingType type, EasingMode mode = EasingMode.In)

指定したイージングタイプとモードで時間割合 (0.0〜1.0) を補間した値を返します。

Sample Code

// Random Integer [0, 100)
int r = Ton.Math.Rand(0, 100);

// Random Float [0.0, 1.0]
float f = Ton.Math.RandF(0f, 1f);

// Distance between (x1,y1) and (x2,y2)
float dist = Ton.Math.GetDistance(x1, y1, x2, y2);

// Angle in radians
float angle = Ton.Math.GetAngle(playerX, playerY, mouseX, mouseY);

// Rectangle vs Rectangle
Rectangle playerRect = new Rectangle((int)player.X, (int)player.Y, 32, 32);
Rectangle bulletRect = new Rectangle((int)bullet.X, (int)bullet.Y, 8, 8);
bool isHitRect = Ton.Math.HitCheckRect(playerRect, bulletRect);

// Circle vs Circle
bool isHitCircle = Ton.Math.HitCheckCircle(
    new Vector2(player.X, player.Y), 16f,
    new Vector2(enemy.X, enemy.Y), 24f
);

// Point in Rectangle
bool isMouseOnButton = Ton.Math.IsPointInRect(mouseX, mouseY, buttonRect);

// Easing (Cubic EaseIn)
float easedT = Ton.Math.Ease(t, EasingType.Cubic, EasingMode.In);