X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy.cpp;h=5e496ec4ae59b8db779e927183650115649e007f;hb=c06f17a80ab84d8a26bf7c7bb381ad3f15596de8;hp=e4f04ff43d078adf0d1a74f74edaac57ab32ae7e;hpb=95ef01464dbf007c0f0d9c3d8a88a147c117385d;p=supertux.git diff --git a/src/badguy.cpp b/src/badguy.cpp index e4f04ff43..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.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)) @@ -213,6 +210,9 @@ 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; @@ -260,11 +260,6 @@ 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* @@ -869,13 +864,25 @@ BadGuy::action(float elapsed_time) if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && start_position.x < scroll_x - base.width && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - 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_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 + Y_OFFSCREEN_DISTANCE) + start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) activate(LEFT); + 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. */ @@ -898,7 +905,7 @@ BadGuy::action(float elapsed_time) if(!seen) return; - + switch (kind) { case BAD_MRICEBLOCK: @@ -962,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;