// ****************************************************************************
//
// Logic 49: Inside the Gates to the Castle
//
// ****************************************************************************

#include "defines.txt"

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



// Check what room the player came from and position them on the
// screen accordingly here, e.g:
/* if (prev_room_no == 44) {
     position(ego,44,72);
     ego_dir = 5;
 }*/
  load.view(1);
  load.view(2);
  if (is_zombie) {
      load.view(103);
      load.view(129);
      }

  animate.obj(o1); //switch
  load.view(handle);
  set.view(o1,handle);
  position(o1,50,152);
  stop.cycling(o1);
  ignore.objs(o1);
  if (gate_switch) {
      set.cel(o1,0);
      }
  else {
      set.cel(o1,1);
      }
  draw (o1);

  animate.obj(o2); //guard
  load.view(107);
  set.view(o2,107);
  position(o2,101,152);
  ignore.objs(o2);
  draw(o2);

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


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

get.posn(o2, temp_x, temp_y); //Guard movement
distance(o2, ego, temp_x2);   //Guard collision-detection

if (temp_x>142) {     //movement
    universe=7;
    set.dir(o2,universe);
    }

if (temp_x<102) {
    universe=3;
    set.dir(o2,universe);
    }

if (temp_x2<=10) { //Collision

     print("You've been captured by the Dream King's guards and sent outside.");
     new.room(44);
     }


if (said("look")) {
  print("You are inside the gate to the castle.");
}

if ((said("look","ladder") ||
     said("climb","ladder"))) {
          print("It looks sturdy enough.  Just push up or down when you're centered on the ladder to climb.");
          }

if ((said("look","statue") ||
     said("push","statue") ||
     said("get","statue"))) {
          print("There are some creepy statues here, and as much as you'd like them out of the way, they are firmly cemented to the floor.");
          }

if (said("look","handle")) {
    print("It's a fairly typical handle.  I wonder what it does.");
    }

if (said("jump")) {
    print("This is a non-jumping game.");
    }


if (said("use","handle")) {
    distance(ego,o1,universe);

    if (universe<=10) {
        if (gate_switch) {
            reset(gate_switch);
            }
        else {
            set(gate_switch);
            }
        new.room(49);
        }
    else {
       print ("Your arms are too short.");
   }

  }

if (ego_edge_code == right_edge) {   // ego touching right edge of screen
  new.room(50);
}

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

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

call(100);

return();