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.

Methods

Constants

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.

Public Class methods

Creates a new map, either from an array containing tilesets’ name, or from arguments being either a tileset’s name or tiles.

[Source]

/*
  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;
}

Public Instance methods

abs2rel(p1, p2)

Alias for absToRel

Converts absolute coordinates into relative ones.

[Source]

/*
  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.

[Source]

/*
  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.

[Source]

/*
  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.

[Source]

/*
  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;
}
add_elem(...)

Alias for addElem

add_tileset(p1)

Alias for addTileset

Centers the map on a point.

[Source]

/*
  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;
}
center_on(p1, p2)

Alias for centerOn

Clears the map.

[Source]

/*
  Clears the map.
*/
VALUE GameMap_clear(VALUE self)
{
   GameMap &ref = getRef<GameMap>(self);
   ref.clear();

   return Qnil;
}

Clears the map’s tiles.

[Source]

/*
  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.

[Source]

/*
  Clears the list of drawables drawn when drawing the map.
*/
VALUE GameMap_clearBetween(VALUE self)
{
   GameMap &ref = getRef<GameMap>(self);
   ref.clearBetween();

   return Qnil;
}
clear_tiles()

Alias for clearTiles

Returns the map’s collisionH.

[Source]

/*
  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.

[Source]

/*
  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;
}
collision_h()

Alias for collisionH

collision_h=(p1)

Alias for collisionH=

Yields each tile.

[Source]

/*
  Yields each tile.
*/
VALUE GameMap_each_tile(VALUE self)
{
   GameMap &ref = getRef<GameMap>(self);
   ref.rbEachTile();

   return Qnil;
}

Yields each tileset.

[Source]

/*
  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.

[Source]

/*
  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;
}
rel2abs(p1, p2)

Alias for relToAbs

Converts relative coordinates into absolute ones.

[Source]

/*
  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.

[Source]

/*
  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;
}
set_tile_size(p1, p2)

Alias for setTileSize

Returns the height of a tile.

[Source]

/*
  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.

[Source]

/*
  Returns the width of a tile.
*/
VALUE GameMap_tileWidth(VALUE self)
{
   GameMap &ref = getRef<GameMap>(self);
   return INT2FIX(ref.getTileW());
}
tile_height()

Alias for tileHeight

tile_width()

Alias for tileWidth

Returns an array containing the map’s tiles.

[Source]

/*
  Returns an array containing the map's tiles.
*/
VALUE GameMap_tiles(VALUE self)
{
   GameMap &ref = getRef<GameMap>(self);
   return ref.rbTiles();
}

Returns an array containing all the map’s tilesets (as Sprite).

[Source]

/*
  Returns an array containing all the map's tilesets (as Sprite).
*/
VALUE GameMap_tilesets(VALUE self)
{
   GameMap &ref = getRef<GameMap>(self);
   return ref.rbTilesets();
}

[Validate]