- activate();
- //Badguy right of screen
- } else if (start_position.x > scroll_x + SCREEN_WIDTH &&
- start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE &&
- start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
- start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) {
- if (start_dir != AUTO) dir = start_dir; else dir = LEFT;
- set_state(STATE_ACTIVE);
- activate();
- //Badguy over or under screen
- } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
- start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE &&
- ((start_position.y > scroll_y + SCREEN_HEIGHT &&
- start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) ||
- (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
- start_position.y < scroll_y - bbox.get_height() ))) {
- if (start_dir != AUTO) dir = start_dir;
- else{
- // if nearest player is to our right, start facing right
- Player* player = get_nearest_player();
- if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
- dir = RIGHT;
- } else {
- dir = LEFT;
- }
- }
- set_state(STATE_ACTIVE);
- activate();
- } else if(state == STATE_INIT
- && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE
- && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE + SCREEN_WIDTH
- && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE
- && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE + SCREEN_HEIGHT ) {
- if (start_dir != AUTO) {
- dir = start_dir;
- } else {
- // if nearest player is to our right, start facing right
- Player* player = get_nearest_player();
- if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
- dir = RIGHT;
- } else {
- dir = LEFT;
+ if (!is_initialized) {
+
+ // if starting direction was set to AUTO, this is our chance to re-orient the badguy
+ if (start_dir == AUTO) {
+ Player* player = get_nearest_player();
+ if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
+ dir = RIGHT;
+ } else {
+ dir = LEFT;
+ }