<-- Back to AG_Intro.3


#include <agar/core.h>
#include <agar/map.h>


The MAP interface implements a two-dimensional map of fixed-size tiles, which are stacks of elements Element types include:
MAP_ITEM_TILEPointer to a RG_Tile(3).
MAP_ITEM_WARPPointer to some other node, possibly on another map. This is commonly used by MAP_Actor(3) objects.

Graphical elements define two displacements in pixels of the image from the tile's origin, the centering offset and the motion offset.

The centering offset is typically assigned by a level designer, and the motion offset is for animation purposes. If the map is drawn scaled, the centering offset is scaled to the tile size, but the motion offset is not.

Graphical elements provide the renderer with a list of graphical transformations that should be applied before the tile is drawn (the resulting tile is cached). A per-element layer attribute also defines the attributed layer.


AG_Object(3)-> MAP.


MAP * MAP_New (void *parent, const char *name)

int MAP_AllocNodes (MAP *map, Uint w, Uint h)

void MAP_FreeNodes (MAP *map)

void MAP_SetZoom (MAP *map, int camera, Uint factor)

MAP_New() allocates, initializes and attaches a new map.

MAP_AllocNodes() allocates w x h nodes, assuming that no node is currently allocated. MAP_AllocNodes() returns 0 on success or -1 on failure. The maximum allowable geometry is defined by MAP_WIDTH_MAX and MAP_HEIGHT_MAX. MAP_FreeNodes() releases the nodes allocated by map.

MAP_Resize() reallocates the nodes arrays, initializing the new nodes and freeing the excess ones. MAP_Resize() returns 0 on sucess or -1 on failure.

MAP_SetZoom() sets the zoom factor for a given map view. Actors are displayed to this scale.


void MAP_NodeInit (MAP_Node *node)

void MAP_NodeDestroy (MAP *map, MAP_Node *node)

int MAP_NodeLoad (MAP *map, AG_DataSource *ds, MAP_Node *node)

void MAP_NodeSave (const MAP *map, AG_DataSource *ds, const MAP_Node *node)

MAP_NodeInit() initializes the node structure. MAP_NodeDestroy() frees all resources allocated by node.

MAP_NodeLoad() loads the contents of node (presumed initialized and empty), from data source ds. MAP_NodeSave() saves the contents of node to ds. Both functions are called implicitely by the load() and save() operations of MAP.


void MAP_ItemInit (MAP_Item *mi)

void MAP_ItemDestroy (MAP *map, MAP_Item *mi)

MAP_ItemInit() initializes the mi structure. MAP_ItemDestroy() frees all resources allocated for mi.


void MAP_MoveItem (MAP *mapSrc, MAP_Node *nodeSrc, MAP_Item *miSrc, MAP *mapDst, MAP_Node *nodeDst, int layerDst)

MAP_Item * MAP_CopyItem (const MAP_Item *miSrc, MAP *mapDst, MAP_Node *nodeDst, int layerDst)

void MAP_DelItem (MAP *map, MAP_Node *node, MAP_Item *mi)

MAP_Item * MAP_TileNew (MAP *map, MAP_Node *node, RG_Tileset *ts, Uint tileID)

MAP_Link * MAP_LinkNew (MAP *map, MAP_Node *nodeDst, const char *targetMap, int x, int y, Uint8 dir)

MAP_MoveItem() moves item miSrc from nodeSrc (of mapSrc) over to nodeDst (of mapDst).

MAP_CopyItem() inserts a copy of miSrc on top of nodeDst. The copy is associated with layerDst (or -1 = the source layer).

MAP_DelItem() deletes item mi from node.

MAP_TileNew() creates a reference to the RG_Tile(3) element identified by tileID in the given RG_Tileset(3).

MAP_LinkNew() Creates a link to the node x, y of targetMap. This is the pathname of the destination map (as returned by AG_ObjectCopyName()).


void MAP_AttachActor (MAP *map, MAP_Actor *actor)

void MAP_DetachActor (MAP *map, MAP_Actor *actor)

MAP_AttachActor() attaches the given actor to the map. An object dependency is automatically created, and the map operation of the actor is invoked. This operation is usually responsible for inserting tiles onto the map.

MAP_DetachActor() detaches the given actor from the map. Any pending timer events related to the actor are cancelled, tiles related to the actor are removed and the object dependency is removed.

See MAP_Actor(3) for more information.


AG_Object(3), MAP_Actor(3), MAP_View(3), SG_Intro(3)


The MAP class first appeared in Agar 1.0. ElectronTubeStore