# Newbie - Trying to make a "Taiko"-like game

**URL:** <https://discourse.processing.org/t/newbie-trying-to-make-a-taiko-like-game/9120>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [March 8, 2019, 6:10pm UTC](https://discourse.processing.org/t/newbie-trying-to-make-a-taiko-like-game/9120 "2019-03-08T18:10:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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 9, 2019, 9:00am UTC](https://discourse.processing.org/t/newbie-trying-to-make-a-taiko-like-game/9120/3 "2019-03-09T09:00:25Z")

</div>

> [@Shii](#):
>
> I also want the balls to come every second,

That requires a small **timer** and then the `boules.add(...` part from above. The position of the ball is randomly, see command `random()`.

A timer looks like this:

```auto

if(millis() - timeStarted > 1000){

      boules.add(new Boule.........
      timeStarted=millis();

}

```

**Example**

Example not using your code above…

```auto

ArrayList<Ball> balls = new ArrayList();

int timeStarted=0; 

void setup() {
  size(800, 800);
  noStroke();
  timeStarted=-1000;
} // func 

void draw() {
  background(255);

  // for-loop
  for (int i = balls.size()-1; i >= 0; i--) { 
    Ball ball = balls.get(i);
    ball.move();
    ball.display();
  } // for 

  // a new for-loop to delete balls
  // (it is better to have 2 separate for-loops)
  for (int i = balls.size()-1; i >= 0; i--) { // going backwards 
    Ball ball = balls.get(i);
    if (ball.y+ball.h > height) {
      balls.remove(i);
    } // if
  } // for

  checkTimer();

  fill(0); //black
  text(balls.size(), 
    20, height-20);
} // func 

void checkTimer() {
  // timer

  int rectWidth = 20;
  int rectHeight = 20;

  float rCol, gCol, bCol;

  if (millis() - timeStarted > 1000) {
    // new ball
    rCol = random(255);
    gCol = random(255);
    bCol = random(255);

    balls.add(new Ball(random(width), random(-60, 60), 
      rectWidth, rectHeight, 
      rCol, gCol, bCol));

    timeStarted=millis();
  }
}

// ==================================================

class Ball {  
  // pos
  float x;
  float y;

  // size
  float w;
  float h;

  // movement 
  float speed = 5;

  // color // or use color 
  float r, g, b;

  // constr
  Ball(float tempX, float tempY, 
    float tempW, float tempH, 
    float tempR, float tempG, float tempB) {

    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;

    r = tempR;
    g = tempG;
    b = tempB;
  }// constr

  void move() {
    y = y + speed;
  }

  void display() {
    fill(r, g, b);
    ellipse(x, y, w, h);
  }
  //
} // class
//

```

---

_[View the full topic](https://discourse.processing.org/t/newbie-trying-to-make-a-taiko-like-game/9120)._
