home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / oop.swg / 0015_OOPOBJS.PAS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  5.9 KB  |  245 lines

  1. Unit OopObjs;
  2.  
  3. { OOPOBJS.PAS  Version 1.1 Copyright 1992 Scott D. Ramsay }
  4.  
  5. {  OOPOBJS.PAS is free! Go crazy. }
  6. {  When I was learning Linked-List in High School, I thought that I'd only  }
  7. { need it in boring stuff like database Programming.  Doubled linked-list,  }
  8. { is a great way to handle multiple Objects For games.  Throw in some OOP   }
  9. { design and Volia!  Easy managable sprites.                                }
  10. {  I give this code to Public Domain.  Use it as you see fit.  Just include }
  11. { the first comment line when distributing the source code, Thanks.         }
  12.  
  13. {  Changes from 1.0:                                                        }
  14. {    Added new parameter in method checkhit.                                }
  15. {          Var item:pobj                                                    }
  16. {      Is a Pointer to the Object which called the checkhit                 }
  17.  
  18. Interface
  19.  
  20. Type
  21.   plist   = ^tlist;
  22.   PObjs   = ^tobjs;
  23.   tobjs   = Object
  24.               nx,ny,                       { Sprite Position               }
  25.               flp,                         { Sprite number (For animation) }
  26.               nrx,                         { I Forget what this does       }
  27.               num_sprite,                  { Num of sprites per Objects    }
  28.               timeo,                       { How long this Object lasts    }
  29.               pointage     : Integer;      { Score value (For gamers)      }
  30.               mapcolor     : Byte;         { Color For radar display       }
  31.               id,                          { I Forget this one too         }
  32.               explo,                       { True if the Object is explodin}
  33.               overshow     : Boolean;      { See: Procedure DRAWITEMS      }
  34.               powner       : plist;        { The PLIST node which this     }
  35.                                            {  Object belongs               }
  36.               Constructor init(vx,vy:Integer);
  37.               Procedure drawitemObject;Virtual;
  38.               Procedure calcitemObject;Virtual;
  39.               Function checkhit(hx,hy:Integer;Var item:pobjs):Boolean;Virtual;
  40.               Destructor done; Virtual;
  41.             end;
  42.   PobjMov = ^tobjMov;
  43.   tobjMov = Object(tobjs)
  44.               ndx,ndy : Integer;
  45.               Constructor init(vx,vy,vdx,vdy:Integer);
  46.               Procedure calcitemObject; Virtual;
  47.             end;
  48.   tlist = Record
  49.             item      : pobjs;
  50.             prev,next : plist;
  51.           end;
  52.   pkill = ^tkill;
  53.   tkill = Record
  54.             tk   : plist;
  55.             next : pkill;
  56.           end;
  57.  
  58. Procedure addp(Var nkbeg,nkend,p:plist);
  59. Procedure deletep(Var nkbeg,nkend,p:plist);
  60. Procedure calcitems(Var nkbeg:plist);
  61. Procedure drawitems(Var nkbeg:plist;over:Boolean);
  62. Procedure add2kill_list(Var kill:pkill;Var i:plist);
  63. Procedure cleankill_list(Var kill:pkill;Var nkbeg,nkend:plist);
  64. Procedure clean_plist(Var nkbeg,nkend:plist);
  65.  
  66. Implementation
  67.  
  68. Procedure calcitems(Var nkbeg:plist);
  69. Var
  70.   p : plist;
  71. begin
  72.   p := nkbeg;
  73.   While p<>nil do
  74.     begin
  75.       p^.item^.calcitemObject;
  76.       p := p^.next;
  77.     end;
  78. end;
  79.  
  80.  
  81. Procedure drawitems(Var nkbeg:plist;over:Boolean);
  82. {
  83.   This Procedure is usually called from:  (GMorPH.PAS)
  84.      Tmorph.pre_map
  85.      Tmorph.post_map
  86.   The OVER flag tells when this Object should be drawn.  Behind
  87.    geomorph or infront of the geomorph.
  88. }
  89. Var
  90.   p : plist;
  91. begin
  92.   p := nkbeg;
  93.   While p<>nil do
  94.     begin
  95.       if (p^.item^.overshow=over)
  96.         then p^.item^.drawitemObject;
  97.       p := p^.next;
  98.     end;
  99. end;
  100.  
  101.  
  102. Procedure clean_plist(Var nkbeg,nkend:plist);
  103. Var
  104.   p,p2 : plist;
  105. begin
  106.   p := nkbeg;
  107.   While p<>nil do
  108.     begin
  109.       p2 := p;
  110.       p := p^.next;
  111.       dispose(p2^.item,done);
  112.       dispose(p2);
  113.     end;
  114.   nkbeg := nil;
  115.   nkend := nil;
  116. end;
  117.  
  118.  
  119. Procedure addp(Var nkbeg,nkend,p:plist);
  120. begin
  121.   p^.next := nil;
  122.   if nkend=nil
  123.     then
  124.       begin
  125.         nkbeg := p;
  126.         nkend := p;
  127.         p^.prev := nil;
  128.       end
  129.     else
  130.       begin
  131.         p^.prev := nkend;
  132.         nkend^.next := p;
  133.         nkend := p;
  134.       end;
  135. end;
  136.  
  137.  
  138. Procedure deletep(Var nkbeg,nkend,p:plist);
  139. begin
  140.   if nkbeg=nkend
  141.     then
  142.       begin
  143.         nkbeg := nil;
  144.         nkend := nil;
  145.       end
  146.     else
  147.   if nkbeg=p
  148.     then
  149.       begin
  150.         nkbeg := nkbeg^.next;
  151.         nkbeg^.prev := nil;
  152.       end
  153.     else
  154.   if nkend=p
  155.     then
  156.       begin
  157.         nkend := nkend^.prev;
  158.         nkend^.next := nil;
  159.       end
  160.     else
  161.       begin
  162.         p^.next^.prev := p^.prev;
  163.         p^.prev^.next := p^.next;
  164.       end;
  165.   dispose(p^.item,done);
  166.   dispose(p);
  167. end;
  168.  
  169.  
  170. Procedure cleankill_list(Var kill:pkill;Var nkbeg,nkend:plist);
  171. Var
  172.   p,p2 : pkill;
  173. begin
  174.   p := kill;
  175.   While p<>nil do
  176.     begin
  177.       p2 := p;
  178.       p := p^.next;
  179.       deletep(nkbeg,nkend,p2^.tk);
  180.       dispose(p2);
  181.     end;
  182.   kill := nil;
  183. end;
  184.  
  185.  
  186. Procedure add2kill_list(Var kill:pkill;Var i:plist);
  187. Var
  188.   p : pkill;
  189. begin
  190.   new(p);
  191.   p^.tk := i;
  192.   p^.next := kill;
  193.   kill := p
  194. end;
  195.  
  196. (**) { tobjs Methods }
  197.  
  198. Constructor tobjs.init(vx,vy:Integer);
  199. begin
  200.   nx := vx; ny := vy; num_sprite := 1;
  201.   mapcolor := $fb; pointage := 0;
  202.   flp := 0; overshow := False;
  203. end;
  204.  
  205.  
  206. Destructor tobjs.done;
  207. begin
  208. end;
  209.  
  210.  
  211. Procedure tobjs.drawitemObject;
  212. begin
  213.   { i.e.
  214.      fbitdraw(nx,ny,pic[flip]^);
  215.   }
  216. end;
  217.  
  218.  
  219. Procedure tobjs.calcitemObject;
  220. begin
  221. end;
  222.  
  223.  
  224. Function tobjs.checkhit(hx,hy:Integer;Var item:pobjs):Boolean;
  225. begin
  226. end;
  227.  
  228. (**) { tobjMov methods }
  229.  
  230. Constructor tobjMov.init(vx,vy,vdx,vdy:Integer);
  231. begin
  232.   nx := vx; ny := vy; ndx := vdx; ndy := vdy;
  233.   mapcolor := $fb; pointage := 0;
  234.   flp := 0; overshow := False;
  235. end;
  236.  
  237.  
  238. Procedure tobjMov.calcitemObject;
  239. begin
  240.  { These are just simple examples of what should go in the methods }
  241.   inc(nx,ndx); inc(ny,ndy);
  242.   flp := (flp+1)mod num_sprite;
  243. end;
  244.  
  245. end.