
-----------------------------------
sp14
Sat Jan 14, 2006 12:07 pm

help with car
-----------------------------------
i need some help with this car i want it to go when there is a green light but stop when it is red can someone plz help me 

-----------------------------------------------------------------------------------------

import GUI

var pic : int := Pic.FileNew ("C:/Documents and Settings/Administrator/Desktop/project/untitled1.JPG")
Pic.Draw (pic, 0, 10, picCopy)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

setscreen ("graphics")


var pic1 : int := Pic.FileNew ("C:/Documents and Settings/Administrator/Desktop/project/car.JPG")

procedure car
          


for decreasing x : maxx .. 1-40   %Counted loop for the movement of right-to-left
cls
Pic.Draw (pic, 0, 10, picCopy)
delay(5)   
   

    Pic.Draw (pic1, x-120, 230, picCopy)
    
    

View.Update   
end for


end car


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%lights on north side

procedure redlight %red light- N
    drawfillbox (185, 310, 215, 390, 7)
    drawfilloval (200, 330, 10, 10, 2) %green light
    drawfilloval (200, 352, 10, 10, 6) %yellow light
    drawfilloval (200, 374, 10, 10, 12) %red light
    drawfillbox (475, 10, 505, 90, 7)
    drawfilloval (490, 78, 10, 10, 2) %green light
    drawfilloval (490, 54, 10, 10, 6) %yellow light
    drawfilloval (490, 30, 10, 10, 12) %red light
    
end redlight

procedure yellowlight %yellow light- N-S
    drawfillbox (185, 310, 215, 390, 7)
    drawfilloval (200, 330, 10, 10, 2) %green light
    drawfilloval (200, 352, 10, 10, 14) %yellow light
    drawfilloval (200, 374, 10, 10, 4) %red light
    drawfillbox (475, 10, 505, 90, 7)
    drawfilloval (490, 78, 10, 10, 2) %green light
    drawfilloval (490, 54, 10, 10, 14) %yellow light
    drawfilloval (490, 30, 10, 10, 4) %red light
end yellowlight

procedure greenlight %green light- N-S
    drawfillbox (185, 310, 215, 390, 7)
    drawfilloval (200, 330, 10, 10, 10) %green light
    drawfilloval (200, 352, 10, 10, 6) %yellow light
    drawfilloval (200, 374, 10, 10, 4) %red light
    drawfillbox (475, 10, 505, 90, 7)
    drawfilloval (490, 78, 10, 10, 10) %green light
    drawfilloval (490, 54, 10, 10, 6) %yellow light
    drawfilloval (490, 30, 10, 10, 4) %red light
end greenlight
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%lights on east side

procedure greenlight2 %green light- S
drawfillbox (595, 260, 515, 295, 7)
    drawfilloval (530, 277, 10, 10, 10) %green light
    drawfilloval (553, 277, 10, 10, 6) %yellow light
    drawfilloval (576, 277, 10, 10, 4) %red light
    drawfillbox (185, 100, 110, 130, 7)
    drawfilloval (170, 115, 10, 10, 10) %green light
    drawfilloval (147, 115, 10, 10, 6) %yellow light
    drawfilloval (125, 115, 10, 10, 4) %red light
    end greenlight2

procedure redlight2 %red light- S
drawfillbox (595, 260, 515, 295, 7)
    drawfilloval (530, 277, 10, 10, 2) %green light
    drawfilloval (553, 277, 10, 10, 6) %yellow light
    drawfilloval (576, 277, 10, 10, 12) %red light
    drawfillbox (185, 100, 110, 130, 7)
    drawfilloval (170, 115, 10, 10, 2) %green light
    drawfilloval (147, 115, 10, 10, 6) %yellow light
    drawfilloval (125, 115, 10, 10, 12) %red light
    end redlight2

procedure yellowlight2 %yellow light- S
drawfillbox (595, 260, 515, 295, 7)
    drawfilloval (530, 277, 10, 10, 2) %green light
    drawfilloval (553, 277, 10, 10, 14) %yellow light
    drawfilloval (576, 277, 10, 10, 4) %red light
    drawfillbox (185, 100, 110, 130, 7)
    drawfilloval (170, 115, 10, 10, 2) %green light
    drawfilloval (147, 115, 10, 10, 14) %yellow light
    drawfilloval (125, 115, 10, 10, 4) %red light
    end yellowlight2
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% program with buttons


procedure button
loop

exit when GUI.ProcessEvent
redlight
greenlight2
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
redlight
yellowlight2
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
greenlight
redlight2
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
yellowlight
redlight2
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
delay (500)
exit when GUI.ProcessEvent
car
end loop
end button


var start : int := GUI.CreateButton (1, 10, 0, "Start", button)
var quitbutton : int := GUI.CreateButton (80, 10, 0, "Quit", GUI.Quit)





loop
    exit when GUI.ProcessEvent
end loop

-----------------------------------
Delos
Sat Jan 14, 2006 12:30 pm


-----------------------------------
First, I've told you this before.  Use 
C:/Documents and Settings/Administrator/Desktop/project/car.JPG")


Now, how am I supposed to run this programme...Instead of just posting code, post the file with the pic, zipped up.  Makes all of our lives easier.

I can guess that for your particular problem, you'll have to have a variable or two that will determine when the car is allowed to move.  So:

if trafficLight.colour = "red" then
   car.movement := "stop"
elsif trafficLight.colour = "green" then
   car.movement := "go"
end

