PFont my = createFont("arial unicode ms",100); PImage img1 = loadImage("kobito1.gif"); PImage img2 = loadImage("kobito2.gif"); //ゲームの状態を管理 //0はオープニング //1はゲーム画面 int game = 0; //オープニングの文字の初期位置 int xx = 300; //Enterキーが押されたかどうかのフラグ //0がオフ //1がオン int yy = 0; //プレイヤーの走っている状態を判定 //0と1を交互に繰り返す int player = 0; //プレイヤーのy座標 int a = 250; //地面、オブジェクト、アイテム、敵のx座標 int x = 0; //ジャンプしている間増えるフラグ //1以上でジャンプ中 int jumpflag = 0; //地面についているかの判定のフラグ //0で地面についている //1は空中 int groundflag = 0; //アイテムをとった個数のフラグ int itemflag = 0; //アイテムごとに取得したかの判定のフラグ //0が未取得 //1が取得済 int[] item1flag = new int[100]; int[] item2flag = new int[100]; //ポイントを格納する変数 int p; //ゲームオーバーしてるかどうかの判定 //0がプレイ中 //1がゲームオーバー int gameover = 0; void setup(){ size(600,400); } void draw(){ background(0); if( game == 0){ stroke (255); line( 0, 260, 600, 260 ); if( (0 <= player) && (player <= 6) ){ image(img1, 160,a-57,80,112); player ++; } else{ image(img2, 160,a-57,80,112); player ++; if(player >= 14) player = 0; } if(yy == 0){ if(keyPressed == true){ if(key == ENTER){ yy = 1; } else opening(my); } else opening(my); } else { xx -= 4; opening(my); if( xx <= -300){ game = 1; //各変数の初期化; xx = 300; yy = 0; player = 0; a = 250; x = 0; jumpflag = 0; groundflag = 0; itemflag = 0; for(int aa = 0;aa < 100;aa++){ item1flag[aa] = 0; item2flag[aa] = 0; } gameover = 0; } } } else{ //プレイヤーの描写 if( (0 <= player) && (player <= 6) ){ image(img1, 160,a-57,80,112); player ++; } else{ image(img2, 160,a-57,80,112); player ++; if(player >= 14) player = 0; } //地面の描写 line( x, 260, x+50000, 260 ); //オブジェクト1 for(int i1 = 0;i1<100;i1++){ line(x+800+(i1*2000), 200, x+1000+(i1*2000), 200); } //オブジェクト2 for(int i2 = 0;i2<100;i2++){ line(x+1000+(i2*2000), 150, x+1200+(i2*2000), 150); } //オブジェクト3 for(int i3 = 0;i3<100;i3++){ line(x+2000+(i3*2000), 200, x+2200+(i3*2000), 200); } fill(255); //アイテム1 for(int k1 = 0;k1<100;k1++){ if (item1flag[k1] == 0) rect(x+1150 + (k1*2000), 140, 10, 10); } //アイテム2 for(int k2 = 0;k2<100;k2++){ if(item2flag[k2] == 0) rect(x+1500 + (k2*2000), 200, 10, 10); } fill(255); //敵1 for(int m1 = 0;m1<100;m1++){ triangle(x+1800 + (m1*1500), 240, x+1790 + (m1*1500), 260, x+1810 + (m1*1500), 260); } //敵2 for(int m2 = 0;m2<100;m2++){ triangle(x+2800 + (m2*1500), 240, x+2790 + (m2*1500), 260, x+2810 + (m2*1500), 260); } fill(255); //ジャンプボタンの説明 if(gameover == 0){ textFont(my); textAlign(CENTER); textSize(30); text("UP↑ to jump",300,330); } //ジャンプ判定 if(gameover == 0){ if(groundflag == 0){ if(keyPressed == true) { if(keyCode == UP){ jumpflag = 1; groundflag = 1; } } } } if(jumpflag >= 1){ a -= 10; jumpflag ++; if(jumpflag == 12) jumpflag = 0; } //重力 a += 3; //各種判定 //オブジェクト1 for(int j1 = 0;j1<100;j1++){ if( ( (-800 - (j1*2000)) <= x) && (x <= (-600 - (j1*2000) ) ) && (185 <= a) && (a <= 195) && (jumpflag == 0) ){ a = 190; groundflag = 0; } } //オブジェクト2 for(int j2 = 0;j2<100;j2++){ if( ( (-1000 - (j2*2000) ) <= x) && (x <= ( -800 - (j2*2000) ) ) && (135 <= a) && (a <= 145) && (jumpflag == 0) ){ a = 140; groundflag = 0; } } //オブジェクト3 for(int j3 = 0;j3<100;j3++){ if( ( (-2000 - (j3*2000) ) <= x) && (x <= ( -1800 - (j3*2000) ) ) && (185 <= a) && (a <= 195) && (jumpflag == 0) ){ a = 190; groundflag = 0; } } //アイテム1 for(int l1 = 0;l1<100;l1++){ if(item1flag[l1] == 0){ if( ( (-965 - (l1*2000) ) <= x) && (x <= ( -945 - (l1*2000) ) ) && (135 <= a) && (a <= 155) ){ itemflag ++; item1flag[l1] = 1; } } } //アイテム2 for(int l2 = 0;l2<100;l2++){ if(item2flag[l2] == 0){ if( ( (-1315 - (l2*2000) ) <= x) && (x <= ( -1295 -(l2*2000) ) ) && (195 <= a) && (a <= 215) ){ itemflag ++; item2flag[l2] = 1; } } } //敵1 for(int n1 = 0;n1<100;n1++){ if( ( (-1615 - (n1*1500) ) <= x) && (x <= ( -1585 - (n1*1500) ) ) && (235 <= a) && (a <= 265) ){ if(x <= -14000) x += 11; else if(x <= -9000) x += 9; else if(x <= -5000) x += 7; else if(x <= -2000) x += 5; else x += 3; textFont(my); textAlign(LEFT); textSize(50); text("Game Over",100,200); textSize(30); text("Please Space!",130,300); gameover = 1; if(keyPressed == true) { if(key == ' ' ) game = 0; } } } //敵2 for(int n2 = 0;n2<100;n2++){ if( ( (-2615 - (n2*1500) ) <= x) && (x <= ( -2585 - (n2*1500) ) ) && (235 <= a) && (a <= 265) ){ if(x <= -14000) x += 11; else if(x <= -9000) x += 9; else if(x <= -5000) x += 7; else if(x <= -2000) x += 5; else x += 3; textFont(my); textAlign(LEFT); textSize(50); text("Game Over",100,200); textSize(30); text("Please Space!",100,300); gameover = 1; if(keyPressed == true) { if(key == ' ' ) game = 0; } } } //一番下の地面についているかの判定 if (a >= 250){ a = 250; groundflag = 0; } //距離、アイテムによるポイント表示 textFont(my); textAlign(LEFT); textSize(20); if(gameover == 0){ rect(95, 38, 10, 10); text("= 100 point",120,50); triangle(100, 60, 90, 80, 110, 80); text("= gameover",120,77); } text("POINT : ",400,50); p = -x; p += itemflag * 100; text( p ,480,50); //スクロール(移動)のスピード if(x <= -14000) x -= 11; else if(x <= -9000) x -= 9; else if(x <= -5000) x -= 7; else if(x <= -2000) x -= 5; else x -= 3; } } void opening(PFont my){ textFont(my); textSize(50); textAlign(CENTER); text("Running dwarf",xx,180); textSize(24); text("-走る小人の物語-",xx,220); textSize(20); text("Please Enter!",xx,300); }