Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualServant of the Lord

Posted 01 January 2013 - 11:10 AM

'@' symbol disapearing problem:

 

Let's mentally remove all the code that's unrelated to drawing the player, and see if we can spot the problem in the reduced code.

 

while(!gameover)
{
        system("cls");
        show_map(map);
 
        map[hero.w_vertical][hero.w_horizontal] = hero.w_image;
 
        //...removed alot of code here just for visuallizing....
 
        if(GetAsyncKeyState(VK_UP))
        {
            map[hero.w_vertical][hero.w_horizontal] = ' ';
            hero.w_vertical -=1;
        }
 
       //...
}
 
See the problem?
 
Let's mark the major events:
while(...)
{
        show_map(map); //DRAW MAP
 
        map[hero.w_vertical][hero.w_horizontal] = hero.w_image; //ADD PLAYER TO MAP
 
        if(...moving...) //IF MOVING
        {
            map[hero.w_vertical][hero.w_horizontal] = ' '; //REMOVE PLAYER FROM MAP
        }
}
 
The code says:
  • Draw map.
  • Add player to map.
  • If moving, remove player from map.
 
Since we're looping, that means the drawing happens like this:
  • Draw map.
  • Add player to map.
  • If moving, remove player from map.
  • Draw map.
  • Add player to map.
  • ...etc...
 
Let me highlight it:
  • Draw map.
  • Add player to map.
  • If moving, remove player from map.
  • Draw map.
  • Add player to map.
  • ...etc...
 
If we're moving, the player is continually added to, and then removed from, the map in-between draws.
 
The solution is to add the player to the map before the map is drawn. wink.png

#1Servant of the Lord

Posted 01 January 2013 - 11:09 AM

'@' symbol disapearing problem:

 

Let's mentally remove all the code that's unrelated to drawing the player, and see if we can spot the problem in the reduced code.

 

while(!gameover)</div>
<div>{</div>
<div>        system("cls");</div>
<div>        show_map(map);</div>
<div> </div>
<div>        map[hero.w_vertical][hero.w_horizontal] = hero.w_image;</div>
<div> </div>
<div>        //...removed alot of code here just for visuallizing....</div>
<div> </div>
<div>        if(GetAsyncKeyState(VK_UP))</div>
<div>        {</div>
<div>            map[hero.w_vertical][hero.w_horizontal] = ' ';</div>
<div>            hero.w_vertical -=1;</div>
<div>        }</div>
<div> </div>
<div>       //...</div>
<div>}
 
See the problem?
 
Let's mark the major events:
while(...)</div>
<div>{</div>
<div>        show_map(map); //DRAW MAP</div>
<div> </div>
<div>        map[hero.w_vertical][hero.w_horizontal] = hero.w_image; //ADD PLAYER TO MAP</div>
<div> </div>
<div>        if(...moving...) //IF MOVING</div>
<div>        {</div>
<div>            map[hero.w_vertical][hero.w_horizontal] = ' '; //REMOVE PLAYER FROM MAP</div>
<div>        }</div>
<div>}
 
The code says:
  • Draw map.

  • Add player to map.

  • If moving, remove player from map.

 
Since we're looping, that means the drawing happens like this:
  • Draw map.

  • Add player to map.

  • If moving, remove player from map.

  • Draw map.

  • Add player to map.

  • ...etc...

 
Let me highlight it:
  • Draw map.

  • Add player to map.

  • If moving, remove player from map.

  • Draw map.

  • Add player to map.

  • ...etc...

 
If we're moving, the player is continually added to, and then removed from, the map in-between draws.
 
The solution is to add the player to the map before the map is drawn. wink.png

PARTNERS