World::action(double frame_ratio)
{
tux.action(frame_ratio);
+ keep_in_bounds();
/* Handle bouncy distros: */
for (unsigned int i = 0; i < bouncy_distros.size(); i++)
for (unsigned int i = 0; i < broken_bricks.size(); i++)
broken_bricks[i]->action(frame_ratio);
- /* Handle distro counting: */
- if (counting_distros)
- {
- distro_counter--;
-
- if (distro_counter <= 0)
- counting_distros = -1;
- }
-
// Handle all kinds of game objects
for (unsigned int i = 0; i < bouncy_bricks.size(); i++)
bouncy_bricks[i]->action(frame_ratio);
/* ++i handled at end of the loop */) {
if ((*i)->is_removable()) {
delete *i;
- i = bad_guys.erase(i);
+ i = bad_guys.erase(i);
} else {
++i;
}
}
}
+// the space that it takes for the screen to start scrolling
+#define X_SPACE 80
+
+/* 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()
{
add_bouncy_distro(((int)(x + 1) / 32) * 32,
(int)(y / 32) * 32);
+ // TODO: don't handle this in a global way but per-tile...
if (!counting_distros)
{
counting_distros = true;
- distro_counter = 50;
+ distro_counter = 5;
+ }
+ else
+ {
+ distro_counter--;
}
if (distro_counter <= 0)
- plevel->change(x, y, TM_IA, tile->next_tile);
+ {
+ counting_distros = false;
+ plevel->change(x, y, TM_IA, tile->next_tile);
+ }
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
player_status.score = player_status.score + SCORE_DISTRO;