// ****************************************************************************
//
// Logic 21: Just yet another trail
//
// ****************************************************************************

#include "defines.txt"

if (new_room) {
  load.pic(room_no);
  draw.pic(room_no);
  discard.pic(room_no);
  set.horizon(37);



// Check what room the player came from and position them on the
// screen accordingly here, e.g:
// if (prev_room_no == 5) {
//   position(ego,12,140);
// }
  if (prev_room_no==22){
  position(ego,38,161);
  }
  animate.obj(o1); //VG shaking tree
  load.view(0);
  load.view(2);

  set.priority(o1, 15);

  animate.obj(o2); //falling coconuts
  load.view(coconut);
  set.view(o2, coconut);
  set.priority(o2, 15);
  ignore.objs(o2);

  load.sound(15);
  sound(15, sound_flag);

  draw(ego);
  show.pic();
}

if (said("look")) {
  print("This bend of the trail sports a small grove of coconut trees");
}

if (said("look","tree")) {
  print("Cool... coconut trees!");
  }

if (said("hit","tree")) {
    print("Ow!");
    }

if (said("shake","tree")) {
  if (!has("coconut")) {
    position.v(o1, new_ego_x, new_ego_y);
    set.view(o1, 0);
    erase(ego);
    draw(o1);
    ego_dir=0;
    program.control();
    move.obj(o1, 26, 131, 1, done_flag);
   }
  else {
    print("You have more than enough coconuts to go around.");
    }
  }

if (done_flag) {
    reset(done_flag);
    set.view(o1, 2);
    end.of.loop(o1, more_done_flag);
    }

if (more_done_flag) {
    reset(more_done_flag);
    set.view(o1, 0);
    start.cycling(o1);
    move.obj.v(o1, new_ego_x, new_ego_y, 2, really_done_flag);
    }

if (really_done_flag) {
    reset(really_done_flag);
    erase(o1);
    draw(ego);
    position(o2,24,61);
    draw(o2);
    move.obj(o2, 24, 131, 2, penultimate_done_flag);
    }

if (penultimate_done_flag) {
    reset(penultimate_done_flag);
    print("Some coconuts fall to the ground.");
    print("You pick them up and store them in the recesses of your raver pants.");
    get("coconut");
    score++;
    erase(o2);
    player.control();
    }

if (said("climb","tree")) {
    print("No, the trees are too \"shaky\".");
    }

if (said("get","coconut")) {
    print("You can't reach the coconuts from the ground.");
    }

if (said("look","coconut")) {
    if (!has("coconut")){
     print("You put the lime in the coconut...");
     print("You drink it all up.");
     }
    else {
         show.obj(coconut);
         }
   }

if (said("look","grass")) {
    print("Just grass.");
    }

if (said("look","cloud")) {
    print("The sky is like a corral for a herd of puffy, little clouds.");
    }

if (said("look","plants")) {
    print("None of these are medicinal plants.");
    }

if (said("look","path")) {
    print("Yep, just a path.");
    }

if ((said("hit","tree") ||
     said("push","tree"))) {
    print("It shakes a little, but not enough.");
    }



if (ego_edge_code == bottom_edge) {   // ego touching bottom edge of screen
  new.room(22);
}

if (ego_edge_code == left_edge) {     // ego touching left edge of screen
  new.room(20);
}

if (sound_flag) {
    sound(15, sound_flag);
    }

return();