since i am studying pascal for my computer science course, i thought i may aswell do it as best as i can. ive made a maze game (very very very basic) to test some things. However i cannot get ''collision detection'' to work so it stops moving into a wall.
program maze1a;
uses
sysutils,crt;
{$R *.RES}
const
up = 72;
down = 80;
left = 75;
right = 77;
var
number_moves :integer;
key_press :char;
temp_x :integer;
temp_y :integer;
main_area :array[1..10,1..10] of char;
load_stream :text;
procedure load_maze;
var
k:integer;
l:integer;
begin
assignfile(load_stream,''maze.dat'');
reset(load_stream);
for k:= 1 to 10 do
begin
for l:= 1 to 10 do
begin
read(load_stream,main_area[l,k]);
end;
end;
for k:= 1 to 10 do
begin
for l:= 1 to 10 do
begin
write(main_area[l,k]);
end;
end;
end;
procedure move_up;
begin
temp_x := wherex;
temp_y := wherey;
gotoxy(temp_x,temp_y);
write('' '');
gotoxy(temp_x,temp_y-1);
write(''X'');
gotoxy(temp_x,temp_y-1);
end;
procedure move_down;
begin
temp_x := wherex;
temp_y := wherey;
gotoxy(temp_x,temp_y);
write('' '');
gotoxy(temp_x,temp_y+1);
write(''X'');
gotoxy(temp_x,temp_y+1);
end;
procedure move_left;
begin
temp_x := wherex;
temp_y := wherey;
gotoxy(temp_x,temp_y);
write('' '');
gotoxy(temp_x-1,temp_y);
write(''X'');
gotoxy(temp_x-1,temp_y);
end;
procedure move_right;
begin
temp_x := wherex;
temp_y := wherey;
gotoxy(temp_x,temp_y);
write('' '');
gotoxy(temp_x+1,temp_y);
write(''X'');
gotoxy(temp_x+1,temp_y);
end;
begin
load_maze;
number_moves := 0;
gotoxy(2,2);
write(''X'');
gotoxy(2,2);
repeat
begin
key_press := readkey;
case key_press of
chr(up) : move_up;
chr(down) : move_down;
chr(left) : move_left;
chr(right): move_right;
end;
end
until number_moves = 100;
readln;
end.
the way i tried implementing the collision detection is in the ''move right'' procedure i had it checking the cell to the right of its current location in the array. however,i ran it and i cudnt move,so i tried getting it to print wot was in the cell on the right somewhere else so i cud see whether it was recognising the space or a wall, and it recognised a space as a wall,
procedure move_right;
begin
temp_x := wherex;
temp_y := wherey;
if main_area[temp_x+1,temp_y] = '' '' then
begin
gotoxy(temp_x,temp_y);
write('' '');
gotoxy(temp_x+1,temp_y);
write(''X'');
gotoxy(temp_x+1,temp_y);
end;
end;
so its starting location is 2,2 and it shud check the array in 2,3 where it shud find a space:
@@@@@@@@@@
@ @
@ @@@@@@ @
@ @@@@@@ @
@ @
@ @@ @@ @
@ @
@@@@@@@@@@
but it shows up a @
what is wrong?
What about me? What about Raven?