debugging - C++ Function not working as expected -
so know broad topic, i'm not sure how describe , i'm not sure bug is. i'm making game in console window, roguelike-rpg, (i haven't done random dungeon yet, i've done in other languages.) , i'm having problems dealing walls.
i have function called placemeeting(real x, real y)
use check collisions, appears returning bad values , couldn't tell why. have couple of macros defined: #define , &&
, #define real double
.
here function:
bool globalclass::placemeeting(real x, real y) { //the return value -- false until proven otherwise bool collision = false; //loop through walls check collision for(int = 0; < wallcount; i++) { //if there collision, 'say' if (x == wallx[ ] , y == wally[ ]) { //set 'collision' true collision = true; } } return collision; }
but strange catch doesn't work when displaying screen. player collides them same though there not displayed. stranger, first wall being displayed. here walls defined:
int wallcount; //array of walls real wallx[ 1 ]; real wally[ 1 ];
and
wallcount = 1; //basic wall stuff; placeholder wallx[ 0 ] = 10; wally[ 0 ] = 10;
so have function used render screen (in console window of course.) , looks this:
for (int y = oglobal.viewy; y < oglobal.viewy + oglobal.viewheight; y++) { //the inner 'x' loop of view for(int x = oglobal.viewx; x < oglobal.viewx + oglobal.viewwidth; x++) { //call function check spot , print returns screen += oglobal.checkspot(x, y); } }
that's not whole function, actual screen refreshing. after 'screen' printed screen, reduce buffer time. , of course, checkspot:
string globalclass::checkspot(real x, real y) { string spriteatspot; //first check player if (x == oplayer.x , y == oplayer.y) { spriteatspot = oplayer.sprite; } else if (placemeeting(x, y)) //its teh wall suckas { spriteatspot = wall_sprite; } else //nothing here, return space { spriteatspot = empty_sprite; } //return sprite return spriteatspot; }
i know it's lot of code, don't know screwed up.
i appreciate help!
p.s. here image understand http://i.imgur.com/8xnahit.png
i'm not sure if i'm missing something, since rogue-like games tile-based, necessary make x , y values doubles? remember being told doubles finicky compare, since if assume should equal, off, causing comparison return false when you'd think return true.
Comments
Post a Comment