Recent

Author Topic: zombies! (inc)  (Read 416 times)

speter

  • Hero Member
  • *****
  • Posts: 528
zombies! (inc)
« on: April 07, 2026, 03:31:14 am »
Another 1980s Spectrum BASIC game from Tim Hartnell's 1983 "Giant Book of Spectrum Games". The original game (by Raymond Blake) is a mighty 50 lines long.

As an experiment, I uploaded the scan (PDF) to Gemini and asked it to create a clean copy of the BASIC code. I think it corrected about half the OCR "typos' (the book's font is atrocious); which saved me some work. I then asked Gemini to produce a free pascal (console app) translation; which (again) saved me some work. 8-)

The game 'map' has trees as obstables and "pits" as fatal traps; so the objective of the game is to "lead" zombies into pits. The original game had 6 zombies, in my version I have included a spin-edit, so the player can specify how many zombies (2-9) are going to be chasing them.

I changed the zombie movement, so that they move in a direction (only) 60% of the time, which means they will move diagonally 36% of the time (and sometimes don't move at all). :P

Enjoy,
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

speter

  • Hero Member
  • *****
  • Posts: 528
Re: zombies! (inc)
« Reply #1 on: April 07, 2026, 03:51:43 am »
In case anyone is interested, here is Gemini's (console app) translation:
Code: Pascal  [Select][+][-]
  1. program Zombies;
  2.  
  3. uses crt, math;
  4.  
  5. const
  6.   max_x = 30; // Columns [cite: 30]
  7.   max_y = 20; // Rows [cite: 29]
  8.   num_zombies = 6; [cite: 57, 74]
  9.   num_trees = 25; [cite: 27, 33]
  10.   num_pits = 12; [cite: 35]
  11.  
  12. type
  13.   TZombie = record
  14.     x, y: integer;
  15.     active: boolean;
  16.   end;
  17.  
  18. var
  19.   board: array[0..max_x, 0..max_y] of char;
  20.   zombies: array[1..num_zombies] of TZombie;
  21.   px, py: integer;
  22.   i, tx, ty: integer;
  23.   ch: char;
  24.   gameOver: boolean;
  25.   zombiesInPits: integer;
  26.  
  27. procedure InitializeBoard;
  28. var
  29.   cx, cy: integer;
  30. begin
  31.   clrscr;
  32.   zombiesInPits := 0;
  33.  
  34.   // Initialize board with empty spaces [cite: 49, 53]
  35.   for cx := 0 to max_x do
  36.     for cy := 0 to max_y do
  37.       board[cx, cy] := ' ';
  38.  
  39.   // Place Trees (T) [cite: 7, 80]
  40.   for i := 1 to num_trees do
  41.     begin
  42.       tx := random(max_x);
  43.       ty := random(max_y);
  44.       board[tx, ty] := 'T';
  45.       GotoXY(tx + 1, ty + 1);
  46.       textcolor(Green);
  47.       write('T');
  48.     end;
  49.  
  50.   // Place Pot-holes (O) [cite: 6, 36]
  51.   for i := 1 to num_pits do
  52.     begin
  53.       tx := random(max_x);
  54.       ty := random(max_y);
  55.       board[tx, ty] := 'O';
  56.       GotoXY(tx + 1, ty + 1);
  57.       textcolor(Blue);
  58.       write('O');
  59.     end;
  60. end;
  61.  
  62. procedure PlaceZombies;
  63. begin
  64.   for i := 1 to num_zombies do
  65.     begin
  66.       // Ensure zombies don't spawn on trees or pits [cite: 37]
  67.       repeat
  68.         tx := random(max_x);
  69.         ty := random(max_y);
  70.       until board[tx, ty] = ' ';
  71.      
  72.       zombies[i].x := tx;
  73.       zombies[i].y := ty;
  74.       zombies[i].active := true;
  75.       GotoXY(tx + 1, ty + 1);
  76.       textcolor(Red);
  77.       write('Z'); // [cite: 40, 68]
  78.     end;
  79. end;
  80.  
  81. begin
  82.   randomize; [cite: 16]
  83.   repeat
  84.     InitializeBoard;
  85.    
  86.     // Starting Player position [cite: 22, 23]
  87.     px := 15;
  88.     py := 10;
  89.     while board[px, py] <> ' ' do
  90.       inc(px);
  91.    
  92.     PlaceZombies;
  93.    
  94.     gameOver := false;
  95.     while not gameOver do
  96.     begin
  97.       // Draw Player [cite: 46, 56]
  98.       GotoXY(px + 1, py + 1); textcolor(Yellow); write('P');
  99.      
  100.       // Control: 5=Left, 6=Down, 7=Up, 8=Right [cite: 10, 48]
  101.       ch := readkey;
  102.       GotoXY(px + 1, py + 1); write(' '); // Erase old P [cite: 49]
  103.      
  104.       tx := px; ty := py;
  105.       case ch of
  106.         '7': dec(ty); // Up
  107.         '6': inc(ty); // Down
  108.         '5': dec(tx); // Left
  109.         '8': inc(tx); // Right
  110.       end;
  111.  
  112.       // Check Player Collision [cite: 52, 66]
  113.       if (tx >= 0) and (tx <= max_x) and (ty >= 0) and (ty <= max_y) then
  114.         begin
  115.           if board[tx, ty] = 'O' then
  116.             begin
  117.               GotoXY(1, 22);
  118.               textcolor(LightRed);
  119.               write('Fool, you fell down a pit!'); [cite: 89, 91]
  120.               gameOver := true;
  121.             end
  122.           else if board[tx, ty] = ' ' then
  123.             begin
  124.               px := tx;
  125.               py := ty;
  126.             end;
  127.         end;
  128.  
  129.       // Move Zombies [cite: 11]
  130.       for i := 1 to num_zombies do
  131.       begin
  132.         if zombies[i].active then
  133.         begin
  134.           GotoXY(zombies[i].x + 1, zombies[i].y + 1); write(' '); // Erase old Z [cite: 63]
  135.          
  136.           // Zombies move toward player
  137.           tx := zombies[i].x + Sign(px - zombies[i].x);
  138.           ty := zombies[i].y + Sign(py - zombies[i].y);
  139.          
  140.           if board[tx, ty] = 'O' then
  141.           begin
  142.             zombies[i].active := false;
  143.             inc(zombiesInPits);
  144.             GotoXY(1, 23); textcolor(LightCyan); write('Whoops goes another zombie'); [cite: 83]
  145.           end
  146.           else if board[tx, ty] = ' ' then
  147.           begin
  148.             zombies[i].x := tx;
  149.             zombies[i].y := ty;
  150.           end;
  151.          
  152.           if zombies[i].active then
  153.           begin
  154.             GotoXY(zombies[i].x + 1, zombies[i].y + 1); textcolor(Red); write('Z'); [cite: 67]
  155.             // Check if zombie caught player [cite: 69]
  156.             if (zombies[i].x = px) and (zombies[i].y = py) then
  157.             begin
  158.               GotoXY(1, 22); textcolor(LightRed); write('The zombies claim another victim'); [cite: 92]
  159.               gameOver := true;
  160.             end;
  161.           end;
  162.         end;
  163.       end;
  164.  
  165.       // Check for Win condition
  166.       if zombiesInPits = num_zombies then
  167.       begin
  168.         GotoXY(1, 22); textcolor(LightGreen); write('You have escaped the zombies!'); [cite: 77]
  169.         gameOver := true;
  170.       end;
  171.     end;
  172.  
  173.     GotoXY(1, 24); textcolor(White); write('Press any key for a new game...'); [cite: 95]
  174.     readkey;
  175.   until false;
  176. end.

One comment: the original translation included a function sign(); I removed that and added "Math" to the uses list (because that function is already there).

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

 

TinyPortal © 2005-2018