Added collision spaces

2025-08-09 18:46:33 +02:00
parent 4ff0f42318
commit 7f27d63784
2 changed files with 90 additions and 1 deletions

@@ -2,9 +2,74 @@
Class representing the GameLib inside the ModuleServerAPI.
## Collision
### toSpace
Creates a timespan object.
```javascript
api.GameLib.Collision.toSpace(x, y, width, height, id?);
```
| Argument | Type | Description |
| ------------- | ------ | ------------------------------------------------------------------------------------- |
| x | number | The x coordinate of the top-left corner of the element you want to make a space from. |
| y | number | The y coordinate of the top-left corner of the element you want to make a space from. |
| width | number | The width of the element you want to make a space from. |
| height | number | The height of the element you want to make a space from. |
| (Optional) id | string | The id of the space. |
**Return** [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace) _CollisionSpace instance._
### getObjectsInSpace
Get all objects in a space.
```javascript
api.GameLib.Collision.getObjectsInSpace(space, objects);
```
| Argument | Type | Description |
| -------- | ---------------------------------------------------------- | ---------------------------------------- |
| space | [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace) | The space object you want to check with. |
| objects | [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace)[] | An array of collision spaces. |
**Return** [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace)[] _CollisionSpace instances._
### isOverlapping
Check if two spaces are overlapping.
```javascript
api.GameLib.Collision.isOverlapping(space1, space2);
```
| Argument | Type | Description |
| -------- | -------------------------------------------------------- | ------------------------ |
| space1 | [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace) | The first space object. |
| space2 | [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace) | The second space object. |
**Return** boolean _True if the spaces are overlapping, false otherwise._
### getDistance
Get the distance between two spaces.
```javascript
api.GameLib.Collision.getDistance(space1, space2);
```
| Argument | Type | Description |
| -------- | -------------------------------------------------------- | ------------------------ |
| space1 | [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace) | The first space object. |
| space2 | [CollisionSpace](./ModuleServerAPIGameLibCollisionSpace) | The second space object. |
**Return** boolean _ The distance between the two spaces._
## Timing
Several functions to synchronize clients using the synced time you can retrieve using `api.getTime()`.
Several functions to synchronize clients.
### toTimeSpan

@@ -0,0 +1,24 @@
# ModuleServerApi - GameLib CollisionSpace
Simple object used to calculated collision with other spaces.
## Structure
```JSON
{
"id": "123",
"xLeft": 1,
"xRight": 2,
"yTop": 1,
"yBottom": 2
}
```
| Attribute | Type | Description |
| ------------- | ------ | -------------------- |
| (Optional) id | string | The id of the space. |
| xLeft | number | The left x value. |
| xRight | number | The right x value. |
| yTop | number | The top y value. |
| yBottom | number | the bottom y value. |