# Help me with a scoring system?

**URL:** https://discourse.processing.org/t/help-me-with-a-scoring-system/26338
**Category:** Coding Questions
**Tags:** homework
**Created:** [December 17, 2020, 2:18pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338 "2020-12-17T14:18:02Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![reneetjuh](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@reneetjuh](https://discourse.processing.org/u/reneetjuh)
#### Post date: [December 17, 2020, 2:18pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/1 "2020-12-17T14:18:03Z")

</div>

hey everyone reading this!

so im wokring on a small project and im super stuck. How do I added a scoring system?

so there is a mouse (animal) that’s on the mouse(pc)

and I want him to collect cheese trough the game.

Now I’m wondering what the best way to do this is?  
Im still a beginner and this coding confuses me a lot.

please help me out? 🙂

(also this is polly the worst coding you’ve ever seen)

boolean hit = false;  
boolean dood = false;  
MousePlayer f1;  
Enemy g1;  
int [] cheeses;  
Cheesey h1;  
Cheesey i1;  
Cheesey j1;  
Cheesey k1;  
Cheesey l1;  
Cheesey m1;  
Cheesey n1;  
Cheesey o1;  
Cheesey p1;  
Cheesey q1;  
Cheesey r1;  
int score = 0;

////////////////

float c1x = 0; // circle 1 position  
float c1y = 0; // (controlled by mouse)  
float c1r = 20; // radius  
float easing = 0.10;  
float c2x = 260; // circle 2 position  
float c2y = 260;  
float c2r = 50;  
////////////////  
float t2x = 400;  
float t2y = 600;  
float t1r = 100;  
float t2r = 100;  
float t2l = 100;

////////////

float x1 = 680;  
float y1 = 480;

float length =200;  
float x = 150;  
float y = 100;  
float speed = 6;

float i = 180;  
float j = 200;  
float x3 = 10;  
float y3 = 10;  
float x4 = 10;  
float y4 = 10;  
float size4 = 10;  
float xSpeed = 6;  
float xSpeed2 = 4;  
float size3 = 100;  
float rectX = 300;  
float rectY;  
float rectWidth;  
float rectHeight;

color c = color( 250, 230,0);  
color r = color (250, 0, 0);

void setup(){

```
size(800, 800);

```

}

void draw() {

```
background(100, 100, 100);

```

float targetX = mouseX;  
float dx = targetX - x;  
x += dx \* easing;

float targetY = mouseY;  
float dy = targetY - y;  
y += dy \* easing;  
///////////////////////

```
  f1 = new MousePlayer (x-20, y+10, 100);
        g1 = new Enemy (x1-20, y1+5, y1+100);
        
        h1 = new Cheesey (x3+500, y3-30, size3-10);
         i1 = new Cheesey (x3+20, y3+20, size3-10);
         j1 = new Cheesey (x3+540, y3-340, size3-10);
         k1 = new Cheesey (x3+80, y3-380, size3-10);
         l1 = new Cheesey (x3+360, y3+200, size3+100);
         m1 = new Cheesey (x3-80, y3-200, size3-10);
         n1 = new Cheesey (x3+400, y3-500, size3-10);
         o1 = new Cheesey (x3+320, y3-10, size3-10);
         p1 = new Cheesey (x3-100, y3-300, size3-10);
         q1 = new Cheesey (x4+300, y4-200, size4-10);
         
        textSize(32);

```

text(“points”, 650, 100);  
///////////

x1 += xSpeed;

//enemy place  
if (x1 \< 400 || x1 \> height + 500) {  
xSpeed += 1;  
}else {  
xSpeed += -1;  
}

////////////////  
c1x = mouseX;  
c1y = mouseY;

boolean hit = Triangel(c1x,c1y,c1r, c2x,c2y,c2r);  
if (hit) {  
textSize(32);  
text(“I”, 700, 100);  
fill (0, 200,10);  
noStroke ();  
triangle(x3+140+80, y3+655-380, x3+166+80, y3+615-380, x3+200+80, y3+620-380);  
triangle(x3+200+80, y3+618-380, x3+138+80, y3+656-380, x3+195+80, y3+640-380);

}else {  
fill (0, 0, 0);

}

x = mouseX;  
y = mouseY-40;

boolean dood = Ellipse(x, y, t1r, t2x, t2y, t2r);  
if (dood) {

fill(400, 0, 0);  
stroke ( 100,24,20);

```
  background ( 150, 0, 0);

```

stroke (205,15);

textAlign(CENTER);  
textSize(17);  
fill (250,250,250);  
text(“OOOFFF you died :(”, 400, 400);

}

//////////////////////////

stroke (205,15);

textAlign(RIGHT);  
textSize(17);  
fill (250,250,250);  
text(“Hi! welcome to the game cheesy!, click to start and use W A S D to walk”, 600, 60);

}

void mousePressed(){

x = mouseX;  
y = mouseY;

////////////////////////  
}

boolean Triangel (float c1x, float c1y, float c1r, float c2x, float c2y, float c2r){

float distX = c1x - c2x;  
float distY = c1y - c2y;  
float distance = sqrt( (distX_distX) + (distY_distY) );

// if the distance is less than the sum of the circle’s  
// radii, the circles are touching!  
if (distance \<= c1r+c2r) {  
return true;  
}

return false;  
}  
boolean Ellipse (float x1, float y1, float t1r, float t2x, float t2y, float t2r){

float distX = x1 - t2x;  
float distY = y1 - t2y;  
float distance = sqrt( (distX_distX) + (distY_distY) );

// if the distance is less than the sum of the circle’s  
// radii, the circles are touching!  
if (distance \<= t1r+t2r) {  
return true;  
}  
return false;  
}

🙂 this is class one

class Cheesey{

float x4 = 10;  
float y4 = 10;  
float x3 = 10;  
float y3 = 10;  
float size3 = 10;  
color c = color( 250, 230,0);  
color r = color (250, 0, 0);

```
Cheesey (float x3, float y3, float size3){

```

noStroke ();

fill ( c);  
if (hit){  
fill ®;  
noStroke ();  
triangle(x3+140, y3+655, x3+166, y3+615, x3+200, y3+620);  
}  
triangle(x3+140, y3+655, x3+166, y3+615, x3+200, y3+620);

stroke (25,15);

fill ( 230, 150,0);  
if (hit){  
fill ( 230, 0,0);  
noStroke ();  
}  
triangle(x3+200, y3+618, x3+138, y3+656, x3+195, y3+640);

stroke (250, 230,0);  
if (hit){  
stroke ( 230, 0,0);  
}  
ellipse ( x3+168, y3+626,12, 12);  
noStroke ();  
ellipse ( x3+161, y3+640,10, 10);

stroke (230, 150,0);  
if (hit){  
stroke ( 230, 0,0);  
}  
fill ( 230, 150,0);  
if (hit){  
fill ( 230, 0,0);  
}  
ellipse ( x3+185,y3+628,10, 10);  
}

}

🙂 this is class 2

class Enemy{

float enemy = 100;  
float speed = 4;

Enemy (float x1, float y1, float xSpeed){

stroke ( 60,20,10);  
strokeWeight (3);

//rat  
fill(100, 0, 10);  
ellipse(x1+50, y1+75, 10, 15);

// leg 2

fill(100, 0, 10);  
ellipse(x1+5, y1+75, 10, 15);

// ear 21  
fill(100, 0, 10);  
ellipse(x1+45, y1+10, 55, 40);

// ear11  
fill(100, 0, 10);  
ellipse(x1+45, y1+10, 50, 35);

// nose brown  
fill(100, 0, 10);  
ellipse(x1+75, y1+40, 45, 12);

// big body  
fill(100, 0, 10);  
ellipse(x1+25, y1+50, 100, 50);

// nose mouse pink  
fill(100, 0, 10);  
ellipse(x1+96, y1+35, 10, 10);

// head mouse  
fill(100, 0, 10);  
ellipse(x1+55, y1+35, 50, 50);

// ear 2  
fill(100, 0, 10);  
ellipse(x1+35, y1+10, 55, 40);

// ear pink 2  
fill(100, 0, 10);  
ellipse(x1+35, y1+10, 50, 35);

// eyes black  
fill(0, 0, 0);  
ellipse(x1+55, y1+35, 5, 5);

// eyes white  
fill(225, 225, 225);  
ellipse(x1+54, y1+35, 2, 2);

// leg 2  
fill(100, 0, 10);  
ellipse(x1+35, y1+75, 10, 15);

// leg 3  
fill(100, 0, 10);  
ellipse(x1-9, y1+75, 10, 15);

// tail

noFill();  
stroke(255, 102, 0);  
stroke(0, 0, 0);  
bezier(x1-75, y1+50, x1-40, y1+50, x1-35, y1+15, x1-20, y1+40);

line(x1+60, y1+30, x1+45, y1+25);

}

}

🙂 this is class 3

class MousePlayer {

float x = 200;  
float y = 200;  
float speed = 14;  
Boolean isHit = false;

MousePlayer (float x, float y, float size){

```
  background(100,100,100); 

```

stroke ( 24,20);  
strokeWeight (3);

fill(200, 100, 0);  
ellipse(x+50, y+75, 10, 15);

// leg 2

fill(200, 100, 0);  
ellipse(x+5, y+75, 10, 15);

// ear 21  
fill(200, 100, 0);  
ellipse(x+45, y+10, 45, 40);

// ear11  
fill(200, 100, 100);  
ellipse(x+45, y+10, 40, 35);

// nose brown  
fill(200, 100, 0);  
ellipse(x+75, y+40, 35, 12);

// big body  
fill(200, 100, 0);  
ellipse(x+25, y+50, 100, 50);

// nose mouse pink  
fill(200, 100, 100);  
ellipse(x+92, y+35, 10, 10);

// head mouse  
fill(200, 100, 0);  
ellipse(x+55, y+35, 50, 50);

// ear 2  
fill(200, 100, 0);  
ellipse(x+35, y+10, 45, 40);

// ear pink 2  
fill(200, 100, 100);  
ellipse(x+35, y+10, 40, 35);

// eyes black  
fill(0, 0, 0);  
ellipse(x+55, y+35, 5, 5);

// eyes white  
fill(225, 225, 225);  
ellipse(x+54, y+35, 2, 2);

//

// leg 2  
fill(200, 100, 0);  
ellipse(x+35, y+75, 10, 15);

// leg 3  
fill(200, 100, 0);  
ellipse(x-9, y+75, 10, 15);

// tail

noFill();  
stroke(255, 102, 0);  
stroke(0, 0, 0);  
bezier(x-75, y+50, x-40, y+50, x-35, y+15, x-20, y+40);  
}

void keyPressed()  
{  
if(key == ‘w’)  
{  
y = y - speed;  
}  
if(key == ‘s’)  
{  
y = y + speed;  
}  
if(key == ‘a’)  
{  
x = x - speed;  
}  
if(key == ‘d’)  
{  
x = x + speed;  
}  
}  
}

☹ I hope you guys can help me out?  
any other ideas are welcome ofc!!

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 17, 2020, 2:28pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/2 "2020-12-17T14:28:13Z")

