home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug086.arc
/
HUSTLE.LBR
/
PLAY.IZ
/
PLAY.I
Wrap
Text File
|
1979-12-31
|
4KB
|
172 lines
procedure erase_target;
begin
with target do
begin
redraw(x-1,y,x+1,y);
redraw(x-1,y+1,x+1,y+1);
redraw(x-1,y-1,x+1,y-1);
end;
end; (* erase_target *)
procedure moveplayer;
var
c :char;
procedure hit_something;
var
value :byte;
function istarget :boolean;
begin
with player do with tail do with target do
if ((head.y in [y-1,y+1]) and (head.x >= x-1) and (head.x <= x+1)) or
((head.x in [x-1,x+1]) and (head.y >= y-1) and (head.y <= y+1))
then istarget := true
else istarget := false;
end; (* istarget *)
begin (* hit_something *)
gameover := not istarget;
if not gameover
then with player do
begin
value := random(9)+1;
score := score + value;
tail.tail_lag := tail.tail_lag - value * 2;
target_total := target_total + 1;
rating := (target_total*1000) div (elapsedtime + tail.headstart);
target.dwell := -1;
erase_target;
gobble_sound;
end;
end; (* hit_something *)
begin (* moveplayer *)
with player do with tail do
begin
if keypressed
then begin
read(kbd,c);
if c in ['Q','q'] then
begin
diry := 1;
dirx := 0;
end
else
if c in ['A','a'] then
begin
diry := -1;
dirx := 0;
end
else
if c in ['['] then
begin
dirx := -1;
diry := 0;
end
else
if c in [']'] then
begin
dirx := 1;
diry := 0;
end;
end;
with head do
begin
x := x + dirx;
y := y + diry;
end;
if headstart < maxtail_len
then headstart := headstart + 1
else begin
headstart := 1;
elapsedtime := elapsedtime + maxtail_len;
end;
if tail_lag >= 0
then begin
if tailend < maxtail_len
then tailend := tailend + 1
else tailend := 1;
with component [tailend] do replot(x,y);
end;
if tail_lag < 0
then tail_lag := tail_lag + 1;
with head do if pixthere(x,y) then hit_something;
if not gameover
then begin
with head do plot(x,y);
component [headstart] := head;
end;
end; (* with player *)
end; (* moveplayer *)
procedure set_target;
function target_drawn :boolean;
(* Attempt to draw target at new coordinates. *)
var
x1,x2,y1,y2,dy,dx :byte;
clear :boolean;
begin
clear := true;
with target do
if (x in [1,158]) or (y in [1,70]) (* would target be off screen? *)
then clear := false
else begin
x1 := x - 1;
x2 := x + 1;
y1 := y - 1;
y2 := y + 1;
end;
if clear
then begin (* test if target would overdraw something *)
dy := y1;
while (dy <= y2) and clear do
begin
dx := x1;
while (dx <= x2) and clear do
begin
clear := not pixthere(dx,dy);
dx := dx + 1;
end;
dy := dy + 1;
end;
end;
if clear
then begin
draw(x1,y1,x1,y2); (* draw vertical lines *)
draw(x2,y1,x2,y2);
draw(x1,y1,x2,y1); (* draw horizontal lines *)
draw(x1,y2,x2,y2);
end;
target_drawn := clear;
end; (* target_drawn *)
begin (* set_target *)
with target do
begin
if dwell = 0
then erase_target;
if dwell <= 0
then if random > 0.9
then begin
repeat
x := 1 + random(158);
y := 1 + random(70);
until target_drawn;
dwell := random(100) + 80;
popup_sound;
end;
if dwell > 0
then dwell := dwell - 1;
end;
end; (* set_target *)