
-----------------------------------
dabbuji
Wed Jun 06, 2007 4:53 pm

Police Car
-----------------------------------
Hello people, 

I am drawing a police car for my project and i have to blink the police light. I have to blink the blue and the red light on the siren; so how would i do that ? How do i particularly blink 2 colors on the siren?

-----------------------------------
crump3ts
Wed Jun 06, 2007 7:31 pm

Re: Police Car
-----------------------------------
Assuming that you are going to use images, I would create a seperate image for each version of the police car:
An image for the car with no blinkers on, an image for the red siren and an image for the blue, etc... Then display them so that it looks like the lights
are flashing; draw the image of the car with the red light, then the blue light, then red, then blue, etc...

As to how to animate it this way, it will take some work.

-----------------------------------
DIIST
Wed Jun 06, 2007 8:42 pm

Re: Police Car
-----------------------------------
Is this what you are talking about :? 

setscreen ("graphics:400;300,nobuttonbar,offscreenonly")
var redLight : boolean := false
loop
    cls

    drawbox (50, 50, 200, 100, 7)
    drawbox (200, 50, 350, 100, 7)

    if redLight then
        drawfillbox (51, 51, 199, 99, 12)
        drawfillbox (201, 51, 349, 99, 1)

    else
        drawfillbox (51, 51, 199, 99, 4)
        drawfillbox (201, 51, 349, 99, 9)
    end if

    View.Update
    delay (100)

    redLight := not redLight

end loop

I know, bad choice of variables, but im assuming you want something like this to occur with the lights right?
Just use boolean variable to hold the value of true or false if one of the lights is on or off. 
 :wink:

-----------------------------------
dabbuji
Sun Jun 10, 2007 10:15 am

Re: Police Car
-----------------------------------
ty man for the help, it works now

-----------------------------------
dabbuji
Sun Jun 10, 2007 10:22 am

Re: Police Car
-----------------------------------
yo, i made new dimensions for the siren so it fits on the police car, but the siren doesn't blink anymore and the car doesn't move as well. So help me out as my project is due tomorrow 

drawfillbox (0,0,maxx,maxy,black)

var y1 : array 1 .. 8 of int := init (2,5,69,74,74,69,5,2)
var y2 : array 1 .. 8 of int := init (305,312,312,305,276,269,269,276)
drawfillpolygon (y1,y2,8,white)
drawfillbox (21,304,55,278,blue)

var y3 : array 1..8 of int := init (6,10,14,18,18,14,10,6)
var y4 : array 1..8 of int := init (306,308,308,306,276,274,274,276)
drawfillpolygon (y3,y4,8,black)

var y6 : array 1..8 of int := init (58,62,66,70,70,66,62,58)
var y5 : array 1..8 of int := init (306,308,308,306,276,274,274,276)
drawfillpolygon (y6,y5,8,black)

drawfillarc (76,281,2,4,0,360,yellow)
drawfillarc (76,303,2,4,0,360,yellow)
drawfillarc (4,303,2,4,0,360,red)
drawfillarc (4,281,2,4,0,360,red)

var redLight : boolean := false
loop

    drawbox (31,313,45,291,7)
    drawbox (31,291,45,269,7)
   
    if redLight then 
    drawfillbox (32,314,44,290,12)
    drawfillbox (32,292,44,268,1)
    
    else
    
    drawfillbox (32,314,44,290,12)
    drawfillbox (32,292,44,268,1)
    
    end if
   View.Update
   delay (100)
   redLight := not redLight
    
    end loop

var cary: int  
cary := Pic.New (1,268,75,313)
for car3move : 1..400
Pic.Draw (cary,car3move,268,picCopy)
delay (5)
end for

-----------------------------------
jrblast
Sun Jun 10, 2007 11:12 am

RE:Police Car
-----------------------------------
First of all, use the code tags when posting code.
Second, the car doesn't move because you have an infinite loop before it (an infinite loop is one that will never exit either because there is no exit condition, or it can never be made true). Third, your draw colours in the else are wrong. DIIST had 4 and 9 which were working well, but you have then as 12 and 1... The same colours your using in the if part. Fourth, you are moving the car and flashing the siren seperately. You have to do them simoultaneously. Simple solution - move the flashing code into the for loop (get rid of the other loop) and find a way to make the siren change every few times the loop runs instead of every time. Btw, you will need to add car3move to the x value of the drawbox and drawfillboxes. Good luck :)

-----------------------------------
dabbuji
Sun Jun 10, 2007 12:00 pm

Re: Police Car
-----------------------------------
Ok the siren is blinking now, but i am unclear on your last part about the moving car as well as the blinking siren. My coordinates are already up there so can u paste that on your turing program and help fix the problem.

-----------------------------------
DifinityRJ
Sun Jun 10, 2007 3:29 pm

Re: Police Car
-----------------------------------
Take the X coord's and Y coord's for your siren and put them into variable(s), then fix that loop problem as explained before, and when your increasing your car's x position do the same to the siren's x position.

Other possible ideas, get 2 pictures 1 of your car with the Red light, and the other with the blue light, and add a counter to change between them ( much easier for you ).

-----------------------------------
dabbuji
Mon Jun 11, 2007 6:52 am

police car
-----------------------------------
ohhh, ty man, it's finally working now.
I moved both the car and the siren at the same time and removed the loop.
