summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-03-12 14:18:34 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2022-03-12 14:18:34 -0500
commit71354cdc7b5b3aa2bbf12ff29dc53b084d3250c4 (patch)
tree134761b89f14121ef5030d801e5a7b4538f07c8a
parent4b6e5eb5d3e0733c239a7a231da91a9977c38246 (diff)
downloadether-71354cdc7b5b3aa2bbf12ff29dc53b084d3250c4.tar.gz
ether-71354cdc7b5b3aa2bbf12ff29dc53b084d3250c4.tar.bz2
ether-71354cdc7b5b3aa2bbf12ff29dc53b084d3250c4.zip
lamp sprite, courtesy of canaripack
-rwxr-xr-xres/lamp.pngbin0 -> 235 bytes
-rw-r--r--src/renderer.cpp50
-rw-r--r--src/renderer.h1
3 files changed, 19 insertions, 32 deletions
diff --git a/res/lamp.png b/res/lamp.png new file mode 100755 index 0000000..c27a246 --- /dev/null +++ b/res/lamp.png
Binary files 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()
134 } 134 }
135 135
136 SDL_SetTextureBlendMode(tileset_.get(), SDL_BLENDMODE_BLEND); 136 SDL_SetTextureBlendMode(tileset_.get(), SDL_BLENDMODE_BLEND);
137
138 {
139 surface_ptr pfs(IMG_Load("../res/lamp.png"));
140 if (!pfs)
141 {
142 throw img_error();
143 }
144
145 lamp_ = texture_ptr(SDL_CreateTextureFromSurface(ren_.get(), pfs.get()));
146 }
147
148 SDL_SetTextureBlendMode(lamp_.get(), SDL_BLENDMODE_BLEND);
137} 149}
138 150
139void Renderer::render( 151void Renderer::render(
@@ -179,41 +191,11 @@ void Renderer::render(
179 } else { 191 } else {
180 draw = false; 192 draw = false;
181 } 193 }
182 } else {
183 int alpha = 255;
184
185 switch (game.map.at(x,y).tile)
186 {
187 case Tile::Floor:
188 {
189 SDL_SetRenderDrawColor(ren_.get(), 210, 210, 210, alpha);
190 break;
191 }
192
193 case Tile::Wall:
194 {
195 SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, alpha);
196 break;
197 }
198
199 case Tile::Dust:
200 {
201 SDL_SetRenderDrawColor(ren_.get(), 210, 210, 210, alpha);
202 break;
203 }
204
205 case Tile::Lamp:
206 {
207 SDL_SetRenderDrawColor(ren_.get(), 0, 255, 255, alpha);
208 drawColour = true;
209 break;
210 }
211 }
212 } 194 }
213 195
214 if (draw) 196 if (draw)
215 { 197 {
216 if (game.map.at(x,y).tile == Tile::Floor || game.map.at(x,y).tile == Tile::Dust) { 198 if (game.map.at(x,y).tile != Tile::Wall) {
217 SDL_Rect tileRect {17 * 16, 15 * 16, 16, 16}; 199 SDL_Rect tileRect {17 * 16, 15 * 16, 16, 16};
218 SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); 200 SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect);
219 201
@@ -222,7 +204,7 @@ void Renderer::render(
222 tileRect.y = game.map.at(x,y).renderId / 24 * 16; 204 tileRect.y = game.map.at(x,y).renderId / 24 * 16;
223 SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); 205 SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect);
224 } 206 }
225 } else if (game.map.at(x,y).tile == Tile::Wall) { 207 } else {
226 SDL_Rect tileRect { 208 SDL_Rect tileRect {
227 game.map.at(x,y).renderId % 24 * 16, 209 game.map.at(x,y).renderId % 24 * 16,
228 game.map.at(x,y).renderId / 24 * 16, 210 game.map.at(x,y).renderId / 24 * 16,
@@ -232,6 +214,10 @@ void Renderer::render(
232 SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect); 214 SDL_RenderCopy(ren_.get(), tileset_.get(), &tileRect, &rect);
233 } 215 }
234 216
217 if (game.map.at(x,y).tile == Tile::Lamp) {
218 SDL_RenderCopy(ren_.get(), lamp_.get(), nullptr, &rect);
219 }
220
235 if (drawColour) { 221 if (drawColour) {
236 SDL_RenderFillRect(ren_.get(), &rect); 222 SDL_RenderFillRect(ren_.get(), &rect);
237 } 223 }
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:
131 texture_ptr dustFade_; 131 texture_ptr dustFade_;
132 texture_ptr playerSheet_; 132 texture_ptr playerSheet_;
133 texture_ptr tileset_; 133 texture_ptr tileset_;
134 texture_ptr lamp_;
134}; 135};
135 136
136#endif /* end of include guard: RENDERER_H_6A58EC30 */ 137#endif /* end of include guard: RENDERER_H_6A58EC30 */