TileMap Class Reference

This class is responsible for drawing the level tiles. More...

#include <tilemap.hpp>

Inherits GameObject, and ScriptInterface.

List of all members.

Public Member Functions

 TileMap (const TileSet *tileset)
 TileMap (const Reader &reader)
 TileMap (const TileSet *tileset, std::string name, int z_pos, bool solid_, size_t width_, size_t height_)
virtual ~TileMap ()
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
virtual void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.
void goto_node (int node_no)
 Move tilemap until at given node, then stop.
void start_moving ()
 Start moving tilemap.
void stop_moving ()
 Stop tilemap at next node.
virtual void expose (HSQUIRRELVM vm, SQInteger table_idx)
virtual void unexpose (HSQUIRRELVM vm, SQInteger table_idx)
void set (int width, int height, const std::vector< unsigned int > &vec, int z_pos, bool solid)
void resize (int newwidth, int newheight, int fill_id=0)
 resizes the tilemap to a new width and height (tries to not destroy the existing map)
size_t get_width () const
size_t get_height () const
Vector get_offset () const
Vector get_movement (bool actual) const
 Get the movement of this tilemap.
boost::shared_ptr< Pathget_path ()
boost::shared_ptr< PathWalkerget_walker ()
void set_offset (const Vector &offset)
Vector get_tile_position (int x, int y) const
Rectf get_bbox () const
Rectf get_tile_bbox (int x, int y) const
Rect get_tiles_overlapping (const Rectf &rect) const
int get_layer () const
bool is_solid () const
void set_solid (bool solid=true)
 Changes Tilemap's solidity, i.e.
const Tileget_tile (int x, int y) const
 returns tile in row y and column y (of the tilemap)
const Tileget_tile_at (const Vector &pos) const
 returns tile at position pos (in world coordinates)
uint32_t get_tile_id (int x, int y) const
 returns tile in row y and column y (of the tilemap)
uint32_t get_tile_id_at (const Vector &pos) const
 returns tile at position pos (in world coordinates)
void change (int x, int y, uint32_t newtile)
void change_at (const Vector &pos, uint32_t newtile)
void change_all (uint32_t oldtile, uint32_t newtile)
 changes all tiles with the given ID
void set_drawing_effect (DrawingEffect effect)
DrawingEffect get_drawing_effect ()
void fade (float alpha, float seconds=0)
 Start fading the tilemap to opacity given by alpha.
void set_alpha (float alpha)
 Instantly switch tilemap's opacity to alpha.
float get_alpha ()
 Return tilemap's opacity.

Private Types

typedef std::vector< uint32_t > Tiles

Private Member Functions

void update_effective_solid (void)
 TileMap (const TileMap &)
TileMapoperator= (const TileMap &)

Private Attributes

const TileSettileset
Tiles tiles
bool real_solid
bool effective_solid
float speed_x
float speed_y
int width
int height
int z_pos
Vector offset
Vector movement
 The movement that happened last frame.
DrawingEffect drawing_effect
float alpha
 requested tilemap opacity
float current_alpha
 current tilemap opacity
float remaining_fade_time
 seconds until requested tilemap opacity is reached
boost::shared_ptr< Pathpath
boost::shared_ptr< PathWalkerwalker
DrawingContext::Target draw_target
 set to LIGHTMAP to draw to lightmap


Detailed Description

This class is responsible for drawing the level tiles.

Definition at line 39 of file tilemap.hpp.


Member Typedef Documentation

typedef std::vector<uint32_t> TileMap::Tiles [private]

Definition at line 173 of file tilemap.hpp.


Constructor & Destructor Documentation

TileMap::TileMap ( const TileSet tileset  ) 

Definition at line 28 of file tilemap.cpp.

00028                                            :
00029   tileset(new_tileset), 
00030   tiles(),
00031   real_solid(false),
00032   effective_solid(false),
00033   speed_x(1), 
00034   speed_y(1), 
00035   width(0),
00036   height(0), 
00037   z_pos(0), 
00038   offset(Vector(0,0)),
00039   movement(0,0),
00040   drawing_effect(NO_EFFECT),
00041   alpha(1.0), 
00042   current_alpha(1.0),
00043   remaining_fade_time(0),
00044   path(),
00045   walker(),
00046   draw_target(DrawingContext::NORMAL)
00047 {
00048 }

