| 198 | } |
| 199 | |
| 200 | void TileMap::draw(Camera *camera) { |
| 201 | if (!atlas || !atlas->sourceRectangles || t_mapSize.x <= 0 || t_mapSize.y <= 0) |
| 202 | return; |
| 203 | |
| 204 | float transx = (int)(camera->position.x + camera->size.x / 2) * w_depth; |
| 205 | float transy = (int)(camera->position.y + camera->size.y / 2) * w_depth; |
| 206 | Vector2 trans = Vector2(transx, transy); |
| 207 | Vector2 bl = camera->position - position; |
| 208 | Vector2 tr; |
| 209 | tr.x = camera->position.x + camera->size.x - position.x; |
| 210 | tr.y = camera->position.y + camera->size.y - position.y; |
| 211 | Point BottomLeft = worldToTile(bl - trans, w_tileSize); |
| 212 | Point TopRight = worldToTile(tr - trans, w_tileSize); |
| 213 | |
| 214 | Point min; |
| 215 | Point max; |
| 216 | min.x = std::max(0, BottomLeft.x - 1); |
| 217 | max.x = std::min(TopRight.x + 1, t_mapSize.x); |
| 218 | min.y = std::max(0, BottomLeft.y - 1); |
| 219 | max.y = std::min(TopRight.y + 1, t_mapSize.y); |
| 220 | |
| 221 | Min = min; |
| 222 | Max = max; |
| 223 | |
| 224 | dstRect.w = w_tileSize.x; |
| 225 | dstRect.h = w_tileSize.y; |
| 226 | |
| 227 | if (atlas) |
| 228 | glBindTexture(GL_TEXTURE_2D, *(atlas->texture)); |
| 229 | glPushMatrix(); |
| 230 | glTranslatef(transx, transy, 0.0f); |
| 231 | glBegin(GL_QUADS); |
| 232 | for (int y = min.y; y < max.y; y++) { |
| 233 | for (int x = min.x; x < max.x; x++) { |
| 234 | if (imageLayer[x][y].tileIndex < 0) |
| 235 | continue; |
| 236 | float b = -0.64f * ((imageLayer[x][y].bounce - 5) * |
| 237 | (imageLayer[x][y].bounce - 5)) + |
| 238 | 16.0f; |
| 239 | dstRect.x = (int)position.x + x * w_tileSize.x; |
| 240 | dstRect.y = (int)(position.y + y * w_tileSize.y + b); |
| 241 | DrawTile(camera, dstRect, imageLayer[x][y].tileIndex); |
| 242 | } |
| 243 | } |
| 244 | glEnd(); |
| 245 | glPopMatrix(); |
| 246 | } |
| 247 | |
| 248 | void TileMap::DrawTile(Camera *camera, ScreenRect dstRect, int index) { |
| 249 | if (!atlas || !atlas->sourceRectangles) |
no test coverage detected