From be9ccb73bc20b03f62c77f5d529602a10ef4eda9 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 12 Mar 2022 12:09:58 -0500 Subject: player has a sprite now thanks to world of solaria --- src/renderer.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 2dac07e..0aaa14a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -110,6 +110,18 @@ Renderer::Renderer() SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, 255); SDL_RenderFillRect(ren_.get(), nullptr); + + { + surface_ptr pfs(IMG_Load("../res/player.png")); + if (!pfs) + { + throw img_error(); + } + + playerSheet_ = texture_ptr(SDL_CreateTextureFromSurface(ren_.get(), pfs.get())); + } + + SDL_SetTextureBlendMode(playerSheet_.get(), SDL_BLENDMODE_BLEND); } void Renderer::render( @@ -140,10 +152,7 @@ void Renderer::render( { bool draw = true; - if ((game.player_x == x && game.player_y == y) && game.renderPlayer) - { - SDL_SetRenderDrawColor(ren_.get(), 255, 255, 0, 255); - } else if (!game.map.at(x,y).lit) + if (!game.map.at(x,y).lit) { if (drawDark) { @@ -191,6 +200,11 @@ void Renderer::render( TILE_HEIGHT}; SDL_RenderFillRect(ren_.get(), &rect); + + if ((game.player_x == x && game.player_y == y) && game.renderPlayer) + { + SDL_RenderCopy(ren_.get(), playerSheet_.get(), &game.playerAnim.getRenderRect(), &rect); + } } } } -- cgit 1.4.1