PFont myFont; //フォントを格納するための箱を用意します。 int fsize = 48; int score=0;//スコア int time=90;//ゲーム時間 //自機 int x=240; int y=250; int dx=0; int dy=0; int walk=0; //hiroigame int sx=160; int sy=250; int sdx=0; int swalk=0; //chourigame int wp=1; int wscore=0; int diff=3;//難易度 int[] fire = new int[6]; int[] firex = new int[6]; int[] firey = new int[6]; int[] enemy = new int[6];//HP int[] enemyo = new int[6];//種類 int[] enemys = new int[6];//次出現まで int[] enemyx = new int[6]; int[] enemyy = new int[6]; int nowfire = 0; int firewait = 0; //振ってくるリンゴ int ringox =0; int ringoy =-100; //ボールの位置 int ballx =0; int bally =0; int balldx =0; int balldy =0; int ballstate =0;//発射中? int miss = 0; int moded = 0; //ゲーム中? PImage back,rin,s00,s01,s02,s03,s04,s05,k00,k01,k02,k03,k04,k05,e01,e02,e03,e04,e05,s11,s12,s13; PImage title,inter,clr,b01,b02,b03,b04; int hitcheck(int px,int py,int nx1,int ny1,int nx2, int ny2) { /* px,pyという座標が、nx1,ny1,nx2,ny2で生成される四角の中にあれば1を返す。 */ if (px >= nx1 && px <= nx2 && py >= ny1 && py <=ny2) { return 1; } else { return 0; } } void ringofall(int rx,int ry) { if (ringox==0) { ringox = rx; ringoy = ry; } } void incoming() { float somex; int somey; for(int i=0; i<5; i++) { if (enemy[i]==0 && enemys[i] <= 0) { enemyo[i] = floor(random(4))+1; if (enemyo[i]==1) { enemy[i] = 100; } else if (enemyo[i]==2) { enemy[i] = 500; } else if (enemyo[i]==3) { enemy[i] = 300; } else if (enemyo[i]==4) { enemy[i] = 100; } enemys[i] = 50+diff*80+int(random(120)); enemyx[i] = 440; enemyy[i] = int(random(200))+25; if (enemyo[i]==2) { enemyy[i] = 230; } } if (enemy[i]>0) {//出現してるなら somex=0; somey=0; if (enemyo[i]==1) { enemyx[i] -= 5; image(e01, enemyx[i], enemyy[i]); } else if (enemyo[i]==2) { enemyx[i] -= 2; image(e02, enemyx[i], enemyy[i]); } else if (enemyo[i]==3) { enemyx[i] -= 6; image(e03, enemyx[i], enemyy[i]); } else if (enemyo[i]==4) { enemyx[i] -= 8; somex = ((enemyx[i]%360)+1); somex = radians(somex); somex = sin(somex)*70; image(e04, enemyx[i], enemyy[i]+somex); } else if (enemyo[i]==5) { image(b01, enemyx[i]-35, enemyy[i]-20); enemyo[i]++; } else if (enemyo[i]==6) { image(b02, enemyx[i]-35, enemyy[i]-20); enemyo[i]++; } else if (enemyo[i]==7) { image(b03, enemyx[i]-35, enemyy[i]-20); enemyo[i]++; } else if (enemyo[i]==8) { image(b04, enemyx[i]-35, enemyy[i]-20); enemyo[i]=0; enemy[i]=0; } //fill(255,200,0,100); somey = enemyy[i] + floor(somex); //rect(enemyx[i],somey,50,50); //弾との当たり判定 if (wp==1 && enemy[i]>1) { for(int p=0; p<6; p++) { if (hitcheck(firex[p],firey[p],enemyx[i],somey,(enemyx[i]+50),somey+50)==1 && fire[p]==1) { enemy[i]-=100; fire[p]=0; if (enemy[i]<=1) { if (enemyo[i]==4) { enemyy[i]=somey; wscore+=20; } else if (enemyo[i]==1) { wscore+=10; } else if (enemyo[i]==2) { wscore+=30; } else if (enemyo[i]==3) { wscore+=20; } enemy[i] = 1; enemyo[i] = 5; } } } } else if (wp==2 && enemy[i]>1) { if (fire[0]==1 && (hitcheck(firex[0],firey[0]-18,enemyx[i],somey,enemyx[i]+50,somey+50)==1 || hitcheck(firex[0],firey[0]+18,enemyx[i],somey,enemyx[i]+50,somey+50)==1)) { enemy[i] = 1; fire[0]=0; if (enemyo[i]==4) { enemyy[i]=somey; wscore+=20; } else if (enemyo[i]==1) { wscore+=10; } else if (enemyo[i]==2) { wscore+=30; } else if (enemyo[i]==3) { wscore+=20; } enemyo[i] = 5; firex[nowfire] = firex[0]; firey[nowfire] = firey[0]; fire[nowfire]=15; nowfire++; if (nowfire >= 6) { nowfire = 1; } } for (int p=1;p<6;p++) { if (fire[p]>=1 && (hitcheck(enemyx[i],somey,firex[p]-50,firey[p]-50,firex[p]+50,firey[p]+50)==1 || hitcheck(enemyx[i],somey+50,firex[p]-50,firey[p]-50,firex[p]+50,firey[p]+50)==1)) { enemy[i]=1; if (enemyo[i]==4) { enemyy[i]=somey; wscore+=20; } else if (enemyo[i]==1) { wscore+=10; } else if (enemyo[i]==2) { wscore+=30; } else if (enemyo[i]==3) { wscore+=20; } enemyo[i] = 5; } } } else if (wp==3 && enemy[i]>1) { if (fire[0]==1 && (hitcheck(enemyx[i],somey,x,y-58,400,y+42)==1 || hitcheck(enemyx[i],somey+25,x,y-58,400,y+42)==1 || hitcheck(enemyx[i],somey+25,x,y-58,400,y+42)==1)) { enemy[i]-=20; if (enemy[i]<=1) { if (enemyo[i]==4) { enemyy[i]=somey; wscore+=20; } else if (enemyo[i]==1) { wscore+=10; } else if (enemyo[i]==2) { wscore+=30; } else if (enemyo[i]==3) { wscore+=20; } enemy[i]=1; enemyo[i] = 5; } } } if (enemyx[i]<=0) { enemy[i]=0; miss++; } } enemys[i]--; } } void reset() { score=0;//スコア time=90;//ゲーム時間 //自機 x=200; y=250; dx=0; walk=0; sx=200; sy=250; sdx=0; swalk=0; wp=1; wscore=0; diff=3;//難易度 wp=1; wscore=0; nowfire = 0; firewait = 0; //振ってくるリンゴ ringox =0; ringoy =-100; //ボールの位置 ballx =0; bally =0; balldx =0; balldy =0; ballstate =0;//発射中? miss = 0; for(int i=0; i<6; i++) { fire[i]=0; firex[i]=0; firey[i]=0; enemy[i]=0; enemyo[i]=0; enemys[i]=30+i*30; enemyx[i]=0; enemyy[i]=0; } } void setup(){ size(400, 300); //ウィンドウのサイズを決定(横幅、縦幅) colorMode(RGB,255); //カラーモードを設定(モード、最大値) background(233,246,255); //背景の色を指定(R,G,B)この場合は白 frameRate(30); //フレームレートを設定(fps:frame per seconds) noStroke(); //線をなしに設定 back = loadImage("ringowood.png"); rin = loadImage("ringo.png"); s00 = loadImage("s00.png"); s01 = loadImage("s01.png"); s02 = loadImage("s02.png"); s03 = loadImage("s03.png"); s04 = loadImage("s04.png"); s05 = loadImage("s05.png"); s11 = loadImage("s11.png"); s12 = loadImage("s12.png"); s13 = loadImage("s13.png"); k00 = loadImage("k00.png"); k01 = loadImage("k01.png"); k02 = loadImage("k02.png"); k03 = loadImage("k03.png"); k04 = loadImage("k04.png"); k05 = loadImage("k05.png"); e01 = loadImage("e01.png"); e02 = loadImage("e02.png"); e03 = loadImage("e03.png"); e04 = loadImage("e04.png"); e05 = loadImage("e05.png"); b01 = loadImage("b01.png"); b02 = loadImage("b02.png"); b03 = loadImage("b03.png"); b04 = loadImage("b04.png"); title = loadImage("title.png"); inter = loadImage("interval.png"); clr = loadImage("clear.png"); myFont = loadFont("tesma.vlw"); reset(); } void menuindex() { image(title, 0,0); if (hitcheck(mouseX,mouseY,180,120,280,150)==1) { fill(200,200,200,160); rect(180,120,100,30); if (mousePressed == true) {//スタート reset(); moded=1; return; } } else { fill(200,200,200,100); rect(180,120,100,30); } fill(40);//テキストの色をグレーに設定 fill(100);//テキストの色をグレーに設定 textFont(myFont,24); //フォント、フォントの大きさを指定 text("START",190,140); } void hiroistart() { fill(186,215,96,255); rect(0,270,400,130); image(back, -25, -25); image(k01,sx-30,210); image(s00,x-30,y-20); time--; textFont(myFont,30); //フォント、フォントの大きさを指定 fill(130,140,255,255); if (time>=90) { text("G",100,150); } else if (time>=85) { text("GE",100,150); } else if (time>=80) { text("GET",100,150); } else if (time>=75) { text("GET R",100,150); } else if (time>=70) { text("GET RE",100,150); } else if (time>=65) { text("GET REA",100,150); } else if (time>=60) { text("GET READ",100,150); } else if (time>=55) { text("GET READY",100,150); } else if (time>=50) { text("GET READY!",100,150); } else if (time>=40) { } else if (time>=30) { text("GET READY!",100,150); } else if (time>=20) { } else if (time>0) { text("GET READY!",100,150); } else if (time <=0) { time = 1800; moded=2; } } void hiroigame() { image(back, -25, -25); fill(186,215,96,255); rect(0,270,400,130); fill(100);//テキストの色をグレーに設定 textFont(myFont,24); //フォント、フォントの大きさを指定 text("Remain:" + time,10,290); //スコア text("Score:" + score,230,290); //スコア //自機移動 dx=0; sdx=0; //キーボードが押されている場合 if (xmouseX+4) { dx=-7; if (walk == 0) { walk = 1; } } if (keyPressed) { if (key == 'a') { sdx=-7; if (ballstate==0) { balldx=-5; balldy=-5;ballstate=1; } if (swalk ==0) { swalk = 1; } } else if (key == 's') { sdx=7; if (ballstate==0) { balldx=5; balldy=-5;ballstate=1; } if (swalk ==0) { swalk = 1; } } } if (dx==0) { walk=0; } if (sdx==0) { swalk=0; } x+=dx; sx+=sdx; if (x<=0) {x=0;} if (x>=400) {x=400;} if (sx<=0) {sx=0;} if (sx>=400) {sx=400;} if (swalk == 0) { image(k01,sx-30,210); } else if (swalk >= 1) { if (swalk == 1) { image(k01,sx-30,210); swalk++; } else if (swalk == 2) { image(k02,sx-30,210); swalk++; } else if (swalk == 3) { image(k03,sx-30,210); swalk++; } else if (swalk == 4) { image(k04,sx-30,210); swalk++; } else if (swalk == 5) { image(k05,sx-30,210); swalk=1; } } if (walk == 0) { image(s00,x-30,y-20); } else if (walk >= 1) { if (walk == 1) { image(s01,x-30,y-20); walk++; } else if (walk == 2) { image(s02,x-30,y-20); walk++; } else if (walk == 3) { image(s03,x-30,y-20); walk++; } else if (walk == 4) { image(s04,x-30,y-20); walk++; } else if (walk == 5) { image(s05,x-30,y-20); walk=1; } } //ブロック崩し if (ballstate!=0) { ballx+=balldx; bally+=balldy; } else if (ballstate==0) { ballx = sx+20; bally = sy-20; } if (ballx>400) { ballx = 400; balldx*=-1; } else if (ballx<0) { ballx = 0; balldx *= -1; } else if (bally<0) { bally = 0; balldy *= -1; } else if (bally>270) { ballx = sx+20; bally = sy-20; balldx=0;balldy=0; ballstate=0; time -= 90; delay(500); } if (hitcheck(ballx,bally+10,sx-20,sy-10,sx+60,sy) == 1 && ballstate==1) {//小人にヒット if (ballx <=sx-10) { balldx=-7; balldy=-3; } else if (ballx <= sx) { balldx=-6; balldy=-4; } else if (ballx <= sx+10) { balldx=-5; balldy=-5; } else if (ballx <= sx+20) { balldx=-4; balldy=-6; } else if (ballx <= sx+30) { balldx=4; balldy=-6; } else if (ballx <= sx+40) { balldx=5; balldy=-5; } else if (ballx <= sx+50) { balldx=6; balldy=-4; } else if (ballx <= sx+60) { balldx=7; balldy=-3; } bally = sy-21; } //リンゴ落下開始 if (hitcheck(ballx+10,bally,45,70,75,100)==1 || hitcheck(ballx+10,bally,140,30,170,60)==1 || hitcheck(ballx+10,bally,235,80,265,110)==1 || hitcheck(ballx+10,bally,320,50,350,80)==1) { balldx*=-1; ballx-=1; ringofall(ballx+25,bally); } else if (hitcheck(ballx-10,bally,45,70,75,100)==1 || hitcheck(ballx-10,bally,140,30,170,60)==1 || hitcheck(ballx-10,bally,235,80,265,110)==1 || hitcheck(ballx-10,bally,320,50,350,80)==1) { balldx*=-1; ballx+=1; ringofall(ballx-25,bally); } else if (hitcheck(ballx,bally-10,45,70,75,100)==1 || hitcheck(ballx,bally-10,140,30,170,60)==1 || hitcheck(ballx,bally-10,235,80,265,110)==1 || hitcheck(ballx,bally-10,320,50,350,80)==1) { balldy*=-1; bally+=1; ringofall(ballx,bally-25); } else if (hitcheck(ballx,bally+10,45,70,75,100)==1 || hitcheck(ballx,bally+10,140,30,170,60)==1 || hitcheck(ballx,bally+10,235,80,265,110)==1 || hitcheck(ballx,bally+10,320,50,350,80)==1) { balldy*=-1; bally-=1; ringofall(ballx,bally+25); } if (ringox!=0 && ringoy<265) {//リンゴ落下中 ringoy+=3; } if (hitcheck(x,y,ringox-30,ringoy-30,ringox+30,ringoy+20)==1) { if (ringoy<265) { score+=3; } else { score++; } ringox=0;ringoy=-100; } image(rin, ringox-10, ringoy-10); fill(255,161,0,200); ellipse(ballx,bally,20,20); /* リンゴブロック四つ rect(45,70,30,30); rect(140,30,30,30); rect(235,80,30,30); rect(320,50,30,30); */ if (ballstate==0) { fill(255,200,0,255); text("Press A or S key to Start...",40,150); //スコア } else { time--; } if (time<=0) { moded = 3; } } void interval() { image(inter,0,0); fill(100);//テキストの色をグレーに設定 textFont(myFont,19); //フォント、フォントの大きさを指定 text("Your Score:" + score,30,40); text("START COOKING",30,70); if (hitcheck(mouseX,mouseY,25,55,205,75)==1) { fill(200,200,200,160); rect(25,55,180,20); if (mousePressed == true) { miss=0; time=90; if (score>=60) { diff=0; } else if (score>=50) { diff=1; } else if (score>=40) { diff=2; } else if (score>=30) { diff=3; } else if (score>=20) { diff=4; } else { diff=5; } moded=6; } } else { fill(200,200,200,100); rect(25,55,180,20); } } void chouristart() { fill(186,215,96,255); rect(0,270,400,130); image(back, -200, -25); image(k00, 20, 180); image(s11, x-50, y-30); time--; textFont(myFont,30); //フォント、フォントの大きさを指定 fill(130,140,255,255); if (time>=90) { text("G",100,150); } else if (time>=85) { text("GE",100,150); } else if (time>=80) { text("GET",100,150); } else if (time>=75) { text("GET R",100,150); } else if (time>=70) { text("GET RE",100,150); } else if (time>=65) { text("GET REA",100,150); } else if (time>=60) { text("GET READ",100,150); } else if (time>=55) { text("GET READY",100,150); } else if (time>=50) { text("GET READY!",100,150); } else if (time>=40) { } else if (time>=30) { text("GET READY!",100,150); } else if (time>=20) { } else if (time>0) { text("GET READY!",100,150); } else if (time <=0) { time = 2700; moded=4; } } void chourigame() { smooth(); int somex,somey; fill(186,215,96,255); rect(0,270,400,130); image(back, -200, -25); image(k00, 20, 180); fill(100);//テキストの色をグレーに設定 textFont(myFont,24); //フォント、フォントの大きさを指定 text("miss:" + miss,10,290); //スコア text("Score:" + wscore,230,290); //スコア text("Remain:" + time,10,20); //スコア time--; if (time<=0) { moded=5; } /* 自機移動 */ dx = int((mouseX - x)*0.2); dy = int((mouseY - y)*0.2); x+=dx; y+=dy; /* 攻撃 */ if (firewait >0) { firewait--; } if (wp==1) { image(s11, x-50, y-30); if (mousePressed==true && firewait==0) { firex[nowfire] = x+48; firey[nowfire] = y-5; fire[nowfire]=1; nowfire++; if (nowfire >= 6) { nowfire = 0; } x-=2; firewait = 10; } } else if (wp==2) { image(s12, x-50, y-30); if (mousePressed==true && firewait==0) { firex[0] = x+48; firey[0] = y-5; fire[0]=1; x-=5; firewait = 30; } } else if (wp==3) { image(s13, x-50, y-30); if (mousePressed==true && firewait==0) { fire[0]=1; firewait = 60; } } if (keyPressed==true && firewait==0) { if (key == 'z') { nowfire=0; wp=1; } if (key == 'x') { nowfire=1; wp=2; } if (key == 'c') { nowfire=1; wp=3; } } /* 敵出現・移動 */ incoming(); /* 弾処理 */ if (wp==1) { for(int i=0; i<6; i++) { if (fire[i] == 1) { firex[i] += 6; if (firex[i] >=400) { fire[i] =0; firey[i]=500; } fill(255,30,0,230); rect(firex[i]-5,firey[i]-1,5,2); } } } else if (wp==2) { if (fire[0]==1) { firex[0]+=10; if (firex[0] >= 425) { fire[0] = 0; firey[0]=500; } for(int i=5;i>=0;i--) { fill(255,(155+i*20),0); ellipse(firex[0],firey[0],(i*6+6),(i*3)+3); } } for(int p=1;p<6;p++) { if (fire[p] >= 1) { fill(255,106,93,17*fire[p]); fire[p]--; ellipse(firex[p],firey[p],100,100); } } } else if (wp==3 && fire[0]==1) { if (firewait<=30) { fire[0]=0; } for(int i=5;i>=0;i--) { fill(255-i*31,255-i*19,255); ellipse(x+440,y-8,775+i*5,20+i); } } } void gameover() { int somex,somey,somez; image(clr,0,0); if (hitcheck(mouseX,mouseY,5,270,145,300)==1) { fill(160,160); rect(5,270,140,30); if (mousePressed == true) { moded=0; } } else { fill(200,100); rect(5,270,140,30); } fill(100);//テキストの色 textFont(myFont,30); //フォント、フォントの大きさを指定 text("CLEARED!!",212,22); fill(255,157,144);//テキストの色 text("CLEARED!!",210,20); textFont(myFont,24); //フォント、フォントの大きさを指定 text("Your Score:",5,105); somex = score*20; somey = miss*50; somez = somex + wscore - somey; if (somez<0) { somez =0; } textFont(myFont,18); //フォント、フォントの大きさを指定 text("Ringo: " + score + " x 20",15,120); text("= " + somex,200,120); text("Miss : " + miss + " x 50",15,135); rect(88,130,5,2); rect(213,130,5,2); text("= " + somey,195,135); text("Score:",15,150); text(wscore,220,150); fill(160);//テキストの色 rect(5,153,250,2); textFont(myFont,24); //フォント、フォントの大きさを指定 text("Total: " + somez,151,171); fill(255,157,144);//テキストの色 text("Total: " + somez,150,170); text("RESTART",10,290); } void draw(){ fill(233,246,255,255);//背景の塗りを白の半透明に設定 rect(0,0,400,300);//背景色でウィンドウを塗りつぶす if (moded == 0) {//メニュー画面 menuindex(); } else if (moded == 1) { hiroistart(); } else if (moded == 2) { hiroigame(); } else if (moded == 3) { interval(); } else if (moded == 4) { chourigame(); } else if (moded==5) { gameover(); } else if (moded==6) { chouristart(); } }