Open jinwei14 opened 5 years ago
I am able to print a string in each time slot. however due to the lack of LPS knowledge I am not able to make the car move
oadModule('./modules/module.js').
true -> testPrint('The car has started').
% set of facts.
fluents([
move, stop, waitting
]).
% cause state transition via init fact terminate fact
events ([redLight,greenLight]).
% Reactive rules
actions ([arrival]).
% describes the facts that are true at time 1
initially( move).
lpsDefineObject(car, image, [
position(150, 340),
size(64, 64),
isHidden(0),
image(car),
zIndex(100)
]).
% describe events taking place in the transition from one time point to the next
observe( redLight) from 1 to 2.
observe( greenLight) from 3 to 4.
observe (redLight) from 7 to 8.
observe (greenLight) from 9 to 10.
%stop at time 13
move(12)->
arrival(12,13),
testPrint('I have stopped').
move(T1) ->
testPrint('I am moving'),
fireTruckPosition(X, Y, T1),
testPrint(X),
townPosition(fireStation, _, Tx, Ty),
NumCyclesNeeded = floor(abs(X - Tx) / 64),
T2 = T1 + NumCyclesNeeded,
cycleInterval(CT),
AnimationDuration = CT * NumCyclesNeeded,
handleTruckFlip(X, Tx) at T1,
lpsAnimateMoveObject(fireTruck, AnimationDuration, Tx + 16, Ty + 16) from T1 to T2,
fireTruckMove(Tx, Ty) from T1 to T2.
% testPrint('Hello World').
% % describe the laws of cause and effect
% (redLight) initiates waitting if move.
% (redLight) terminates move if move.
%
% (greenLight) initiates move if waitting.
% (greenLight) terminates waitting if waitting.
%
% (arrival) initiates stop if move.
% (arrival) terminates move if move.
updates(fireTruckMove(X, Y), fireTruckPosition(_, _), fireTruckPosition(X, Y)).
initiates(redLight, waitting) <-
move.
terminates(redLight, move). <-
move.
initiates(greenLight, move) <-
waitting.
terminates(greenLight, waitting). <-
waitting.
initiates(arrival, stop) <-
move.
terminates(arrival, move). <-
move.