Class: TonMath
ゲーム開発に役立つ数学・乱数などのユーティリティ関数群です。
Methods
int Rand(int min, int max)
指定範囲の整数の乱数を返します。
min: 最小値max: 最大値(排他的)
float RandF(float min, float max)
指定範囲の浮動小数点の乱数を返します。
min: 最小値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)
二つの矩形の当たり判定(交差判定)を行います。
x1, y1, w1, h1: 矩形1の情報x2, y2, w2, h2: 矩形2の情報
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 */ }