void TileMap::set_alpha(float alpha_) { m_alpha = alpha_; m_current_alpha = m_alpha; m_remaining_fade_time = 0; update_effective_solid (); }
void TileMap::set_alpha(float alpha_) { this->alpha = alpha_; this->current_alpha = alpha; this->remaining_fade_time = 0; update_effective_solid (); }
void TileMap::update(float dt_sec) { // handle tilemap fading if (m_current_alpha != m_alpha) { m_remaining_fade_time = std::max(0.0f, m_remaining_fade_time - dt_sec); if (m_remaining_fade_time == 0.0f) { m_current_alpha = m_alpha; } else { float_channel(m_alpha, m_current_alpha, m_remaining_fade_time, dt_sec); } update_effective_solid (); } // handle tint fading if (m_current_tint.red != m_tint.red || m_current_tint.green != m_tint.green || m_current_tint.blue != m_tint.blue || m_current_tint.alpha != m_tint.alpha) { m_remaining_tint_fade_time = std::max(0.0f, m_remaining_tint_fade_time - dt_sec); if (m_remaining_tint_fade_time == 0.0f) { m_current_tint = m_tint; } else { float_channel(m_tint.red , m_current_tint.red , m_remaining_tint_fade_time, dt_sec); float_channel(m_tint.green, m_current_tint.green, m_remaining_tint_fade_time, dt_sec); float_channel(m_tint.blue , m_current_tint.blue , m_remaining_tint_fade_time, dt_sec); float_channel(m_tint.alpha, m_current_tint.alpha, m_remaining_tint_fade_time, dt_sec); } } m_movement = Vector(0,0); // if we have a path to follow, follow it if (get_walker()) { get_walker()->update(dt_sec); Vector v = get_walker()->get_pos(); if (get_path() && get_path()->is_valid()) { m_movement = v - get_offset(); set_offset(v); } else { set_offset(Vector(0, 0)); } } }
void TileMap::update(float elapsed_time) { // handle tilemap fading if (current_alpha != alpha) { remaining_fade_time = std::max(0.0f, remaining_fade_time - elapsed_time); if (remaining_fade_time == 0.0f) { current_alpha = alpha; } else { float_channel(alpha, current_alpha, remaining_fade_time, elapsed_time); } update_effective_solid (); } // handle tint fading if (current_tint.red != tint.red || current_tint.green != tint.green || current_tint.blue != tint.blue || current_tint.alpha != tint.alpha) { remaining_tint_fade_time = std::max(0.0f, remaining_tint_fade_time - elapsed_time); if (remaining_tint_fade_time == 0.0f) { current_tint = tint; } else { float_channel(tint.red , current_tint.red , remaining_tint_fade_time, elapsed_time); float_channel(tint.green, current_tint.green, remaining_tint_fade_time, elapsed_time); float_channel(tint.blue , current_tint.blue , remaining_tint_fade_time, elapsed_time); float_channel(tint.alpha, current_tint.alpha, remaining_tint_fade_time, elapsed_time); } } movement = Vector(0,0); // if we have a path to follow, follow it if (walker.get()) { Vector v = walker->advance(elapsed_time); movement = v - get_offset(); set_offset(v); } }
void TileMap::set(int newwidth, int newheight, const std::vector<unsigned int>&newt, int new_z_pos, bool newsolid) { if(int(newt.size()) != newwidth * newheight) throw std::runtime_error("Wrong tilecount count."); width = newwidth; height = newheight; tiles.resize(newt.size()); tiles = newt; if (new_z_pos > (LAYER_GUI - 100)) z_pos = LAYER_GUI - 100; else z_pos = new_z_pos; real_solid = newsolid; update_effective_solid (); // make sure all tiles are loaded for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i) tileset->get(*i); }
void TileMap::update(float elapsed_time) { // handle tilemap fading if (current_alpha != alpha) { remaining_fade_time = std::max(0.0f, remaining_fade_time - elapsed_time); if (remaining_fade_time == 0.0f) { current_alpha = alpha; } else { float amt = (alpha - current_alpha) / (remaining_fade_time / elapsed_time); if (amt > 0) current_alpha = std::min(current_alpha + amt, alpha); if (amt < 0) current_alpha = std::max(current_alpha + amt, alpha); } update_effective_solid (); } movement = Vector(0,0); // if we have a path to follow, follow it if (walker.get()) { Vector v = walker->advance(elapsed_time); movement = v - get_offset(); set_offset(v); } }
void TileMap::set(int newwidth, int newheight, const std::vector<unsigned int>&newt, int new_z_pos, bool newsolid) { if (int(newt.size()) != newwidth * newheight) throw std::runtime_error("Wrong tilecount count."); m_width = newwidth; m_height = newheight; m_tiles.resize(newt.size()); m_tiles = newt; if (new_z_pos > (LAYER_GUI - 100)) m_z_pos = LAYER_GUI - 100; else m_z_pos = new_z_pos; m_real_solid = newsolid; update_effective_solid (); // make sure all tiles are loaded for (const auto& tile : m_tiles) m_tileset->get(tile); }
TileMap::TileMap(const Reader& reader) : editor_active(true), tileset(), tiles(), real_solid(false), effective_solid(false), speed_x(1), speed_y(1), width(-1), height(-1), z_pos(0), offset(Vector(0,0)), movement(Vector(0,0)), drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0), path(), walker(), draw_target(DrawingContext::NORMAL) { tileset = current_tileset; assert(tileset != NULL); reader.get("name", name); reader.get("solid", real_solid); reader.get("speed", speed_x); reader.get("speed-y", speed_y); z_pos = reader_get_layer (reader, /* default = */ 0); if(real_solid && ((speed_x != 1) || (speed_y != 1))) { log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl; speed_x = 1; speed_y = 1; } const lisp::Lisp* pathLisp = reader.get_lisp("path"); if (pathLisp) { path.reset(new Path()); path->read(*pathLisp); walker.reset(new PathWalker(path.get(), /*running*/false)); Vector v = path->get_base(); set_offset(v); } std::string draw_target_s = "normal"; reader.get("draw-target", draw_target_s); if (draw_target_s == "normal") draw_target = DrawingContext::NORMAL; if (draw_target_s == "lightmap") draw_target = DrawingContext::LIGHTMAP; if (reader.get("alpha", alpha)) { current_alpha = alpha; } /* Initialize effective_solid based on real_solid and current_alpha. */ effective_solid = real_solid; update_effective_solid (); reader.get("width", width); reader.get("height", height); if(width < 0 || height < 0) throw std::runtime_error("Invalid/No width/height specified in tilemap."); if(!reader.get("tiles", tiles)) throw std::runtime_error("No tiles in tilemap."); if(int(tiles.size()) != width*height) { throw std::runtime_error("wrong number of tiles in tilemap."); } bool empty = true; // make sure all tiles used on the tilemap are loaded and tilemap isn't empty for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i) { if(*i != 0) { empty = false; } tileset->get(*i); } if(empty) { log_info << "Tilemap '" << name << "', z-pos '" << z_pos << "' is empty." << std::endl; } }
void TileMap::set_solid(bool solid) { this->real_solid = solid; update_effective_solid (); }
TileMap::TileMap(const TileSet *tileset_, const ReaderMapping& reader) : GameObject(reader), ExposedObject<TileMap, scripting::TileMap>(this), PathObject(), m_editor_active(true), m_tileset(tileset_), m_tiles(), m_real_solid(false), m_effective_solid(false), m_speed_x(1), m_speed_y(1), m_width(-1), m_height(-1), m_z_pos(0), m_offset(Vector(0,0)), m_movement(Vector(0,0)), m_flip(NO_FLIP), m_alpha(1.0), m_current_alpha(1.0), m_remaining_fade_time(0), m_tint(1, 1, 1), m_current_tint(1, 1, 1), m_remaining_tint_fade_time(0), m_running(false), m_draw_target(DrawingTarget::COLORMAP), m_new_size_x(0), m_new_size_y(0), m_new_offset_x(0), m_new_offset_y(0), m_add_path(false) { assert(m_tileset); reader.get("solid", m_real_solid); bool backward_compatibility_fudge = false; if (!reader.get("speed-x", m_speed_x)) { if (reader.get("speed", m_speed_x)) { backward_compatibility_fudge = true; } } if (!reader.get("speed-y", m_speed_y)) { if (backward_compatibility_fudge) { m_speed_y = m_speed_x; } } m_z_pos = reader_get_layer(reader, 0); if (!Editor::is_active()) { if (m_real_solid && ((m_speed_x != 1) || (m_speed_y != 1))) { log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl; m_speed_x = 1; m_speed_y = 1; } } init_path(reader, false); std::string draw_target_s = "normal"; reader.get("draw-target", draw_target_s); if (draw_target_s == "normal") m_draw_target = DrawingTarget::COLORMAP; if (draw_target_s == "lightmap") m_draw_target = DrawingTarget::LIGHTMAP; if (reader.get("alpha", m_alpha)) { m_current_alpha = m_alpha; } std::vector<float> vColor; if (reader.get("tint", vColor)) { m_current_tint = Color(vColor); m_tint = m_current_tint; } /* Initialize effective_solid based on real_solid and current_alpha. */ m_effective_solid = m_real_solid; update_effective_solid (); reader.get("width", m_width); reader.get("height", m_height); if (m_width < 0 || m_height < 0) { //throw std::runtime_error("Invalid/No width/height specified in tilemap."); m_width = 0; m_height = 0; m_tiles.clear(); resize(static_cast<int>(Sector::get().get_width() / 32.0f), static_cast<int>(Sector::get().get_height() / 32.0f)); m_editor_active = false; } else { if (!reader.get("tiles", m_tiles)) throw std::runtime_error("No tiles in tilemap."); if (int(m_tiles.size()) != m_width * m_height) { throw std::runtime_error("wrong number of tiles in tilemap."); } } bool empty = true; // make sure all tiles used on the tilemap are loaded and tilemap isn't empty for (const auto& tile : m_tiles) { if (tile != 0) { empty = false; } m_tileset->get(tile); } if (empty) { log_info << "Tilemap '" << get_name() << "', z-pos '" << m_z_pos << "' is empty." << std::endl; } }