Asteroids
TThing = class
procedure CollideWith(AOther: TThing); // default: elastic collision
end;
TSpaceShip = class(TThing)
procedure CollideWith(AAsteroid: TAsteroid); // bang!
end;
TAsteroid = class(TThing)
procedure CollideWith(ASpaceShip: TSpaceShip); // bang!
procedure CollideWith(ABullet: TBullet); // destroy Asteroid
end;
TBullet = class(TThing)
procedure CollideWith(AAsteroid: TAsteroid); // destroy Asteroid
end;
for thing in allThings do
begin
thing.move;
for otherThing in allThings do
if atSamePlace(thing, otherThing);
thing.collideWith(otherThing);
end;