</div>

EDIT: I didn’t read your question well. I thought you were asking how to create variables. I didn’t notice you already know how to do it

if you want to create a scoring system you need to create a variable. I recommend int. it stands for Integer and is a simple variable. It only accepts whole numbers and its range is quite big -2^32 to +2^32(~ 10^10 or a billion).

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 17, 2020, 2:30pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/3 "2020-12-17T14:30:36Z")

</div>

You define a variable by entering the variable type. (int, float, char, String, ArrayList, boolean,…) simple variables are those that start with lower case (int, float, char, boolean,…).

```auto
int i = 15;
float c = width;
int score = 0;

```

structure:  
[type] [name] = [value]

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 17, 2020, 2:31pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/4 "2020-12-17T14:31:54Z")

</div>

by the way could you write what this program is supposed to do?

---

<div class="post-metadata">

### Author: ![reneetjuh](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@reneetjuh](https://discourse.processing.org/u/reneetjuh)
#### Post date: [December 17, 2020, 3:28pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/5 "2020-12-17T15:28:36Z")

</div>

Aahh okay! thanks for the help!

Well the ‘player’ (mouse), needs to collect the cheese on screen. and with every cheese a point needs to be added 🙂

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 17, 2020, 3:50pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/6 "2020-12-17T15:50:51Z")

