new Math(game)
The Math object offers various standard math functions like measuring a distance or angles.
Parameters:
Name | Type | Description |
---|---|---|
game |
Carrot.Game | The core game object. |
Members
DEG_TO_RAD
Degrees to Radians factor.
Properties:
Name | Type | Description |
---|---|---|
Carrot.Math#DEG_TO_RAD |
integer |
PI :integer
PI.
Type:
- integer
Properties:
Name | Type | Description |
---|---|---|
Carrot.Math#PI |
integer |
PI2 :integer
Twice PI.
Type:
- integer
Properties:
Name | Type | Description |
---|---|---|
Carrot.Math#PI2 |
integer |
RAD_TO_DEG
Degrees to Radians factor.
Properties:
Name | Type | Description |
---|---|---|
Carrot.Math#RAD_TO_DEG |
integer |
Methods
angleBetween(a, b) → {floar}
Calculates the angle between two entities in degrees. Both must have x / y coordinates.
Parameters:
Name | Type | Description |
---|---|---|
a |
Carrot.Sprite | object | The first entity. |
b |
Carrot.Sprite | object | The second entity. |
Returns:
- Type
- floar
angleBetweenPoints(x1, y1, x2, y2) → {integer}
Calculates the angle between two vectors in degrees.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
integer | x1 |
y1 |
integer | x1 |
x2 |
integer | x2 |
y2 |
integer | y2 |
Returns:
- Type
- integer
degToRad(degrees) → {float}
Converts degrees to radians.
Parameters:
Name | Type | Description |
---|---|---|
degrees |
integer | Angle in degrees. |
Returns:
Angle in radians.
- Type
- float
distanceBetween(a, b) → {float}
Calculates the distance between two entities. Both must have x / y coordinates.
Parameters:
Name | Type | Description |
---|---|---|
a |
Carrot.Sprite | object | The first entity. |
b |
Carrot.Sprite | object | The second entity. |
Returns:
- Type
- float
distanceBetweenPoints(x1, y1, x2, y2) → {floar}
Calculates the distance between two vectors in pixels.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
integer | x1 |
y1 |
integer | x1 |
x2 |
integer | x2 |
y2 |
integer | y2 |
Returns:
- Type
- floar
integerInRange(min, max) → {integer}
Returns an integer between (including) min and (including) max
Parameters:
Name | Type | Description |
---|---|---|
min |
integer | Min. |
max |
integer | Max. |
Returns:
- Type
- integer
radToDeg(radians) → {integer}
Converts radians to degrees.
Parameters:
Name | Type | Description |
---|---|---|
radians |
integer | Angle in radians. |
Returns:
Angle in degrees.
- Type
- integer