String lines[]; String gun = ""; int linecount; invader i ; ArrayList invaders = new ArrayList(); ArrayList invadersToKill = new ArrayList(); ArrayList deads = new ArrayList(); ArrayList deadsToKill = new ArrayList(); ArrayList killers = new ArrayList(); ArrayList killersToKill = new ArrayList(); float counter = 0; float timeToNext = 200; float timer = timeToNext; void setup() { size(400, 400); //textFont(loadFont("Arial-Black-14.vlw"), 14); lines = loadStrings("words.txt"); linecount = lines.length; lowLag.init(); lowLag.load('click.mp3'); lowLag.load('end.mp3'); lowLag.load('bigboom.mp3'); lowLag.load('smallboom.mp3'); frameRate(30); //stopChromesDamnDeleteButtonThing(); } boolean virgin = true; void mousePressed() { virgin = false; if (lives <= 0) { lives = 3; timeToNext = 200; timer = timeToNext; invaders = new ArrayList(); deads = new ArrayList(); killers = new ArrayList(); counter = 0; invader newinv = new invader(); invaders.add(newinv); } score = 0; } int score = 0; int lives = 0; void draw() { counter++; background(128); if (virgin) { fill(255); text("click to play", 10, 100); text("PHONEME INVADERS", 80, 150); text("type the word that is sounded out", 100, 200); text("before it destroys your planet", 100, 220); text("or whatever", 100, 240); } else { if(lives == 0){ text("click to play", 10, 100); text("PHONEME INVADERS", 80, 150); } } fill(0); text(gun, 10, 390); fill(255); for (invader inv : invaders) { if (lives > 0) { inv.move(); } inv.show(); if (inv.y > 375) { lives--; if(lives == 0) lowLag.play('end.mp3'); invadersToKill.add(inv); killers.add(inv); lowLag.play('bigboom.mp3'); } } invaders.removeAll(invadersToKill); invadersToKill.clear(); for (invader inv : killers) { fill(128, 0, 0); inv.killershow(); } fill(0); for (invader inv : deads) { inv.deadmove(); if (inv.y > 400) { deadsToKill.add(inv); } inv.show(); } deads.removeAll(deadsToKill); deadsToKill.clear(); timer--; if (timer == 0) { if (timeToNext > 50) { timeToNext-= 10; } timer = timeToNext; invaders.add(new invader()); } line(0, 350, 400, 350); text("score:"+score+" lives:"+lives, 200, 390); if (invaders.size() == 0) { invaders.add(new invader()); } } boolean tryToKill(String s) { boolean gotit = false; if (lives>0) { for (invader inv : invaders) { if (inv.word.equals(s)) { invadersToKill.add(inv); inv.kill(); deads.add(inv); //println("kill"); score++; lowLag.play('smallboom.mp3'); gotit = true; } else { //println(inv.word +" vs "+s); } } invaders.removeAll(invadersToKill); invadersToKill.clear(); } return gotit; } void doDeleteInGameThanksChrome(){ if (gun.length() > 0) { gun = gun.substring(0, gun.length()-1); } } void keyPressed() { if (keyCode == ENTER || keyCode == RETURN) { gun = ""; } if (keyCode == BACKSPACE || keyCode == DELETE) { if (gun.length() > 0) { gun = gun.substring(0, gun.length()-1); } return; } if (key >= 'a' && key <= 'z') { gun += str(key); lowLag.play('click.mp3'); } if (tryToKill(gun)){ gun = ""; } } class invader { String word; String[] parts; float x, y; float xs[]; float xp[]; float fat; float speed; invader() { String line = lines[int(random(linecount))] ; word = digWord(line); //println(word); parts = digParts(line); xp = new float[parts.length]; calcfat(); x = random(400 - fat); for (int i = 0; i < parts.length; i++) { xp[i] += x; } y = 0; speed = 1 + random(.3); } void move() { y += speed; } void calcfat() { fat = 0; for (int i = 0; i < parts.length; i++) { xp[i] = fat; fat += textWidth(parts[i])+5; } //println("fat is "+fat); } void killershow() { pushMatrix(); translate(x + (fat / 2),y); rotate(-PI/2); text(word, 0,0); popMatrix(); } void kill() { speed -= 1; xs = new float[parts.length]; for (int i = 0; i < parts.length; i++) { xs[i] = random(-.5, .5); } } void deadmove() { for (int i = 0; i < parts.length; i++) { xp[i] += xs[i]; } speed += .1; y += speed; } void show() { for (int i = 0; i < parts.length; i++) { text(parts[i], xp[i], y); } } String digWord(String full) { String[] tabsplit = full.split("\t"); return tabsplit[0]; } String [] digParts(String full) { String[] tabsplit = full.split("\t"); String[] spacesplit = tabsplit[1].split(" "); return spacesplit; } }