# 15 coins game - pls help im stuck

**URL:** <https://discourse.processing.org/t/15-coins-game-pls-help-im-stuck/27268>\
**Category:** Coding Questions\
**Created:** [January 21, 2021, 3:50pm UTC](https://discourse.processing.org/t/15-coins-game-pls-help-im-stuck/27268 "2021-01-21T15:50:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grave](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Grave](https://discourse.processing.org/u/Grave)\
**Post date:** [January 21, 2021, 3:50pm UTC](https://discourse.processing.org/t/15-coins-game-pls-help-im-stuck/27268/1 "2021-01-21T15:50:59Z")

</div>

How can I make the class Candy disappear when Eyeball touch it?  
String gameState;  
PImage sc; // SCARLET FOREST  
void setup() {  
size(810, 810);  
eyeballSetup();  
for(int i=0;i\<candies.length;i++){  
candies[i] = new Candy(random(width),random(height));  
gameState = “START”;  
sc=loadImage(“SC.png”);  
}  
}

void draw() {

if(gameState == “START”){  
startGame();  
} else if(gameState==“PLAY”){  
playGame();  
}else if(gameState== “WIN”){  
winGame();  
}else if(gameState == “LOSE”){  
loseGame();  
}

}

void startGame(){  
background(sc);  
image(sc,810,810);  
textAlign(CENTER);  
textSize(50);  
fill(181,60,126);  
text(“Click here to play”,width/2,height/2-20);  
textSize(40);  
fill(188,50,127);  
text(“levels 1 2 3”, width/2,height/2+30);  
if(mousePressed==true){  
gameState = “PLAY”;

}  
}  
void playGame(){  
background(sc);  
image(sc,810,810);  
// Move eyeball.  
eyeballMove();  
// Draw coins.  
for(int i=0;i\<candies.length;i++){  
candies[i].draw();  
}  
// Draw eyeball.  
eyeballDraw(x, y, rot);

}  
void winGame(){  
}  
void loseGame(){  
}  
void resetGame(){  
}

void keyPressed() {  
if (key==‘w’||key==‘W’) {  
eyeballUp();  
} else if (key==‘s’||key==‘S’) {  
eyeballDown();  
} else if (key==‘a’||key==‘A’) {  
eyeballLeft();  
} else if (key==‘d’||key==‘D’) {  
eyeballRight();  
}  
}

//class  
class Candy {  
float candy\_x, candy\_y;  
boolean candy\_isVisible;  
Candy(float ix, float iy){  
candy\_x = ix;  
candy\_y = iy;  
candy\_isVisible = true;  
}  
void draw(){  
if(!candy\_isVisible){  
return;  
}  
fill(255,0,90);  
rect(candy\_x, candy\_y,30,50);  
}  
}

Candy[] candies = new Candy[15];

* * *

int r; // EyeBall’s raio.

int pupil\_r, x, y, rot; // Eyeball’s Features.  
int speed=3; // Eyeball’s speed

// Eyeball’s functions…

void eyeballSetup(){

r= 30;  
pupil\_r= 10;

x=width/2;  
y=height/2;  
rot=0;  
}

void eyeballMove() {  
if (rot==0) {  
y=y+speed;  
eyeballDown();  
}  
if (rot==90) {  
x=x-speed;  
eyeballLeft();  
}  
if (rot==180) {  
y=y-speed;  
eyeballUp();  
}  
if (rot==270) {  
x=x+speed;  
eyeballRight();  
}

if (x\<25) {  
x=x+speed;  
eyeballRight();  
}  
if (x\>785) {  
x=x-speed;  
eyeballLeft();  
}  
if (y\<25) {  
y=y+speed;  
eyeballDown();  
}  
if (y\>785) {  
eyeballUp();  
}  
}

void eyeballDraw(int x, int y, int rot) {  
//olho  
ellipseMode(CENTER);

translate(x, y);

rotate(radians(rot));  
fill(255);  
noStroke();  
ellipse(0, 0, r,r);

//pupila  
fill(0);  
ellipse(0,0, pupil\_r, pupil\_r);

}

void eyeballUp() {  
rot=180;  
}

void eyeballDown() {  
rot=0;  
}

void eyeballLeft() {  
rot=90;  
}

void eyeballRight() {  
rot=270;  
}

//PS im stuck pls help

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [January 21, 2021, 4:21pm UTC](https://discourse.processing.org/t/15-coins-game-pls-help-im-stuck/27268/2 "2021-01-21T16:21:38Z")

</div>

You will need to check if the eyeball has touched each candy.

Loop over all the candies. For each candy, see if the eyeball is touching it (You know where the candy and the eyeball are! How can you tell if they are touching?), if it is touching it, then that candy should disappear.

---

<div class="post-metadata">

**Author:** ![ReyzArtz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/reyzartz/32/11750_2.png) [@ReyzArtz](https://discourse.processing.org/u/ReyzArtz)\
**Post date:** [January 23, 2021, 6:56am UTC](https://discourse.processing.org/t/15-coins-game-pls-help-im-stuck/27268/3 "2021-01-23T06:56:47Z")

</div>

in the draw candy function or any separate function check the distance between the candy position and the eye position if they touch to delete the candy
