I see.
Okey dokey. Best way I can explain this is with a demo of how I set up a project.
In this game we have RedThings and BlueThings. They are extended from GameObject and override certain methods to behave differently. But they also can access the original methods of GameObject with the "super" keyword.
Code:
ArrayList objects;
void setup(){
size(400, 400);
smooth();
objects = new ArrayList();
for(int i = 0; i < 100; i++){
spawnObject();
}
}
void draw(){
background(0);
for(int i = 0; i < objects.size(); i++){
GameObject object = (GameObject)objects.get(i);
if(object.active){
object.main();
} else {
objects.remove(i);
i--;
}
}
}
void spawnObject(){
if(random(1) > 0.5){
objects.add(new RedThing(random(width), random(height), random(10, 20)));
} else {
objects.add(new BlueThing(random(width), random(height), random(10, 20)));
}
}
void mousePressed(){
spawnObject();
}
class RedThing extends GameObject{
RedThing(float x, float y, float radius){
super(x, y, radius);
}
void move(){
x += 2;
super.move();
}
void draw(){
fill(255,0,0);
super.draw();
}
}
class BlueThing extends GameObject{
BlueThing(float x, float y, float radius){
super(x, y, radius);
}
void move(){
y += 2;
super.move();
}
void draw(){
fill(0,0,255);
super.draw();
}
}
class GameObject{
float x, y, radius;
boolean active;
GameObject(float x, float y, float radius){
this.x = x;
this.y = y;
this.radius = radius;
active = true;
}
void main(){
move();
draw();
if(collision()){
active = false;
}
}
void move(){
if(x > width + radius) x = -radius;
if(x < -radius) x = width + radius;
if(y > height + radius) y = -radius;
if(y < -radius) y = height + radius;
}
void draw(){
ellipse(x, y, radius * 2, radius * 2);
}
boolean collision(){
return (mouseX - x) * (mouseX - x) + (mouseY - y) * (mouseY - y) <= radius * radius;
}
}