SNES Collision Detection. More...
#include <snes/types.h>Go to the source code of this file.
Classes | |
| struct | Rect |
| Axis-aligned bounding box (rectangle) More... | |
Functions | |
| u8 | collidePoint (s16 x, s16 y, Rect *r) |
| Check point vs rectangle collision. | |
| u8 | collideRect (Rect *a, Rect *b) |
| Check rectangle vs rectangle collision (AABB) | |
| u8 | collideRectEx (Rect *a, Rect *b, s16 *overlapX, s16 *overlapY) |
| Check if two rectangles overlap and return overlap amount. | |
| u8 | collideRectTile (Rect *r, u8 *tilemap, u16 mapWidth) |
| Check collision between rectangle and tilemap. | |
| u8 | collideTile (s16 px, s16 py, u8 *tilemap, u16 mapWidth) |
| Check collision with tile at pixel coordinates. | |
| u8 | collideTileEx (s16 px, s16 py, u8 *tilemap, u16 mapWidth, u8 tileSize) |
| Check collision with tile using custom tile size. | |
| u8 | rectContains (Rect *inner, Rect *outer) |
| Check if rectangle is completely inside another. | |
| void | rectGetCenter (Rect *r, s16 *cx, s16 *cy) |
| Get rectangle center point. | |
| void | rectInit (Rect *r, s16 x, s16 y, u16 w, u16 h) |
| Initialize a rectangle. | |
| void | rectSetPos (Rect *r, s16 x, s16 y) |
| Set rectangle position. | |
SNES Collision Detection.
Simple collision detection routines for game objects.
This module provides:
Check point vs rectangle collision.
Tests if a point is inside a rectangle.
| x | Point X coordinate |
| y | Point Y coordinate |
| r | Rectangle to test against |
Check rectangle vs rectangle collision (AABB)
Tests if two axis-aligned bounding boxes overlap.
| a | First rectangle |
| b | Second rectangle |
Check if two rectangles overlap and return overlap amount.
Tests collision and returns the overlap distance for each axis. Useful for collision response (pushing objects apart).
| a | First rectangle |
| b | Second rectangle |
| overlapX | Pointer to store X overlap (negative = left, positive = right) |
| overlapY | Pointer to store Y overlap (negative = up, positive = down) |
Check collision between rectangle and tilemap.
Tests if any corner of the rectangle touches a solid tile. Useful for checking if a moving object would collide with the world.
| r | Rectangle to test |
| tilemap | Pointer to collision tilemap |
| mapWidth | Width of tilemap in tiles |
Check collision with tile at pixel coordinates.
Looks up the tile at a given pixel position and returns whether it's solid. Tiles are assumed to be 8x8 pixels.
| px | Pixel X coordinate |
| py | Pixel Y coordinate |
| tilemap | Pointer to collision tilemap (1 byte per tile, 0=empty, nonzero=solid) |
| mapWidth | Width of tilemap in tiles |
Check collision with tile using custom tile size.
Like collideTile() but allows custom tile sizes (8, 16, etc).
| px | Pixel X coordinate |
| py | Pixel Y coordinate |
| tilemap | Pointer to collision tilemap |
| mapWidth | Width of tilemap in tiles |
| tileSize | Size of tiles in pixels (must be power of 2: 8, 16, 32) |
Check if rectangle is completely inside another.
| inner | Inner rectangle (potentially contained) |
| outer | Outer rectangle (container) |
Get rectangle center point.
| r | Rectangle |
| cx | Pointer to store center X |
| cy | Pointer to store center Y |
Initialize a rectangle.
| r | Rectangle to initialize |
| x | Left edge X |
| y | Top edge Y |
| w | Width |
| h | Height |