// ****************************************************************************
//
// Logic 2: First room
//
// ****************************************************************************

#include "defines.txt"

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

  // The next 6 lines need only be in the first room of the game
  if ((prev_room_no == 1 ||    // just come from intro screen
      prev_room_no == 0)) {    // or just started game
    position(ego,80,100);
    position(ego2,80,140);
    status.line.on();
    accept.input();
  }

// 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);
// }
  animate.obj(ego2);
  load.view(4);
  set.view(ego2,4);
  stop.cycling(ego2);

// configure cursor
  set.view(ego,arrow_cursor); // Set the ego to the arrow cursor
  set.priority(ego,15);
  set(arrow_cursor_flag);
  load.view(arrow_cursor);
  load.view(look_cursor);
  load.view(action_cursor);
  load.view(talk_cursor);

// load and display the tool bar
  animate.obj(o6);
  load.view(6);
  set.view(o6,6);
  position(o6,0,22);
  draw(o6);

// initialization of the door
  animate.obj(o8);
  load.view(8);
  set.view(o8,8);
  set.loop(o8,0);
  set.cel(o8,0);
  position(o8,33,132);
  ignore.blocks(o8);
  ignore.objs(o8);
  set.priority(o8,4);
  stop.cycling(o8);
  draw(o8);

// reset some flags
  reset(door_finished_opening);
  reset(ego2_through_doorway);

// draw cursor and ego, show picture
  draw(ego); // Draws the cursor on the screen
  draw(ego2); // Draws the ego on the screen
  show.pic();
}

// Tool bar functions
if (controller(key_esc) && posn(ego,0,0,19,33)) {
  reset(look_cursor_flag);
  reset(action_cursor_flag);
  reset(talk_cursor_flag);

  set.view(ego,arrow_cursor);

  set(arrow_cursor_flag);
}

if (controller(key_esc) && posn(ego,20,0,39,33)) {
  reset(arrow_cursor_flag);
  reset(action_cursor_flag);
  reset(talk_cursor_flag);

  set.view(ego,look_cursor);

  set(look_cursor_flag);
}

if (controller(key_esc) && posn(ego,40,0,59,33)) {
  reset(arrow_cursor_flag);
  reset(look_cursor_flag);
  reset(talk_cursor_flag);

  set.view(ego,action_cursor);

  set(action_cursor_flag);
}

if (controller(key_esc) && posn(ego,60,0,79,33)) {
  reset(arrow_cursor_flag);
  reset(look_cursor_flag);
  reset(action_cursor_flag);

  set.view(ego,talk_cursor);

  set(talk_cursor_flag);
}

if (controller(key_esc) && posn(ego,80,0,100,33)) {
    set(inventory_select_enabled);    // enable choice of inventory item in inventory screen
    status();   // show inventory screen - player selects an inventory item
}

// Point & Click routines
if (controller(key_esc) && isset(arrow_cursor_flag) && posn(ego,0,34,160,167)) {
  get.posn(ego,v212,v213);
  start.cycling(ego2);
  move.obj.v(ego2,v212,v213,1,f214);
}

if(isset(f214)) {
  set.cel(ego2,0);
  stop.cycling(ego2);
  reset(f214);
} 

if (controller(key_esc) && posn(ego,31,104,41,141) && isset(action_cursor_flag)) {
    stop.motion(ego2);
    program.control();
    end.of.loop(o8,door_finished_opening);
}

if (controller(key_esc) && posn(ego,31,94,41,131) && isset(look_cursor_flag)) {
  print("This is a door example.");
}

if (controller(key_esc) && posn(ego,31,94,41,131) && isset(talk_cursor_flag)) {
  print("You can't talk to the door.");
}

if (door_finished_opening) {
   reset(door_finished_opening);  // If door_finished_opening remains set, the
                                  // following code will be executed on every
                                  // cycle (which we don't want).
   ignore.blocks(ego);        // allow ego to cross the blue control line
   move.obj(ego2,32,105,1,ego2_through_doorway);
}

if (ego2_through_doorway) {
   observe.blocks(ego2);
   new.room(2);
}

if (said("look")) {
  print("This is the AGI Mouse Demo/Template Game Version 0.7");
}

if (ego_edge_code == horizon_edge) {  // ego touching horizon
  new.room(2);
}

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

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

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

return();