
:-object wasp2 : [bcilib].

var url = './street/street5.wrl'.

var timelimit = 300.

main :-
	text_area(Browser),
	set_output(Browser),
	format('Loading street1 from ~w~n', [url]),
	loadURL(url),
	format('The bus1 is going to jump in front of you in 5 seconds,~n'),
	format('then you can drive the bus for ~w seconds~n', [timelimit]),
 	delay(5000),
 	jump(bus1),
 	drive(bus1,timelimit).

jump(Object) :-
	getSFVec3f(proxSensor,position,X,_Y,Z),
	Z1 is Z-5,
	setPosition(Object,X, 0.0 ,Z1).

drive(_,0):-!.	

drive(Object,N) :- N>0, N1 is N-1,
	format('time left: ~w seconds~n', [N]),
	delay(1000),
	getSFVec3f(proxSensor,position,X,_Y,Z),
	getSFRotation(proxSensor,orientation,_X2,Y2,_Z2,R2),
	setPosition(Object,X, 0.0 ,Z),
	R3 is sign(Y2)*R2 + 1.571,
	setRotation(Object,0.0,1.0,0.0,R3),
	drive(Object,N1).



:-end_object wasp2.

