Pastebin

New pastes are no longer accepted · Stats

Latest Pastes

ASCII Portal

program portal;



uses

	crt;

	

var

	portal1			:string;

	portal2			:string;

	human			:string;

	humanx			:integer;

	humany			:integer;

	portal1x		:integer;

	portal2x		:integer;

	portal1y		:integer;

	portal2y		:integer;

	facing			:integer;

	portalgun		:string;

	portalgunx		:integer;

	portalguny		:integer;

	key				:char;

	level			:integer;

	wallxmax		:integer;

	wallymax		:integer;

	wallxmin		:integer;

	wallymin		:integer;
	levelloaded		:boolean;

	

procedure set_variables;

begin

	level:=1;

	portal1:='@';

	portal2:='@';

	human:='Å';

	portalgun:='ᵒ';

	humanx:=wallxmin+1;

	humany:=wallymin+1;

end;



procedure map1;

begin

	wallxmax:=21;

	wallxmin:=1;

	wallymax:=11;

	wallymin:=1;
	levelloaded:=true;

end;



procedure draw_world;

var

	drawwallx:	integer;

	drawwally:	integer;

begin

	gotoXY(1,1);

	writeln(humanx,' ',humany);

	gotoXY(humanx,humany);

	writeln(human);

	gotoXY(portalgunx,portalguny);

	writeln(portalgun);

	if (level=1) and (levelloaded=false) then map1;

	drawwallx:=wallxmax;

	drawwally:=wallymax;

	repeat

		 gotoxy(drawwallx,drawwally);

		 writeln('#');

		 drawwallx:=drawwallx-1;

	until(drawwallx=wallxmin);

	repeat

		gotoxy(drawwallx,drawwally);

		writeln('#');

		drawwally:=drawwally-1;

	until(drawwally=wallymin);

	repeat

		gotoxy(drawwallx,drawwally);

		writeln('#');

		drawwallx:=drawwallx+1;

	until(drawwallx=wallxmax);

	repeat

		gotoxy(drawwallx,drawwally);

		writeln('#');

		drawwally:=drawwally+1;

	until(drawwally=wallymax);
	gotoXY(portal1x,portal1y);

	TextColor(red);

	writeln(portal1);

	gotoXY(portal2x,portal2y);

	TextColor(blue);

	writeln(portal2);

	TextColor(white);

	delay(10);

end;



procedure portal1move;

begin

	if (facing=1) then

		begin

			portal1x:=wallxmin;

			portal1y:=humany;

		end;

	if (facing=2) then

		begin

			portal1x:=humanx;

			portal1y:=wallymax;

		end;

	if (facing=3) then

		begin

			portal1x:=wallxmax;

			portal1y:=humany;

		end;

	if (facing=4) then

		begin

			portal1x:=humanx;

			portal1y:=wallymin;

		end;

end;



procedure portal2move;

begin

	if (facing=1) then

		begin

			portal2x:=wallxmin;

			portal2y:=humany;

		end;

	if (facing=2) then

		begin

			portal2x:=humanx;

			portal2y:=wallymax;

		end;

	if (facing=3) then

		begin

			portal2x:=wallxmax;

			portal2y:=humany;

		end;

	if (facing=4) then

		begin

			portal2x:=humanx;

			portal2y:=wallymin;

		end;

end;



procedure movement;

begin

	if (keypressed) then

		begin

			key:=Readkey;

				if (key='a') then

					if (humanx>wallxmin+1) then

						begin

							humanx:=humanx-1;

							facing:=1;

						end
					else if (humanx-1=portal1x) and (humany=portal1y)
					  or (humanx-1=portal2x) and (humany=portal2y) then 
						begin
							humanx:=humanx-1;
							facing:=1;
						end;

				if (key='s') then
				  if (humany<wallymax-1) then 

					begin

						humany:=humany+1;

						facing:=2;

					end
				else if (humany+1=portal1y) and (humanx=portal1x)
				  or (humany+1=portal2y) and (humanx=portal2x) then 
					begin
						humany:=humany+1;
						facing:=2;
					end;

				if (key='d') then
				  if (humanx<wallxmax-1) then

					begin

						humanx:=humanx+1;

						facing:=3;

					end
				else if (humanx+1=portal1x) and (humany=portal1y)
				  or (humanx+1=portal2x) and (humany=portal2y) then 
					begin
						humanx:=humanx+1;
						facing:=3;
					end;

				if (key='w') then

					if (humany>wallymin+1) then

						begin

							humany:=humany-1;

							facing:=4;

						end
					else if (humany-1=portal1y) and (humanx=portal1x) 
					  or (humany-1=portal2y) and (humany=portal1y) then 
						begin
							humany:=humany-1;
							facing:=4;
						end;

				if (key='p') then

					begin

						portal1move;

					end;

				if (key='o') then

					begin

						portal2move

					end;
				if (key='1') then 
					begin
						wallxmax:=wallxmax+1;
					end;
				if (key='2') then 
					begin
						wallymax:=wallymax+1;
					end;
				if (key='3') then 
					begin
						wallxmax:=wallxmax-1;
					end;
				if (key='4') then 
					begin
						wallymax:=wallymax-1;
					end;

		end;

end;



procedure portal_check;

begin
	if (humanx=portal1x) and (humany=portal1y) then
		begin
			if (portal2x=wallxmin) then 

				begin

					humanx:=portal2x+1;

					humany:=portal2y;

				end;
			if (portal2x=wallxmax) then 
				begin
					humanx:=portal2x-1;
					humany:=portal2y;
				end;
			if (portal2y=wallymax) then 
				begin
					humanx:=portal2x;
					humany:=portal2y-1;
				end;
			if (portal2y=wallymin) then 
				begin
					humanx:=portal2x;
					humany:=portal2y+1;
				end;
		end;
	if (humanx=portal2x) and (humany=portal2y) then
		begin

			if (portal1x=wallxmin) then 
				begin

					humanx:=portal1x+1;

					humany:=portal1y;

				end;

			if (portal1x=wallxmax) then 
				begin
					humanx:=portal1x-1;
					humany:=portal1y;
				end;
			if (portal1y=wallymax) then
				begin
					humanx:=portal1x;
					humany:=portal1y-1;
				end;
			if (portal1y=wallymin) then
				begin
					humanx:=portal1x;
					humany:=portal1y+1;
				end;
		end;
end;



procedure portalgunmove;

begin

	if (facing=1) then

		begin

			portalgunx:=humanx-1;

			portalguny:=humany;

		end;

	if (facing=2) then

		begin

			portalgunx:=humanx;

			portalguny:=humany+1;

		end;

	if (facing=3) then

		begin

			portalgunx:=humanx+1;

			portalguny:=humany;

		end;

	if (facing=4) then

		begin

			portalgunx:=humanx;

			portalguny:=humany-1;

		end;

end;



begin

	set_variables;

		repeat

			clrscr;

			movement;

			portalgunmove;

			portal_check;

			draw_world;

		until (humanx=40) and (humany=40);

end.