class - C++ list looping -
im quite stuck here. have been trying , googling past 2 days cant figure out. have class called player , called enemy inherits player. have list stores coordinates bullets , loop trough them in player. im trying access , loop trough same list check collision in enemy builds on player, not enter loop. guess somehow empty why?
struct structshoot { float x; float y; }; class player { private: blablabla protected: list<structshoot>::iterator it; list<structshoot> shoot_list; structshoot test; public: void render(sdl_surface* dest); }; void player::render(sdl_surface* dest) { //works fine, see other loop down below for(it = shoot_list.begin(); != shoot_list.end();) { shoot.moveset(it->x, it->y); shoot.draw(dest); it->y--; if((it->y) < -25) { = shoot_list.erase(it); } else { it++; } } } class enemy : protected player { public: void render(sdl_surface* dest); }; void enemy::render(sdl_surface* dest) { sdl_rect a, b; //does not enter loop!? ever. why? for(it = shoot_list.begin(); != shoot_list.end();) { sdl_quit(); a.x = enemy.getx(); a.y = enemy.gety(); a.w = enemy.getwidth(); a.h = enemy.getheight(); b.x = it->x; b.y = it->y; b.w = 10; b.h = 19; it->y--; if (collision(a, b) == true) { sdl_quit(); } if(it->y < -25) { = shoot_list.erase(it); } else { it++; } } }
you should make render virtual use polymorphism.
virtual void render(sdl_surface* dest);
i suppose every time call player::render, because of such code:
player* enemy = new enemy(); enemy->render(); // there player::render calling if make render virtual use virtual table detect correct function should called in place. have make render virtual.
Comments
Post a Comment