void setup(){ size(500,500); smooth(); textSize(20); } boolean virgin = true; boolean gamePlaying = false; void keyPressed(){ if(key == ' '){ wave = 0; virgin = false; gamePlaying = true; balls = new HashSet(); } } HashSetballs = new HashSet(); Ring r = new Ring(5); boolean hitting; int wave = 0; void draw(){ /*if(hitting){ background(200); } else { background(0); }*/ background(50); if(balls.size() == 0){ wave++; for(int i = 0; i < wave; i++){ balls.add(new Ball()); } } ArrayList ballsToKill = new ArrayList(); hitting = false; for(Ball b : balls){ if(gamePlaying) b.move(); if(b.check()){ ballsToKill.add(b); } b.draw(); } balls.removeAll(ballsToKill); r.draw(mouseX,mouseY); fill(255); textAlign(CENTER); if(! gamePlaying){ if(! virgin){ text("You made it to Wave "+wave+"!",250,100); } text("DRAGGIN' BALLZ\n\nDEVOUR SPHERES WITH YOUR\nRAVENOUS MOUTH ONLY\n\nDO NOT LET SPHERES TOUCH BODY\n\nHOLD MOUSE TO REVERSE ROTATION\n\nSPACE TO START",250,150); } else { text("Wave "+wave,250,480); } } float ACC = .1; class Ball{ float x,y,xs,ys; float sz = 25; Ball(){ float a = random(PI*2); x = 250+cos(a)* 400; y = 250+sin(a)* 400; } boolean check(){ if(! gamePlaying) return false; Ring ptr = r; while(ptr != null){ if(dist(x,y,ptr.x,ptr.y) < (ptr.sz + sz)/2){ if(! ptr.isHead){ gamePlaying = false; return false; } return true; //hitting = true; } ptr = ptr.kid; } return false; } void move(){ if(x < mouseX) xs += ACC; if(x > mouseX) xs -= ACC; if(y < mouseY) ys += ACC; if(y > mouseY) ys -= ACC; x += xs; y += ys; xs *= .95; ys *= .95; } void draw(){ stroke(20,20,80); fill(80,80,250); strokeWeight(2); ellipse(x,y,sz,sz); } } color GREEN = color(40,160,40); color DARKGREEN = color(20,80,20); class Ring { float sz = 40; float a = 0; float rot = random(-.04,.04); boolean isHead = false; Ring kid = null; Ring(int kids){ if(kids == 0) isHead = true; else kid = new Ring(kids-1); } float x,y; void draw(float px,float py){ x = px; y = py; if(gamePlaying | virgin){ if(mousePressed) a -= rot; else a += rot; } strokeWeight(2); stroke(DARKGREEN); fill(GREEN); ellipse(x,y,sz,sz); if(kid != null){ float kidx = x+cos(a) * sz; float kidy = y+sin(a) * sz; kid.draw(kidx,kidy); } if(isHead){ stroke(100,0,0); fill(50,0,0); ellipse(x,y,sz*cos(a),sz*sin(a) ); } } }