# How to make a game with many different objects (ArrayList)

**URL:** <https://discourse.processing.org/t/how-to-make-a-game-with-many-different-objects-arraylist/16839>\
**Category:** Coding Questions\
**Created:** [January 3, 2020, 4:30pm UTC](https://discourse.processing.org/t/how-to-make-a-game-with-many-different-objects-arraylist/16839 "2020-01-03T16:30:48Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [January 14, 2020, 10:46pm UTC](https://discourse.processing.org/t/how-to-make-a-game-with-many-different-objects-arraylist/16839/6 "2020-01-14T22:46:17Z")

</div>

here is an example

using `interface` and `implements`

```auto

// demo for interface and implements
// Interface allows to bring different kinds of objects in one ArrayList

ArrayList<BasicItem3D> list = new ArrayList(); 

void setup() {
  size(950, 650, P3D);

  for (int x=0; x<7; x++) {
    for (int y=0; y<7; y++) {
      if (random(100) > 50) 
        list.add(new ClassBox( 300.0+x*74, 100.0+y*74, random(-150, 150)));
      else
        list.add(new ClassSphere( 300.0+x*74, 100.0+y*74, random(-150, 150)));
    }//for
  }//for
  //
}//func

void draw() {
  background(0);
  lights();

  for (BasicItem3D item : list) {
    item.display();
  }//for
}//func

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

interface BasicItem3D {
  void display();
  void move();
}//interface

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

class ClassSphere implements BasicItem3D {
  PVector pos = new PVector(0, 0, 0); 

  // constr 
  ClassSphere(float x, float y, float z) {
    pos.set(x, y, z);
  }// constr 

  void display() {
    noStroke();
    fill(255, 0, 0);
    pushMatrix();
    translate(pos.x, pos.y, pos.z);
    sphere (39);
    popMatrix();
  } 

  void move() {
  }
  //
}//class

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

class ClassBox implements BasicItem3D {
  PVector pos = new PVector(0, 0, 0); 

  // constr 
  ClassBox(float x, float y, float z) {
    pos.set(x, y, z);
  }// constr 

  void display() {
    stroke(0);
    fill(200);
    pushMatrix();
    translate(pos.x, pos.y, pos.z);
    box (39);
    popMatrix();
  } 

  void move() {
  }
  //
}//class
//

```

---

_[View the full topic](https://discourse.processing.org/t/how-to-make-a-game-with-many-different-objects-arraylist/16839)._
