Wednesday, April 29, 2020

ARTILLER.P

[Table of Contents]
ARTILLERY.ATR Disk Image




ARTILLER.P is from page 115 of the book Apple Pascal Games by Douglas Hergert and Joseph T. Kalash, published by Sybex.

It is a simple combat game where you attempt to knock out the enemy's base.

It could be a much better game if

  • the computer shot back
  • a graphical display was implemented

It has been slightly modified to work with Kyan Pascal and fit on the Atari 8-bit display.

Source Code


(*
 * Artillery
 * Fire a shell at an enemy outpost
 *
 * From the book 'Apple Pascal Games'
 * by Douglas Hergert and Joseph T. Kalash
 *
 * ARTILLER.P
 * Kyan Pascal 2.x / Atari 8-bit
 *)

Program ARTILLERY(Input,Output);
Const
   NUMSHELLS =     10;    (* Allowed 10 shells per target *)
   MINDIST   =    100;    (* Minimum distance for a target *)
   MAXDIST   =   1000;    (* Maximum distance for a target *)

   VELOCITY  =  200.0;    (* Initial velocity of 200 ft/sec *)
   GRAVITY   =   32.2;    (* Gravity of 32.2 ft/sec^2 *)
   PI        = 3.1415;
Var
   ANGLE  : REAL;         (* Angle to shoot at *)
   ENEMY  : INTEGER;      (* How far away the enemy is *)
   KILLED : INTEGER;      (* How many we have hit *)
   SHOTS  : 0..NUMSHELLS; (* Number of shells left *)
   CH     : CHAR;         (* Used to answer questions *)
   HIT    : BOOLEAN;      (* Whether the enemy has been hit *)

#i RANDOMS.I

   (*
    * DIST
    * Returns how far the shell went
    *)
   Function DIST : INTEGER;

      (*
       * TIMEINAIR
       * Figures out how long the shell
       * stays in the air
       *)
      Function TIMEINAIR:REAL;
      Begin
         TIMEINAIR := (2*VELOCITY * SIN(ANGLE)) / GRAVITY
      End; (* TIMEINAIR *)

   Begin
      DIST := ROUND((VELOCITY * COS(ANGLE)) * TIMEINAIR)
   End; (* DIST *)

   (*
    * FIRE
    * The user fires at the enemy
    *)
   Procedure FIRE;
   Begin
      Seed(Random_Byte,Random_Byte,Random_Byte,Random_Byte);
   (* ENEMY := MINDIST + RANDOM MOD MAXDIST; *)
      ENEMY := RANDOM(MINDIST,MAXDIST);

      Writeln('The enemy is ',ENEMY:3,' feet away!!!');
      SHOTS := NUMSHELLS;

      Repeat
         Write('What angle? ');
         Readln(ANGLE);
         ANGLE := (ANGLE * PI)/180.0; (* Convert from degrees to radians *)
         HIT := ABS(ENEMY-DIST) <= 1;
         If HIT Then
         Begin
            KILLED := KILLED + 1;
            Writeln('You hit him!!!');
            Writeln('It took you ',(NUMSHELLS-SHOTS),' shots');
            If KILLED = 1 Then
               Writeln('You have killed one enemy')
            Else
            Begin
               Writeln('You have now destroyed ',KILLED,' enemies of');
               Writeln('democracy');
            End;
         End
         Else
         Begin
            SHOTS := SHOTS - 1;
            If DIST > ENEMY Then
               Write('You over shot by ')
            Else
               Write('You under shot by ');
            Writeln(ABS(ENEMY - DIST))
         End
      UNTIL (SHOTS = 0) OR HIT;

      If SHOTS = 0 THEN
         Writeln('You have run out of ammo')
      End; (* Fire *)

Begin
   Write(Chr(125));
   Writeln('Welcome to Artillery');
   Writeln;
   Writeln('You are in the middle of a war');
   Writeln('(Depressing, no?) and are being charged');
   Writeln('by thousands of enemies.');
   Writeln('You job is to destroy their outpost.');
   Writeln('You have at your disposal, ');
   Writeln('a cannon, which you can shoot at any');
   Writeln('angle. As this is war, supplies are');
   Writeln('short, so you only have ',NUMSHELLS,' per target');
   Writeln;

   KILLED := 0;
   Repeat
      Writeln('********************');
      FIRE;
      Write('I see another one, care to shoot again? ');
      Readln(CH);
      While NOT (CH in ['Y','N']) Do
      Begin
         Writeln('Please answer YES or NO');
         Write('Want to try again? ');
         Readln(CH);
      End
   Until CH <> 'Y';

   Writeln;
   Writeln('You killed ', KILLED, ' of the enemy');
End. (* ARTILLERY 7/7/81 D.H. *)

Sample Run



No comments:

Post a Comment