float y; float x = 0.0; float speed = 2.0; float y; float x = 0.0; float speed = 2.0; float s = x; float t = x; float a,b; float c,d; float e,f; float g; void setup(){ size(500,500); noStroke(); rectMode(CORNER); fill(185,240,255); rect(0,0,500,345);//空(青) rectMode(CORNER); fill(33,232,100); rect(0,345,500,155);//地面(緑) fill(0); text("汽車を連結してください。画面をクリックしてから、キー「1」「2」「3」を長押しすると2両目以降が出てきて連結できます。最後の車両が連結されると出発します。", 80,420,320,100); a = -40; b = 50; c = -280; d = 100; e = -30; f = 60; g = -20; y = 310; x = 500; s = 500; t = 500; } void draw(){ if (t == 435) { noStroke(); rectMode(CORNER); fill(33,232,100); rect(0,355,500,145);//地面(緑) fill(185,240,255); rectMode(CORNER); rect(0,0,500,200); a += 1; if (a > width+40) { a = -40; b = random(width - 350); } cloud1(a,b); c += 1; if (c > width+40) { c = -40; d = random(width - 350); } cloud2(c,d); e += 0.5; if (e > width+40) e = -30; husen(e,f); g += 1; fill(124,40,40); noStroke(); rectMode(CORNER); rect(g,345,20,10); } stroke(1); fill(255); rectMode(CENTER);//↓1両目 fill(255,152,152); rect(80,300,120,60); rect(80+30,300-50,60,40); fill(222,254,255); rect(80+30,300-45,40,30);//まど fill(255,152,152); rect(80+30,300-75,70,10);//上の平たいやつ rect(80-30,300-45,25,30);//煙突 fill(0); ellipse(80+30,300+30,30,30); ellipse(80-30,300+30,30,30); fill(110,110,110); ellipse(80+30,300+30,15,15); ellipse(80-30,300+30,15,15); fill(0); rect(80+64,300+15,7.5,2);//↑1両目 if (x <= 205) { train1(205,y); } if (s <= 320) { train2(320,y); } if (t <= 435) { train3(435,y); } } void keyPressed(){ noStroke(); fill(185,240,255); rect(328,305,360,80); stroke(1); if ((keyPressed == true) && (key == '1')) { train1(x,y);//2両目 x -= speed; if (x <= 205) { x = 205; noStroke(); fill(185,240,255); rect(385,305,230,80); stroke(1); } } if ((keyPressed == true) && (key == '2')) { train2(s,y);//3両目 s -= speed; train1(205,y); if (s <= 320) { s = 320; noStroke(); fill(185,240,255); rect(435,305,100,80); stroke(1); } } if ((keyPressed == true) && (key == '3')) { train3(t,y);//4両目 t -= speed; train1(205,y); train2(320,y); if (t <= 435) { t = 435; noStroke(); fill(185,240,255); rect(500,305,20,80); stroke(1); } } } void train1 (float x, float y) { rectMode(CENTER);//2両目 fill(255,255,152); rect(x,y,100,50); fill(222,254,255); rect(x,y-10,20,20); rect(x+30,y-10,20,20); rect(x-30,y-10,20,20); fill(0); ellipse(x+25,y+25,20,20); ellipse(x-25,y+25,20,20); fill(110,110,110); ellipse(x+25,y+25,10,10); ellipse(x-25,y+25,10,10); fill(0); rect(x-53,y+5,7.5,2); rect(x+54,y+5,7.5,2); } void train2 (float s, float y) { rectMode(CENTER);//3両目 fill(152,255,152); rect(s,y,100,50); fill(222,254,255); rect(s,y-10,20,20); rect(s+30,y-10,20,20); rect(s-30,y-10,20,20); fill(0); ellipse(s+25,y+25,20,20); ellipse(s-25,y+25,20,20); fill(110,110,110); ellipse(s+25,y+25,10,10); ellipse(s-25,y+25,10,10); fill(0); rect(s-53,y+5,7.5,2); rect(s+54,y+5,7.5,2); } void train3 (float t, float y) { rectMode(CENTER);//4両目 fill(152,152,255); rect(t,y,100,50); fill(222,254,255); rect(t,y-10,20,20); rect(t+30,y-10,20,20); rect(t-30,y-10,20,20); fill(0); ellipse(t+25,y+25,20,20); ellipse(t-25,y+25,20,20); fill(110,110,110); ellipse(t+25,y+25,10,10); ellipse(t-25,y+25,10,10); fill(0); rect(t-53,y+5,7.5,2); } void cloud1 (float a, float b) { fill(255); noStroke(); ellipse(a-10,b+10,30,30); ellipse(a+10,b+10,30,30); ellipse(a-10,b-10,30,30); ellipse(a+10,b-10,30,30); ellipse(a-25,b,30,30); ellipse(a+25,b,30,30); } void cloud2 (float c, float d) { fill(255); noStroke(); ellipse(c-10,d+10,30,30); ellipse(c+10,d+10,30,30); ellipse(c-10,d-10,30,30); ellipse(c+10,d-10,30,30); ellipse(c-25,d,30,30); ellipse(c+25,d,30,30); } void husen (float e, float f) { fill(255,50,50); noStroke(); ellipse(e,f,40,50); rectMode(CENTER); rect(e,f+25,20,10); stroke(2); line(e,f+30,e-10,f+70); }