float x; float y; float a; float b; float c; float d; float e; float f; float g; float h; float i; float j; float k; float l; float m; float n; float o; float p; float r1; float r2; float r3; int hikou = 0; int timer=millis(); PFont myFont; void setup(){ size(500,500); frameRate(60); x=width/2; y=height/2; a=width; b=height/2; c=width-300; d=height/3; e=width+100; f=height/4; g=width+200; h=height/5; i=width+300; j=height/6; k=width-200; l=height/7; m=width/3; n=height/4; o=width+100; p=height-100; r1=100; r2=50; r3=80; } void draw(){ background(45,180,250); if(hikou== 0){ noStroke(); kumo1(m,n); kumo2(o,p); myFont=createFont("メイリオ",20); textFont(myFont); textSize(30); fill(255); text("Click to start!",160,390); x=width/2; y=height/2; a=480; b=height/2; m=width/3; n=height/4; o=width+100; p=height-100; timer=0; if(mousePressed == true){ //初めにクリックしたとき hikou = 1; y-=2; timer+=1000; } }else if(mousePressed){ //気球が浮く y-=2; }else{ y+=1; } if(y>height-80){ //下画面外に出ない y=height-80; } if(y<50){ y=50; } m-=0.3; //雲1が右から if(m < -100){ m = width+100; n = random(height/2); } noStroke(); kumo1(m,n); o-=0.3; //雲2が右から if(o < -100){ o = width+100; p = random(height/2,height); } kumo2(o,p); stroke(0); kikyuu(x,y); smooth(); a-=1; //障害物1が右から if(a < 0){ a = width+10; b = random(height); } bird1(a,b); timer+=17; if(timer<15000){ //10m超えたら鳥追加 c=-50; }else{ c-=1; //障害物2 if(c < 0){ c = width+10; d = random(height/2); //この範囲で } } bird2(c,d); if(timer<20000){ e=-50; }else{ e-=1; //障害物3 if(e < 0){ e = width+10; f = random(height/2,height); //この範囲で } } bird3(e,f); if(timer<25000){ g=-50; }else{ g-=1; //障害物4 if(g < 0){ g = width+10; h = random(height/2,height); //この範囲で } } bird4(g,h); if(timer<30000){ i=-50; }else{ i-=1; //障害物5 if(i < 0){ i = width+10; j = random(height/2); //この範囲で } } bird5(i,j); if(timer<40000){ k=-50; }else{ k-=1; //障害物6 if(k < 0){ k = width+10; l = random(height); //この範囲で } } bird6(k,l); textSize(50); fill(38,38,38); text(nf(timer/1000, 1)+" m",30,50);//スコア textSize(22); //右下の文字 fill(38,38,38,80); text("Keep clicking:UP",300,450); text("Avoid bird!",345,480); if(dist(x,y,a,b)<=r3){ //1の敵に当たるとゲームオーバー background(38,96,173); textSize(60); fill(218,225,33); text("GAME OVER",80,height/4); textSize(50); fill(255,255,255); text(nf(timer/1000, 1)+" m",190,200); kikyuu(250,300); textSize(30); fill(255,255,255); text("Press ENTER Key",130,450); noLoop(); } if(dist(x,y,c,d)<=r3){ //2の敵に当たるとゲームオーバー background(38,96,173); textSize(60); fill(218,225,33); text("GAME OVER",80,height/4); textSize(50); fill(255,255,255); text(nf(timer/1000, 1)+" m",190,200); kikyuu(250,300); textSize(30); fill(255,255,255); text("Press ENTER Key",130,450); noLoop(); } if(dist(x,y,e,f)<=r3){ //3の敵に当たるとゲームオーバー background(38,96,173); textSize(60); fill(218,225,33); text("GAME OVER",80,height/4); textSize(50); fill(255,255,255); text(nf(timer/1000, 1)+" m",190,200); kikyuu(250,300); textSize(30); fill(255,255,255); text("Press ENTER Key",130,450); noLoop(); } if(dist(x,y,g,h)<=r3){ //4の敵に当たるとゲームオーバー background(38,96,173); textSize(60); fill(218,225,33); text("GAME OVER",80,height/4); textSize(50); fill(255,255,255); text(nf(timer/1000, 1)+" m",190,200); kikyuu(250,300); textSize(30); fill(255,255,255); text("Press ENTER Key",130,450); noLoop(); } if(dist(x,y,i,j)<=r3){ //5の敵に当たるとゲームオーバー background(38,96,173); textSize(60); fill(218,225,33); text("GAME OVER",80,height/4); textSize(50); fill(255,255,255); text(nf(timer/1000, 1)+" m",190,200); kikyuu(250,300); textSize(30); fill(255,255,255); text("Press ENTER Key",130,450); noLoop(); } if(dist(x,y,k,l)<=r3){ //6の敵に当たるとゲームオーバー background(38,96,173); textSize(60); fill(218,225,33); text("GAME OVER",80,height/4); textSize(50); fill(255,255,255); text(nf(timer/1000, 1)+" m",190,200); kikyuu(250,300); textSize(30); fill(255,255,255); text("Press ENTER Key",130,450); noLoop(); } } void keyPressed(){ //ENTERキーを押すとスタートに戻る if(key==ENTER){ hikou=0; loop(); } } void kikyuu(float x,float y){ line(x-20,y,x-10,y+60);//左 line(x,y,x,y+60);//真ん中 line(x+20,y,x+10,y+60);//右 fill(251,231,49); ellipse(x,y,r1,r1);//本体 fill(184,139,70); rect(x-20,y+60,40,20);//箱 } void bird1(float a,float b){ fill(244,250,37); triangle(a-r2+30,b-8,a-r2+30,b+10,a-r2+20,b);//くちばし fill(28,255,255); arc(a,b,r2,r2,0,PI);//下体 arc(a-r2/4,b+1,r2/2,r2/2,PI,TWO_PI);//上体 fill(28,5,255); triangle(a+r2/3,b-10,a+r2/4,b+10,a-10,b+10);//翼 } void bird2(float c,float d){ //緑 fill(244,250,37); triangle(c-r2+30,d-8,c-r2+30,d+10,c-r2+20,d);//くちばし fill(171,255,127); arc(c,d,r2,r2,0,PI);//下体 arc(c-r2/4,d+1,r2/2,r2/2,PI,TWO_PI);//上体 fill(0,230,65); triangle(c+r2/3,d-10,c+r2/4,d+10,c-10,d+10);//翼 } void bird3(float e,float f){ //ピンク fill(244,250,37); triangle(e-r2+30,f-8,e-r2+30,f+10,e-r2+20,f);//くちばし fill(242,216,223); arc(e,f,r2,r2,0,PI);//下体 arc(e-r2/4,f+1,r2/2,r2/2,PI,TWO_PI);//上体 fill(249,37,00); triangle(e+r2/3,f-10,e+r2/4,f+10,e-10,f+10);//翼 } void bird4(float g,float h){ //黒 fill(244,250,37); triangle(g-r2+30,h-8,g-r2+30,h+10,g-r2+20,h);//くちばし fill(155,155,155); arc(g,h,r2,r2,0,PI);//下体 arc(g-r2/4,h+1,r2/2,r2/2,PI,TWO_PI);//上体 fill(38,38,38); triangle(g+r2/3,h-10,g+r2/4,h+10,g-10,h+10);//翼 } void bird5(float i,float j){ //紫 fill(244,250,37); triangle(i-r2+30,j-8,i-r2+30,j+10,i-r2+20,j);//くちばし fill(213,160,224); arc(i,j,r2,r2,0,PI);//下体 arc(i-r2/4,j+1,r2/2,r2/2,PI,TWO_PI);//上体 fill(167,107,223); triangle(i+r2/3,j-10,i+r2/4,j+10,i-10,j+10);//翼 } void bird6(float k,float l){ fill(244,250,37); triangle(k-r2+30,l-8,k-r2+30,l+10,k-r2+20,l);//くちばし fill(248, 220, 133); arc(k,l,r2,r2,0,PI);//下体 arc(k-r2/4,l+1,r2/2,r2/2,PI,TWO_PI);//上体 fill(255,183,76); triangle(k+r2/3,l-10,k+r2/4,l+10,k-10,l+10);//翼 } void kumo1(float m,float n){ fill(255); ellipse(m,n,180,100); } void kumo2(float o,float p){ fill(255); ellipse(o,p,180,100); } //参考出典:http://wise9.jp/archives/1992 // Processingをはじめよう(著:Casey Reas、Ben Fry、訳:船田 巧)