boolean gamePlaying = false; boolean gameTitle = true; eggclass egg; int SCREENSIZE = 400; HashSet sperms = new HashSet(); int score = 0; void setup(){ size(400,400); ellipseMode(CENTER_RADIUS); textFont(loadFont("Arial-Black-14.vlw"),14); egg = new eggclass(); framerate(60); } boolean freeze = false; void keyPressed(){ // freeze = true; } void mouseReleased(){ if(! gamePlaying){ gamePlaying = true; gameTitle = false; sperms.clear(); addSperm(); score = 1; } else { score++; addSperm(); } } void draw(){ background(180,40,40); if(gamePlaying){ Iterator i = sperms.iterator(); while(i.hasNext()){ spermclass sperm = (spermclass)i.next(); if(! freeze){sperm.move();} } } // end if(gamePlaying) egg.draw(); Iterator i = sperms.iterator(); while(i.hasNext()){ spermclass sperm = (spermclass)i.next(); sperm.draw(); if(sperm.hit(egg)){ gamePlaying = false; gameTitle = false; } } fill(255); textAlign(CENTER); if(!gameTitle) { text("score: "+score,200,20);} if((! gamePlaying) ){ if(! gameTitle){ text("OH NOES!",200,100); text("YOUR PREGGERS!!!!!!",200,150); text("SEMEN HAS MILLIONS OF SPERMS!!!",200,200); text("remember sometimes the only way to win",200,250); text("is not to play!!!!!!!",200,300); text("~o ~o ~o click to try again o~ o~ o~",200,350); } else { text("~o ~o ~o look out! o~ o~ o~",200,100); text("you are a precious egg cell!",200,150); text("try not to get PREGGERS!!!!!",200,200); text("click to start and look out for SPERMS!!!",200,250); text("then click to add more SPERMS!!!",200,300); } } } //--------------------------------add sperm void addSperm(){ float x,y; x = mouseX; y = mouseY; while(abs(mouseX - x ) < 80 ||abs(mouseY - y ) < 80){ if( int(random(2)) == 0){ if( int(random(2)) ==0){ x = -20; } else { x = SCREENSIZE + 20; } y = random(SCREENSIZE - 30)+ 30; } else { if( int(random(2)) ==0){ y = -20; } else { y = SCREENSIZE + 20; } x = random(SCREENSIZE - 30)+ 30; } } sperms.add( new spermclass(x,y)); } //--------------------------------EGG CLASS class eggclass{ public float x,y; void draw(){ if(gamePlaying || gameTitle){ x = mouseX; y = mouseY ; } stroke(0); fill(0); ellipse(x,y,5,5); noFill(); ellipse(x,y,10,10); } eggclass(){ } } //--------------------------------SPERM CLASS class spermclass{ float xs, ys, x, y; float tailx[] = new float[100] ; float taily[] = new float[100]; float accel = .05; int tailsize = 20; spermclass(float px, float py){ x = px; y = py; for(int i = 0; i < tailsize; i++){ tailx[i] = x; taily[i] = y; } } void move(){ for(int i = tailsize-1; i > 0; i--){ tailx[i] = tailx[i-1]; taily[i] = taily[i-1]; } tailx[0] = x; taily[0] = y; if(x < mouseX) { xs += accel; } else { xs -= accel; } if(y < mouseY) ys += accel; else ys -= accel; xs *= .99; ys *= .99; x += xs; y += ys; } void draw(){ stroke(0); for(int i = 1; i < tailsize; i++){ line(tailx[i],taily[i],tailx[i-1],taily[i-1]); } fill(0); ellipse(x,y,3,3); } boolean hit(eggclass egg){ if(sqrt( ((x - egg.x) *(x - egg.x) ) + ((y - egg.y) *(y - egg.y) ) ) < 13 ){ return true; } return false; } }