From 71354cdc7b5b3aa2bbf12ff29dc53b084d3250c4 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 12 Mar 2022 14:18:34 -0500 Subject: lamp sprite, courtesy of canaripack --- res/lamp.png | Bin 0 -> 235 bytes src/renderer.cpp | 50 ++++++++++++++++++-------------------------------- src/renderer.h | 1 + 3 files changed, 19 insertions(+), 32 deletions(-) create mode 100755 res/lamp.png diff --git a/res/lamp.png b/res/lamp.png new file mode 100755 index 0000000..c27a246 Binary files /dev/null and b/res/lamp.png differ diff --git a/src/renderer.cpp b/src/renderer.cpp index 00b557a..2ccafb9 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -134,6 +134,18 @@ Renderer::Renderer() } SDL_SetTextureBlendMode(tileset_.get(), SDL_BLENDMODE_BLEND); + + { + surface_ptr pfs(IMG_Load("../res/lamp.png")); + if (!pfs) + { + throw img_error(); + } + + lamp_ = texture_ptr(SDL_CreateTextureFromSurface(ren_.get(), pfs.get())); + } + + SDL_SetTextureBlendMode(lamp_.get(), SDL_BLENDMODE_BLEND); } void Renderer::render( @@ -179,41 +191,11 @@ void Renderer::render( } else { draw = false; } - } else { - int alpha = 255; - - switch (game.map.at(x,y).tile) - { - case Tile::Floor: - { - SDL_SetRenderDrawColor(ren_.get(), 210, 210, 210, alpha); - break; - } - - case Tile::Wall: - { - SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, alpha); - break; - } - - case Tile::Dust: - { - SDL_SetRenderDrawColor(ren_.get(), 210, 210, 210, alpha); - break; - } - - case Tile::Lamp: - { - SDL_SetRenderDrawColor(ren_.get(), 0, 255, 255, alpha); - drawColour = true; - break; - } - } } if (draw) { - if (game.map.at(x,y).tile == Tile::Floor || game.map.at(x,y).tile == Tile::Dust) { + if (game.map.at(x,y).tile != Tile::Wall) { SDL_Rect tileRect {17 * 16, 15 * 16, 16, 16}; SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); @@ -222,7 +204,7 @@ void Renderer::render( tileRect.y = game.map.at(x,y).renderId / 24 * 16; SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); } - } else if (game.map.at(x,y).tile == Tile::Wall) { + } else { SDL_Rect tileRect { game.map.at(x,y).renderId % 24 * 16, game.map.at(x,y).renderId / 24 * 16, @@ -232,6 +214,10 @@ void Renderer::render( SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); } + if (game.map.at(x,y).tile == Tile::Lamp) { + SDL_RenderCopy(ren_.get(), lamp_.get(), nullptr, &rect); + } + if (drawColour) { SDL_RenderFillRect(ren_.get(), &rect); } diff --git a/src/renderer.h b/src/renderer.h index 8551e26..57d9702 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -131,6 +131,7 @@ private: texture_ptr dustFade_; texture_ptr playerSheet_; texture_ptr tileset_; + texture_ptr lamp_; }; #endif /* end of include guard: RENDERER_H_6A58EC30 */ -- cgit 1.4.1