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

#include "defines.txt"

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

  // 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);
    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);
// }

// load blockage views
   load.view(10);
   load.view(55);

   // add blockage if necessary..  this doesn't work really well at the moment.

	if (room_up == 255)
	{
	  add.to.pic(10,0,0,63,84,4, 0);
	}

	if (room_left == 255)
	{
          	add.to.pic(55,0,0,49,133,0, 0);
	}
	if (room_right == 255)
	{
	  add.to.pic(55,0,0,95,133,4, 0);
	}

	if (room_down == 255)
	{
          	add.to.pic(55,0,3,60,120,4, 0);
	}
 // if in correct room, display gem
  if (index == 33)
  {
    animate.obj(o2);
    load.view(103);
    set.view(o2,103);
    position(o2,74,106);
    draw(o2);
    set(f100);
  }
  else
  {
    reset(f100);
  }

  draw(ego);
  show.pic();

  display(24,0, "room: %v50|3");

  reset(f255);
}

if (said("get", "gem"))
{
  if (isset(f100))
  {
    if (obj.in.box(o2, 66, 101, 90, 111))
    {
      erase(o2);
      print("Pinkun got the gem!");
      print("um.. that's the end of the game.");
      quit(1);
    }
    else
    {
      print("Pinkun can not reach gem from here!");
    }

  }
  else
  {
    print("Pinkun does not see gem.");
  }

}

if (said("look")) {
  print("Pinkun see trees.");
}

// reset player control if just moved ego
if (isset(f255))
{
 player.control();
}

// if hit control line
if (isset(f3))
{
// check position
// top
   if (obj.in.box(o0,0,76,160,76))
   {
    if(room_up != 255)
    {
      index=room_up; call(10);
      reposition.to(o0,74,118);
      new.room(2);
    }
    else
    {
      print("Too thick.  Pinkun no like.");
      move.obj(o0,70,80,0,f255);
    }

   }
   // right
   if (obj.in.box(o0,103,0,113,168))
   {
    if(room_right != 255)
    {
      index=room_right; call(10);
      reposition.to(o0, 51,101);
      new.room(2);
    }
    else
    {
      print("Too thick.  Pinkun no like.");
      move.obj(o0,96,101,0,f255);
    }
   }
   // left
   if (obj.in.box(o0,45,0,55,168))
   {
    if(room_left != 255)
    {
      index=room_left; call(10);
      reposition.to(o0, 96,101);
      new.room(2);
    }
    else
    {
      print("Too thick.  Pinkun no like.");
      move.obj(o0,51,101,0,f255);
    }
   }
   // down
   if (obj.in.box(o0,0,134,160,134))
   {
    if(room_down != 255)
    {
      index=room_down; call(10);
       reposition.to(o0, 70,80);
      new.room(2);
    }
    else
    {
      print("Too thick.  Pinkun no like.");
      move.obj(o0,74,118,0,f255);
    }
   }
}


return();