/** * @brief Returns the pixel bits object of a frame. * * It represents the transparent bits of the frame and permits to detect pixel collisions. * The pixel collisions must be enabled. * * @param frame a frame of the animation * @return the pixel bits object of a frame */ PixelBits& SpriteAnimationDirection::get_pixel_bits(int frame) const { SOLARUS_ASSERT(pixel_bits != NULL, "Pixel-precise collisions are not enabled for this sprite"); SOLARUS_ASSERT(frame >= 0 && frame < nb_frames, "Invalid frame number"); return *pixel_bits[frame]; }
/** * \brief Returns a boolean value saved. * \param key Name of the value to get. * \return The boolean value associated with this key or false. */ bool Savegame::get_boolean(const std::string& key) const { SOLARUS_ASSERT(LuaTools::is_valid_lua_identifier(key), std::string("Savegame variable '") + key + "' is not a valid key"); bool result = false; const auto& it = saved_values.find(key); if (it != saved_values.end()) { const SavedValue& value = it->second; SOLARUS_ASSERT(value.type == SavedValue::VALUE_BOOLEAN, std::string("Value '") + key + "' is not a boolean"); result = value.int_data != 0; } return result; }
/** * \brief Returns a integer value saved. * \param key Name of the value to get. * \return The integer value associated with this key or 0. */ int Savegame::get_integer(const std::string& key) const { SOLARUS_ASSERT(LuaTools::is_valid_lua_identifier(key), std::string("Savegame variable '") + key + "' is not a valid key"); int result = 0; const auto& it = saved_values.find(key); if (it != saved_values.end()) { const SavedValue& value = it->second; SOLARUS_ASSERT(value.type == SavedValue::VALUE_INTEGER, std::string("Value '") + key + "' is not an integer"); result = value.int_data; } return result; }
/** * \brief Returns the tileset associated to this map. * \return the tileset */ Tileset& Map::get_tileset() { SOLARUS_ASSERT(tileset != nullptr, std::string("Missing tileset in map '") + get_id() + "'" ); return *tileset; }
/** * \brief Returns a string value saved. * \param key Name of the value to get. * \return The string value associated with this key or an empty string. */ const std::string& Savegame::get_string(const std::string& key) const { SOLARUS_ASSERT(LuaTools::is_valid_lua_identifier(key), std::string("Savegame variable '") + key + "' is not a valid key"); const auto& it = saved_values.find(key); if (it != saved_values.end()) { const SavedValue& value = it->second; SOLARUS_ASSERT(value.type == SavedValue::VALUE_STRING, std::string("Value '") + key + "' is not a string"); return value.string_data; } static const std::string empty_string = ""; return empty_string; }
/** * \brief Returns whether a saved value is an integer. * \param key Name of the value to get. * \return true if this value exists and is an integer. */ bool Savegame::is_integer(const std::string& key) const { SOLARUS_ASSERT(LuaTools::is_valid_lua_identifier(key), std::string("Savegame variable '") + key + "' is not a valid key"); bool result = false; const auto& it = saved_values.find(key); if (it != saved_values.end()) { const SavedValue& value = it->second; result = (value.type == SavedValue::VALUE_INTEGER); } return result; }
/** * \brief Returns a pixel value of this surface. * * The pixel format is preserved: if it is lower than 32 bpp, then the unused * upper bits of the value are is padded with zeros. * * \param index Index of the pixel to get. * \return The value of this pixel. */ uint32_t Surface::get_pixel(int index) const { SOLARUS_ASSERT(internal_surface != NULL, "Attempt to read a pixel on a hardware or a buffer surface."); SDL_PixelFormat* format = internal_surface->format; // Test from the most common to the most exotic. switch (format->BytesPerPixel) { case 1: { uint8_t* pixels = static_cast<uint8_t*>(internal_surface->pixels); return pixels[index]; } case 4: { uint32_t* pixels = static_cast<uint32_t*>(internal_surface->pixels); return pixels[index]; } case 2: { uint16_t* pixels = static_cast<uint16_t*>(internal_surface->pixels); return pixels[index]; } case 3: { // Manual cast of the pixel into uint32_t. uint8_t* bytes = static_cast<uint8_t*>(internal_surface->pixels); return *reinterpret_cast<uint32_t*>(&bytes[index * 3]) & 0xffffff00 >> 8; } } std::ostringstream oss; oss << "Unknown pixel depth: " << format->BitsPerPixel; Debug::die(oss.str()); return 0; }