boid/Main.java

54 lines
1.3 KiB
Java
Raw Normal View History

2020-06-27 15:44:16 +02:00
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++) {
2020-06-27 16:19:15 +02:00
boids[i] = new Boid(WIDTH, HEIGHT, i % 16);
2020-06-27 15:44:16 +02:00
}
d = new Display(WIDTH, HEIGHT, this);
}
public void run() {
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
2020-06-27 16:19:15 +02:00
for (int i = 0; i < BOID_COUNT; i++) {
boids[i].simulate(i % 16);
2020-06-27 15:44:16 +02:00
}
ChunkManager.clear();
for (Boid b : boids) {
ChunkManager.register(b);
}
d.repaint();
}
}, 100, FRAME_STEP);
}
@Override
public Drawable[] get_drawables() {
return boids;
}
}