//p1 //alex Dahlgren Project 123 5/5/15 float alexX, alexY; //hero float johnX, johnY; //monster float horizon; float goldX, goldY; float sunX, sunY; //sun placement float houseX, houseY; float bird1X, bird1Y, bird1DX=5; float birdW = 40, birdH = 10; float bomb1X, bomb1Y, bomb1DX, bomb1DY; float gravity = 9.81; float birdR = 250, birdG = 0, birdB = 250; int score = 0; void setup() { size( 640, 480); frameRate( 30 ); johnX = pmouseX; johnY = pmouseY; alexX = width*3/5; alexY = height*3/5; sunX = width*4/5; sunY = height/5; horizon = height/3; houseX = width*.5; houseY = horizon-20; score = 0; reset(); } void draw() { //new frame scene(); birdaction(); tree(); house(); john(); alex(); gold(); hit(); } void reset(){ alexX= random(0,width); alexY = random(0,height); johnX = random(0,width); johnY = random(0,height); goldX = random(0,width); goldY = random(horizon,height); bird1X = 0; bird1Y = 10; birdW = 20 * random(0.5,5); birdH = birdW/2; birdR = random(0,250); birdG = random(0,250); birdB = random(0,250); } void scene(){ background( 50, 200, 250); fill(200,0,00); textSize(10); text("John the monster chases the hero alex", 20,20); fill(200,0,0); textSize(10); text("Alex Dahlgren, project 123 5/5/15", 20,10); fill(0); text( "SCORE= " + score, horizon-50,40 ); fill(birdR, birdG, birdB); triangle(bird1X,birdH,bird1X,birdH+10,birdW+bird1X,birdH); if(bomb1Y > 0) { fill(random(60,250), 0,0); ellipse(bomb1X,bomb1Y,birdW/14,birdH); } sun(); //grass } void birdaction() { bird1X = bird1X + bird1DX; if(bird1X > width+40) reset(); if (bomb1Y > 0) { bomb1X = bomb1X + bomb1DX; bomb1Y = bomb1Y + bomb1DY; bomb1DY = bomb1DY + gravity; if (bomb1Y > height) { bomb1Y = 0;} } } void bombaction() { bomb1X = bird1X+10; bomb1Y = bird1Y; bomb1DX = bird1DX * .75; bomb1DY = 0; } void tree(){ //trees fill(137,107,7); noStroke(); rectMode(CENTER); ellipseMode(CENTER); int treeY = (height/3)-30; for(int treeX = 0; treeX < width; treeX += 120) { rect( treeX, treeY, 10,100); } for( int treeT = 0; treeT < width; treeT += 120) { fill(0,200,0); ellipse(treeT, horizon - 86, 20,20); } } void house() { float houseX, houseY; houseX=width*1/2; houseY=horizon-20; fill(0,0,120); noStroke(); rectMode(CENTER); rect(houseX, houseY, 40,50); fill(255,0,20); triangle( houseX-30, houseY-20, houseX+30, houseY-20, houseX, houseY-100); //aestetics fill(255,0,0); rect(houseX+10,houseY-10,10,10); rect(houseX-10,houseY-10,10,10); rect(houseX,houseY+15,5,10); //grass fill(0,250,0); rectMode(CORNER); rect(0,horizon, width, height*3/4); } void sun() { boolean day = true; sunX = sunX + 3; sunX = sunX % width+2; horizon = height/3; fill( 255, 240, 3); ellipseMode(CENTER); noStroke(); ellipse( sunX, sunY, 30,30); } void gold() { if (goldY > horizon) { fill(0,200,200); ellipse(goldX, goldY, 30,30); } } void mousePressed () { goldX = mouseX; goldY = mouseY; johnX = random(0,width); johnY = random(0,height); } void alex() { alexX = alexX + (goldX - alexX)/10; alexY = alexY + (goldY - alexY)/10; fill(0); noStroke(); rectMode(CENTER); rect(alexX,alexY, 20,40); ellipseMode(CENTER); fill(0); ellipse(alexX,alexY-30,20,20); //legs rect(alexX-5,alexY+25,5,20); rect(alexX+5,alexY+25,5,20); //arms rect(alexX+5,alexY-10,35,5); rect(alexX-5,alexY-10,35,5); } void john () { johnY = johnY