# Score and score multiplier for a clicker

**URL:** <https://discourse.processing.org/t/score-and-score-multiplier-for-a-clicker/27994>\
**Category:** Coding Questions\
**Created:** [February 22, 2021, 10:47am UTC](https://discourse.processing.org/t/score-and-score-multiplier-for-a-clicker/27994 "2021-02-22T10:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torikusu](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@Torikusu](https://discourse.processing.org/u/Torikusu)\
**Post date:** [February 22, 2021, 10:47am UTC](https://discourse.processing.org/t/score-and-score-multiplier-for-a-clicker/27994/1 "2021-02-22T10:47:43Z")

</div>

Hello,  
with this code I would like there to be a counter every time I press a square, but if I put too long or if I press next to it the counter goes back to 0  
and even if it is possible a score multiplier, imagine that one square is worth 1 point and if I press correctly on 17 square then the next one will be worth 17 point and so on until I am wrong or are too long sorry for my poor English

```auto
int wait = 1000, lastTime = 0, score = 0, size = 50; //temps, score et taille
PVector pos = new PVector(random(0,600-size),random(0,600-size));

void setup() {
  fullScreen(); //plein ecran
   }

void draw() {
  background(0); //couleur du fond
  square(pos.x,pos.y,size); //localisation carré
   
     if(mousePressed && mouseX > pos.x && mouseX < pos.x + size && mouseY > pos.y && mouseY < pos.y + size) //si clique sur souris alors l'enlever
      {     
         score++;        
         pos = new PVector(random(width-size),random(height-size)); //localisation aleatoire
         lastTime = millis(); //timer
            }
  
     if(lastTime + wait < millis()) {pos = new PVector(random(width-size),random(height-size)); lastTime = millis(); } //si trop de temps a cliquer alors enlever le carré
   }

```

---

<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:** [February 22, 2021, 1:56pm UTC](https://discourse.processing.org/t/score-and-score-multiplier-for-a-clicker/27994/2 "2021-02-22T13:56:44Z")

</div>

Cleaned up example code:

```auto
int wait = 1000;
int lastTime = 0; 
int score = 0; 
int bonus = 1;
int square_size = 50;
float square_x;
float square_y;

void setup() {
  //fullScreen();
  size(600, 400);
  randomize_square_position();
}

void draw() {
  background(0);
  fill(255);
  if (lastTime + wait < millis()) {
    randomize_square_position();
  }
  rect(square_x, square_y, square_size, square_size);
  text(score, 20, 20);
}

void mousePressed() {
  if ( over_square() ) {     
    score += bonus;
    bonus++;
  } else {
    score = 0;
    bonus = 1;
  }
  randomize_square_position();
}

void randomize_square_position() {
  square_x = random(width - square_size);
  square_y = random(height - square_size);
  lastTime = millis();
}

boolean over_square() {
  return(
    mouseX > square_x &&
    mouseX < square_x + square_size && 
    mouseY > square_y && 
    mouseY < square_y + square_size
    );
}

```

---

<div class="post-metadata">

**Author:** ![Torikusu](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@Torikusu](https://discourse.processing.org/u/Torikusu)\
**Post date:** [February 22, 2021, 4:28pm UTC](https://discourse.processing.org/t/score-and-score-multiplier-for-a-clicker/27994/3 "2021-02-22T16:28:20Z")

</div>

Thank you very much that’s exactly what I wanted I was blocking it for a while but you really help me !
