# Faster and faster squares (Click game)

**URL:** https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043
**Category:** Processing
**Created:** [February 24, 2021, 8:54am UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043 "2021-02-24T08:54:30Z")
**Posts on this page:** 9
**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 24, 2021, 8:54am UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/1 "2021-02-24T08:54:30Z")

</div>

Hello,  
I would like in my game that every 15 seconds the speed of appearance of the edges increases by x time (example the first 15 seconds is 1 square every 1 second then the next 15 seconds will be 1 square every 0.7seconds … etc) except that when I had done it it had worked but in reverse.

```auto
int wait = 1000;
int lastTime = 0; 
int score = 0; 
int score2 = 0;
int bonus = 1;
int square_size = 50;
float square_x;
float square_y;
final int menu = 0;
final int jeux = 1;
int state = menu;
PFont font;
PImage img;
PFont police;

void setup() {
  size(900,600); //feunetre 900x600
  smooth(); //dessine la geometrie avec des arretes lisses
  police = loadFont("Arial-Black-48.vlw"); //charger police d'écriture 
  img=loadImage("Sans titre-67.jpg"); //quel image je dois charger (au prealable mis dans data)
}

// **********Changement de fenetre********* \\

void draw() {
  switch (state) {
  case menu:
    showMenu(); //developpement plus bas
    break; //passer a l'instruction suivante 
  case jeux:
    handlejeux(); //developpement plus bas
    break; //passer a l'instruction suivante 
  default:
    println ("Unknown state (in draw) "
      + state
      + " ++++++++++++++++++++++");
    exit(); //quitter le programme
    break; //passer a l'instruction suivante 
  } 
}

//**********Multiplicateur de score (score de base + bonus)*********\\

void mousePressed() {
  if (state!=jeux)
    return; 

 if ( over_square() ) {     
    score += bonus; //plus j'appuye plus je gagne du score
    bonus++;

    score2 += 1;         
  } else {
    score = 0; //score de base
    bonus = 1; //score +1 par combo

    score2 = 0; //autre score mais avance de 1
  }
  randomize_square_position();
}

void keyPressed() {
  switch (state) {
  case menu:
    keyPressedForMenu(); //developpement plus bas
    break; //passer a l'instruction suivante 
  case jeux:
    keyPressedForjeux(); //developpement plus bas
    break; //passer a l'instruction suivante 
  default:
    println ("Unknown state (in keypressed) "
      + state
      + " ++++++++++++++++++++++");
    exit(); //quitter le programme
    break; //passer a l'instruction suivante 
  } 
} 

//**********Action si touche pressé (changement de background)*********\\

void keyPressedForMenu() {

  switch(key) {
  case '1': //si j'appuye sur 1....
    state = jeux; //changer ecran sur jeux
    break; //passer a l'instruction suivante 
    
  case 'x': //si j'appuye sur x....
  case 'X': //ou X
    exit(); //quitter
    break; //passer a l'instruction suivante 
  }
} 

void keyPressedForjeux() {
  switch(key) {
  default:
    key=0; 
    state = menu;
    break; //passer a l'instruction suivante 
  }

} 

//**********Apparence visuel du menu (emplacement des textes...etc)**********\\

void showMenu() { //Mon ecran menu
  image (img,0,0); //joli photo fais pas mes soins ;)
} 

// **********Mon jeux********** \\

void handlejeux() { //mon ecran jeux
  background(78, 61, 40); //couleur du fond noir 
  fill(255); //couleur blanche
  if (lastTime + wait < millis()) { //si j'ai pas click au bout de X temps
    randomize_square_position(); //alors nouveau carré
  }
  rect(square_x, square_y, square_size, square_size); //dessin du carré
  textFont(police,32); //mettre la police d'écriture
  text("Score = ", 680,50, height-25); //Afficher "Score =" a certaine coo
  textFont(police,32); //mettre la police d'écriture
  textSize(32); //taille du texte
  textFont(police,32); //mettre la police d'écriture
  text(score, 830,50, height-25); //coordonnée du score
  textFont(police,32); //mettre la police d'écriture
  text("X ", 30,570, height-25); //Afficher "X" a certaine coo
  textFont(police,32); //mettre la police d'écriture
  text(score2, 60,570, height-25); //coordonnée du score
}

void randomize_square_position() { //commande du random spawn
  square_x = random(width - square_size); //Spawn random de carré sur les coo X
  square_y = random(height - square_size); //Spawn random de carré sur les coo Y
  lastTime = millis(); //depop si trop long
}

boolean over_square() {
  return(
    mouseX > square_x && //si je click sur le carré, alors disparition  
    mouseX < square_x + square_size &&      
    mouseY > square_y && 
    mouseY < square_y + square_size
    );
}

```

---

<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: [February 24, 2021, 10:45am UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/2 "2021-02-24T10:45:54Z")

</div>

This is your variable wait (see this line: `if (lastTime + wait < millis()) {`).

wait is 1000 (milliseconds, so 1 second)

you can reduce wait by 90 in `randomize_square_position() `

---

<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 24, 2021, 2:07pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/3 "2021-02-24T14:07:06Z")

</div>

Yes I know but I would like the speed to change every 15 seconds. With what I have already I can just change the speed but it will always remain the same speed it will not increase progressively

---

<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: [February 24, 2021, 2:09pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/4 "2021-02-24T14:09:25Z")

</div>

> [@Torikusu](#):
>
> change every 15

Okay, make a timer for this and say wait -= 90;

You already have another timer so you should be able to do it on your own

---

<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: [February 24, 2021, 2:36pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/5 "2021-02-24T14:36:13Z")

</div>

To decrease the wait every 15 seconds you can just use

```auto
float wait = 1000 - millis()/15000*90; //gradual decrease (\)
float wait2 = 1000 - floor(millis()/15000)*90; //sharp decrease (`-_)

```

---

<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 24, 2021, 3:02pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/6 "2021-02-24T15:02:32Z")

</div>

Thanks but it is marked every time: “unexpected token : float”  
Its the : "int lastTime = 0 ; " which poses a problem?

---

<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: [February 24, 2021, 3:07pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/7 "2021-02-24T15:07:53Z")

</div>

I forgot to add a ;  
I edited the code now (add a ; before the comment)

---

<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 24, 2021, 4:14pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/8 "2021-02-24T16:14:02Z")

</div>

> [@CodeMasterX](#):
>
> ```auto
> float wait = 1000 - millis()/15000*90; //gradual decrease (\)
> float wait2 = 1000 - floor(millis()/15000)*90; //sharp decrease (`-_)
> 
> ```

Thanks but I have to edit

```auto
  if (lastTime + wait < millis()) { //si j'ai pas click au bout de X temps
    randomize_square_position(); //alors nouveau carré

```

for this to work because I don’t see any difference with just the variables

---

<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: [February 24, 2021, 4:21pm UTC](https://discourse.processing.org/t/faster-and-faster-squares-click-game/28043/9 "2021-02-24T16:21:28Z")

</div>

> [@Torikusu](#):
>
> because I don’t see any difference with just the variables

yeah don’t worry, I was just providing an alternative. Feel free to use anything, it’s your code after all : P
