conditional doesn't work
in
Programming Questions
•
1 year ago
Hi guys
In school, we use Processing for our informatic course. I want to creat two points, and if they are on the same X-coordinate, the white point shall change his position. But my code doesn't work and I find the problem. Why does the red code not creat new coordinates if the X-coordinate is similar?
Thank you for your help.
- int rad = 30;
- float xpos;
- float ypos;
- float xspeed = 4;
- float yspeed = 4;
- int xdirection = 0;
- int ydirection = 0;
- float xball;
- float yball;
- color grau = color(100,100,100);
- void setup(){
- size(1000,800);
- background(0,0,0);
- frameRate(30);
- xpos=width/2;
- ypos=height/2;
- ellipseMode(RADIUS);
- noStroke();
- smooth();
- }
- void keyPressed(){
- if (keyPressed==true){
- if (key == 'a'){
- xdirection = -1;
- }
- if (key =='w'){
- ydirection = -1;
- }
- if (key=='s'){
- ydirection = 1;
- }
- if (key == 'd'){
- xdirection = 1;
- }
- }
- }
- void draw(){
- background(0,0,0);
- if (xball == xpos){
- xball = random(500);
- yball = random(400);
- }
- fill(255,255,255);
- ellipse(xball,yball,10, 10);
- fill(grau);
- xpos = xpos+(xspeed*xdirection);
- ypos = ypos+(yspeed*ydirection);
- ellipse(xpos,ypos,rad,rad);
- if (xpos == 700 && ypos==400){
- rad = rad +10;
- }
- }
1