VgaGames4 - object man-pages

[.. upper level ..]

vg4->object->collision_call()

Call a collision-function for each given collision.

SYNTAX
int vg4->object->collision_call(void *vgame, unsigned int instanceid, struct VG_Coll *collp, int nr_coll)

FUNCTION PARAMETERS
vgame Private structure of the game, or NULL if not existing
instanceid Instance-ID for moving object-instance
collp Array of collisions (got from vg4->collision->setpos())
nr_coll Number of collisions in collp

RETURN VALUE
Returns the return-value of the collision-functions (one from enum VG_COLL_RETURNS)

DESCRIPTION
Call a collision-function for each given collision. The collision-function must be registered with vg4->object->collision_add(). The correct collision-function of each collision is chosen according to the moving instanceid and each hit collp[]->instanceid. If it is not found, VG_COLL_RETURN_CONTINUE is returned. The return-value should be interpreted as follows: - VG_COLL_RETURN_CONTINUE Continue moving - VG_COLL_RETURN_STOP_X Stop x-moving and continue y-moving - VG_COLL_RETURN_STOP_Y Stop y-moving and continue x-moving - VG_COLL_RETURN_STOP Step one back and stop moving - VG_COLL_RETURN_DEAD (Destroy yourself and) return immediately If the collision-functions return different return-values, VG_COLL_RETURN_DEAD precedes VG_COLL_RETURN_STOP[_XY] which precedes VG_COLL_RETURN_CONTINUE.

EXAMPLE
/* move object-instance one step to the right and check for collision */

struct VG_Coll *collp;
int canz, iret;

/* move one step and set new position into collision-tag ctag */
rect.x++;  /* increment x-value of the rectangle of object-instance */

/* update position and check for collisions */
canz = vg4->collision->setpos(ctag, instanceid, &rect, &collp);

/* call corresponding collision-functions */
iret = vg4->object->collision_call(vgame, instanceid, collp, canz);
if (collp != NULL) { free(collp); }
if (iret == VG_COLL_RETURN_STOP || iret == VG_COLL_RETURN_STOP_X) {
  /* back to last position and update position */
  rect.x--;
  vg4->collision->setpos(ctag, instanceid, &rect, NULL);
} else if (iret == VG_COLL_RETURN_DEAD) {  /* destroy and return */
  vg4->object->destroy(vgame, instanceid);
  return;
}

SEE ALSO
vg4->object->collision_add() vg4->collision->setpos() vg4->misc->move_and_check_collisions()