We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Working a making a pac- man move back and forth on the screen. this is all ive got. i want it to keep bouncing back and forth.
float x =0; float xmovel =150/2; int dirl =1; float speed = 1;
void setup(){ size(500,500); frameRate(60); translate(250,250); }
void draw(){ print(mouseX," : "); println(mouseY);
background(255);
//facing right if (dirl == 1){ noStroke(); fill(254,255,0); arc(0+xmovel,250,150,150,.5-x,5.8+x); x = x + .050; if (x > .6){ x = 0; } fill(0); ellipse(41+xmovel,212,15,15); }
if (dirl == -1){ // facing left noStroke(); fill(254,255,0); arc(0+xmovel,250,150,150,radians(-152)-x,radians(152)+x); x = x + .050; if (x > .6){ x = 0; } fill(0); ellipse(-40+xmovel,212,15,15); }
if (xmovel > 420){ dirl = -dirl; xmovel = 400;
} xmovel = dirl*speed+xmovel; println(xmovel);
}
void keyPressed(){ if (key == 'u'){ speed++; } if (key == 'd'){ speed--; } }
Answers
You didn't have a condition that would check if he bounced off the left wall, so I added one for you. You also probably don't want him to have a negative speed, so I added a check for that too.
Wow thx alot