TileMap::TileMap ( const Reader reader  ) 

Definition at line 50 of file tilemap.cpp.

References alpha, current_alpha, current_tileset, draw_target, effective_solid, TileSet::get(), lisp::Lisp::get(), lisp::Lisp::get_lisp(), height, DrawingContext::LIGHTMAP, log_info, log_warning, GameObject::name, DrawingContext::NORMAL, path, reader_get_layer(), real_solid, set_offset(), speed_x, speed_y, tiles, tileset, update_effective_solid(), walker, width, and z_pos.

00050                                      :
00051   tileset(),
00052   tiles(),
00053   real_solid(false),
00054   effective_solid(false),
00055   speed_x(1), 
00056   speed_y(1), 
00057   width(-1),
00058   height(-1), 
00059   z_pos(0), 
00060   offset(Vector(0,0)),
00061   movement(Vector(0,0)), 
00062   drawing_effect(NO_EFFECT),
00063   alpha(1.0), 
00064   current_alpha(1.0), 
00065   remaining_fade_time(0),
00066   path(),
00067   walker(),
00068   draw_target(DrawingContext::NORMAL)
00069 {
00070   tileset = current_tileset;
00071   assert(tileset != NULL);
00072 
00073   reader.get("name",   name);
00074   reader.get("solid",  real_solid);
00075   reader.get("speed",  speed_x);
00076   reader.get("speed-y", speed_y);
00077 
00078   z_pos = reader_get_layer (reader, /* default = */ 0);
00079   
00080   if(real_solid && ((speed_x != 1) || (speed_y != 1))) {
00081     log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl;
00082     speed_x = 1;
00083     speed_y = 1;
00084   }
00085 
00086   const lisp::Lisp* pathLisp = reader.get_lisp("path");
00087   if (pathLisp) {
00088     path.reset(new Path());
00089     path->read(*pathLisp);
00090     walker.reset(new PathWalker(path.get(), /*running*/false));
00091     Vector v = path->get_base();
00092     set_offset(v);
00093   }
00094 
00095   std::string draw_target_s = "normal";
00096   reader.get("draw-target", draw_target_s);
00097   if (draw_target_s == "normal") draw_target = DrawingContext::NORMAL;
00098   if (draw_target_s == "lightmap") draw_target = DrawingContext::LIGHTMAP;
00099 
00100   if (reader.get("alpha", alpha)) {
00101     current_alpha = alpha;
00102   }
00103 
00104   /* Initialize effective_solid based on real_solid and current_alpha. */
00105   effective_solid = real_solid;
00106   update_effective_solid ();
00107 
00108   reader.get("width", width);
00109   reader.get("height", height);
00110   if(width < 0 || height < 0)
00111     throw std::runtime_error("Invalid/No width/height specified in tilemap.");
00112 
00113   if(!reader.get("tiles", tiles))
00114     throw std::runtime_error("No tiles in tilemap.");
00115 
00116   if(int(tiles.size()) != width*height) {
00117     throw std::runtime_error("wrong number of tiles in tilemap.");
00118   }
00119 
00120   bool empty = true;
00121 
00122   // make sure all tiles used on the tilemap are loaded and tilemap isn't empty
00123   for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i) {
00124     if(*i != 0) {
00125       empty = false;
00126     }
00127 
00128     tileset->get(*i);
00129   }
00130 
00131   if(empty)
00132     log_info << "Tilemap '" << name << "', z-pos '" << z_pos << "' is empty." << std::endl;
00133 }

TileMap::TileMap ( const TileSet tileset,
std::string  name,
int  z_pos,
bool  solid_,
size_t  width_,
size_t  height_ 
)

Definition at line 135 of file tilemap.cpp.

References LAYER_GUI, and resize().

