Is there a command to set the cursor coordinate?

I am currently making a game in processing. I want it to be where you move the ball with your mouse, and when it touches the side, it stops. However, when I start the game, the cursor is inside one of the walls, causing the game to stop. How can I fix this? Here's my code:

CODE REMOVED SEE NEXT COMMENT

Answers

  • edited June 2015

    Sorry how the formatting is all weird. It just went like that

    int gameOver = 0;
    
    Ball playerBall;
    Wall sideWall;
    
    void setup() {
      size(400,600);
      noStroke();
      playerBall = new Ball(color(random(0,255),random(0,254),random(0,255)),mouseX,height);
      sideWall = new Wall(color(0,255,0));
    }
    
    void draw() {
      background(255);
      playerBall.display();
      sideWall.side();
      sideWall.touch();
    }
    
    class Ball {
      color c;
      float xpos;
      float ypos;
    
      Ball(color tempC, float tempXpos, float tempYpos) {
        c = tempC;
        xpos = width/2;
        ypos = height - 10;
      }
    
      void display() {
        noStroke();
        fill(c);
        if (mouseX != pmouseX) {
          fill(255);
          rect(0,height-20,width,20);
          fill(c);
          ellipse(mouseX,height-10,10,10);
        } else {
          ellipse(mouseX,height-10,10,10);
        }
      }
    }
    
    class Wall {
      color c;
    
      Wall(color tempC) {
        c = tempC;
      }
    
      void side() {
        if (gameOver >= 1) {
    
        } else {
          noStroke();
          fill(c);
          rect(0,0,100,height);
          rect(300,0,width,height);
        }
      }
    
      void touch() {
        if (gameOver >= 1) {
    
        } else {
          if (dist(0,height-10,mouseX,height-10) <= 105) {
    
            background(0);
            gameOver = 1;
          } else {
    
          }
        }
      }
    }
    
  • Maybe require the user to click the Ball before it starts following the mouse?

  • I have removed the original code and corrected the code formatting in your second effort ;)

Sign In or Register to comment.