: i've been trying to expand on my simple letter scrolling programand add the ability to control the movement of the letter. Unfortunately the nly thing that seems to come up is a small cross of letters and then nothing more. I am really getting confused again. Thanks.
:
: program mrpac;
:
: uses crt;
:
: var
: position : integer;
: pac : string;
: timer : integer ;
: t : integer;
: blank : string;
: c : char;
: posx: integer;
: posy: integer;
:
: begin
: for posx := 1 to 40 do
: begin
: pac := ('c');
: gotoxy(posx,0);
: writeln(pac:posx);
: delay(50);
: gotoxy(posx,1);
:
: write(blank:posx);
: end;
:
: delay(100);
:
: writeln('helo welcome to pacman':0);
: delay(300);
: clrscr;
: write('hit esc to quit');
:
: while c <> #27 do
:
:
: begin
: c := readkey;
: posx := 20;
: posy := 20;
: case c of
: #75 : posx := posx-1;
: #72 : posy := posy + 1;
: #77 : posx := posx+1;
: #80 : posy := posy-1;
: end;
:
: gotoxy(posx,posy);
: write(pac);
: if (posx > 40) or (posx < 1) then break;
: if (posy > 40) or (posy < 1) then break;
: end
: end.
: Matt
Hey there. A few problems here. First off, your program is only displaying a cross because of the
green lines here:
while c <> #27 do
begin
c := readkey;
posx := 20;
posy := 20;
gotoxy(posx,posy);
write(' ');
case c of
#75 : posx := posx-1;
#72 : posy := posy + 1;
#77 : posx := posx+1;
#80 : posy := posy-1;
end;
gotoxy(posx,posy);
write(pac);
if (posx > 40) or (posx < 1) then break;
if (posy > 40) or (posy < 1) then break;
end
Above, you are setting the X & Y values to 20 on every pass. So when they puch up, it subtracts 1 from the number (20-1 = 19) and then writes
pac at PosX,PosY (20,19). Your program then loops again and sets the numbers back to (20,20). Move the
green lines above your loop and that should fix the cross problem.
Also, the
blue lines added above will erase the character before drawing the new one. (Draws a space BEFORE moving the PosX,PosY variables)
Lastly, you should change the
Red loop to a
Repeat...Until loop, although this one isn't quite as important. The reason for this is that when the program first starts, older versions of TP didn't always initialize the variables to zero, so it is *possible* that c could be equal to #27 apon starting and skip over your loop (although very unlikely)
Phat Nat