00136                                                           :
00137   tileset(new_tileset), 
00138   tiles(),
00139   real_solid(solid),
00140   effective_solid(solid),
00141   speed_x(1), 
00142   speed_y(1), 
00143   width(0),
00144   height(0), 
00145   z_pos(z_pos), 
00146   offset(Vector(0,0)),
00147   movement(Vector(0,0)),
00148   drawing_effect(NO_EFFECT), 
00149   alpha(1.0), 
00150   current_alpha(1.0),
00151   remaining_fade_time(0), 
00152   path(),
00153   walker(),
00154   draw_target(DrawingContext::NORMAL)
00155 {
00156   this->name = name;
00157 
00158   if (this->z_pos > (LAYER_GUI - 100))
00159     this->z_pos = LAYER_GUI - 100;
00160 
00161   resize(width, height);
00162 }

TileMap::~TileMap (  )  [virtual]

Definition at line 164 of file tilemap.cpp.

00165 {
00166 }

TileMap::TileMap ( const TileMap  )  [private]


Member Function Documentation

void TileMap::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Implements GameObject.

Definition at line 169 of file tilemap.cpp.

References alpha, current_alpha, get_offset(), movement, remaining_fade_time, set_offset(), update_effective_solid(), and walker.

00170 {
00171   // handle tilemap fading
00172   if (current_alpha != alpha) {
00173     remaining_fade_time = std::max(0.0f, remaining_fade_time - elapsed_time);
00174     if (remaining_fade_time == 0.0f) {
00175       current_alpha = alpha;
00176     } else {
00177       float amt = (alpha - current_alpha) / (remaining_fade_time / elapsed_time);
00178       if (amt > 0) current_alpha = std::min(current_alpha + amt, alpha);
00179       if (amt < 0) current_alpha = std::max(current_alpha + amt, alpha);
00180     }
00181     update_effective_solid ();
00182   }
00183 
00184   movement = Vector(0,0);
00185   // if we have a path to follow, follow it
00186   if (walker.get()) {
00187     Vector v = walker->advance(elapsed_time);
00188     movement = v - get_offset();
00189     set_offset(v);
00190   }
00191 }

void TileMap::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 194 of file tilemap.cpp.

References current_alpha, Tile::draw(), draw_target, drawing_effect, TileSet::get(), get_tile_position(), get_tiles_overlapping(), DrawingContext::get_translation(), height, DrawingContext::NORMAL, DrawingContext::pop_target(), DrawingContext::pop_transform(), DrawingContext::push_target(), DrawingContext::push_transform(), SCREEN_HEIGHT, SCREEN_WIDTH, DrawingContext::set_alpha(), DrawingContext::set_drawing_effect(), DrawingContext::set_target(), DrawingContext::set_translation(), speed_x, speed_y, tiles, tileset, width, Vector::x, Vector::y, and z_pos.

00195 {
00196   // skip draw if current opacity is 0.0
00197   if (current_alpha == 0.0) return;
00198 
00199   context.push_transform();
00200   if(draw_target != DrawingContext::NORMAL) {
00201     context.push_target();
00202     context.set_target(draw_target);
00203   }
00204 
00205   if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);
00206   if(current_alpha != 1.0) context.set_alpha(current_alpha);
00207 
00208   /* Force the translation to be an integer so that the tiles appear sharper.
00209    * For consistency (i.e., to avoid 1-pixel gaps), this needs to be done even
00210    * for solid tilemaps that are guaranteed to have speed 1.
00211    * FIXME Force integer translation for all graphics, not just tilemaps. */
00212   float trans_x = roundf(context.get_translation().x);
00213   float trans_y = roundf(context.get_translation().y);
00214   context.set_translation(Vector(int(trans_x * speed_x),
00215                                  int(trans_y * speed_y)));
00216 
00217   Rectf draw_rect = Rectf(context.get_translation(),
00218         context.get_translation() + Vector(SCREEN_WIDTH, SCREEN_HEIGHT));
00219   Rect t_draw_rect = get_tiles_overlapping(draw_rect);
00220   Vector start = get_tile_position(t_draw_rect.left, t_draw_rect.top);
00221 
00222   Vector pos;
00223   int tx, ty;
00224 
00225   for(pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
00226     for(pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
00227       int index = ty*width + tx;
00228       assert (index >= 0);
00229       assert (index < (width * height));
00230 
00231       if (tiles[index] == 0) continue;
00232       const Tile* tile = tileset->get(tiles[index]);
00233       assert(tile != 0);
00234       tile->draw(context, pos, z_pos);
00235     } /* for (pos y) */
00236   } /* for (pos x) */
00237 
00238   if(draw_target != DrawingContext::NORMAL) {
00239     context.pop_target();
00240   }
00241   context.pop_transform();
00242 }

