X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy.cpp;h=5e496ec4ae59b8db779e927183650115649e007f;hb=4c53a552c13dbe9d587e34e3cf48e82877d09288;hp=da1c49e3ef5a05b9e280f34a6f8d520d0281ed98;hpb=99e8021e04272ce390fb8cf65404b6b2d956f5fc;p=supertux.git diff --git a/src/badguy.cpp b/src/badguy.cpp index da1c49e3e..5e496ec4a 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -159,13 +159,12 @@ BadGuy::~BadGuy() void BadGuy::init() { - base.x = 0; - base.y = 0; - base.width = 0; - base.height = 0; + base.x = start_position.x; + base.y = start_position.y; + base.width = 32; + base.height = 32; mode = NORMAL; - dying = DYING_NOT; old_base = base; dir = LEFT; seen = false; @@ -177,8 +176,6 @@ BadGuy::init() specs = badguyspecs_manager->load(badguykind_to_string(kind)); - set_action("hide", "hide"); - // if we're in a solid tile at start correct that now if(Sector::current()) { if(kind != BAD_FLAME && kind != BAD_FISH && kind != BAD_FLAMEFISH && collision_object_map(base)) @@ -188,20 +185,6 @@ BadGuy::init() while(collision_object_map(base)) --base.y; } - - if(Sector::current()->camera) { - Vector scroll = Sector::current()->camera->get_translation(); - - if(start_position.x > scroll.x - X_OFFSCREEN_DISTANCE && - start_position.x < scroll.x + screen->w + X_OFFSCREEN_DISTANCE && - start_position.y > scroll.y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll.y + screen->h + Y_OFFSCREEN_DISTANCE) { - activate(LEFT); - } - } } else { - if(start_position.x > 0 && start_position.x <= screen->w - && start_position.y > 0 && start_position.y <= screen->h) - activate(LEFT); } } @@ -227,9 +210,12 @@ BadGuy::activate(Direction activation_dir) frozen_timer.init(true); timer.init(true); + dying = DYING_NOT; + seen = true; + dir = activation_dir; float dirsign = activation_dir == LEFT ? -1 : 1; - + set_action("left", "right"); if(kind == BAD_MRBOMB) { physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0); @@ -274,16 +260,26 @@ BadGuy::activate(Direction activation_dir) base.width = 66; base.height = 66; } - - base.x = start_position.x; - base.y = start_position.y; - old_base = base; - seen = true; } Surface* BadGuy::get_image() { +// Set action as the "default" one. +specs->sprite->set_action("left"); +if(BAD_JUMPY) + specs->sprite->set_action("left-up"); +else if(kind == BAD_BOMB) + specs->sprite->set_action("ticking-left"); +else if(kind == BAD_FLAME) + specs->sprite->set_action("normal"); +else if(kind == BAD_STALACTITE) + specs->sprite->set_action("normal"); +else if(kind == BAD_FISH) + specs->sprite->set_action("normal"); +else if(kind == BAD_FLAMEFISH) + specs->sprite->set_action("normal"); + return specs->sprite->get_frame(0); } @@ -505,10 +501,13 @@ BadGuy::action_jumpy(double elapsed_time) } // set direction based on tux - if(tux.base.x > base.x) - dir = RIGHT; - else - dir = LEFT; + if(dying == DYING_NOT) + { + if(tux.base.x > base.x) + dir = RIGHT; + else + dir = LEFT; + } // move physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity); @@ -727,11 +726,14 @@ BadGuy::action_flyingsnowball(double elapsed_time) if(dying == DYING_NOT || dying == DYING_SQUISHED) collision_swept_object_map(&old_base, &base); - // set direction based on tux - if(Sector::current()->player->base.x > base.x) - dir = RIGHT; - else - dir = LEFT; + if(dying == DYING_NOT) + { + // set direction based on tux + if(Sector::current()->player->base.x > base.x) + dir = RIGHT; + else + dir = LEFT; + } // Handle dying timer: if (dying == DYING_SQUISHED && !timer.check()) @@ -751,14 +753,6 @@ BadGuy::action_spiky(double elapsed_time) check_horizontal_bump(); fall(); -#if 0 - // jump when we're about to fall - if (physic.get_velocity_y() == 0 && - !issolid(base.x+base.width/2, base.y + base.height)) { - physic.enable_gravity(true); - physic.set_velocity_y(2); - } -#endif physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity); if (dying != DYING_FALLING) @@ -773,6 +767,13 @@ BadGuy::action_snowball(double elapsed_time) fall(); + // jump when we're about to fall + if (physic.get_velocity_y() == 0 && + !issolid(base.x+base.width/2, base.y + base.height)) { + physic.enable_gravity(true); + physic.set_velocity_y(2); + } + physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); @@ -855,34 +856,53 @@ BadGuy::action(float elapsed_time) 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(!seen) + { + /* Activate badguys if they're just around the screen to avoid + * the effect of having badguys suddenly popping up from nowhere. */ if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && - start_position.x < scroll_x - base.width) + start_position.x < scroll_x - base.width && + start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) 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 && + else if (start_position.x > scroll_x + screen->w && + start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE && + start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) activate(LEFT); - } else { + else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && + start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE && + ((start_position.y > scroll_y + screen->h && + start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) || + (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y))) + { + if(start_position.x < scroll_x - screen->w/2) + activate(RIGHT); + else + activate(LEFT); + } + /* Special case for badguys on start of the level. + * If in the future, it's possible to set Tux start pos, this case + * should contemplate that. */ + else if (start_position.x > 0 && start_position.x < screen->w && + start_position.y > 0 && start_position.y < screen->h) + activate(LEFT); + } + else + { if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4 - || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4) { + || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4) + { seen = false; if(dying != DYING_NOT) remove_me(); + } } - } - + if(!seen) return; @@ -949,6 +969,9 @@ BadGuy::action(float elapsed_time) void BadGuy::draw(DrawingContext& context) { + if(!seen) + return; + if((dir == LEFT && action_left == "hide") || (dir == RIGHT && action_right == "hide")) return; @@ -986,7 +1009,7 @@ BadGuy::set_action(std::string left, std::string right) else { // FIXME: Using the image size for the physics and collision is - // a bad idea, since images should always overlap there physical + // a bad idea, since images should always overlap their physical // representation if(left != 0) { if(base.width == 0 && base.height == 0) { @@ -1184,7 +1207,7 @@ BadGuy::kill_me(int score) void BadGuy::explode(bool right_way) { - BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB); + BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB, true); if(right_way) { badguy->timer.start(0);