</div>

Do you have a way to determine if the mouse eats the cheese?

---

<div class="post-metadata">

### Author: ![reneetjuh](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@reneetjuh](https://discourse.processing.org/u/reneetjuh)
#### Post date: [December 17, 2020, 4:04pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/7 "2020-12-17T16:04:55Z")

</div>

no not yet, I have nu clue how to do it either

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 17, 2020, 6:14pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/8 "2020-12-17T18:14:43Z")

</div>

are both shapes spheres?

---

<div class="post-metadata">

### Author: ![reneetjuh](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@reneetjuh](https://discourse.processing.org/u/reneetjuh)
#### Post date: [December 17, 2020, 8:31pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/9 "2020-12-17T20:31:53Z")

</div>

I think so? im not sure

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 17, 2020, 9:26pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/10 "2020-12-17T21:26:46Z")

</div>

if they are both circle you can try using (blured if you want to do it on your own)

```auto
if(dist(x,y,x2,y2) < r1 + r2) {
   x2 = random(width)
   y2 = random(height)
   score++;
}

```

---

<div class="post-metadata">

### Author: ![reneetjuh](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@reneetjuh](https://discourse.processing.org/u/reneetjuh)
#### Post date: [December 17, 2020, 10:07pm UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/11 "2020-12-17T22:07:42Z")

</div>

ohh okay! thank you so much for the help!! 😀

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 18, 2020, 8:14am UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/12 "2020-12-18T08:14:20Z")

</div>

I just realized that if I gave you an example like circle(x,y,2\*r) you would get used to it and continue to do it this way instead of doing it the lazy way where int r (radius) is actually d (diameter, d = 2 \* r)

---

<div class="post-metadata">

### Author: ![reneetjuh](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@reneetjuh](https://discourse.processing.org/u/reneetjuh)
#### Post date: [December 18, 2020, 9:51am UTC](https://discourse.processing.org/t/help-me-with-a-scoring-system/26338/13 "2020-12-18T09:51:08Z")

</div>

aahhh okay! thanks!!
