Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground colour of player character (@) overlapping other tiles
    text
    copied!<p>I'm making a rogue like game using pdcurses in C++ and all it's going ok at the moment. But I'm facing a problem right now that I don't know how to solve.</p> <p>Let's see a screenshot of the problem for better understanding:</p> <p><img src="https://i.stack.imgur.com/9ylf4.png" alt="http://i.imgur.com/xr9Faj1.png"></p> <p>As you can see, if you zoom in the upper red circle, you can see how the player character is overlapping the enemy troll (t) about 2 pixels on its left side. The problem is that if the player moves to another position, the enemy troll has lost that 2 pixels <strong>forever</strong>, so this is not a thing that just happens while the player is on the left side, but it's permanent.</p> <p>In the other circle the player has moved from right to left on the corridor, and the corridor tiles (#) have lost their left side pixels too.</p> <p>So here is where I update all the graphics stuff:</p> <pre><code>dungeon_.generate(); while(state_ == State::Running) { if(manageInput(windows_[0]) != -1) { // Update here monsters behavior } dungeon_.draw(windows_[0]); player_-&gt;draw(windows_[0]); refreshWindows(windows_); } </code></pre> <p>This is the <strong>refreshWindows(std::vector windows)</strong> method:</p> <pre><code>void Game::refreshWindows(std::vector&lt;WINDOW *&gt; windows) { for(auto w : windows) { Curses::wbox(w, 0, 0); Curses::refresh(w); } } </code></pre> <p>Both <strong>draw methods</strong> of player and dungeon do this, but dungeon also different cases for every tile in the map on drawing:</p> <pre><code>void Player::draw(WINDOW *win) { Curses::mvwaddch(win, location_.y, location_.x, static_cast&lt;char&gt;(type_) | COLOR_PAIR(static_cast&lt;int&gt;(GameObject::Color::White_Green))); } </code></pre> <p>And this is how <strong>int manageInput(WINDOW *win)</strong> looks like:</p> <pre><code>int Game::manageInput(WINDOW *win) { int key = Curses::wgetch(win); if(key != -1) { // Player movement if(key == static_cast&lt;int&gt;(Curses::Key::Up)) { player_-&gt;moveNorth(dungeon_.map()); } [...] } return key; } </code></pre> <p>As you can see, it's a really simple approach which I'm using in my game loop, so I don't know why the hell it's not working. These are things I have tested:</p> <ul> <li>Remove colour support: This is the only way the game works correctly, but of course I want to use colours.</li> <li>Moving the manageInput if after both player and dungeon draws and placing a wclear(windows_[0]); inside the manageInput() if (otherwise it doesn't work). This way seems like the window is cleared and the map get drew again from scratch. This way works too, <strong>but</strong> the window flicks and that's not really cool.</li> </ul> <p>And that's all. I don't know what to do to fix it. If you need more information you can find here the git repository: <a href="https://github.com/SantiagoSanchez/Ruoeg" rel="nofollow noreferrer">https://github.com/SantiagoSanchez/Ruoeg</a></p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload