// Project #3: Sekai chases gold, yuki chases Sekai // // Thomas Kegney, CST 112, 2015 March 18 // float grass; float sunX = 50; float sunY = 10; float speedX = 1; float speedY = 0.2; float sekaiX; float sekaiY; float yukiX, yukiY, yukiDX = 4, yukiDY = 2; float goldX=200,goldY=200; float houseX=100,houseY=300; float near= 20; float score = 0; float space = 150; float treeX=20; float treeY = grass +10; float birdX,birdY; void setup () { // Setup: window size, etc. // size (1000, 1000); grass = height/4; treeY = grass +10; yukiX = 500; } void reset() { //// Move yuki & hero yukiX=500; sekaiX= houseX; sekaiY= houseY; goldX= random( 0,width ); goldY= random( 0,height ); houseX= random( 100, width-100 ); houseY= grass; } void draw () { // scene and charcter setup // scene(); bird(); Sekai(); yuki(); tree(); house(); gold(); textSize(24); fill(0); text ( score, 20, 20); } void bird () { } void gold() { fill (255,200,0); ellipse ( goldX,goldY,30,30); if (goldY < grass) { goldY =grass; } } void scene() { // Scene: sky, sun, grass. // background (200, 200, 255 ); // sky // fill (255, 255, 0); sunX= sunX + speedX; sunY= sunY + speedY; while (sunX > width) { ellipse ( sunX,sunY, 50, 50 ); sunX=0; } while (sunY > grass) { ellipse ( sunX,sunY, 50, 50 ); sunY=0; } ellipse ( sunX,sunY, 50, 50 ); // sun rectMode (CORNER); fill ( 150, 255, 0); rect (0, grass, width, height-grass); // grass } /** Move & draw hero */ void Sekai () { // Move fill(0); // text( int(sekaiX), 20,20 ); text( int(sekaiY), 20,40 ); sekaiX= sekaiX + (goldX-sekaiX)/30; sekaiY= sekaiY + (goldY-sekaiY)/30; //// Display him rectMode (CORNER); fill (255,0,0); rect ( sekaiX, sekaiY, 100, 100); // body ellipse (sekaiX+50, sekaiY-30, 50, 50);// head rect (sekaiX-30, sekaiY+30,70,50); // left arm rect (sekaiX+60, sekaiY+30,70,50); //// Check if hero gets gold. if ( dist( sekaiX,sekaiY, goldX,goldY ) < 100/2 ) { score += 50; reset(); } } void yuki () { fill (0); rectMode (CORNER); fill (0); rect ( yukiX, yukiY, 150, 150); // body ellipse (yukiX+50, yukiY-30, 100, 100);// head rect (yukiX-30, yukiY+30,70,70); // left arm rect (yukiX+60, yukiY+30,70,70); yukiX += (sekaiX-yukiX) / 50; if (yukiX>width) yukiDX = -yukiDX; if (yukiX<0) yukiDX = -yukiDX; yukiY += (sekaiY-yukiY) / 30; // yuki hits sekai if ( dist( yukiX,yukiY, sekaiX,sekaiY ) < 100/3 ) { text (int(score += score - 100), 20, 20); reset(); } } void house () { // build house fill (255,0,0); triangle ( houseX, houseY, houseX+50, houseY-30, houseX+100, houseY); fill (0,0,255); rect ( houseX, houseY, 100, 50); } void tree () { //// DRAW MANY TREES, across the horizon treeX= 20; float treeW=50; while (treeX < width) { fill(150,55,0); rect (treeX,treeY, treeW, -100); fill(0,155,0); ellipse( treeX+treeW/2, treeY-100, treeW*2,treeW*1.5 ); treeX += space; } } void keyPressed() { // click q to quit if (key == 'q') exit(); } void mousePressed() { //// Click to place gold. goldX= mouseX; goldY= mouseY; }