void TileMap::goto_node ( int  node_no  ) 

Move tilemap until at given node, then stop.

Definition at line 245 of file tilemap.cpp.

References walker.

Referenced by scripting::TileMap::goto_node().

00246 {
00247   if (!walker.get()) return;
00248   walker->goto_node(node_no);
00249 }

void TileMap::start_moving (  ) 

Start moving tilemap.

Definition at line 252 of file tilemap.cpp.

References walker.

Referenced by scripting::TileMap::start_moving().

00253 {
00254   if (!walker.get()) return;
00255   walker->start_moving();
00256 }

void TileMap::stop_moving (  ) 

Stop tilemap at next node.

Definition at line 259 of file tilemap.cpp.

References walker.

Referenced by scripting::TileMap::stop_moving().

00260 {
00261   if (!walker.get()) return;
00262   walker->stop_moving();
00263 }

void TileMap::expose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 266 of file tilemap.cpp.

References scripting::expose_object(), and GameObject::name.

00267 {
00268   if (name.empty()) return;
00269   scripting::TileMap* _this = new scripting::TileMap(this);
00270   expose_object(vm, table_idx, _this, name, true);
00271 }

void TileMap::unexpose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 274 of file tilemap.cpp.

References GameObject::name, and scripting::unexpose_object().

00275 {
00276   if (name.empty()) return;
00277   scripting::unexpose_object(vm, table_idx, name);
00278 }

void TileMap::set ( int  width,
int  height,
const std::vector< unsigned int > &  vec,
int  z_pos,
bool  solid 
)

Definition at line 281 of file tilemap.cpp.

References TileSet::get(), height, LAYER_GUI, real_solid, tiles, tileset, update_effective_solid(), width, and z_pos.

00283 {
00284   if(int(newt.size()) != newwidth * newheight)
00285     throw std::runtime_error("Wrong tilecount count.");
00286 
00287   width  = newwidth;
00288   height = newheight;
00289 
00290   tiles.resize(newt.size());
00291   tiles = newt;
00292 
00293   if (new_z_pos > (LAYER_GUI - 100))
00294     z_pos = LAYER_GUI - 100;
00295   else
00296     z_pos  = new_z_pos;
00297   real_solid  = newsolid;
00298   update_effective_solid ();
00299 
00300   // make sure all tiles are loaded
00301   for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
00302     tileset->get(*i);
00303 }

void TileMap::resize ( int  newwidth,
int  newheight,
int  fill_id = 0 
)

resizes the tilemap to a new width and height (tries to not destroy the existing map)

Definition at line 306 of file tilemap.cpp.

References height, tiles, and width.

Referenced by TileMap().

00307 {
00308   if(new_width < width) {
00309     // remap tiles for new width
00310     for(int y = 0; y < height && y < new_height; ++y) {
00311       for(int x = 0; x < new_width; ++x) {
00312         tiles[y * new_width + x] = tiles[y * width + x];
00313       }
00314     }
00315   }
00316 
00317   tiles.resize(new_width * new_height, fill_id);
00318 
00319   if(new_width > width) {
00320     // remap tiles
00321     for(int y = std::min(height, new_height)-1; y >= 0; --y) {
00322       for(int x = new_width-1; x >= 0; --x) {
00323         if(x >= width) {
00324           tiles[y * new_width + x] = fill_id;
00325           continue;
00326         }
00327 
00328         tiles[y * new_width + x] = tiles[y * width + x];
00329       }
00330     }
00331   }
00332 
00333   height = new_height;
00334   width = new_width;
00335 }

size_t TileMap::get_width (  )  const [inline]

Definition at line 72 of file tilemap.hpp.

Referenced by change_all(), and FlipLevelTransformer::transform_tilemap().

