void MapScreen::enter() { if (this->m_init == false) { this->m_init = true; mapinfo.init(); } soundman.playSound("sounds/game/pause1.wav"); // center map on player if (mapinfo.tex != nullptr) { mapinfo.pos = mapinfo.generate_player_coords(); mapinfo.mask.update(mapinfo.pos); } else { mapinfo.pos = glm::vec2(0.0f); } }
void MapScreen::update_mask() { if (mapinfo.mask.enabled) { mapinfo.mask.update(mapinfo.generate_player_coords()); } }
bool MapScreen::render(Renderer&, double elapsed) { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); const glm::vec3 top_cam(mapinfo.pos.x, mapinfo.pos.y + OFFSET_Y, -OFFSET_Z); const glm::vec3 bot_cam(mapinfo.pos.x, mapinfo.pos.y, 0.0); /// map image /// if (mapinfo.tex == nullptr) { // we cant do calculations without the base image return true; } auto& shd = shaders[Shaders::MAP]; shd.bind(); // create mvp matrix mapinfo.matmvp = glm::lookAt( top_cam, bot_cam, glm::vec3(0, -1, 0)); mapinfo.matmvp = mapinfo.projection * mapinfo.matmvp; shd.sendMatrix("matmvp", mapinfo.matmvp); shd.sendFloat("alpha", 1.0f); mapinfo.mapvao.bind(); // render map texture mapinfo.tex->bind(0); mapinfo.mapvao.renderIndexed(GL_TRIANGLES); // render map mask layer if (mapinfo.mask.enabled) { glEnable(GL_BLEND); mapinfo.mask.tex->bind(0); mapinfo.mapvao.renderIndexed(GL_TRIANGLES); glDisable(GL_BLEND); } /// map clouds & shadows /// for (size_t i = 0; i < mapinfo.border.size(); i++) { auto& layer = mapinfo.border.at(i); const float floatx = 0.005 * sin(6.28 * sin(i + elapsed * 0.25)); const float floaty = 0.05 * sin(6.28 * sin(i + elapsed * 0.5)); layer.matmvp = glm::lookAt( top_cam + glm::vec3(0, floatx, floaty), bot_cam + glm::vec3(0, floatx, 0), glm::vec3(0, -1, 0)); layer.matmvp = mapinfo.projection * layer.matmvp; } glEnable(GL_BLEND); shd.sendFloat("alpha", 0.7f); for (auto& layer : mapinfo.border) { if (layer.shadow != nullptr) { shd.sendMatrix("matmvp", layer.matmvp); layer.shadow->bind(0); mapinfo.mapvao.renderIndexed(GL_TRIANGLES); } } glDisable(GL_BLEND); shd.sendFloat("alpha", 1.0f); for (auto& layer : mapinfo.border) { if (layer.cloud != nullptr) { shd.sendMatrix("matmvp", layer.matmvp); layer.cloud->bind(0); mapinfo.mapvao.renderIndexed(GL_TRIANGLES); } } /// map icons /// const bool do_map_icons = uint64_t(elapsed * 2.0f) & 1; if (do_map_icons) { Shader& shdSprite = shaders[Shaders::OBJECTS]; shdSprite.bind(); shdSprite.sendMatrix("matmvp", mapinfo.matmvp); auto& spritegen = mapinfo.spritegen; spritegen.clear(); // player head const auto ptloc = mapinfo.generate_player_coords(); const auto frame = mapinfo.construct_frame(mapinfo.sprite_player, ptloc, 8); spritegen.generate(frame); // JSON-defined icons & script for (const auto& icon : mapinfo.icons) { const auto frame = mapinfo.construct_frame(icon.sprite, mapinfo.transform(icon.pos), 8); spritegen.generate(frame); } spritegen.sort(); spritegen.index(); // render lowest to high spritegen.render(Z_LOWEST, Z_HIGH); } return true; }