Modify a text file: $/project2-2.java
$/project2-2.java
//// Project 2.2 -- add scene and text; move objectts // Draw & move hero, gold, bird. float heroX, heroY; // Position of hero, etc. float heroheadX, heroheadY; float goldX, goldY; float birdX=50, birdY=50; float monsterX=200,monsterY=100; float horizon; int score=0; void setup() { //// Initialization //// size( 640, 480 ); horizon= height/4; heroX= width/2; // Start hero in center of screen heroY= height/2; goldX= width-50; // Gold at lower-right corner. goldY= height-50; } void draw() { // Next frame. scene(); action(); } void action() { // Move & draw all creatures, etc. gold(); bird(); monster(); hero(); } void mousePressed() { //// Event handler for mouse click. goldX= mouseX; goldY= mouseY; background( 255, 255, 0 ); // Flash! score= score + 1; } void gold() { //// Draw gold. fill( 255, 150, random(150) ); stroke( 200+random(50), random(150), random(100) ); strokeWeight( random(3) ); ellipse( goldX, goldY, 20, 20 ); // Reset. stroke(0); strokeWeight( 1 ); fill( 255 ); } void hero() { // move & draw hero // Move toward gold. heroX= heroX + (goldX-heroX)/60; heroY= heroY + (goldY-heroY)/60; // Draw hero fill( 255, 255, 0 ); rectMode( CENTER ); rect( heroX, heroY, 50, 80 ); // Head. heroheadX= heroX; heroheadY= heroY - 80/2 -36/2; fill( 255, 200, 150 ); ellipse( heroheadX, heroheadY, 30, 36 ); // + eyes eyes(); } void eyes() { // Draw eyes // fill( 255, 255, 255 ); ellipse( heroheadX-10, heroheadY, 10, 10 ); // Left ellipse( heroheadX+10, heroheadY, 10, 10 ); // Right fill( 0, 0, 255 ); ellipse( heroheadX-10, heroheadY, 5, 5 ); // Left pupil ellipse( heroheadX+10, heroheadY, 5, 5 ); // Right } void bird() { // Move & draw bird. birdX= birdX + 3; birdX= birdX % width; birdY= birdY + 2 - random(1); birdY= birdY % horizon; fill(0, 0, 255); triangle( birdX, birdY, birdX-40, birdY-20, birdX-40, birdY+20 ); } void scene() { //// sky, etc. background( 150, 200, 255 ); // sky fill( 100, 255, 100 ); // grass rectMode( CORNERS ); rect( 0, horizon, width, height ); // Messages. notes(); // barn. fill( 255, 50, 50 ); float barnX=width*2/3; float barnY= horizon-25; rectMode(CENTER); rect( barnX, barnY, 40, 50 ); // barn triangle( barnX-20,barnY-25, barnX+20,barnY-25, barnX,barnY-45 ); //++++ add sun, clouds, etc. } void notes() { //// Messages on screen fill(0); text( "G O L D R U S H", 200, 30 ); text( "(click to move gold)", 200, 50 ); text( score, width-100, 60 ); text( "Author's name", 20, height-20 ); } void monster() { //// Draw & move ugly monster //+++++ }