how to get the dots/food to disappear when pac man goes over it

edited January 2017 in Questions about Code

this is what i got so far

int i=1; int nxtx; int nxty; float ang=0; float speed=10; int posx=50; int posy=300; PVector[]dots=new PVector[50]; void setup(){ background(128); size(800,600); frameRate(15); ellipseMode(RADIUS); fill(#FAF312); for(int i=0;i<50;i++){ dots[i]=new PVector(random(0,width),random(0,height));} } void draw() { background(128); stroke(10); strokeWeight(10); for(int i=0;i<50;i++){ point(dots[i].x,dots[i].y);} noStroke(); resetShader(); //ang=atan2(mouseY-posy,mouseX-posx); nxtx=posx+=speedcos(ang); nxty=posy+=speedsin(ang); if(nxty<=width1) if(nxty<=height1) translate(posx,posy); rotate(ang); arc(5,0,100,100,.4,6); if(i==1){arc(5,0,100,100,.7,6); i=-i;} else{ellipse(5,0,100,100); i=-i;} //if(keyPressed==){ if(keyPressed==true){ if(keyCode==UP){ang=-PI/2;} if(keyCode==DOWN){ang=PI/2;} if(keyCode==LEFT){ang=PI;} if(keyCode==RIGHT){ang=0;} }}

Tagged:

Answers

  • sorry its not coming out right

  • Edit your post. Select the code. Hit ctrl + o.

  • and please don't start duplicate threads.

  • int i=1; 
    int nxtx; 
    int nxty; 
    float ang=0; 
    float speed=10; 
    int posx=50; 
    int posy=300; 
    PVector[]dots=new PVector[50]; 
    void setup() { 
      background(128); 
      size(800, 600); 
      frameRate(15); 
      ellipseMode(RADIUS); 
      fill(#FAF312); 
      for (int i=0; i<50; i++) { 
        dots[i]=new PVector(random(0, width), random(0, height));
      }
    } 
    void draw() { 
      background(128); 
    
      stroke(10); 
      strokeWeight(10); 
      for (int i=0; i<50; i++) { 
        point(dots[i].x, dots[i].y);
        if (dist(dots[i].x, dots[i].y, posx, posy) < 72) {
          dots[i].x=-1111;
        }
      }
    
      noStroke(); 
      resetShader(); //
    
      if (dist(mouseX, mouseY, posx, posy)>17) {
        ang=atan2(mouseY-posy, mouseX-posx);
    
        nxtx=posx+=speed*cos(ang); 
        nxty=posy+=speed*sin(ang);
      }
    
      //if (nxty<=width1) 
      if (nxty<=height) 
        translate(posx, posy);
    
      rotate(ang); 
      arc(5, 0, 100, 100, .4, 6); 
      if (i==1) {
        arc(5, 0, 100, 100, .7, 6); 
        i=-i;
      } else {
        ellipse(5, 0, 100, 100); 
        i=-i;
      } //
      //  if (keyPressed==) { 
      if (keyPressed==true) { 
        if (keyCode==UP) {
          ang=-PI/2;
        } 
        if (keyCode==DOWN) {
          ang=PI/2;
        } 
        if (keyCode==LEFT) {
          ang=PI;
        } 
        if (keyCode==RIGHT) {
          ang=0;
        }
      }
    }
    
  • This just got stupider. Despite being told to search the forum, you just created a new thread again.

  • i did but the coding there didn't work

  • ??

    My code did work

  • You are not formatting your code properly for this forum. To add the proper formatting, select your code after you've pasted it, and press ctrl + o. This will add 4 spaces to the front of every line, which is what tells the forum that it should be formatted as code.

    Chrisir has posted a fixed, properly formatted version of your code. What, exactly, is the problem?

  • i need to make pac man eat the dots i know what i need to do i just don't know how to do it

  • ??

    my pac man eats dots using the dist function

    Did you try my code at all??

Sign In or Register to comment.