PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
object.h File Reference

snes object engine functionality. More...

#include <snes/snestypes.h>

Go to the source code of this file.

Data Structures

struct  t_objs
 object definition (64 bytes) More...
 

Macros

#define ACT_BURN   0x0020
 Action type BURN for object.
 
#define ACT_CLIMB   0x0008
 Action type CLIMB for object.
 
#define ACT_DIE   0x0010
 Action type DIE for object.
 
#define ACT_FALL   0x0004
 Action type FALL for object.
 
#define ACT_JUMP   0x0002
 Action type JUMP for object.
 
#define ACT_STAND   0x0000
 Action type STAND for object.
 
#define ACT_WALK   0x0001
 Action type WALK for object.
 
#define OB_MAX   64
 
#define OB_TYPE_MAX   64
 
#define T_EMPTY   0x0000
 Type Empty (action will be fall) for tile

 
#define T_FIRES   0x0002
 Type Fire (action will be burn) for tile

 
#define T_LADDER   0x0001
 Type Ladder (action will be climb) for tile

 
#define T_PLATE   0x0008
 Type Plate (action will be jump through and land) for tile

 
#define T_SLOPED1   0x0021
 Type Slope 1x1 Down ◣ (action will be descend on it) for tile.
 
#define T_SLOPELD2   0x0023
 Type Slope 2x1 lower half Down ◣ (action will be descend on it) for tile.
 
#define T_SLOPELU2   0x0022
 Type Slope 2x1 lower half Up ◢ (action will be climb on it) for tile.
 
#define T_SLOPEU1   0x0020
 Type Slope 1x1 Up ◢ (action will be climb on it) for tile

 
#define T_SLOPEUD2   0x0025
 Type Slope 2x1 upper half Down ◣ (action will be descend on it) for tile

 
#define T_SLOPEUU2   0x0024
 Type Slope 2x1 upper half Up ◢ (action will be climb on it) for tile.
 
#define T_SOLID   0xFF00
 Type Solid (action is walk only) for tile

 
#define T_SPIKE   0x0004
 Type Spike (action will be die) for tile

 

Functions

void objCollidMap (u16 objhandle)
 check if an object collides the map More...
 
void objCollidMap1D (u16 objhandle)
 check if an object collides the map More...
 
void objCollidMapWithSlopes (u16 objhandle)
 check if an object collides the map with map slopes management More...
 
u16 objCollidObj (u16 objhandle1, u16 objhandle2)
 check if two objects are colliding More...
 
void objGetPointer (u16 objhandle)
 get the pointer to an object from its handle (need to do -1 to have offset after), objptr will has the pointer of the object More...
 
void objInitEngine (void)
 Initialize object engine, need to be called once.
 
void objInitFunctions (u8 objtype, void *initfct, void *updfct, void *reffct)
 Initialize the object type functions (initialize, update) More...
 
void objKill (u16 objhandle)
 kill an object from the game More...
 
void objKillAll (void)
 kill all objects currently active
 
void objLoadObjects (u8 *sourceO)
 Load all objects for a specific table in memory. More...
 
u16 objNew (u8 objtype, u16 x, u16 y)
 Initialize a new object in game, objgetid will has the id of the object. More...
 
void objRefreshAll (void)
 call refresh function for all objects currently on screen. More...
 
void objUpdateAll (void)
 call update function for all objects currently active (if they are in "virtual screen" coordinates). More...
 
void objUpdateXY (u16 objhandle)
 Update X & Y coordinates of object regarding its own velocitys. More...
 

Variables

t_objs objbuffers [OB_MAX]
 current object buffer with all objects
 
u16 objgetid
 id of current object (useful when creating it)
 
u16 objptr
 pointer to current object
 
u8 objtokill
 put 1 in variable to kill current object
 

Detailed Description

snes object engine functionality.

64 maximum of objects managed by engine

32 type of objects maximum by engine

Macro Definition Documentation

◆ OB_MAX

#define OB_MAX   64

total number of objects in the game

◆ OB_TYPE_MAX

#define OB_TYPE_MAX   64

total number of type of objects in the game

Function Documentation

◆ objCollidMap()

objCollidMap ( u16  objhandle)

check if an object collides the map

Parameters
objhandlehandle of the object

update tilestand, tileabove with tiles on map regarding object attributes

update xvel, yvel with velocity regarding tiles on map

