/** * Move the mouse around to aim the ship.
* Hold down 'w' to move the ship in the direction it is facing.
* Click the mouse or press the ALT key to shoot.
* Shoot the Amoebas to make sound. * **/ import processing.opengl.*; import ddf.contraptions.physics.*; import traer.physics.*; ParticleSystem phys; ArrayList amlist; Ship ship; ArrayList bullets; Reticle ret; MidiSeq seq; void setup() { size(640, 480, OPENGL); //smooth(); ellipseMode(CENTER_RADIUS); colorMode(HSB); noCursor(); phys = new ParticleSystem(0, 0.05); int num = 30; amlist = new ArrayList(num); for(int i = 0; i < num; i++) { spawnAmoeba(); } ship = new Ship(phys.makeParticle(1, width/2, height/2, 0)); bullets = new ArrayList(); ret = new Reticle(); seq = new MidiSeq(); hud = loadFont("hudmono.vlw"); println(javaVersion); } void spawnAmoeba() { Particle p = phys.makeParticle(1, random(0, width), random(0, height), 0); int note = int(random(0, 127)); int vel = int(random(64, 127)); amlist.add( new Amoeba(phys, p, note, vel) ); } PFont hud; void draw() { background(150, 255, 20); phys.tick(); for(int i = 0; i < amlist.size(); i++) { Amoeba p1 = (Amoeba)amlist.get(i); p1.update(); for(int j = i+1; j < amlist.size(); j++) { Amoeba p2 = (Amoeba)amlist.get(j); float d = dist(p1.x(), p1.y(), p2.x(), p2.y()); if ( d < 20 ) { float dx = (p1.x() - p2.x())/d; float dy = (p1.y() - p2.y())/d; p1.addVelocity(dx*2, dy*2); p2.addVelocity(dx*-2, dy*-2); } } p1.draw(); } ship.update(); for(int i = 0; i < amlist.size(); i++) { Amoeba a = (Amoeba)amlist.get(i); float d = dist(a.x(), a.y(), ship.x(), ship.y()); if ( d < 20 ) { float dx = (a.x() - ship.x()) / d; float dy = (a.y() - ship.y()) / d; a.addVelocity(dx*2,dy*2); } } ship.draw(); Iterator iter = bullets.iterator(); while(iter.hasNext()) { Bullet b = (Bullet)iter.next(); b.update(); Iterator aiter = amlist.iterator(); while(aiter.hasNext()) { Amoeba a = (Amoeba)aiter.next(); if ( dist(b.x(), b.y(), a.x(), a.y()) < 10 ) { b.kill(); a.kill(); aiter.remove(); seq.addNote( a.myNote, a.myVel ); spawnAmoeba(); break; } } if ( b.isDead() ) { iter.remove(); } else { b.draw(); } } if ( bullets.isEmpty() ) { seq.muteBulletTrack(); } ret.draw(); fill(255); textFont(hud); text("FPS: " + frameRate, 1, 15); } void close() { seq.close(); }