float horizon; float sunX,sunY; float moonX,moonY; float blobX,blobY; float x,y,z,w; float dx,dy; float dxleg,dyleg; // legs float heroX, heroY; float speed; ///// Hero float dark; //// night int cycle; ////// Day/Night float treeX, treeY; float b1X,b1Y,b1W,b1H; //Tree one,two,three; void setup(){ size(700,500); horizon = height/4; x=width/2; y=height/2; dx= +1; dy= 5; sunX = 0; cycle = 0; b1X = 650; b1Y = 480; b1H = 25; b1W =75 ; } void reset(){ sunX = 700; moonX = 0; } void draw(){ scene(); if (cycle == 0){ sun(); } if (cycle == 1){ dark(); moon(); } tower(); tree(); showbutton(); hero(); door(); //trees(); } void scene(){ background(50,100,200); ////sky fill(90,220,110); rectMode(CORNER); rect(0,horizon,width,height*.80); ///grass } void dark(){ background(25,25,130); ////sky fill(90,220,90); rectMode(CORNER); rect(0,horizon,width,height*.80); ///grass } void door(){ rectMode(CORNER); fill(102,42,10); rect(width/2,horizon-33,width/15,height/7); ////entrance } void tree(){ treeX=50; treeY = 100; noStroke(); fill(139,69,19); rect (treeX+25,treeY,10,30); fill(0,100,0); triangle(treeX,treeY,75,70,treeX+50,treeY); ///// tree top triangle(treeX,treeY-20,75,70-20,treeX+50,treeY-20); /////tree middle triangle(treeX,treeY-40,75,70-40,treeX+50,treeY-40); ////// tree bottom } void showbutton(){ fill(0); rect(b1X,b1Y,b1W,b1H); fill(255); text("restart",b1X-15,b1Y); } void tower(){ rectMode(CENTER); fill(150); //Tower color rect(width/2,horizon-45,width/5,height/3); //// Tower } void hero(){ rectMode(CORNER); stroke(1); fill(0,100,150); /// Heros body color rect( x+10,y-6, 25,40,8,8,0,0); //// Heros body fill(252 , 230 , 201); //face color ellipse(x+25,y-20,30,30); ///// heros head fill(255,100,100); //mouth color stroke(1); ellipse(x+25,y-10,10,5); //// Mouth fill(150,200,120); ellipse(x+30,y-20 ,6,5); /////---- Left Eye ellipse(x+15,y-20 ,6,5); /////---- Right Eye //x = x + dx/2; //y = y + dy/3; } void sun(){ sunY = 50; sunX= sunX+1; fill( 230,235,0 ); //// sun color ellipse( sunX, sunY, 40,40 ); /////sun size if (sunX >= 725 ){ /// Switch to night sunX=0; cycle = +1; } } void moon(){ moonY = 50; moonX = moonX + 1; fill (193,205,193); ////// Moon color ellipse( moonX, moonY, 40,40 ); fill(25,25,130); noStroke(); ellipse( moonX-15, moonY, 30,35 ); stroke(1); if (moonX >= 725 ){ ///// switch to Day moonX=0; cycle = 0; } } void keyPressed() { if(key == 'q'){ reset(); } if(key == 'w') { exit(); } }