Difference between revisions of "AGIWiki/Creating an AGI Game"

Jump to navigation Jump to search
m
syntax
m (Created page with "{{AGIWiki}} '' NOTE: This text, originally by Rainer De Temple'' == Part 1 == === Introduction === By now no doubt you know what [[AGIWiki/AGI|AG...")
 
m (syntax)
Line 61: Line 61:
*  First the picture of the room number is loaded into memory, using the load.pic(room_no) command. Keep in mind that every command has either a semi-colon(;) at the end or an opening brace.  In this case, it’s a semi-colon.  If you wish to change the number of the PICTURE resource which is loaded, you must first set a variable(say, v200)  to that value and invoke the command like this:
*  First the picture of the room number is loaded into memory, using the load.pic(room_no) command. Keep in mind that every command has either a semi-colon(;) at the end or an opening brace.  In this case, it’s a semi-colon.  If you wish to change the number of the PICTURE resource which is loaded, you must first set a variable(say, v200)  to that value and invoke the command like this:


  v200 = 4;
<syntax type="C++">
  load.pic(v200);
v200 = 4;
load.pic(v200);
</syntax>


* discard.pic(room_no) just rids the PICTURE from memory once it is drawn.
* discard.pic(room_no) just rids the PICTURE from memory once it is drawn.
Line 93: Line 95:


So, to add your object definition, add this code to the room(in this case room 2 - LOGIC.002), just under the line:
So, to add your object definition, add this code to the room(in this case room 2 - LOGIC.002), just under the line:
 
<syntax type="C++">
<nowiki>#include "defines.txt"</nowiki>
#include "defines.txt"
</syntax>


add
add


<nowiki>#define your_object_name_with_no_spaces    o1</nowiki>
<syntax type="C++">
#define your_object_name_with_no_spaces    o1
</syntax>


So it should read like this:
So it should read like this:


<nowiki>#include "defines.txt"</nowiki><br>
<syntax type="C++">
<nowiki>#define your_object_name_with_no_spaces    o1</nowiki>
#include "defines.txt"
#define your_object_name_with_no_spaces    o1
</syntax>


The reason we use o1, is because ego, is always o0.
The reason we use o1, is because ego, is always o0.
Line 110: Line 117:


Now, in the initialisation section of the room, we decide which view we want to use for our object, and where we want to put it. The initialisation section is everything between
Now, in the initialisation section of the room, we decide which view we want to use for our object, and where we want to put it. The initialisation section is everything between
 
