Class | Joyau::GameMap |
In: |
Drawable.cpp
|
Parent: | Joyau::Drawable |
This class allows to draw a map, created from some tilesets, and to check collisions between an object and these tiles.
A tileset is a picture, from which tiles are taken.
COL_FULL | = | Joyau::CollisionType.new(true, false, false, false, false) | Collision with everything. | |
COL_LEFT | = | Joyau::CollisionType.new(false, true, false, false, false) | Collision with the left side. | |
COL_RIGHT | = | Joyau::CollisionType.new(false, false, true, false, false) | Collision with the right side. | |
COL_UP | = | Joyau::CollisionType.new(false, false, false, true, false) | Collision with the upper side. | |
COL_DOWN | = | Joyau::CollisionType.new(false, false, false, false, true) | Collision with the downer side. | |
COL_NO | = | Joyau::CollisionType.new(false, false, false, false, false) | Collision with nothing. | |
COL_LEFT_RIGHT | = | Joyau::CollisionType.new(false, true, true, false, false) | Collision with the left and right sides. | |
COL_LEFT_UP | = | Joyau::CollisionType.new(false, true, false, true, false) | Collision with the left and the upper sides. | |
COL_LEFT_DOWN | = | Joyau::CollisionType.new(false, true, false, false, true) | Collision with the left and the downer sides. | |
COL_RIGHT_UP | = | Joyau::CollisionType.new(false, false, true, true, false) | Collision with the right and the upper sides. | |
COL_RIGHT_DOWN | = | Joyau::CollisionType.new(false, false, true, false, true) | Collision with the right and the downer sides. | |
COL_UP_DOWN | = | Joyau::CollisionType.new(false, false, false, true, true) | Collision with the upper and the downer sides. |
Creates a new map, either from an array containing tilesets’ name, or from arguments being either a tileset’s name or tiles.
/* call-seq: new new(tilesets) new(tile, tile2, tile3, tileset, ...) Creates a new map, either from an array containing tilesets' name, or from arguments being either a tileset's name or tiles. */ VALUE wrap<GameMap>(int argc, VALUE *argv, VALUE info) { GameMap *ptr = new GameMap; if (argc >= 1) { if (TYPE(argv[0]) == T_ARRAY) { int size = RARRAY_LEN(argv[0]); for (int i = 0; i < size; ++i) { VALUE val = rb_ary_entry(argv[0], i); ptr->addTileset(StringValuePtr(val)); } } else { for (int i = 0; i < argc; ++i) ptr->addTileset(StringValuePtr(argv[i])); } } VALUE tdata = Data_Wrap_Struct(info, 0, wrapped_free<GameMap>, ptr); return tdata; }
Converts absolute coordinates into relative ones.
/* call-seq: absToRel(x, y) abs2rel(x, y) Converts absolute coordinates into relative ones. */ VALUE GameMap_absToRel(VALUE self, VALUE x, VALUE y) { GameMap &ref = getRef<GameMap>(self); Point ret = ref.absToRel(FIX2INT(x), FIX2INT(y)); return createObject(getClass("Point"), ret); }
Adds a drawable drawn between the map’s tiles.
/* call-seq: addBetween(obj) Adds a drawable drawn between the map's tiles. */ VALUE GameMap_addBetween(VALUE self, VALUE obj)
Adds one or more tiles to the map.
/* call-seq: addElem(tileset_id, tile_x, tile_y, x, y) addElem(tiles) Adds one or more tiles to the map. */ VALUE GameMap_addElem(int argc, VALUE *argv, VALUE self) { if (argc == 5) { GameMap &ref = getRef<GameMap>(self); int tileset = FIX2INT(argv[0]); int tX = FIX2INT(argv[1]); int tY = FIX2INT(argv[2]); int x = FIX2INT(argv[3]); int y = FIX2INT(argv[4]); ref.addElem(tileset, tX, tY, x, y); } else GameMap_push(self, argv[0]); return self; }
Adds a tileset to the map.
/* call-seq: addTileset(tileset) add_tileset(tileset) Adds a tileset to the map. */ VALUE GameMap_addTileset(VALUE self, VALUE name) { GameMap &ref = getRef<GameMap>(self); ref.addTileset(StringValuePtr(name)); return Qnil; }
Centers the map on a point.
/* call-seq: centerOn(x, y) Centers the map on a point. */ VALUE GameMap_centerOn(VALUE self, VALUE x, VALUE y) { GameMap &ref = getRef<GameMap>(self); ref.centerOn(FIX2INT(x), FIX2INT(y)); return Qnil; }
Clears the map.
/* Clears the map. */ VALUE GameMap_clear(VALUE self) { GameMap &ref = getRef<GameMap>(self); ref.clear(); return Qnil; }
Clears the map’s tiles.
/* Clears the map's tiles. */ VALUE GameMap_clearTiles(VALUE self) { GameMap &ref = getRef<GameMap>(self); ref.clearTiles(); return Qnil; }
Clears the list of drawables drawn when drawing the map.
/* Clears the list of drawables drawn when drawing the map. */ VALUE GameMap_clearBetween(VALUE self) { GameMap &ref = getRef<GameMap>(self); ref.clearBetween(); return Qnil; }
Returns the map’s collisionH.
/* Returns the map's collisionH. */ VALUE GameMap_collisionH(VALUE self) { GameMap &ref = getRef<GameMap>(self); return INT2FIX(ref.getCollisionH()); }
Sets the height where collisions are checked. Pixels which have a greater height are ignored.
/* call-seq: collisionH=(val) Sets the height where collisions are checked. Pixels which have a greater height are ignored. */ VALUE GameMap_setCollisionH(VALUE self, VALUE val) { GameMap &ref = getRef<GameMap>(self); ref.setCollisionH(FIX2INT(val)); return val; }
Yields each tile.
/* Yields each tile. */ VALUE GameMap_each_tile(VALUE self) { GameMap &ref = getRef<GameMap>(self); ref.rbEachTile(); return Qnil; }
Yields each tileset.
/* Yields each tileset. */ VALUE GameMap_each_tileset(VALUE self) { GameMap &ref = getRef<GameMap>(self); ref.rbEachTileset(); return Qnil; }
Removes some tiles from the map if they fit to a condition.
/* Removes some tiles from the map if they fit to a condition. */ VALUE GameMap_reject_tiles(VALUE self) { GameMap &ref = getRef<GameMap>(self); ref.rbRejectTiles(); return Qnil; }
Converts relative coordinates into absolute ones.
/* call-seq: relToAbs(x, y) rel2abs(x, y) Converts relative coordinates into absolute ones. */ VALUE GameMap_relToAbs(VALUE self, VALUE x, VALUE y) { GameMap &ref = getRef<GameMap>(self); Point ret = ref.relToAbs(FIX2INT(x), FIX2INT(y)); return createObject(getClass("Point"), ret); }
Sets the size of each tile in the map.
/* call-seq: setTileSize(w, h) set_tile_size(w, h) Sets the size of each tile in the map. */ VALUE GameMap_setTileSize(VALUE self, VALUE w, VALUE h) { GameMap &ref = getRef<GameMap>(self); int _w = FIX2INT(w); int _h = FIX2INT(h); ref.setTileSize(_w, _h); return Qnil; }
Returns the height of a tile.
/* Returns the height of a tile. */ VALUE GameMap_tileHeight(VALUE self) { GameMap &ref = getRef<GameMap>(self); return INT2FIX(ref.getTileH()); }
Returns the width of a tile.
/* Returns the width of a tile. */ VALUE GameMap_tileWidth(VALUE self) { GameMap &ref = getRef<GameMap>(self); return INT2FIX(ref.getTileW()); }
Returns an array containing the map’s tiles.
/* Returns an array containing the map's tiles. */ VALUE GameMap_tiles(VALUE self) { GameMap &ref = getRef<GameMap>(self); return ref.rbTiles(); }