//// GLOBAL DATA //// Will Johnson Project 1 int birdX=100, birdY=100; int birdDX=10; int sunX=100, sunY=100; int guyX=100, guyY=300, guyDX=10, guyDY=5; int dogX=100, dogY=200; float bombX=0, bombY=0, bombDY=0; float gravity= 0.5 * 9.81 / frameRate; boolean eastbound=true; int speed; void setup() { size( 800, 600 ); smooth(); //-- frameRate(5); speed= (int) frameRate; } void draw() { //// Move and show everything // scene(); guy(); dog(); bird(); } void scene() { //// Sky, sun, grass. background( 150, 200, 255 ); // Sky //// Move the sun. sunX = (sunX+1) % width; float xw= (float) sunX / width; sunY = (int) ( 150 - 100*sin( PI*xw ) ); float arc= (float) sin( PI * sunX / width ); sunY = (int) ( 150 - 100*arc ); //-- text( "@@@ sun: "+sunX+","+sunY, sunX, sunY+50 ); //-- text( "@@@ xw: "+xw, sunX, sunY+70 ); float sinyy= sin( PI*( xw ) ); //-- text( "@@@ sin(PI*x/w): "+sinyy, sunX, sunY+90 ); //// Draw the sun. fill( 255, 254, 1 ); // Sun ellipse( sunX, sunY, 40, 40 ); //// Grass fill( 100, 255, 100 ); rectMode( CORNERS); rect( 0, height/3, width, height ); fill( 0 ); text( "Will Johnson CST 112 Project 1", 50, height-20 ); text( "Click for drop.", width-100, 50 ); } void guy() { //// Guy follows mouse. //-- guyX=mouseX; guyY=mouseY; guyX= guyX + guyDX; guyY= guyY + guyDY; fill( 0,255,0 ); // Green shirt rectMode( CENTER ); rect( guyX, guyY, 60, 80 ); fill(255,0,0); rect(guyX+10, guyY+60, 25,35); rect(guyX-20, guyY+60, 25,35); rectMode( CENTER); fill( 0, 200, 200 ); // Cyan face ellipseMode( CENTER ); ellipse( guyX, guyY-40-15, 30,30 ); //// Eye. fill(255,255,255); if (eastbound) { ellipse( guyX+10, guyY-40-20, 5,5 ); } else { ellipse( guyX-10, guyY-40-20, 5,5 ); } } void dog() { if (pmouseX < dogX) eastbound=true; else if (dogX > dogX) eastbound=false; else {} // No change if = fill( 250, 150, 150 ); rectMode( CORNER ); //// Dog chases guy. //dog is on the right if ( ! eastbound){ int dogX=guyDX-50; int dogY=guyDY+100; dogX = dogX + 5*( dogX-dogX ); dogY = dogY + 2*( dogY-dogY ); rect( dogX+80, dogY, 40, 20 ); rect( dogX+70, dogY-10, 20, 10 ); rect(dogX+110,dogY+20,10,5); rect(dogX+90,dogY+20,10,5); } //dog is on the left else { int dogX=guyDX-70; int dogY=guyY+100; dogX = dogX + 5*( guyDX-guyX ); dogY = dogY + 2*( guyDY-guyY ); rect( dogX, dogY, 40, 20 ); rect( dogX+30, dogY-10, 20, 10 ); rect(dogX+30,dogY+20,10,5); rect(dogX+10,dogY+20,10,5); } } void bird() { //// Bird flies across screen. (Press key to drop) birdX = birdX + birdDX; birdX = birdX % width; birdY = birdY + 10 - (int) random( 20 ); fill( 200, 100, 200, 150 ); triangle( birdX,birdY, birdX-50,birdY-15, birdX-50,birdY+15 ); if (birdY >150){ birdY = birdY - 5; } else if (birdY <-200){ birdY= birdY - 10; } //// bomb is falling from bird. if (bombX > 0) { bombX= birdX - 5; bombDY= bombDY + gravity; bombY += bombDY; if (bombY > height) { //// Bomb vanishes at bottom background(255); } fill(150,100,100 ); ellipseMode( CENTER ); triangle( bombX-12,bombY-15, bombX+12,bombY-15, bombX,bombY+15 ); // Fins fill( 70, 0, 70 ); ellipse( bombX, bombY, 16, 30 ); } } void bomb() { //// Bomb falls with gravity. No bomb if zero. } void mousePressed() { //// Drop bomb, when mouse is pressed. bombX = birdX; bombY = birdY; bombDY= 0; background(0); } void keyPressed() { if (key == 's') { speed -= 5; if (speed<1) speed= 30; frameRate( speed ); } }