00073   { return width; }

size_t TileMap::get_height (  )  const [inline]

Definition at line 75 of file tilemap.hpp.

Referenced by change_all(), and FlipLevelTransformer::transform_tilemap().

00076   { return height; }

Vector TileMap::get_offset (  )  const [inline]

Definition at line 78 of file tilemap.hpp.

References offset.

Referenced by FlipLevelTransformer::transform_tilemap(), and update().

00079   { return offset; }

Vector TileMap::get_movement ( bool  actual  )  const [inline]

Get the movement of this tilemap.

The collision detection code may need a non-negative y-movement. Passing `false' as the `actual' argument will provide that. Used exclusively in src/supertux/sector.cpp.

Definition at line 84 of file tilemap.hpp.

References movement, Vector::x, and Vector::y.

00085   {
00086     if(actual) {
00087       return movement;
00088     } else {
00089       return Vector(movement.x, std::max(0.0f,movement.y));
00090     }
00091   }

boost::shared_ptr<Path> TileMap::get_path (  )  [inline]

Definition at line 93 of file tilemap.hpp.

References path.

Referenced by FlipLevelTransformer::transform_tilemap().

00094   { return path; }

boost::shared_ptr<PathWalker> TileMap::get_walker (  )  [inline]

Definition at line 96 of file tilemap.hpp.

References walker.

00097   { return walker; }

void TileMap::set_offset ( const Vector offset  )  [inline]

Definition at line 99 of file tilemap.hpp.

References offset.

Referenced by TileMap(), FlipLevelTransformer::transform_tilemap(), and update().

00100   { this->offset = offset; }

Vector TileMap::get_tile_position ( int  x,
int  y 
) const [inline]

Definition at line 104 of file tilemap.hpp.

References offset.

Referenced by draw(), get_bbox(), and get_tile_bbox().

00105   { return offset + Vector(x,y) * 32; }

Rectf TileMap::get_bbox (  )  const [inline]

Definition at line 107 of file tilemap.hpp.

References get_tile_position().

Referenced by FlipLevelTransformer::transform_tilemap().

Rectf TileMap::get_tile_bbox ( int  x,
int  y 
) const [inline]

Definition at line 110 of file tilemap.hpp.

References get_tile_position().

00111   { return Rectf(get_tile_position(x, y), get_tile_position(x+1, y+1)); }

Rect TileMap::get_tiles_overlapping ( const Rectf rect  )  const

Definition at line 338 of file tilemap.cpp.

References Rectf::get_bottom(), Rectf::get_left(), Rectf::get_right(), Rectf::get_top(), height, Rectf::move(), offset, and width.

Referenced by draw().

00339 {
00340   Rectf rect2 = rect;
00341   rect2.move(-offset);
00342 
00343   int t_left   = std::max(0     , int(floorf(rect2.get_left  () / 32)));
00344   int t_right  = std::min(width , int(ceilf (rect2.get_right () / 32)));
00345   int t_top    = std::max(0     , int(floorf(rect2.get_top   () / 32)));
00346   int t_bottom = std::min(height, int(ceilf (rect2.get_bottom() / 32)));
00347   return Rect(t_left, t_top, t_right, t_bottom);
00348 }

int TileMap::get_layer (  )  const [inline]

Definition at line 117 of file tilemap.hpp.

00118   { return z_pos; }

bool TileMap::is_solid (  )  const [inline]

Definition at line 120 of file tilemap.hpp.

References effective_solid, and real_solid.

Referenced by worldmap::WorldMap::add_object(), Sector::before_object_add(), and Sector::draw().

00121   { return real_solid && effective_solid; }

void TileMap::set_solid ( bool  solid = true  ) 

Changes Tilemap's solidity, i.e.

whether to consider it when doing collision detection.

Definition at line 351 of file tilemap.cpp.

References real_solid, and update_effective_solid().

00352 {
00353   this->real_solid = solid;
00354   update_effective_solid ();
00355 }

const Tile * TileMap::get_tile ( int  x,
int  y 
) const

returns tile in row y and column y (of the tilemap)

Definition at line 369 of file tilemap.cpp.

References TileSet::get(), get_tile_id(), and tileset.

