import ddf.minim.*; /** * Game 40: "Violent Antipathy"
*
*
Go play more games at NMcCoy.net!
* Creative Commons License
This work by Nathan McCoy is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. */ boolean[] keys = new boolean[256]; boolean title; boolean paused; boolean muted; int drawing_ms_last; int physics_ms_last; int CORE_FPS = 540; int DRAWING_FPS = 60; int PHYSICS_FPS = 30; int DRAW_MS = 1000 / DRAWING_FPS; int PHYS_MS = 1000 / PHYSICS_FPS; Minim minim; int GRID_SIZE = 100; Cell[][] grid = new Cell[GRID_SIZE][GRID_SIZE]; ArrayList ants = new ArrayList(); void audioInit() { minim = new Minim(this); } void audioClose() { minim.stop(); } void setup() { size(500, 500); frameRate(600); audioInit(); info_font = loadFont("PressStartK-16.vlw"); for(int x = 0; x < GRID_SIZE; x++) for(int y = 0; y < GRID_SIZE; y++) { grid[x][y] = new Cell(x, y); } for(int i = 0; i < 50; i++) ants.add(new Ant(10, 25)); for(int i = 0; i < 50; i++) { grid[(int)random(GRID_SIZE)][(int)random(GRID_SIZE)].food_amt = (int)random(50)+20; } } void stop() { audioClose(); super.stop(); } void physicsStep() { //for(int x = 0; x < GRID_SIZE; x++) //for(int y = 0; y < GRID_SIZE; y++) //grid[x][y].age(); for(Ant a : ants) a.decideAndMove(); } void drawingStep() { background(192,128,64); for(int x = 0; x < GRID_SIZE; x++) for(int y = 0; y < GRID_SIZE; y++) { grid[x][y].draw(); } for(Ant a : ants) a.draw(); } void draw() { while(physics_ms_last + PHYS_MS < millis()) { if(!paused) { physicsStep(); } physics_ms_last += PHYS_MS; } if(drawing_ms_last + DRAW_MS < millis()) { drawingStep(); drawing_ms_last = millis(); } } void keyPressed() { if(keyCode < 256) if(!keys[keyCode]) { keys[keyCode] = true; down(keyCode); } } void keyReleased() { if(keyCode < 256) if(keys[keyCode]) { keys[keyCode] = false; up(keyCode); } } void down(int theKey) { println(theKey + " down"); if(theKey == 'M') muted = !muted; if(theKey == 'P' && !title) paused = !paused; } void up(int theKey) { println(theKey + " up"); }