-// the space that it takes for the screen to start scrolling
-#define X_SPACE 40
-
-/* This functions takes cares of the scrolling */
-void World::keep_in_bounds()
-{
- int tux_pos_x = (int)(tux.base.x + (tux.base.width/2));
-
- scroll_x += screen->w/2;
-
- if (scroll_x < tux_pos_x - X_SPACE)
- scroll_x = tux_pos_x - X_SPACE;
- else if (scroll_x > tux_pos_x + X_SPACE && level->back_scrolling)
- scroll_x = tux_pos_x + X_SPACE;
-
- scroll_x -= screen->w/2;
-
- if(scroll_x < 0)
- scroll_x = 0;
-}
-
-
-void
-World::collision_handler()
-{
- // CO_BULLET & CO_BADGUY check
- for(unsigned int i = 0; i < bullets.size(); ++i)
- {
- for (BadGuys::iterator j = bad_guys.begin(); j != bad_guys.end(); ++j)
- {
- if((*j)->dying != DYING_NOT)
- continue;
-
- if(rectcollision(bullets[i].base, (*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
- (*j)->collision(0, CO_BULLET);
- bullets[i].collision(CO_BADGUY);
- break; // bullet is invalid now, so break
- }
- }
- }
-
- /* CO_BADGUY & CO_BADGUY check */
- for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
- {
- if((*i)->dying != DYING_NOT)
- continue;
-
- BadGuys::iterator j = i;
- ++j;
- for (; j != bad_guys.end(); ++j)
- {
- if(j == i || (*j)->dying != DYING_NOT)
- continue;
-
- if(rectcollision((*i)->base, (*j)->base))
- {
- // We have detected a collision and now call the
- // collision functions of the collided objects.
- (*j)->collision(*i, CO_BADGUY);
- (*i)->collision(*j, CO_BADGUY);
- }
- }
- }
-
- if(tux.dying != DYING_NOT) return;
-
- // CO_BADGUY & CO_PLAYER check
- for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
- {
- if((*i)->dying != DYING_NOT)
- continue;
-
- if(rectcollision_offset((*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
- < (*i)->base.y + (*i)->base.height/2
- && !tux.invincible_timer.started())
- {
- (*i)->collision(&tux, CO_PLAYER, COLLISION_SQUISH);
- }
- else
- {
- tux.collision(*i, CO_BADGUY);
- (*i)->collision(&tux, CO_PLAYER, COLLISION_NORMAL);
- }
- }
- }
-
- // CO_UPGRADE & CO_PLAYER check
- for(unsigned int i = 0; i < upgrades.size(); ++i)
- {
- if(rectcollision(upgrades[i].base, tux.base))
- {
- // We have detected a collision and now call the collision
- // functions of the collided objects.
- upgrades[i].collision(&tux, CO_PLAYER, COLLISION_NORMAL);
- }
- }
-}
-
-void
-World::add_score(float x, float y, int s)
-{
- player_status.score += s;
-
- FloatingScore* new_floating_score = new FloatingScore();
- new_floating_score->init(x,y,s);
- floating_scores.push_back(new_floating_score);
-}
-
-void
-World::add_bouncy_distro(float x, float y)
-{
- BouncyDistro* new_bouncy_distro = new BouncyDistro();
- new_bouncy_distro->init(x,y);
- bouncy_distros.push_back(new_bouncy_distro);
-}
-
-void
-World::add_broken_brick(Tile* tile, float x, float y)
-{
- add_broken_brick_piece(tile, x, y, -1, -4);
- add_broken_brick_piece(tile, x, y + 16, -1.5, -3);
-
- add_broken_brick_piece(tile, x + 16, y, 1, -4);
- add_broken_brick_piece(tile, x + 16, y + 16, 1.5, -3);
-}
-
-void
-World::add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym)
-{
- BrokenBrick* new_broken_brick = new BrokenBrick();
- new_broken_brick->init(tile, x, y, xm, ym);
- broken_bricks.push_back(new_broken_brick);
-}
-
-void
-World::add_bouncy_brick(float x, float y)
-{
- BouncyBrick* new_bouncy_brick = new BouncyBrick();
- new_bouncy_brick->init(x,y);
- bouncy_bricks.push_back(new_bouncy_brick);
-}
-
-BadGuy*
-World::add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform)
-{
- BadGuy* badguy = new BadGuy(x,y,kind, stay_on_platform);
- bad_guys.push_back(badguy);
- return badguy;
-}
-