00370 {
00371   uint32_t id = get_tile_id(x, y);
00372   return tileset->get(id);
00373 }

const Tile * TileMap::get_tile_at ( const Vector pos  )  const

returns tile at position pos (in world coordinates)

Definition at line 383 of file tilemap.cpp.

References TileSet::get(), get_tile_id_at(), and tileset.

00384 {
00385   uint32_t id = get_tile_id_at(pos);
00386   return tileset->get(id);
00387 }

uint32_t TileMap::get_tile_id ( int  x,
int  y 
) const

returns tile in row y and column y (of the tilemap)

Definition at line 358 of file tilemap.cpp.

References height, tiles, and width.

Referenced by change_all(), get_tile(), get_tile_id_at(), and FlipLevelTransformer::transform_tilemap().

00359 {
00360   if(x < 0 || x >= width || y < 0 || y >= height) {
00361     //log_warning << "tile outside tilemap requested" << std::endl;
00362     return 0;
00363   }
00364 
00365   return tiles[y*width + x];
00366 }

uint32_t TileMap::get_tile_id_at ( const Vector pos  )  const

returns tile at position pos (in world coordinates)

Definition at line 376 of file tilemap.cpp.

References get_tile_id(), offset, Vector::x, and Vector::y.

Referenced by get_tile_at().

00377 {
00378   Vector xy = (pos - offset) / 32;
00379   return get_tile_id(int(xy.x), int(xy.y));
00380 }

void TileMap::change ( int  x,
int  y,
uint32_t  newtile 
)

Definition at line 390 of file tilemap.cpp.

References height, tiles, and width.

Referenced by change_all(), change_at(), and FlipLevelTransformer::transform_tilemap().

00391 {
00392   assert(x >= 0 && x < width && y >= 0 && y < height);
00393   tiles[y*width + x] = newtile;
00394 }

void TileMap::change_at ( const Vector pos,
uint32_t  newtile 
)

Definition at line 397 of file tilemap.cpp.

References change(), offset, Vector::x, and Vector::y.

00398 {
00399   Vector xy = (pos - offset) / 32;
00400   change(int(xy.x), int(xy.y), newtile);
00401 }

void TileMap::change_all ( uint32_t  oldtile,
uint32_t  newtile 
)

changes all tiles with the given ID

Definition at line 404 of file tilemap.cpp.

References change(), get_height(), get_tile_id(), and get_width().

00405 {
00406   for (size_t x = 0; x < get_width(); x++) {
00407     for (size_t y = 0; y < get_height(); y++) {
00408       if (get_tile_id(x,y) != oldtile)
00409         continue;
00410 
00411       change(x,y,newtile);
00412     }
00413   }
00414 }

void TileMap::set_drawing_effect ( DrawingEffect  effect  )  [inline]

Definition at line 144 of file tilemap.hpp.

References drawing_effect.

Referenced by FlipLevelTransformer::transform_tilemap().

00145   {
00146     drawing_effect = effect;
00147   }

DrawingEffect TileMap::get_drawing_effect (  )  [inline]

Definition at line 149 of file tilemap.hpp.

References drawing_effect.

Referenced by FlipLevelTransformer::transform_tilemap().

00150   {
00151     return drawing_effect;
00152   }

void TileMap::fade ( float  alpha,
float  seconds = 0 
)

Start fading the tilemap to opacity given by alpha.

Destination opacity will be reached after seconds seconds. Also influences solidity.

Definition at line 417 of file tilemap.cpp.

References remaining_fade_time.

Referenced by scripting::TileMap::fade().

00418 {
00419   this->alpha = alpha;
00420   this->remaining_fade_time = seconds;
00421 }

void TileMap::set_alpha ( float  alpha  ) 

Instantly switch tilemap's opacity to alpha.

Also influences solidity.

Definition at line 424 of file tilemap.cpp.

References current_alpha, remaining_fade_time, and update_effective_solid().

Referenced by scripting::TileMap::set_alpha().

00425 {
00426   this->alpha = alpha;
00427   this->current_alpha = alpha;
00428   this->remaining_fade_time = 0;
00429   update_effective_solid ();
00430 }

