[Super-tux-commit] supertux/src badguy.cpp,1.45,1.46 world.cpp,1.37,1.38 world.h,1.28,1.29
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-22 17:53:17
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14829 Modified Files: badguy.cpp world.cpp world.h Log Message: - made some arrays private - store badguys in pointers instead of per value Index: world.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- world.h 21 Apr 2004 23:38:13 -0000 1.28 +++ world.h 22 Apr 2004 17:53:08 -0000 1.29 @@ -37,28 +37,27 @@ bouncy distros, etc) that are needed to run a game. */ class World { - public: +private: + std::vector<BadGuy*> bad_guys; Level* level; - Player tux; - + + int distro_counter; + bool counting_distros; + int currentmusic; + + static World* current_; +public: std::vector<BouncyDistro> bouncy_distros; std::vector<BrokenBrick> broken_bricks; std::vector<BouncyBrick> bouncy_bricks; std::vector<FloatingScore> floating_scores; - std::vector<BadGuy> bad_guys; std::vector<Upgrade> upgrades; std::vector<Bullet> bullets; std::vector<ParticleSystem*> particle_systems; - int distro_counter; - bool counting_distros; - - int currentmusic; - - static World* current_; - public: +public: static World* current() { return current_; } static void set_current(World* w) { current_ = w; } @@ -92,7 +91,10 @@ void add_broken_brick(Tile* tile, float x, float y); void add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym); void add_bouncy_brick(float x, float y); - void add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform = false); + + BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform = false); + void remove_bad_guy(BadGuy* badguy); + void add_upgrade(float x, float y, Direction dir, UpgradeKind kind); void add_bullet(float x, float y, float xm, Direction dir); Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- world.cpp 22 Apr 2004 13:24:15 -0000 1.37 +++ world.cpp 22 Apr 2004 17:53:08 -0000 1.38 @@ -72,6 +72,11 @@ World::~World() { + for (unsigned int i = 0; i < bad_guys.size(); ++i) + { + delete bad_guys[i]; + } + halt_music(); // just to be sure (because levelmusic is freed now) delete level; } @@ -168,7 +173,7 @@ bouncy_bricks[i].draw(); for (unsigned int i = 0; i < bad_guys.size(); ++i) - bad_guys[i].draw(); + bad_guys[i]->draw(); tux.draw(); @@ -240,7 +245,7 @@ upgrades[i].action(frame_ratio); for (unsigned int i = 0; i < bad_guys.size(); i++) - bad_guys[i].action(frame_ratio); + bad_guys[i]->action(frame_ratio); /* update particle systems */ std::vector<ParticleSystem*>::iterator p; @@ -262,15 +267,15 @@ { for(unsigned int j = 0; j < bad_guys.size(); ++j) { - if(bad_guys[j].dying != DYING_NOT) + if(bad_guys[j]->dying != DYING_NOT) continue; - if(rectcollision(&bullets[i].base, &bad_guys[j].base)) + if(rectcollision(&bullets[i].base, &bad_guys[j]->base)) { // We have detected a collision and now call the // collision functions of the collided objects. // collide with bad_guy first, since bullet_collision will // delete the bullet - bad_guys[j].collision(0, CO_BULLET); + bad_guys[j]->collision(0, CO_BULLET); bullets[i].collision(CO_BADGUY); break; // bullet is invalid now, so break } @@ -280,20 +285,20 @@ /* CO_BADGUY & CO_BADGUY check */ for(unsigned int i = 0; i < bad_guys.size(); ++i) { - if(bad_guys[i].dying != DYING_NOT) + if(bad_guys[i]->dying != DYING_NOT) continue; for(unsigned int j = i+1; j < bad_guys.size(); ++j) { - if(j == i || bad_guys[j].dying != DYING_NOT) + if(j == i || bad_guys[j]->dying != DYING_NOT) continue; - if(rectcollision(&bad_guys[i].base, &bad_guys[j].base)) + if(rectcollision(&bad_guys[i]->base, &bad_guys[j]->base)) { // We have detected a collision and now call the // collision functions of the collided objects. - bad_guys[j].collision(&bad_guys[i], CO_BADGUY); - bad_guys[i].collision(&bad_guys[j], CO_BADGUY); + bad_guys[j]->collision(&bad_guys[i], CO_BADGUY); + bad_guys[i]->collision(&bad_guys[j], CO_BADGUY); } } } @@ -303,23 +308,23 @@ // CO_BADGUY & CO_PLAYER check for(unsigned int i = 0; i < bad_guys.size(); ++i) { - if(bad_guys[i].dying != DYING_NOT) + if(bad_guys[i]->dying != DYING_NOT) continue; - if(rectcollision_offset(&bad_guys[i].base,&tux.base,0,0)) + if(rectcollision_offset(&bad_guys[i]->base,&tux.base,0,0)) { // We have detected a collision and now call the collision // functions of the collided objects. if (tux.previous_base.y < tux.base.y && tux.previous_base.y + tux.previous_base.height - < bad_guys[i].base.y + bad_guys[i].base.height/2) + < bad_guys[i]->base.y + bad_guys[i]->base.height/2) { - bad_guys[i].collision(&tux, CO_PLAYER, COLLISION_SQUISH); + bad_guys[i]->collision(&tux, CO_PLAYER, COLLISION_SQUISH); } else { tux.collision(&bad_guys[i], CO_BADGUY); - bad_guys[i].collision(&tux, CO_PLAYER, COLLISION_NORMAL); + bad_guys[i]->collision(&tux, CO_PLAYER, COLLISION_NORMAL); } } } @@ -380,13 +385,29 @@ bouncy_bricks.push_back(new_bouncy_brick); } -void +BadGuy* World::add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform) { - bad_guys.push_back(BadGuy()); - BadGuy& new_bad_guy = bad_guys.back(); + bad_guys.push_back(new BadGuy()); + BadGuy* new_bad_guy = bad_guys.back(); - new_bad_guy.init(x,y,kind, stay_on_platform); + new_bad_guy->init(x,y,kind, stay_on_platform); + return new_bad_guy; +} + +void +World::remove_bad_guy(BadGuy* badguy) +{ + for(std::vector<BadGuy*>::iterator i = bad_guys.begin(); + i != bad_guys.end(); ++i) + { + if(*i == badguy) + { + World::current()->bad_guys.erase(i); + delete badguy; + return; + } + } } void @@ -557,10 +578,10 @@ // Bad guys: for (unsigned int i = 0; i < bad_guys.size(); i++) { - if (bad_guys[i].base.x >= x - 32 && bad_guys[i].base.x <= x + 32 && - bad_guys[i].base.y >= y - 16 && bad_guys[i].base.y <= y + 16) + if (bad_guys[i]->base.x >= x - 32 && bad_guys[i]->base.x <= x + 32 && + bad_guys[i]->base.y >= y - 16 && bad_guys[i]->base.y <= y + 16) { - bad_guys[i].collision(&tux, CO_PLAYER, COLLISION_BUMP); + bad_guys[i]->collision(&tux, CO_PLAYER, COLLISION_BUMP); } } Index: badguy.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.cpp,v retrieving revision 1.45 retrieving revision 1.46 diff -u -d -r1.45 -r1.46 --- badguy.cpp 22 Apr 2004 16:52:02 -0000 1.45 +++ badguy.cpp 22 Apr 2004 17:53:08 -0000 1.46 @@ -408,14 +408,7 @@ void BadGuy::remove_me() { - for(std::vector<BadGuy>::iterator i = World::current()->bad_guys.begin(); - i != World::current()->bad_guys.end(); ++i) - { - if( & (*i) == this) { - World::current()->bad_guys.erase(i); - return; - } - } + World::current()->remove_bad_guy(this); } void |