<syntax type="C++">
if (new_room) {
if (new_room) {
 
</syntax>
and
and


Line 118: Line 125:


We want to add our code after the line:
We want to add our code after the line:
 
<syntax type="C++">
draw(ego);
draw(ego);
 
</syntax>
The code we will add here displays a view on the screen:
The code we will add here displays a view on the screen:
 
<syntax type="C++">
animate.obj(&lt;object name&gt;);        //this tells the interpreter, that we're using this object
animate.obj(&lt;object name&gt;);        //this tells the interpreter, that we're using this object
load.view(2);                      //load the view we want to use into memory
load.view(2);                      //load the view we want to use into memory
set.view(&lt;object name&gt;,2);        //this assigns the view to the object we've created
set.view(&lt;object name&gt;,2);        //this assigns the view to the object we've created
set.loop(&lt;object name&gt;,0);        //set the current loop in the view to this value
set.loop(&lt;object name&gt;,0);        //set the current loop in the view to this value
set.cel(&lt;object name&gt;,0);          //set the current cel in the view to this value
set.cel(&lt;object name&gt;,0);          //set the current cel in the view to this value
position(&lt;object name&gt;,43,104);    //where to position the view on the screen.
position(&lt;object name&gt;,43,104);    //where to position the view on the screen.
set.priority(&lt;object name&gt;,11);    //set the priority of the object(change accordingly)
set.priority(&lt;object name&gt;,11);    //set the priority of the object(change accordingly)
ignore.objs(&lt;object name&gt;);
ignore.objs(&lt;object name&gt;);
draw(&lt;object name&gt;);              //finally, draw the view on the screen.
draw(&lt;object name&gt;);              //finally, draw the view on the screen.
 
</syntax>
Set.loop, set.cel, and set.priority aren't really necessary, but can be useful, if they need to be changed later on. Ignore.objs makes the object oblivious to other objects. If this is not set, then another object may stop if it hits this object when moving.
Set.loop, set.cel, and set.priority aren't really necessary, but can be useful, if they need to be changed later on. Ignore.objs makes the object oblivious to other objects. If this is not set, then another object may stop if it hits this object when moving.


Line 160: Line 167:
After you have completed the first two steps, you are ready to add your Item to the room. This is done with the following code, added to the room: In the defines section(after the #include line):
After you have completed the first two steps, you are ready to add your Item to the room. This is done with the following code, added to the room: In the defines section(after the #include line):


<nowiki>#define &lt;item name&gt; o1        //replace &lt;item name&gt; with your own.</nowiki><br>
<syntax type="C++">
#define &lt;item name&gt; o1        //replace &lt;item name&gt; with your own.
    
    
<nowiki>animate.obj(&lt;item name&gt;);</nowiki><br>
animate.obj(&lt;item name&gt;);
<nowiki>load.view(2);</nowiki><br>
load.view(2);
<nowiki>set.view(&lt;item name&gt;,2);</nowiki><br>
set.view(&lt;item name&gt;,2);
<nowiki>set.loop(&lt;item name&gt;,0);</nowiki><br>
set.loop(&lt;item name&gt;,0);
<nowiki>set.cel(&lt;item name&gt;,0);</nowiki><br>
set.cel(&lt;item name&gt;,0);
<nowiki>position(&lt;item name&gt;,43,104);  //use your own position and priority here.</nowiki><br>
position(&lt;item name&gt;,43,104);  //use your own position and priority here.
<nowiki>set.priority(&lt;item name&gt;,11);</nowiki><br>
set.priority(&lt;item name&gt;,11);
<nowiki>ignore.objs(&lt;item name&gt;);</nowiki><br>
ignore.objs(&lt;item name&gt;);
<nowiki>stop.cycling(&lt;item name&gt;);</nowiki><br>
stop.cycling(&lt;item name&gt;);
<nowiki>draw(&lt;item name&gt;);</nowiki><br>
draw(&lt;item name&gt;);
 
</syntax>
''' Modifying LOGIC.090 '''
''' Modifying LOGIC.090 '''


This logic, in the template game, handles non-room-specific functions, like get item and look item. Add this code under the section that says put various input responses here:
This logic, in the template game, handles non-room-specific functions, like get item and look item. Add this code under the section that says put various input responses here:
 
<syntax type="C++">
if (said("look","&lt;your item name&gt;")) {  // &lt;your item name&gt; must be replaced
if (said("look","&lt;your item name&gt;")) {  // &lt;your item name&gt; must be replaced
  if (has("&lt;object name&gt;")) {          // &lt;object name&gt; is the name you put in the OBJECT file
  if (has("&lt;object name&gt;")) {          // &lt;object name&gt; is the name you put in the OBJECT file
     show.obj(220);                      // 220 is the number of the view with the
     show.obj(220);                      // 220 is the number of the view with the
                                        // close-up and description of your item.
                                        // close-up and description of your item.
  }
  }
  else {
  else {
    reset(input_parsed);
    reset(input_parsed);
  }
  }
}
}
 
</syntax>
Also needing to be added is the code for getting the object:
Also needing to be added is the code for getting the object:
 
<syntax type="C++">
if (said("get","&lt;your item name&gt;")) {
if (said("get","&lt;your item name&gt;")) {
  if (has("&lt;object name&gt;")) {
  if (has("&lt;object name&gt;")) {
    print("You already have it.");
    print("You already have it.");
  }
  }
  else {
  else {
    reset(input_parsed);
    reset(input_parsed);
  }
  }
}
}
 
</syntax>
''' Getting the item from the room '''
''' Getting the item from the room '''


The above code was necessary for looking at the item in your inventory, or trying to get it if you already have it, but it's not good enough for getting the item from the specific room it's in. Use this code for that:
The above code was necessary for looking at the item in your inventory, or trying to get it if you already have it, but it's not good enough for getting the item from the specific room it's in. Use this code for that:
 
<syntax type="C++">
if (said("get","&lt;your item name&gt;")) {
if (said("get","&lt;your item name&gt;")) {
  v255 = 2;                                //obj.in.room only accepts variables
  v255 = 2;                                //obj.in.room only accepts variables
  if (obj.in.room("&lt;object name&gt;",v255)) {  //so we make v255 equal to 2(the room number).
  if (obj.in.room("&lt;object name&gt;",v255)) {  //so we make v255 equal to 2(the room number).
    if (posn(ego,37,111,51,124)) {          //substitute these values with your own.
    if (posn(ego,37,111,51,124)) {          //substitute these values with your own.
      print("Ok.");
      print("Ok.");
      erase(&lt;your item name&gt;);
      erase(&lt;your item name&gt;);
      get("&lt;object name&gt;");
      get("&lt;object name&gt;");
    }
    }
    else {
    else {
      print("You're not close enough.");
      print("You're not close enough.");
    }
    }
  }
  }
  else {
  else {
    reset(input_parsed);    // let logic 90 take care of it
    reset(input_parsed);    // let logic 90 take care of it
  }
  }
}
}
 
</syntax>
Of course, we don't necesarily have to use v255, we can use any available Variable. The posn(ego,x1,y1,x2,y2) command, requires that x1,y1 is the top left corner of an imaginary box, and x2,y2 the lower right corner. Don't forget to enter the words you use into the WORDS.TOK file! This code is for looking at the item:
Of course, we don't necesarily have to use v255, we can use any available Variable. The posn(ego,x1,y1,x2,y2) command, requires that x1,y1 is the top left corner of an imaginary box, and x2,y2 the lower right corner. Don't forget to enter the words you use into the WORDS.TOK file! This code is for looking at the item:
 
<syntax type="C++">
  if (said("look","&lt;your item name&gt;")) {
  if (said("look","&lt;your item name&gt;")) {
   v255 = 2;
   v255 = 2;
Line 230: Line 238:
   }
   }
  }
  }
 
</syntax>
Finally, if you do not wish the item to be drawn when it isn't in the room(ie you have taken it), then replace the line above which said this:
Finally, if you do not wish the item to be drawn when it isn't in the room(ie you have taken it), then replace the line above which said this:
 
<syntax type="C++">
  draw(&lt;your item name&gt;);
  draw(&lt;your item name&gt;);
 
</syntax>
to this:
to this:
 
<syntax type="C++">
  v255 = 2;
  v255 = 2;
  if (obj.in.room("&lt;object name&gt;",v255)) { draw(&lt;your item name&gt;); }
  if (obj.in.room("&lt;object name&gt;",v255)) { draw(&lt;your item name&gt;); }
 
</syntax>
[[Category:AGIWiki/Tutorials]]
[[Category:AGIWiki/Tutorials]]
875

edits

Navigation menu