float TileMap::get_alpha (  ) 

Return tilemap's opacity.

Note that while the tilemap is fading in or out, this will return the current alpha value, not the target alpha.

Definition at line 433 of file tilemap.cpp.

References current_alpha.

Referenced by scripting::TileMap::get_alpha().

00434 {
00435   return this->current_alpha;
00436 }

void TileMap::update_effective_solid ( void   )  [private]

Definition at line 442 of file tilemap.cpp.

References current_alpha, effective_solid, and real_solid.

Referenced by set(), set_alpha(), set_solid(), TileMap(), and update().

00443 {
00444   if (!real_solid)
00445     effective_solid = false;
00446   else if (effective_solid && (current_alpha < .25))
00447     effective_solid = false;
00448   else if (!effective_solid && (current_alpha >= .75))
00449     effective_solid = true;
00450 }

TileMap& TileMap::operator= ( const TileMap  )  [private]


Member Data Documentation

const TileSet* TileMap::tileset [private]

Definition at line 171 of file tilemap.hpp.

Referenced by draw(), get_tile(), get_tile_at(), set(), and TileMap().

Tiles TileMap::tiles [private]

Definition at line 174 of file tilemap.hpp.

Referenced by change(), draw(), get_tile_id(), resize(), set(), and TileMap().

bool TileMap::real_solid [private]

Definition at line 180 of file tilemap.hpp.

Referenced by is_solid(), set(), set_solid(), TileMap(), and update_effective_solid().

bool TileMap::effective_solid [private]

Definition at line 181 of file tilemap.hpp.

Referenced by is_solid(), TileMap(), and update_effective_solid().

float TileMap::speed_x [private]

Definition at line 184 of file tilemap.hpp.

Referenced by draw(), and TileMap().

float TileMap::speed_y [private]

Definition at line 185 of file tilemap.hpp.

Referenced by draw(), and TileMap().

int TileMap::width [private]

Definition at line 186 of file tilemap.hpp.

Referenced by change(), draw(), get_tile_id(), get_tiles_overlapping(), resize(), set(), and TileMap().

int TileMap::height [private]

Definition at line 186 of file tilemap.hpp.

Referenced by change(), draw(), get_tile_id(), get_tiles_overlapping(), resize(), set(), and TileMap().

int TileMap::z_pos [private]

Definition at line 187 of file tilemap.hpp.

Referenced by draw(), set(), and TileMap().

Vector TileMap::offset [private]

Definition at line 188 of file tilemap.hpp.

Referenced by change_at(), get_offset(), get_tile_id_at(), get_tile_position(), get_tiles_overlapping(), and set_offset().

Vector TileMap::movement [private]

The movement that happened last frame.

Definition at line 189 of file tilemap.hpp.

Referenced by get_movement(), and update().

DrawingEffect TileMap::drawing_effect [private]

Definition at line 191 of file tilemap.hpp.

Referenced by draw(), get_drawing_effect(), and set_drawing_effect().

float TileMap::alpha [private]

requested tilemap opacity

Definition at line 192 of file tilemap.hpp.

Referenced by TileMap(), and update().

float TileMap::current_alpha [private]

current tilemap opacity

Definition at line 193 of file tilemap.hpp.

Referenced by draw(), get_alpha(), set_alpha(), TileMap(), update(), and update_effective_solid().

float TileMap::remaining_fade_time [private]

seconds until requested tilemap opacity is reached

Definition at line 194 of file tilemap.hpp.

Referenced by fade(), set_alpha(), and update().

boost::shared_ptr<Path> TileMap::path [private]

Definition at line 196 of file tilemap.hpp.

Referenced by get_path(), and TileMap().

boost::shared_ptr<PathWalker> TileMap::walker [private]

Definition at line 197 of file tilemap.hpp.

Referenced by get_walker(), goto_node(), start_moving(), stop_moving(), TileMap(), and update().

DrawingContext::Target TileMap::draw_target [private]

set to LIGHTMAP to draw to lightmap

Definition at line 199 of file tilemap.hpp.

Referenced by draw(), and TileMap().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:37 2014 for SuperTux by  doxygen 1.5.1