# Need help with code for school

**URL:** https://discourse.processing.org/t/need-help-with-code-for-school/19062
**Category:** Coding Questions
**Tags:** homework
**Created:** [March 27, 2020, 12:09am UTC](https://discourse.processing.org/t/need-help-with-code-for-school/19062 "2020-03-27T00:09:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![comrade](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@comrade](https://discourse.processing.org/u/comrade)
#### Post date: [March 27, 2020, 12:09am UTC](https://discourse.processing.org/t/need-help-with-code-for-school/19062/1 "2020-03-27T00:09:44Z")

</div>

int x;  
int y;  
int wx;  
int wy;  
int s = 0;

PImage sunf;  
PImage bee;

void setup(){  
size(1920,1080);  
x = (int)random(200,1700);  
y = (int)random(200, 800);  
bee = loadImage(“bee.png”);  
sunf = loadImage(“sunf.jpg”);  
}

void draw(){  
wx = x + 50;  
wy = y + 20;  
background(255);  
image(sunf,x,y);  
image(bee, mouseX, mouseY);  
if(wx == mouseX && wx == mouseY){  
x = (int)random(200,1700);  
y = (int)random(200, 800);  
s++;  
textSize(32);  
fill(0);  
textAlign(RIGHT);  
text(s, 1920,0);  
}  
}

I am trying to make a basic game in my digital technology class. I want it so when the mouse is over the sunflower(sunf) it moves to a new random location and adds 1 to a score counter in the top right and the is a bee following the mouse. when I run my code the sunflower shows on and the bee follows the mouse but when the mouse is over the sunflower nothing happens.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 27, 2020, 12:15am UTC](https://discourse.processing.org/t/need-help-with-code-for-school/19062/2 "2020-03-27T00:15:52Z")

</div>

Hello,

Welcome!

Please format your code so we can read it easily and cut and paste it and run it:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

There are a lot of resources here:  
[www.processing.org](http://www.processing.org)

`:)`

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 27, 2020, 9:04am UTC](https://discourse.processing.org/t/need-help-with-code-for-school/19062/3 "2020-03-27T09:04:16Z")

</div>

> [@comrade](#):
>
> if(wx == mouseX && wx == mouseY){

The second wx must be wy!

It’s hard to hit a spot exactly with the mouse.

Instead allow for a distance between sunf and mouse of 16 pixel or so

Eg if(dist(wx,wy, mouseX,mouseY) \< 16)

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [March 29, 2020, 8:44pm UTC](https://discourse.processing.org/t/need-help-with-code-for-school/19062/4 "2020-03-29T20:44:11Z")

</div>

Welcome to the forum! Please edit your post and format your code.

[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)
