void GameScene::draw(sf::RenderTarget& target) { target.Clear(sf::Color(255,255,255)); sf::Vector2f cam_topleft = view().GetCenter() - view().GetHalfSize(); sf::Vector2f cam_bounds = view().GetHalfSize() * 2.0f; sf::Vector2f bgtile( background_->transformed_width(), background_->transformed_height()); for (int j = -1; j <= cam_bounds.y/bgtile.y + 1; j++) { for (int i = -1; i <= cam_bounds.x/bgtile.x + 1; i++) { sf::Vector2f tilepos(cam_topleft); tilepos.x /= bgtile.x; tilepos.y /= bgtile.y; tilepos.x = std::floor(tilepos.x) * bgtile.x; tilepos.y = std::floor(tilepos.y) * bgtile.y; tilepos.x += i * bgtile.x; tilepos.y += j * bgtile.y; background_->set_position(tilepos); background_->draw(target); } } for (Entity* d : decorations_) { d->draw(target); } for (Effect* e : effects_) { e->draw(target); } for (Entity* p : platforms_) { p->draw(target); } for (Entity* g : goalflags_) { g->draw(target); } for (Entity* c : collectibles_) { c->draw(target); } player_.draw(target); }
bool Room::LoadGrid(int grid, File* f) { std::string s; for (int y = 0; y < m_gridsize.y; y++) { if (!f->GetDataLine(&s)) { f->ReportError("Expected grid line " + ToString(y)); return false; } Strings strs = Split(s, ' '); if ((int)strs.size() != m_gridsize.x) { f->ReportError("Grid size does not match tile data."); return false; } for (int x = 0; x < m_gridsize.x; x++) { int t = ToInt(strs[x]); if (t == 0) { continue; // no tile here } if (t > (int)m_texNames.size()) { f->ReportError("Tile number too big: " + strs[x] + " in grid pos (" + ToString(x) + ", " + ToString(y) + ")"); return false; } std::string tex = m_texNames[t - 1]; // Centre grid on origin Vec3f tilepos( ((float)x - (float)m_gridsize.x * 0.5f) * m_tilesize.x, ((float)y - (float)m_gridsize.y * 0.5f) * m_tilesize.y, (float)grid); bool blend = (grid > 0); Tile tile(tilepos, m_tilesize, Vec2i(x, y), tex, blend); m_tiles[grid].push_back(tile); } } return true; }