+ Sizef level(Sector::current()->get_width(), Sector::current()->get_height());
+ Sizef screen(SCREEN_WIDTH, SCREEN_HEIGHT);
+ Sizef parallax_image_size = (1.0f - speed) * screen + level * speed;
+
+ // FIXME: Implement proper clipping here
+ int start_x = -parallax_image_size.width / 2.0f / image->get_width() - 1;
+ int end_x = parallax_image_size.width / 2.0f / image->get_width() + 1;
+ int start_y = -parallax_image_size.height / 2.0f / image->get_height() - 1;
+ int end_y = parallax_image_size.height / 2.0f / image->get_height() + 1;
+
+ switch(alignment)
+ {
+ case LEFT_ALIGNMENT:
+ for(int y = start_y; y < end_y; ++y)
+ {
+ Vector p(pos.x - parallax_image_size.width / 2.0f,
+ pos.y + y * image->get_height() - image->get_height() / 2.0f);
+ context.draw_surface(image.get(), p, layer);
+ }
+ break;
+
+ case RIGHT_ALIGNMENT:
+ for(int y = start_y; y < end_y; ++y)
+ {
+ Vector p(pos.x + parallax_image_size.width / 2.0f - image->get_width(),
+ pos.y + y * image->get_height() - image->get_height() / 2.0f);
+ context.draw_surface(image.get(), p, layer);
+ }
+ break;
+
+ case TOP_ALIGNMENT:
+ for(int x = start_x; x < end_x; ++x)
+ {
+ Vector p(pos.x + x * image->get_width() - image->get_width() / 2.0f,
+ pos.y - parallax_image_size.height / 2.0f);
+ context.draw_surface(image.get(), p, layer);
+ }
+ break;