Help me with a scoring system?

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? :slight_smile:

(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( (distXdistX) + (distYdistY) );

// 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( (distXdistX) + (distYdistY) );

// 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;
}

:slight_smile: 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);
}

}

:slight_smile: 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);

}

}

:slight_smile: 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;
}
}
}

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

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).

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,…).

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

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

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

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 :slight_smile:

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

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

are both shapes spheres?

I think so? im not sure

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

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

ohh okay! thank you so much for the help!! :grinning:

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)

aahhh okay! thanks!!