diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/renderer.cpp | 50 | ||||
-rw-r--r-- | src/renderer.h | 1 |
2 files changed, 19 insertions, 32 deletions
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 | ||
139 | void Renderer::render( | 151 | void 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 */ |