Game object engine with physics and collision (CONTRIB module) More...
#include <snes/types.h>Go to the source code of this file.
Classes | |
| struct | t_objs |
| Game object data structure. More... | |
Macros | |
| #define | OB_MAX 80 |
| Maximum number of objects in the game. | |
| #define | OB_SIZE 64 |
| Object size in bytes. | |
| #define | OB_TYPE_MAX 64 |
| Maximum number of object types. | |
Functions | |
| void | objCollidMap (u16 objhandle) |
| Check object collision with map tiles. | |
| void | objCollidMap1D (u16 objhandle) |
| Check object collision with map (no gravity) | |
| void | objCollidMapWithSlopes (u16 objhandle) |
| Check object collision with map tiles including slopes. | |
| u16 | objCollidObj (u16 objhandle1, u16 objhandle2) |
| Test collision between two objects. | |
| void | objGetPointer (u16 objhandle) |
| Get pointer to an object from its handle. | |
| void | objInitEngine (void) |
| Initialize the object engine. | |
| void | objInitFunctions (u8 objtype, void *initfct, void *updfct, void *reffct) |
| Register callback functions for an object type. | |
| void | objInitGravity (u16 objgravity, u16 objfriction) |
| Set gravity and friction values. | |
| void | objKill (u16 objhandle) |
| Kill an object. | |
| void | objKillAll (void) |
| Kill all active objects. | |
| void | objLoadObjects (u8 *sourceO) |
| Load objects from a data table. | |
| u16 | objNew (u8 objtype, u16 x, u16 y) |
| Create a new object. | |
| void | objRefreshAll (void) |
| Refresh sprites for all on-screen objects. | |
| void | objUpdateAll (void) |
| Update all active objects. | |
| void | objUpdateXY (u16 objindex) |
| Update object position from velocity. | |
Variables | |
| u16 | objgetid |
| Handle of the last object created by objNew() | |
| u16 | objptr |
| Current object pointer (byte offset, for internal use) | |
| u8 | objtokill |
| Set to 1 inside a callback to kill the current object. | |
| t_objs | objWorkspace |
| Object workspace (Bank $00) | |
Game object engine with physics and collision (CONTRIB module)
lib/contrib/object.asm and is not transitively included by <snes.h>. Examples that use it must #include <snes/object.h> explicitly and list object in their Makefile's LIB_MODULES. See lib/contrib/README.md for the policy.Provides managed game objects with:
Because the object buffer resides in Bank $7E (not directly accessible from C), a workspace pattern is used. Before each C callback, the engine copies the current object's data to objWorkspace (Bank $00). After the callback returns, changes are copied back.
Based on: PVSnesLib object engine by Alekmaul Slope management: Nub1604 License: zlib (compatible with MIT)
| #define OB_MAX 80 |
Maximum number of objects in the game.
| #define OB_SIZE 64 |
Object size in bytes.
| #define OB_TYPE_MAX 64 |
Maximum number of object types.
| void objCollidMap | ( | u16 | objhandle | ) |
Check object collision with map tiles.
Tests collision in Y (gravity/jumping) then X (walls). Updates tilestand, tileabove, tilesprop, tilebprop in objWorkspace. Applies friction to X velocity. Applies gravity if airborne.
| objhandle | Object index (as received in update callback) |
| void objCollidMap1D | ( | u16 | objhandle | ) |
Check object collision with map (no gravity)
For top-down movement without gravity.
| objhandle | Object index |
| void objCollidMapWithSlopes | ( | u16 | objhandle | ) |
Check object collision with map tiles including slopes.
Like objCollidMap but also handles slope tiles (T_SLOPEU1..T_SLOPEUD2).
| objhandle | Object index |
Test collision between two objects.
Uses AABB (axis-aligned bounding box) collision.
| objhandle1 | First object index |
| objhandle2 | Second object index |
| void objGetPointer | ( | u16 | objhandle | ) |
Get pointer to an object from its handle.
Validates the handle and populates objWorkspace with the object's data. Sets objptr to the buffer offset (1-based), or 0 if invalid.
| objhandle | Object handle (from objNew/objgetid) |
| void objInitEngine | ( | void | ) |
Initialize the object engine.
Clears all object buffers, resets linked lists, and sets default gravity/friction values. Call once at game start.
| void objInitFunctions | ( | u8 | objtype, |
| void * | initfct, | ||
| void * | updfct, | ||
| void * | reffct | ||
| ) |
Register callback functions for an object type.
| objtype | Object type index (0-63) |
| initfct | Init callback: void init(u16 xp, u16 yp, u16 type, u16 minx, u16 maxx) |
| updfct | Update callback: void update(u16 idx) — called per frame |
| reffct | Refresh callback: void refresh(u16 idx) — called for on-screen objects (or NULL) |
Set gravity and friction values.
| objgravity | Gravity acceleration per frame (default: 41) |
| objfriction | Horizontal friction deceleration (default: 16) |
| void objKill | ( | u16 | objhandle | ) |
Kill an object.
| objhandle | Object handle |
| void objKillAll | ( | void | ) |
Kill all active objects.
| void objLoadObjects | ( | u8 * | sourceO | ) |
Load objects from a data table.
Table format: [x:u16, y:u16, type:u16, minx:u16, maxx:u16]... terminated by 0xFFFF. Calls each type's init function for every object loaded.
| sourceO | Pointer to object data table |
Create a new object.
| objtype | Object type (0-63) |
| x | Initial X position in map pixels |
| y | Initial Y position in map pixels |
| void objRefreshAll | ( | void | ) |
Refresh sprites for all on-screen objects.
Calls the refresh function for objects that are on screen (-32 to 256 X, -32 to 224 Y). Useful to avoid flickering in scrolling games.
| void objUpdateAll | ( | void | ) |
Update all active objects.
Iterates through all active objects. For each object within the "virtual screen" (-64 to 320 X, -64 to 288 Y), calls the type's update function with objWorkspace pre-populated.
| void objUpdateXY | ( | u16 | objindex | ) |
Update object position from velocity.
Adds xvel/yvel to xpos/ypos (24-bit fixed point).
| objindex | Raw object index (0-79), NOT the handle from objNew. Use the index passed to your update callback, or extract from handle with (handle & 0xFF). |
|
extern |
Current object pointer (byte offset, for internal use)
|
extern |
Set to 1 inside a callback to kill the current object.
|
extern |
Object workspace (Bank $00)
Single 64-byte workspace populated before each C callback. Read/write this in init, update, and refresh callbacks. Changes are automatically copied back to the object buffer.