Monday, October 02, 2006

Vehicles' Movements

Then let's code the vehicles movements routine and a random event routine when those vehicles happen to appear.

Here is the code for the different vehicles' movements:

// Movement - ambulance
case AmbulancePos
of 4: begin AmbulancePos:=0; ImageAmbulance3.Visible:=false; end;
3: begin AmbulancePos:=4; ImageAmbulance2.Visible:=false; ImageAmbulance3.Visible:=true; end;
2: begin AmbulancePos:=3; ImageAmbulance1.Visible:=false; ImageAmbulance2.Visible:=true; end;
1: begin AmbulancePos:=2; ImageAmbulance1.Visible:=true; end;
end;
// Movement - police car
case PolicePos
of 4: begin PolicePos:=0; ImagePolice3.Visible:=false; end;
3: begin PolicePos:=4; ImagePolice2.Visible:=false; ImagePolice3.Visible:=true; end;
2: begin PolicePos:=3; ImagePolice1.Visible:=false; ImagePolice2.Visible:=true; end;
1: begin PolicePos:=2; ImagePolice1.Visible:=true; end;
end;
// Movement - army car
case ArmyPos
of 4: begin ArmyPos:=0; ImageArmy3.Visible:=false; end;
3: begin ArmyPos:=4; ImageArmy2.Visible:=false; ImageArmy3.Visible:=true; end;
2: begin ArmyPos:=3; ImageArmy1.Visible:=false; ImageArmy2.Visible:=true; end;
1: begin ArmyPos:=2; ImageArmy1.Visible:=true; end;
end;


And here is the code for the random events:

RdmEvent:=random(12); // Random event calculation
// Event - Cars appear
if RdmEvent=0 then begin // Event - ambulance
if AmbulancePos=0 then begin AmbulancePos:=1;
end;
end;
if RdmEvent=1 then begin // Event - police car
if PolicePos=0 then begin PolicePos:=1;
end;
end;
if RdmEvent=2 then begin // Event - army car
if ArmyPos=0 then begin ArmyPos:=1;
end;
end;


No comments: