separate (gameutils)


procedure testPortals is
 yfloorl, yfloorr: float;
begin

	if atleftportal and (currenttime-portaltime>2.0) then

		for i in 1..nko loop onledge(i):=false; end loop;

		yfloorl := -ymax+aheight;
		yme := ytgt2;
		if (yme<yfloorl ) then yme:=yfloorl; end if;
		if (yme>yfloorl) then
			jumptime:=currenttime;
			pyjump:=yme;
			vyjump:=0.0;
			jumping:=true;
		end if;

		-- slightly more accurate (30jan17):
		if wall2=no then
			horiang:=onepi;
			xlook:=0.0;
			zlook:=-1.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall2=so then
			horiang:=0.0;
			xlook:=0.0;
			zlook:=+1.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall2=ea then
			horiang:=halfpi;
			xlook:=+1.0;
			zlook:=0.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall2=we then
			horiang:=-halfpi;
			xlook:=-1.0;
			zlook:=0.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall2=up then
			xlook:=0.0;
			cylook:=-1.0;
			zlook:=0.0;
			horiang:=0.0; --no matter
			vertang:=-halfpi;
		elsif wall2=dn then
			xlook:=0.0;
			cylook:=+1.0;
			zlook:=0.0;
			horiang:=0.0; --no matter
			vertang:=+halfpi;
		end if;


		xme:=xtgt2;
		zme:=ztgt2;

		xme := xme + (margin+event_horizon)*xlook;
		yme := yme + (margin+event_horizon)*cylook;
		zme := zme + (margin+event_horizon)*zlook;

		if wall2=up then
			dungeonLocal:=true;
			prepwormhole(currenttime, 
				xtgt2,ytgt2+20.0,ztgt2, xtgt2,ytgt2,ztgt2, xme,yme,zme);

		elsif wall2=dn then
			dungeonLocal:=true;
			prepwormhole(currenttime, 
				xtgt2,ytgt2-20.0,ztgt2, xtgt2,ytgt2,ztgt2, xme,yme,zme);

		else
			-- note:  as written, tunnel allows only 6 directions=sides of cube
			dungeonLocal:=true;
			prepwormhole(currenttime, 
				xtgt2-20.0*xlook,yme,ztgt2-20.0*zlook, xtgt2,yme,ztgt2, xme,yme,zme);
		end if;

		oxme:=xme;
		oyme:=yme;
		ozme:=zme;
		portaltime := currenttime;

		if inpool(xme,yme,zme) and (level=3) then
			lavadead:=true;
		end if;

		snd4ada_hpp.playSnd(xport); -- Xport

		worm_defined:=true;

	elsif atrightportal and (currenttime-portaltime>2.0) then


		for i in 1..nko loop onledge(i):=false; end loop;

		yfloorr := -ymax+aheight;
		yme := ytgt1;
		if (yme<yfloorr ) then yme:=yfloorr; end if;
		if (yme>yfloorr) then
			jumptime:=currenttime;
			pyjump:=yme;
			vyjump:=0.0;
			jumping:=true;
		end if;


		-- slightly more accurate (30jan17):
		if wall1=no then
			horiang:=onepi;
			xlook:=0.0;
			zlook:=-1.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall1=so then
			horiang:=0.0;
			xlook:=0.0;
			zlook:=+1.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall1=ea then
			horiang:=halfpi;
			xlook:=+1.0;
			zlook:=0.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall1=we then
			horiang:=-halfpi;
			xlook:=-1.0;
			zlook:=0.0;
			vertang := 0.0;
			cylook:=0.0;
		elsif wall1=up then
			xlook:=0.0;
			cylook:=-1.0;
			zlook:=0.0;
			horiang:=0.0; --no matter
			vertang:=-halfpi;
		elsif wall1=dn then
			xlook:=0.0;
			cylook:=+1.0;
			zlook:=0.0;
			horiang:=0.0; --no matter
			vertang:=+halfpi;
		end if;


		xme:=xtgt1;
		zme:=ztgt1;

		xme := xme + (margin+event_horizon)*xlook;
		yme := yme + (margin+event_horizon)*cylook;
		zme := zme + (margin+event_horizon)*zlook;



		if wall1=up then
			dungeonLocal:=true;
			prepwormhole(currenttime, 
				xtgt1,ytgt1+20.0,ztgt1, xtgt1,ytgt1,ztgt1, xme,yme,zme);

		elsif wall1=dn then
			dungeonLocal:=true;
			prepwormhole(currenttime, 
				xtgt1,ytgt1-20.0,ztgt1, xtgt1,ytgt1,ztgt1, xme,yme,zme);

		else
			-- note:  as written, tunnel allows only 6 directions = sides of cube
			dungeonLocal:=true;
			prepwormhole(currenttime, 
				xtgt1-20.0*xlook,yme,ztgt1-20.0*zlook, xtgt1,yme,ztgt1, xme,yme,zme);
		end if;


		oxme:=xme;
		oyme:=yme;
		ozme:=zme;
		portaltime := currenttime;

		if inpool(xme,yme,zme) and (level=3) then
			lavadead:=true;
		end if;

		snd4ada_hpp.playSnd(xport); -- Xport

		worm_defined:=true;

	end if;


end testPortals;

