import java.util.Timer; import java.util.TimerTask; public class Main implements DrawableCollection { private static final int WIDTH = 800; private static final int HEIGHT = 600; private static final int BOID_COUNT = 10000; private static final int CHUNKS_X = 32; private static final int CHUNKS_Y = 32; private static final int FRAME_STEP = 16; private static final float MAX_SPEED = 1; private Boid[] boids; private Display d; public static void main(String[] args) throws InterruptedException { ChunkManager.init(WIDTH, HEIGHT, CHUNKS_X, CHUNKS_Y); PhysicsObject.width = WIDTH; PhysicsObject.height = HEIGHT; PhysicsObject.max_speed = MAX_SPEED; new Main().run(); } public Main() { boids = new Boid[BOID_COUNT]; for (int i = 0; i < BOID_COUNT; i++) { boids[i] = new Boid(WIDTH, HEIGHT, i % 16); } d = new Display(WIDTH, HEIGHT, this); } public void run() { new Timer().scheduleAtFixedRate(new TimerTask() { @Override public void run() { for (int i = 0; i < BOID_COUNT; i++) { boids[i].simulate(i % 16); } ChunkManager.clear(); for (Boid b : boids) { ChunkManager.register(b); } d.repaint(); } }, 100, FRAME_STEP); } @Override public Drawable[] get_drawables() { return boids; } }