c++ - trouble checking for overlap in a 2-D array of chars -
i having trouble part of program takes dynamically allocated object called userrect , checks overlapping on array of chars arranged in shape of rectangle. other rectangles rect[0] , rect[1] randomly placed on imaginary grid in console window.
rect[0] prints out '0' rect[1] prints out '1' userrect prints out '#' if no overlap present. userrect prints out '+' @ each char in array overlapping object.
the object userrect movable w,a,s,d keys. supposed happen when user moves userrect object , overlaps rect object. each character overlaps replaced '+'.
the program not printing '+' when userrect overlapping rectangle. can point out causing this?
here sample of code:
bool isoverlapping(rect const & r) const { return !(min.x >= r.max.x || max.x <= r.min.x || min.y >= r.max.y || max.y <= r.min.y); } int main() { srand(time(null)); // initialization rect * userrect; const int rectsize = 5; rect rect[rectsize]; const int array_size = 13; // size of userrect userrect = new rect(); // set rect[0].setrandom(rect[0]); rect[1].setrandombypointer(& rect[1]); userrect->setmin(7, 5); userrect->setmax(10, 9); //rect0.setmin(10, 2); //rect0.setmax(14, 4); //rect1.setmin(1, 6); //rect1.setmax(5, 15); int userinput; { // draw rect[0].draw('0'); rect[1].draw('1'); (int = 0; < array_size; i++) { if (userrect->isoverlapping(rect[i])) { userrect->draw('+'); } else userrect->draw('#'); }
i have figured out wrong. problem in loop. if userrect within boundaries of rect[0] not within bounds of rect[1] userrect->draw('#');
overwrite userrect->draw('+');
operation executed before it. thank guys help.
Comments
Post a Comment