prom p = new prom(); bird b = new bird(); int rockscore = 0; int yourscore = 0; float showVictory = -200; HashSet noms = new HashSet(); void setup(){ frameRate(60); size(150,150); smooth(); textFont(loadFont("Arial-Black-12.vlw"),12); p.x = 75; p.y = 75; } void draw() { background(0,0,128); stroke(0); strokeWeight(2); fill(0,128,0); rectMode(CORNER); rect(0,100,150,75); fill(128,0,0); text("liver:", 10,140); noStroke(); p.drawbar(); stroke(0); strokeWeight(2); fill(128); ellipse(75,75,100,100); p.move(); p.heal(); p.draw(); Iterator i = noms.iterator(); while(i.hasNext()){ nom n= (nom)i.next(); if(n.draw()){ i.remove(); } } b.move(); b.draw(); if(showVictory >= -300){ fill(200+(5*(showVictory % 10))); text("EAGLE VICTORY!",showVictory,75); showVictory --; } } void mousePressed() { if(mouseX > (p.x - (p.sz/2)) && mouseX < (p.x + (p.sz/2)) && mouseY > (p.y - (p.sz/2)) && mouseY < (p.y + (p.sz/2))){ p.held = true; p.offx = mouseX - p.x; p.offy = mouseY - p.y; } } void mouseDragged(){ if(p.held){ p.x = mouseX - p.offx; p.y = mouseY - p.offy; } } void mouseReleased(){ p.held = false; } class prom{ boolean held; float x,y,sz,offx,offy,xs,ys; float liver=100; float bloody; prom(){ sz = 30; } void draw(){ stroke(0); strokeWeight(2); fill(128,128,0); rectMode(CENTER); line(50,50,x - (sz/2) , y - (sz/2)); line(100,50,x +(sz/2) , y - (sz/2)); line(50,100,x - (sz/2) , y + (sz/2)); line(100,100,x +(sz/2) , y + (sz/2)); rect(x,y,sz,sz); noStroke(); fill(128,0,0,bloody); rect(x,y,5,5); } void bite(){ liver -= 30; bloody = 255; } void heal(){ if(liver <= 0){ bloody -= .6; if(bloody <= 0){ liver = 100; b.wait = 200; } } } void move(){ if(!held){ if(x < 75){ xs += .4; } else { if(x > 76) { xs -= .4; } } if(y < 74){ ys += .4; } else { if(y > 76){ ys -= .4; } } xs *= .9; ys *= .9; x += xs; y += ys; } else { xs =0; ys = 0; } } void drawbar(){ if(liver > 0){ rect(43,132,liver,8); } } } class bird{ float x = 75; float y = 10; float down = 5; float w = 12; float wdir = 1; int wait; int mode; int SEEK = 1; int HOVER = 2; int EAT = 3; int dir = 1; bird(){ mode = HOVER; wait = 200; } void move(){ down += wdir; if(down > 10){ wdir = -2; } if(down < 0){ wdir = 2; } if(mode == SEEK){ if(x < p.x){ x++; } else { x--; } if(y < p.y){ y++; } else { y--; } if(abs(x - p.x) <= 1 && abs(y - p.y) <= 1){ if(random(25) < 1){ noms.add(new nom(x,y)); p.bite(); } } if(p.liver <= 0){ mode = HOVER; showVictory = 150; } }//end mode == SEEK if(mode == HOVER){ if(x > 140){ dir = -1; } if(x < 10){ dir = 1; } if(y < 10) { y++; } if(y > 10) { y--; } x += dir; wait--; if(wait <= 0 && p.liver > 0){ mode = SEEK; } } //end mode == HOVER } void draw(){ stroke(255); line(x-w, y+down,x,y); line(x+w, y+down,x,y); } } class nom{ float x,y,bright; nom(float px, float py){ x = px; y = py; bright=255; } boolean draw() { fill(255,255,255,bright); text("nom",x,y); y -= .2; bright-= 5; return !(bright > 0); } }