home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / J4FTUT02.ZIP / temp / techtut / tut2 / tech02.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1997-09-10  |  8.1 KB  |  248 lines

  1. {
  2.  
  3.         TechTutor2
  4.         Alien code, a simple (not working) example.
  5.  
  6.         Coding by P.Bestebroer
  7.         FreeWare
  8.  
  9.         This source will not work on it's own, it just shows how to
  10.         do alien-code into you'r game...
  11.         The source code was ripped from one of my game-projects, but
  12.         because of this little tech-info I extruded variables wich where
  13.         needed in my game, but are not allways used.
  14.  
  15.         Contacting:
  16.  
  17.          HTTP://people.zeelandnet.nl/rpb/
  18.         EMAIL:just4fun@zeelandnet.nl
  19.  
  20. }
  21. PROGRAM Tech02;
  22.  
  23. USES CRT,OBJECTS;
  24. {─────────────────────────────────────────────────────────────────────────────}
  25. {
  26.         First create the BASE_ALIEN variables
  27. }
  28. TYPE   Pactor = ^Tactor;   { this is the Base_Alien code }
  29.        Tactor = object
  30.          Xposition,
  31.          Yposition    : integer;          { Xposition and Yposition       }
  32.          Xstart,Ystart: integer;          { X+Y start positions           }
  33.          Xspeed,
  34.          Yspeed       : real;              { Xspeed and Yspeed             }
  35.          xdir,ydir    : shortint;          { direction of movement         }
  36.          AI           : byte;              { AI state                      }
  37.          energy       : byte;              { energy of the alien           }
  38.          ID           : byte;              { alien number                  }
  39.          killed       : boolean;           { if actor is out of loop       }
  40.          I_frame,
  41.          f_Frame,                          { Animation frame data          }
  42.          a_Frame,
  43.          c_frame,
  44.          t_frame,
  45.          s_Frame     : byte;
  46.          n_frame     : shortint;
  47.          cycle       : boolean;
  48.  
  49.          CONSTRUCTOR INIT(xp,yp:integer);       { initialisation of alien    }
  50.            PROCEDURE sub_init;           Virtual;  { for some extra init     }
  51.            PROCEDURE animate;            Virtual;  { animate the images      }
  52.            FUNCTION see_if_hit:boolean;  Virtual;  { see if hit by bullet    }
  53.            FUNCTION PLAYER_HIT:boolean;  Virtual;  { see if hitting the player}
  54.            PROCEDURE putit;              Virtual;  { draw the alien          }
  55.            PROCEDURE movement;           Virtual;  { moving the alien        }
  56.            PROCEDURE acting;             Virtual;  { the AI procedure        }
  57.          DESTRUCTOR DONE;                       { For erasing alien          }
  58.       END;
  59. {=-=-=-=-=   Now create the Specific_Alien variables  =-=-=-=-=}
  60. TYPE  PGroundWalker = ^TGroundWalker;   { A ground-walker (ie. soldier) }
  61.       TGroundWalker = object(TACTOR)    { is based on the Base_Actor    }
  62.            PROCEDURE SUB_INIT; Virtual; { For extra variables initialisation }
  63.            PROCEDURE Acting; VIRTUAL;   { For the AI of the Ground-Walkers }
  64.       END;
  65.  
  66.       PFlying = ^TFlying;               { A flying enemie }
  67.       TFlying = object(TACTOR)          { is based on the Base_Actor   }
  68.            PROCEDURE SUB_INIT; Virtual; { for extra variables initialisation }
  69.            PROCEDURE Acting; VIRTUAL;   { for the AI of the Ground-Walkers }
  70.          end;
  71.  
  72.  
  73. VAR  act       : array[0..255] of Pactor;       { array of the actors        }
  74.      actor_a   : byte;                          { amount of actors in game   }
  75. {────────────────────────────────────────────────────────────────────────────}
  76. {
  77.         These are the procedures wich could be used....
  78. }
  79. CONSTRUCTOR TACTOR.Init(xp,yp:integer); { to initialise an alien }
  80. BEGIN
  81.   {
  82.      Set the position variables,
  83.      the energy, the default values (ie. Killed=False)
  84.   }
  85. END;
  86.  
  87. PROCEDURE TACTOR.SUB_INIT;     { this is replaced by the specific_alien code }
  88. BEGIN
  89.  ABSTRACT;
  90. END;
  91.  
  92. PROCEDURE TACTOR.ANIMATE;      { For the image-animations }
  93. BEGIN
  94.   {
  95.       Animate the alien walking, flying, shooting, etc...
  96.   }
  97. END;
  98.  
  99. FUNCTION TACTOR.PLAYER_HIT:boolean; { see if hitting the player }
  100. BEGIN
  101.   {
  102.       Check on collision between the player and the alien
  103.   }
  104. END;
  105.  
  106. FUNCTION TACTOR.SEE_IF_HIT:boolean; { See if hit by a bullet }
  107. BEGIN
  108.  {
  109.       Walk thru the bullets, and check on collision with the alien..
  110.       if hit set the KILLED flag to TRUE
  111.  }
  112. END;
  113.  
  114. PROCEDURE TACTOR.PUTIT; { Draw the alien on screen }
  115. BEGIN
  116.  {
  117.      Draw the current frame-image of the alien on screen
  118.  }
  119. END;
  120.  
  121. PROCEDURE TACTOR.MOVEMENT; { This is for the moving of the specific_aliens }
  122. BEGIN
  123.   ABSTRACT
  124. END;
  125.  
  126.  
  127. PROCEDURE TACTOR.ACTING; { This will handle the AI of the specific_alien }
  128. BEGIN
  129.  ABSTRACT;
  130. END;
  131.  
  132.  
  133. DESTRUCTOR TACTOR.DONE;  { For erasing the alien from memory }
  134. BEGIN
  135. END;
  136.  
  137.  
  138. {────────────────────────────────────────────────────────────────────────────}
  139. {             The custom-home-made-do-it-yourself enemy code                 }
  140. {────────────────────────────────────────────────────────────────────────────}
  141. PROCEDURE TGroundWalker.SUB_INIT;
  142. BEGIN
  143.   {
  144.     Put the specific initialisation for the GroundWalking enemy
  145.     in this little procedure...
  146.   }
  147. END;
  148.  
  149. PROCEDURE TGroundWalker.Acting;
  150. BEGIN
  151.  {
  152.    Put all code for movement, collision detection and other things in this
  153.    procedure...
  154.    This is the "core" of the GroundWalking enemy, or call it his
  155.    Artificial Intelligence routines
  156.  }
  157. END;
  158. {────────────────────────────────────────────────────────────────────────────}
  159. PROCEDURE TFlying.SUB_INIT;
  160. BEGIN
  161.   {
  162.     Put the specific initialisation for the Flying enemy
  163.     in this little procedure...
  164.   }
  165. END;
  166.  
  167. PROCEDURE TFlying.Acting;
  168. BEGIN
  169.  {
  170.    Put all code for movement, collision detection and other things in this
  171.    procedure...
  172.    This is the "core" of the Flying enemy, or call it his
  173.    Artificial Intelligence routines
  174.  }
  175. END;
  176. {────────────────────────────────────────────────────────────────────────────}
  177. {
  178.         This code will intialise all the different aliens
  179.  
  180.         Expects : AI Number of the alien and other init variables
  181.         Returns : a Pointer to the new TACTOR type
  182.  
  183. }
  184. FUNCTION AddActor(ai:byte;xp,yp:integer):Pactor;
  185. BEGIN
  186.  Addactor:=NIL;
  187.  case ai of
  188.     1 : addActor:=new(PGroundWalker,init(xp,yp)); { first alien type }
  189.     2 : addActor:=new(PFlying,init(xp,yp));       { second alien type }
  190.     { ... }
  191.  end;
  192. END;
  193. {────────────────────────────────────────────────────────────────────────────}
  194. {
  195.  
  196.         Process the actor_list
  197.  
  198.         Expects: Nothing
  199.         Returns: Nothing
  200.  
  201. }
  202. PROCEDURE DoActors;
  203. VAR i       : word;
  204. BEGIN
  205.  if actor_a=0 then exit;        { no actors to process                       }
  206.  i:=1;                          { start with first actor                     }
  207.  while i<actor_a+1 do begin
  208.    with act[i]^ do begin
  209.         if not KILLED then begin        { if alien still lives,              }
  210.            Acting;      { make it act (moving, shooting, etc...)             }
  211.            PutIt;       { and draw it. PUTIT could be cald from within ACTING}
  212.         end;
  213.    end;
  214.    inc(i);              { go to next actor in the array                      }
  215.  end;
  216. END;
  217. {────────────────────────────────────────────────────────────────────────────}
  218. BEGIN
  219.   while port[$60]<>156 do ;
  220.   textcolor(7); textbackground(0); clrscr;
  221.   writeln('TechTutor #2');
  222.   writeln('written by P.Bestebroer, Just4Fun Productions');
  223.   writeln('');
  224.   writeln('This examples contains procedures for some great aliens/objects and things');
  225.   writeln;
  226.   writeln('Just like the previous tutor, this example needs some extra work aswell');
  227.   writeln('Although the examples work, they wont display anything on the screen.');
  228.   writeln('There are also no real "acting/movement" procedures because that is');
  229.   writeln('upto you to implement (the easiest and most fun job!)');
  230.   writeln;
  231.   writeln('You should use a great VGA unit (SuperFX engine for example ;) and ');
  232.   writeln('implement the things like drawing the objects');
  233.   writeln;
  234.   writeln('Watch out for the other techtutors...');
  235.   writeln;
  236.   writeln('Press a key');
  237.  
  238.   writeln;
  239.   writeln;
  240.   writeln;
  241.   writeln('----------------------------------');
  242.   writeln('Contacting: just4fun@zeelandnet.nl');
  243.   writeln('http://people.zeelandnet.nl/rpb   ');
  244.   writeln('----------------------------------');
  245.   repeat until port[$60]<>156;
  246.  
  247. END.
  248.