Home | AGI Documentation | AGI Tutorials | AGI Tools | AGI Wiki | Community

4.5 Discussion of Sample LOGIC Code from KQ4

Last updated: 31 August 1997
Retrived from the Internet Archive
 

Kings Quest IV: Room 7

Some of you may know that "The Official Book of King's Quest" included three small fragments of AGI code for ROOM 7 in the AGI version of KQ4. These fragments are given below along with the same fragments taken from the game itself. There are a few differences which is to be expected but generally the code is very similar. These examples show how the coder wrote the code and what it now looks like in the final product. I've included a few comments where some interesting observations can be seen.


Animating the smoke

FROM THE BOOK

 animate.obj( smoke);
 ignore.horizon( smoke);
 set.view( smoke, v.fish.cabin);
 set.loop( smoke, 1);
 ignore.blocks( smoke);
 position( smoke, 95, 16);
 work = 3;
 step.time( smoke, work);
 cycle.time( smoke, work);
 draw( smoke);

FROM THE GAME

 animate.obj(7);
 ignore.horizon(7);
 set.view(7, 114);
 set.loop(7, 1);
 ignore.objs(7);                [ These two lines have been added.
 set.priority(7, 5);            [
 ignore.blocks(7);
 position(7, 95, 16);
 assignn(152, 3);               [ Equivalent to 'work = 3;'
 step.time(7, 152);
 cycle.time(7, 152);
 draw(7);

COMMENTS


Opening the door

FROM THE BOOK

if (said( open, door)) {     [ must be close enough
  if (posn( ego, 86, 120, 106, 133)) {
    if (!night) {
      if ( door.open) {
        print("The door is already open. . .
      }
      else {
        set( game.control);
        set.priority( ego, 11);
        start.update( door);
        end.of.loop( door, door.done);
      }
    }
    else {
      print("You can't -- it's locked...
    }
  }
  else {
    set( notCloseEnough);
  }
}

FROM THE GAME

if (said(OPEN, DOOR||DOORS||DOORWAY||DOORWAYS)) { 
  if (posn(0, 86, 120, 106, 133)) { 
    if (!isset(38)) { 
      if (isset(231)) { 
        print("The door is already open.");  
      }
      else { 
        set(36);
        prevent.input();
        start.update(5);
        assignn(152, 3);
        cycle.time(5, 152);
        end.of.loop(5, 232);
        sound(70, 154);
      }
    }           
    else { 
      print("You can't.  It's locked and you 
             don't have the key.");
    }
  }
  else { 
    set(113);
  }
}

Unlocking the door

FROM THE BOOK

 if (said( unlock, door)) {     [must be close enough
   if (posn( ego, 86, 120, 106, 133)) {
     if (!night) {
       print("The door is already unlocked. . .
     }
     else {
       printf("You can't, it's locked. . .
     }
   }
   else {
     set( notCloseEnough);
   }
 }

FROM THE GAME

 if (said(UNLATCH||UNLOCK, DOOR||DOORS||DOORWAY||DOORWAYS)) { 
   if (posn(0, 86, 120, 106, 133)) { 
     if (!isset(38)) { 
       print("The door is already unlocked.");
     }
     else { 
       print("You can't.  It's locked and you 
              don't have the key.");
     }
   }
   else { 
     set(113);
   }
 }

Knocking on the door

FROM THE BOOK

 if ((said( knock, at, door) || said( knock) ||
      said( knock, on, door) || said( knock, door)) {
   if (posn( ego, 86, 120, 106, 133)) {
     if (!night) {
       print("You knock on the door. . .
              a woman says. . .
     }
     else {
       printf("You knock on the. . .
               a man calls out. . .
     }
   }
   else {
     set( notCloseEnough);
   }
 }

FROM THE BOOK

 if (said(BANG||KNOCK||RAP||TAP) ||
     said(BANG||KNOCK||RAP||TAP, DOOR||DOORS||DOORWAY||DOORWAYS)) { 
   if (posn(0, 86, 120, 106, 133)) { 
     if (!isset(38)) { 
       print("You assertively knock on the shanty 
              door.  A woman's voice answers, "Jest come on in!"");
     }
     else { 
       print("You assertively knock on the shanty 
              door.  From inside, a man's voice calls out, "D'ya know 
              what TIME it is?!  GO AWAY!!"");
     }
   }
   else { 
     set(113);
   }
 }

Fall rocks

FROM THE BOOK

 if (hit.special) {
   if ((rf2 || rf3 || rf4)) {
     reset(hit.special);
     get.posn(ego, priorx, priory);
     position.f(dude, priorx, priory);
     ignore.blocks(dude);
     set( game.control);
     set.view( dude, v.ego.land);
     if ((ego.dir == 3 || ego.dir == 4)) {
       set.loop( dude, 2);
     }
     else {
       set.loop( dude, 3);
     }
     fix.loop(dude);
     work = 3;
     step.size( dude, work);
     work = 3;
     cycle.time( dude, work);
     start.cycling(dude);
     erase(ego);
     draw(dude);
     if (rf3) {
       work6 = 0;
       move.obj.f( dude, tempx, tempy, work6, fall.done);
     }
     if (rf4) {
       work6 = 0;
       move.obj.f( dude, tempx, tempy, work6, fall.done);
     }
     if (rf2) {
       if (priory < 125) {
         set.priority( dude, 9);
         tempy=132;
         work6=0;
         move.obj.f( dude, ego,x, tempy, work6, fall.done);
       }
       else {
         set.priority(dude, 15);
         tempy = 156;
         work6 = 0;
         move.obj.f( dude, ego.x, tempy, work6, fall.done);
       }
     }
   }
 }

FROM THE GAME

 if (isset(3)) {     [ hit.special
   if (isset(222) || isset(223) || isset(224)) {     [ rf2, rf3, rf4
     reset(3);
     sound(51, 154);
     get.posn(0, 134, 135);
     position.v(12, 134, 135);
     ignore.blocks(12);
     set(36);
     prevent.input();
     set.view(12, 11);
     if (equaln(6, 3) || equaln(6, 4)) { 
       set.loop(12, 2);
     }
     else { 
       set.loop(12, 3);
     }  
     fix.loop(12);
     assignn(152, 3);
     step.size(12, 152);
     assignn(152, 3);
     cycle.time(12, 152);
     start.cycling(12);
     erase(0);
     draw(12);
     if (isset(223)) { 
       assignn(158, 0);
       move.obj.v(12, 107, 108, 158, 226);
     }
     if (isset(224)) {
       assignn(158, 0);
       move.obj.v(12, 107, 108, 158, 226);
       set.priority(12, 14);
     }
     if (isset(222)) { 
       if (lessn(135, 125)) { 
         set.priority(12, 9);
         assignn(108, 132);
         assignn(158, 0);
         move.obj.v(12, 33, 108, 158, 226);
       }
       else { 
         set.priority(12, 14);
         assignn(108, 158);
         assignn(158, 0);
         move.obj.v(12, 33, 108, 158, 226);
       }
     }
   }
 }
 

by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.
Thank you.
pixe
Top

© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.