Examples
games/likemario/LikeMario.c.

◆ objCollidMap1D()

objCollidMap1D ( u16  objhandle)

check if an object collides the map

Parameters
objhandlehandle of the object

update tilestand, tileabove with tiles on map regarding object attributes

update xvel, yvel with no gravity regarding tiles on map

◆ objCollidMapWithSlopes()

objCollidMapWithSlopes ( u16  objhandle)

check if an object collides the map with map slopes management

Parameters
objhandlehandle of the object

update tilestand, tileabove with tiles on map regarding object attributes

update xvel, yvel with velocity regarding tiles on map

the map can contain slopes, check the constants ($20..$25) the add them to your map

◆ objCollidObj()

objCollidObj ( u16  objhandle1,
u16  objhandle2 
)

check if two objects are colliding

Parameters
objhandle1handle of the 1st object
objhandle2handle of the 2nd object
Returns
1 if collision detected, 0 elsewhere

◆ objGetPointer()

objGetPointer ( u16  objhandle)

get the pointer to an object from its handle (need to do -1 to have offset after), objptr will has the pointer of the object

Parameters
objhandlehandle of the object
Examples
games/likemario/LikeMario.c, and objects/moveobjects/moveobjects.c.

◆ objInitFunctions()

objInitFunctions ( u8  objtype,
void *  initfct,
void *  updfct,
void *  reffct 
)

Initialize the object type functions (initialize, update)

Parameters
objtypeThe type of object depending of the game
initfctThe address of the function when we init the type of object
updfctThe address of the function when we update the type of object (need to be called once per frame)
reffctThe address of the function when we refresh sprites of object (need to be called once per frame)

init function must have 5 unsigned short (u16) parameters

  • xp,yp are default coordinates values for x and y
  • type is the type oobjects
  • minx, miny are minimal and maximal values for objects in x axis

update function must have 1 parameter

  • idx is the id of the object in the object list

refresh function must have 1 parameter

  • idx is the id of the object in the object list
Examples
games/likemario/LikeMario.c, objects/mapandobjects/mapandobjects.c, objects/moveobjects/moveobjects.c, and objects/nogravityobject/nogravityobjects.c.

◆ objKill()

objKill ( u16  objhandle)

kill an object from the game

Parameters
objhandlehandle of the object

◆ objLoadObjects()

objLoadObjects ( u8 *  sourceO)

Load all objects for a specific table in memory.

Parameters
sourceOtable of objects

Call, after loading, each init function of the type of objects for each object

The table has an entry with x,y,type,minx,maxx for each object

  • x,y are coordinates of object,
  • type if the type of the object (maximum 32 types)
  • minx,maxx are the coordinates of minimum & maxinmum possible on x

the last four parameters are useful to do some actions where minimum or maximum is reached

The table needs to finish with FFFF to indicate that no more objects are availables

Examples
games/likemario/LikeMario.c, objects/mapandobjects/mapandobjects.c, objects/moveobjects/moveobjects.c, and objects/nogravityobject/nogravityobjects.c.

◆ objNew()

objNew ( u8  objtype,
u16  x,
u16  y 
)

Initialize a new object in game, objgetid will has the id of the object.

Parameters
objtypeThe type of object depending of the game
xThe X coordinate of object on map or screen
yThe Y coordinate of object on map or screen
Returns
id of the object in object id table
Examples
games/likemario/LikeMario.c, and objects/moveobjects/moveobjects.c.

◆ objRefreshAll()

objRefreshAll ( void  )

call refresh function for all objects currently on screen.

useful to avoid flickering when using a platform scrolling game.

screen coordinates are -32<x<256 and -32<y<y<224.

◆ objUpdateAll()

objUpdateAll ( void  )

call update function for all objects currently active (if they are in "virtual screen" coordinates).

"virtual screen" coordinates are -64<x<320 and -64<y<288.

Examples
games/likemario/LikeMario.c, objects/mapandobjects/mapandobjects.c, objects/moveobjects/moveobjects.c, and objects/nogravityobject/nogravityobjects.c.

◆ objUpdateXY()

objUpdateXY ( u16  objhandle)

Update X & Y coordinates of object regarding its own velocitys.

Parameters
objhandlehandle of the object

It uses xvel and yvel to do such computation

Examples
games/likemario/LikeMario.c.