Class: TonMath

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

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 HitCheck(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)

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

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);

// Simple AABB Collision
bool isHit = Ton.math.HitCheck(
    player.X, player.Y, 32, 32,
    bullet.X, bullet.Y, 8, 8
);
if (isHit) { /* Damage */ }