diff options
Diffstat (limited to 'src/renderer.cpp')
| -rw-r--r-- | src/renderer.cpp | 80 |
1 files changed, 66 insertions, 14 deletions
| diff --git a/src/renderer.cpp b/src/renderer.cpp index 0aaa14a..00b557a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
| @@ -122,6 +122,18 @@ Renderer::Renderer() | |||
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | SDL_SetTextureBlendMode(playerSheet_.get(), SDL_BLENDMODE_BLEND); | 124 | SDL_SetTextureBlendMode(playerSheet_.get(), SDL_BLENDMODE_BLEND); |
| 125 | |||
| 126 | { | ||
| 127 | surface_ptr pfs(IMG_Load("../res/runninbloods.png")); | ||
| 128 | if (!pfs) | ||
| 129 | { | ||
| 130 | throw img_error(); | ||
| 131 | } | ||
| 132 | |||
| 133 | tileset_ = texture_ptr(SDL_CreateTextureFromSurface(ren_.get(), pfs.get())); | ||
| 134 | } | ||
| 135 | |||
| 136 | SDL_SetTextureBlendMode(tileset_.get(), SDL_BLENDMODE_BLEND); | ||
| 125 | } | 137 | } |
| 126 | 138 | ||
| 127 | void Renderer::render( | 139 | void Renderer::render( |
| @@ -151,12 +163,19 @@ void Renderer::render( | |||
| 151 | for (int x = game.map.getLeft(); x < game.map.getRight(); x++) | 163 | for (int x = game.map.getLeft(); x < game.map.getRight(); x++) |
| 152 | { | 164 | { |
| 153 | bool draw = true; | 165 | bool draw = true; |
| 166 | bool drawColour = false; | ||
| 167 | SDL_Rect rect { | ||
| 168 | game.map.getTrueX(x) * TILE_WIDTH, | ||
| 169 | game.map.getTrueY(y) * TILE_HEIGHT, | ||
| 170 | TILE_WIDTH, | ||
| 171 | TILE_HEIGHT}; | ||
| 154 | 172 | ||
| 155 | if (!game.map.at(x,y).lit) | 173 | if (!game.map.at(x,y).lit) |
| 156 | { | 174 | { |
| 157 | if (drawDark) | 175 | if (drawDark) |
| 158 | { | 176 | { |
| 159 | SDL_SetRenderDrawColor(ren_.get(), 40, 40, 40, 255); | 177 | SDL_SetRenderDrawColor(ren_.get(), 40, 40, 40, 255); |
| 178 | drawColour = true; | ||
| 160 | } else { | 179 | } else { |
| 161 | draw = false; | 180 | draw = false; |
| 162 | } | 181 | } |
| @@ -186,6 +205,7 @@ void Renderer::render( | |||
| 186 | case Tile::Lamp: | 205 | case Tile::Lamp: |
| 187 | { | 206 | { |
| 188 | SDL_SetRenderDrawColor(ren_.get(), 0, 255, 255, alpha); | 207 | SDL_SetRenderDrawColor(ren_.get(), 0, 255, 255, alpha); |
| 208 | drawColour = true; | ||
| 189 | break; | 209 | break; |
| 190 | } | 210 | } |
| 191 | } | 211 | } |
| @@ -193,22 +213,47 @@ void Renderer::render( | |||
| 193 | 213 | ||
| 194 | if (draw) | 214 | if (draw) |
| 195 | { | 215 | { |
| 196 | SDL_Rect rect { | 216 | if (game.map.at(x,y).tile == Tile::Floor || game.map.at(x,y).tile == Tile::Dust) { |
| 197 | game.map.getTrueX(x) * TILE_WIDTH, | 217 | SDL_Rect tileRect {17 * 16, 15 * 16, 16, 16}; |
| 198 | game.map.getTrueY(y) * TILE_HEIGHT, | 218 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); |
| 199 | TILE_WIDTH, | 219 | |
| 200 | TILE_HEIGHT}; | 220 | if (game.map.at(x,y).renderId != -1) { |
| 201 | 221 | tileRect.x = game.map.at(x,y).renderId % 24 * 16; | |
| 202 | SDL_RenderFillRect(ren_.get(), &rect); | 222 | tileRect.y = game.map.at(x,y).renderId / 24 * 16; |
| 223 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); | ||
| 224 | } | ||
| 225 | } else if (game.map.at(x,y).tile == Tile::Wall) { | ||
| 226 | SDL_Rect tileRect { | ||
| 227 | game.map.at(x,y).renderId % 24 * 16, | ||
| 228 | game.map.at(x,y).renderId / 24 * 16, | ||
| 229 | 16, | ||
| 230 | 16}; | ||
| 231 | |||
| 232 | SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); | ||
| 233 | } | ||
| 203 | 234 | ||
| 204 | if ((game.player_x == x && game.player_y == y) && game.renderPlayer) | 235 | if (drawColour) { |
| 205 | { | 236 | SDL_RenderFillRect(ren_.get(), &rect); |
| 206 | SDL_RenderCopy(ren_.get(), playerSheet_.get(), &game.playerAnim.getRenderRect(), &rect); | ||
| 207 | } | 237 | } |
| 208 | } | 238 | } |
| 209 | } | 239 | } |
| 210 | } | 240 | } |
| 211 | 241 | ||
| 242 | if (game.renderPlayer) { | ||
| 243 | SDL_Rect rect { | ||
| 244 | game.map.getTrueX(game.player_x) * TILE_WIDTH, | ||
| 245 | game.map.getTrueY(game.player_y) * TILE_HEIGHT, | ||
| 246 | TILE_WIDTH, | ||
| 247 | TILE_HEIGHT}; | ||
| 248 | |||
| 249 | if (game.moving) { | ||
| 250 | rect.x = game.moveProgress.getProgress(game.map.getTrueX(game.player_oldx) * TILE_WIDTH, rect.x); | ||
| 251 | rect.y = game.moveProgress.getProgress(game.map.getTrueY(game.player_oldy) * TILE_HEIGHT, rect.y); | ||
| 252 | } | ||
| 253 | |||
| 254 | SDL_RenderCopy(ren_.get(), playerSheet_.get(), &game.playerAnim.getRenderRect(), &rect); | ||
| 255 | } | ||
| 256 | |||
| 212 | texture_ptr mask( | 257 | texture_ptr mask( |
| 213 | SDL_CreateTexture( | 258 | SDL_CreateTexture( |
| 214 | ren_.get(), | 259 | ren_.get(), |
| @@ -250,10 +295,17 @@ void Renderer::render( | |||
| 250 | SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 0); | 295 | SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 0); |
| 251 | SDL_RenderClear(ren_.get()); | 296 | SDL_RenderClear(ren_.get()); |
| 252 | 297 | ||
| 253 | int fadeX = game.map.getTrueX(x) - game.map.at(x,y).lightRadius; | 298 | int posToUseX = game.map.getTrueX(x); |
| 254 | int fadeY = game.map.getTrueY(y) - game.map.at(x,y).lightRadius; | 299 | int posToUseY = game.map.getTrueY(y); |
| 255 | int fadeRight = game.map.getTrueX(x) + game.map.at(x,y).lightRadius; | 300 | if (game.map.at(x,y).lightType == Source::Player && game.moving) { |
| 256 | int fadeBottom = game.map.getTrueY(y) + game.map.at(x,y).lightRadius; | 301 | posToUseX = game.moveProgress.getProgress(game.map.getTrueX(game.player_oldx), posToUseX); |
| 302 | posToUseY = game.moveProgress.getProgress(game.map.getTrueY(game.player_oldy), posToUseY); | ||
| 303 | } | ||
| 304 | |||
| 305 | int fadeX = posToUseX - game.map.at(x,y).lightRadius; | ||
| 306 | int fadeY = posToUseY - game.map.at(x,y).lightRadius; | ||
| 307 | int fadeRight = posToUseX + game.map.at(x,y).lightRadius; | ||
| 308 | int fadeBottom = posToUseY + game.map.at(x,y).lightRadius; | ||
| 257 | 309 | ||
| 258 | SDL_Rect fadeRect { | 310 | SDL_Rect fadeRect { |
| 259 | fadeX * TILE_WIDTH, | 311 | fadeX * TILE_WIDTH, |
