+ if (fabsf(tux.base.x - base.x) < 200 && base.y < tux.base.y && tux.dying == DYING_NOT)
+ physic.set_velocity(-2.0f, -2.0f);
+ else
+ physic.set_velocity(-WINGLING_FLY_SPEED, 0);
+ }
+
+ physic.apply(elapsed_time, base.x, base.y);
+
+
+ // Handle dying timer:
+ if (dying == DYING_SQUISHED && !timer.check())
+ remove_me();
+}
+
+
+void
+BadGuy::action(float elapsed_time)
+{
+ float scroll_x = World::current()->camera->get_translation().x;
+ float scroll_y = World::current()->camera->get_translation().y;
+
+ // BadGuy fall below the ground
+ if (base.y > World::current()->get_level()->height * 32) {
+ remove_me();
+ return;
+ }
+
+ // Kill us if we landed on spikes
+ if (dying == DYING_NOT
+ && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
+ && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
+ || isspike(base.x, base.y + base.height)
+ || isspike(base.x + base.width, base.y + base.height)))
+ {
+ physic.set_velocity_y(3);
+ kill_me(0);
+ }
+
+ if(!seen) {
+ /* activate badguys if they're just inside the offscreen_distance around the
+ * screen. Don't activate them inside the screen, since that might have the
+ * effect of badguys suddenly popping up from nowhere
+ */
+ if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
+ start_position.x < scroll_x - base.width)
+ activate(RIGHT);
+ else if(start_position.x > scroll_y - Y_OFFSCREEN_DISTANCE &&
+ start_position.y < scroll_y - base.height)
+ activate(LEFT);
+ else if(start_position.x > scroll_x + screen->w &&
+ start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE)
+ activate(LEFT);
+ else if(start_position.y > scroll_y + screen->h &&
+ start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
+ activate(LEFT);
+ } else {
+ if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE
+ || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE
+ || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE
+ || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) {
+ seen = false;
+ if(dying != DYING_NOT)
+ remove_me();
+ }
+ }
+
+ if(!seen)
+ return;
+
+ switch (kind)
+ {
+ case BAD_MRICEBLOCK:
+ action_mriceblock(elapsed_time);
+ break;
+
+ case BAD_JUMPY:
+ action_jumpy(elapsed_time);
+ break;
+
+ case BAD_MRBOMB:
+ action_mrbomb(elapsed_time);
+ break;
+
+ case BAD_BOMB:
+ action_bomb(elapsed_time);
+ break;
+
+ case BAD_STALACTITE:
+ action_stalactite(elapsed_time);
+ break;
+
+ case BAD_FLAME:
+ action_flame(elapsed_time);
+ break;
+
+ case BAD_FISH:
+ action_fish(elapsed_time);
+ break;
+
+ case BAD_BOUNCINGSNOWBALL:
+ action_bouncingsnowball(elapsed_time);
+ break;
+
+ case BAD_FLYINGSNOWBALL:
+ action_flyingsnowball(elapsed_time);
+ break;
+
+ case BAD_SPIKY:
+ action_spiky(elapsed_time);
+ break;
+
+ case BAD_SNOWBALL:
+ action_snowball(elapsed_time);
+ break;
+
+ case BAD_WINGLING:
+ action_wingling(elapsed_time);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void
+BadGuy::draw(Camera& viewport, int)
+{
+ float scroll_x = viewport.get_translation().x;
+ float scroll_y = viewport.get_translation().y;
+
+ // Don't try to draw stuff that is outside of the screen
+ if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
+ return;
+
+ if(sprite_left == 0 || sprite_right == 0)
+ {
+ return;
+ }
+
+ Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
+ sprite->draw(viewport.world2screen(Vector(base.x, base.y)));
+
+ if (debug_mode)
+ fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150);
+}
+
+void
+BadGuy::set_sprite(Sprite* left, Sprite* right)
+{
+ if (1)
+ {
+ base.width = 32;
+ base.height = 32;
+ }
+ else
+ {
+ // FIXME: Using the image size for the physics and collision is
+ // a bad idea, since images should always overlap there physical
+ // representation
+ if(left != 0) {
+ if(base.width == 0 && base.height == 0) {
+ base.width = left->get_width();
+ base.height = left->get_height();
+ } else if(base.width != left->get_width() || base.height != left->get_height()) {
+ base.x -= (left->get_width() - base.width) / 2;
+ base.y -= left->get_height() - base.height;
+ base.width = left->get_width();
+ base.height = left->get_height();
+ old_base = base;