Hey, I'm making a simple moving car at night with its headlight bulbs and I'm using PROCESSING software, not java. What I tried to make is when the car touches the right border, the headlight bulb of the right side of the car should be changed to the left side of the same car. It doesn't work with this code below. Any suggestions?
float moveX, moveY, speed = 3;
float dia;
void setup() {
size(600, 400);
background(0);
moveX = width/2;
moveY = height/2;
dia = 50;
}
void draw() {
background(0);
rectMode(CENTER);
noStroke();
fill(255);
rect(moveX, moveY, dia, 20);
moveX += speed;
if (moveX <= 25 || moveX >= width-25)
speed *= -1;
fill(255, 255, 0, 150); // BELOW THIS POINT, IT DOESN'T WORK!
if (moveX >= 0 && moveX <= width) {
triangle(moveX+80, height/2+10, moveX+80, height/2, moveX+20, height/2+5);
triangle(moveX+80, height/2-10, moveX+80, height/2, moveX+20, height/2-5);
}
else if (moveX <= 0 && moveX >= width) {
triangle(moveX-80, height/2+10, moveX-80, height/2, moveX-20, height/2+5);
triangle(moveX-80, height/2-10, moveX-80, height/2, moveX-20, height/2-5);
}
}