import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; //TODO: //score //sounds //death //pre/post screen //code liberally stolen from http://processing.org/learning/topics/follow3.html //so thanks Keith Peters float SNAKEHEADSIZE = 18; float DUDESIZE = 5; float APPLESIZE = 10; float segx[] = new float[15]; float segy[] = new float[15]; float segLength = 9; float dudeChance = 0; float dudeSpeedRange = 2; HashSet dudes = new HashSet(); HashSet apples = new HashSet(); int TITLE=0; int PLAY=1; int DEAD=2; boolean applesgone = false; AudioSnippet hooray; AudioSnippet chomp[] = new AudioSnippet[5]; int gamerun = TITLE; int score; void setup() { size(200, 200); Minim.start(this); textFont(loadFont("BlackadderITC-Regular-30.vlw"),30); textAlign(CENTER); smooth(); strokeWeight(5); ellipseMode(CENTER); hooray = Minim.loadSnippet("hooray.mp3"); for(int i = 0; i < chomp.length; i++){ chomp[i] = Minim.loadSnippet(i+".mp3"); } } void mouseClicked(){ if(gamerun == TITLE || gamerun == DEAD){ startGame(); } } void stop() { hooray.close(); for(int i = 0; i < chomp.length; i++){ chomp[i].close(); } super.stop(); } void startGame(){ dudeChance = 40; dudes.clear(); apples.clear(); apples.add(new apple(100,70,0,-1)); apples.add(new apple(70,130,-.5,.5)); apples.add(new apple(130,130,.5,.5)); addDude(); gamerun = 1; score = 0; applesgone = false; } float mx,my; void draw() { if(gamerun == TITLE){ fill(0); text("DRAGGIN",100,40); text("save thine apples",100,80); text("and thy ass",100,110); text("from yon villagers",100,140); text("(clickest to play)",100,180); return; } if(dudes.size()==0||random(40)< 1){ addDude(); if(dudeChance > 5){ dudeChance -= .1; } dudeSpeedRange += .01; } if(gamerun != DEAD){ mx = mouseX; my = mouseY; } background(226); if(gamerun != DEAD){ stroke(0,128,0, 100); fill(0,128,0, 100); } else { stroke(0,20,0, 100); fill(0,40,0, 100); } dragSegment(0, mx, my); for(int i=0; i 100){ lateralSpeed *= -1; } float x=0,y=0, xs=0,ys=0; int r = int(random(4)); if(r == 0){ //leftwall x = -5; y = posOnWall; xs = mainSpeed; ys = lateralSpeed; } if(r == 1){ //rightwall x = 200+5; y = posOnWall; xs = -1*mainSpeed; ys = lateralSpeed; } if(r == 2){ //topwall x = posOnWall; y = -5; xs = lateralSpeed; ys = mainSpeed; } if(r == 3){ //topwall x = posOnWall; y = 200+5; xs = lateralSpeed; ys = -1* mainSpeed; } dude d = new dude(x,y,xs,ys,int(random(2))); //make sure guy isn't going for offscreen apple if(d.targetapple != null && farOffscreen(d.targetapple.x,d.targetapple.y,30)){ d.mode = MODEFIGHT; } if(d.mode == MODEFIGHT){ //target is a random segment on dragon d.dragontarget = int(random(segx.length)); } dudes.add(d); } boolean farOffscreen(float x, float y, float far){ if (x < -far || x > 200+far || y < -far || y > 200+far){ return true; } return false; } class apple{ dude carrier = null; boolean offscreen = false; float offsetx, offsety; float x,y; float gox,goy; apple(float px,float py, float pgox, float pgoy){ x = px; y = py; gox = pgox; goy = pgoy; } void draw(){ stroke(255,0,0, 100); fill(255,0,0, 100); ellipse(x,y,APPLESIZE,APPLESIZE) ; stroke(0,255,0,100); line(x+1,y-APPLESIZE,x+1,y-APPLESIZE); } }