String sounds[] = {"fx/Ping_01.mp3", "fx/Ping_02.mp3", "fx/Ping_03.mp3", "fx/Ping_04.mp3", "fx/Ping_05.mp3", "fx/Ping_06.mp3", "fx/Ping_07.mp3", "fx/Ping_08.mp3", "fx/Ping_09.mp3", "fx/Ping_10.mp3" }; Tree t = new Tree(125,24,300); boolean virgin = true; void setup(){ size(250,250); textSize(24); smooth(); textAlign(CENTER); lowLag.init(); for(int i = 0; i < sounds.length; i++){ lowLag.load(sounds[i]); } } Keepup o = new Keepup(); int highscore = 0; int score = 0; float scoreX;// = float scoreY; float scoreLive; void draw(){ background(200,255,200); o.move(); t.y = 150 - (o.y/ 2); t.draw(); o.draw(); fill(255); //text("HELLO",125,125); drawScore(); text("BEST:"+highscore,125,55 - (o.y/ 2)); } void drawScore(){ if(scoreLive > 50 || score == 0) return; text(score,scoreX,scoreY ); scoreLive += 3; } void mousePressed(){ virgin = false; o.hit(mouseX, mouseY); } class Keepup{ float sz = 50; float x = 125; float y = 225; float a = 0; float xs,ys,as; boolean hit(float mx, float my){ float d = dist(x,y,mx,my); if(d > sz/2) return false; score++; //play correspondoing sound int soundToPlay = score - 1; if(soundToPlay >= sounds.length) soundToPlay = sounds.length - 1; lowLag.play(sounds[soundToPlay]); if(score > highscore) highscore = score; scoreX = x; scoreY = y; scoreLive = 1; float ha = atan2(my-y,mx-x); // stroke(0); // line(125,125,125+100*cos(ha),125+100*sin(ha)); ha = ha/PI; ha += .5; if(ha > 0 && ha < 1){//cw as += d/200; } else { as -= d/200; } ys = -(my + sz/2 - y )/8; xs -= (mx - x)/8; return true; } void move(){ if(! virgin) ys += .1; x += xs; y += ys; a+=as; if(x250-o.sz/2){ x = 250-o.sz/2; xs *= -.8; as *= .5;} if(y>250-o.sz/2){ score = 0; y = 250-o.sz/2; ys *= -.8;;xs*=.99; as *= .5; //if(abs(ys) < .3) float ns = (as+xs/8)/2; //if(abs(ns)*4 < 3*abs(as)) as = ns ; } } void draw(){ pushMatrix(); translate(x,y); rotate(a); stroke(0); strokeWeight(2); noFill(); ellipse(0,-sz/4,sz/2,sz*1.1); strokeWeight(3); fill(170); rect(-sz/4,-sz/1.6,sz/2,sz/2); fill(230,100,0); ellipse(0,0,sz,sz); popMatrix(); //reflection noStroke(); fill(255,200); pushMatrix(); translate(x-sz/3,y-sz/3); rotate(PI/8); rect(0,0,sz/8,sz/8); translate(0,sz/5); triangle(0,0,sz/6,0,sz/6,sz/6); popMatrix(); } } class Ornament{ float x,y; color c; Ornament(float x, float y){ this.x = x; this.y = y; this.c = color(random(128,255),random(128,255),random(128,255)); } } class Tree { float x,y; float MINSIZE = width/10; float MAXSIZE = width / 5; float WIDTH,HEIGHT; float xs; ArrayList ornaments = new ArrayList(); //float stroke ; Tree(float x, float y, float basesize){ this.x = x; this.y = y; WIDTH = basesize * (.5 ); // basesize * random(.8,1.2); HEIGHT = basesize *( .5 ); ; //stroke = basesize / 5; xs = 4*(.1 + norm(getBottom(),0,250)); //int c = Math.round(random(3,8)); for(int i = 1; i <= 3; i++){ // addOrnament(i/4.0); } //addOrnament(4.0/5.0); } void addOrnament(float yper){ // triangle(x,y-HEIGHT*.5,x-.75*WIDTH,y+HEIGHT,x+.75*WIDTH,y+HEIGHT); //float yper = random(1); float oy = (-HEIGHT*.5) + (yper * (1.5 * HEIGHT)); float xper = random(-1,1); //xper = 1; float ox = xper * yper * .75 * WIDTH; ornaments.add(new Ornament(ox,oy)); } void draw(){ strokeWeight(10); stroke(128); doTrunk(); noStroke(); doTrunk(); stroke(128); doGreen(); noStroke(); doGreen(); } float getBottom(){ return y+HEIGHT*1.5; } void doTrunk(){ fill(150,75,25); rect(x -WIDTH*.075,y+HEIGHT*.5,WIDTH*.15,HEIGHT); } void doGreen(){ fill(100,200,100); //upper mytri(-HEIGHT*.5, 0, WIDTH*.35); //middle mytri(-HEIGHT*.35,HEIGHT*.5,WIDTH*.55); //lower mytri(-HEIGHT*.2,HEIGHT,-WIDTH*.75); } void mytri(float topOffset, float botOffset, float widthOffset){ triangle(x,y+topOffset,x - widthOffset,y+botOffset,x+widthOffset, y+botOffset); } }