タイトル画面を設定したいです。
##スタート画面が始まり、ゲームが実行され、60秒経過したら、終了画面になるようにしたいです。
case0でエラーが出ます。誰か分かる方教えて下さい。
prosseing
1 2String question; 3String answer; 4String input; 5int score;![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-06-26/66e46fec-9b3a-4637-920e-6944c5255320.png) 6float imgX=900; 7float imgVX=1; 8PImage img; 9PImage[] imgs; 10int sce=0; 11 12Button button; 13void setup() { 14 size(800, 800); 15 textSize(48); 16 /* パネルの大きさ*/ 17 rectMode(CENTER, CENTER); 18 colorMode(HSB,360,100,100); 19 textAlign(CENTER,CENTER); 20 21 button=new Button(width/2,height/2,200,100,color(190,100,70),"PUSH!!"); 22 23 24 imgs=new PImage[]{ 25 loadImage("ika.png"), 26 loadImage("sake.png"), 27 }; 28 imgVX=random(1,5); 29float f = random(imgs.length); // 0以上2未満のfloat値(1.234のような) 30 int i = int(f); // 0か1(小数点以下を切り捨てる) 31 img = imgs[i]; 32 33 34} 35 36void draw() { 37 38 39 40 41 42 background(127); 43 44 switch(sce){ 45 case 0; 46 button.run0(); 47 48 if(button.isPush()){ 49 sce=1; 50 } 51 break; 52 53 case 1; 54 55 break; 56} 57 58 59 60 61 showPanel(); // パネルの表示 62 63 mato(); 64 65 66textAlign(LEFT, BASELINE); 67 text("SCORE: " + score, 10, 50); 68 //textAlign(LEFT, BOTTOM); 69 //text(answer, 10, 250); 70 textAlign(CENTER, BOTTOM); 71 text(input, 0, 0, width, 250); 72 73 ps.run(); 74 75 76} 77int reg = 0, val = 0; 78String op = "="; 79 80void calc(int id) { 81 switch(id) { 82 case 0: // 0以外の数字を入力した場合 83 case 1: 84 case 2: 85 case 4: 86 case 5: 87 case 6: 88 case 8: 89 case 9: 90 case 10: 91 if (disp == "0") { // "0" で始まる文字列にならないようにする 92 disp = ""; 93 } 94 disp = disp+label[id]; // dispの後ろに1文字つなぐ 95 break; 96 case 12: // "0" 97 if (disp != "0") { 98 disp = disp + "0"; 99 } 100 break; 101 case 3: // "+/-" プラスマイナス符号の入れ替え 102 if (disp == "0") { 103 } else if (disp.substring(0,1).equals("-")) { 104 // 文字列 disp の最初の文字がマイナスのとき 105 // マイナスを取り去った文字列をdispに代入 106 disp = disp.substring(1); 107 } else { // 先頭にマイナスをつける 108 disp = "-" + disp; 109 } 110 break; 111 case 11: // "+" 112 reg = int(disp); // dispの文字列を整数値にしてしまっておく 113 disp = "0"; 114 op = "+"; // 次にイコールがきたら足し算する 115 break; 116 case 7: // "-" 117 reg = int(disp); 118 disp = "0"; 119 op = "-"; // 次いイコールがきたら引き算する 120 break; 121 case 13: // "=" 計算して結果を文字列として disp に代入 122 val = int(disp); 123 if (op == "+") { 124 op = "="; 125 val = reg + val; 126 disp = str(val); 127 } else if (op == "-") { 128 op = "="; 129 val = reg - val; 130 disp = str(val); 131 } 132 break; 133 default: 134 break; 135 } 136} 137String disp = "0"; 138final float x = 20; 139final float y = 300; 140final float w = 800 - 40; 141final float h = 400; 142final String[] label = { 143 "7", "8", "9", 144 "4", "5", "6", 145 "1", "2", "3", 146 "0", "", "C" }; 147final ParticleSystem ps = new ParticleSystem(); 148 149void mousePressed() { 150 if (mouseX < x || mouseX > x + w) return; 151 if (mouseY < y || mouseY > y + h) return; 152 153 int i = int(3 * (mouseX - x) / w); 154 int j = int(4 * (mouseY - y) / h); 155 String s = label[getID(i, j)]; 156 157 if (s.equals("C")) { // クリア 158 input = ""; 159 return; 160 } 161 162 input += s; 163 if (input.equals(answer)) { // 正解 164 score++; 165 ps.addParticle(new PVector(imgX, 150), question); 166 imgX = 1000; // 範囲外に飛ばすことで、matoでの再設定を誘発させる 167 } 168} 169void showPanel() { 170 rect(x, y, w, h); 171 172 for (int i = 0; i < label.length; i++) { 173 showLabel(i); 174 } 175} 176 177void showLabel(int i) { 178 float bw = w / 3; 179 float bh = h / 4; 180 float bx = x + (i % 3) * bw; 181 float by = y + (i / 3) * bh; 182 183 fill(200); 184 rect(bx, by, bw, bh); 185 fill(0); 186 textAlign(CENTER, CENTER); 187 text(label[i], bx, by, bw, bh); 188} 189 190int getID(int i, int j) { 191 return j * 3 + i; 192} 193 194 195 196 void mato() { 197 if (width < imgX) { 198 imgX = 0; 199 int a = int(random(1, 100)); 200 int b = int(random(1, 100)); 201 question = a + "+" + b; // 問題を文字列化 202 answer = str(a + b); // 答えも文字列化 203 input = ""; 204 205 imgVX = random(1, 5); 206 img = imgs[int(random(imgs.length))];//画像がランダムで選ばれる。 207 } 208 209 image(img, imgX, 150, 100, 100);//X軸を等速直線に動く 210 textAlign(LEFT, BASELINE); 211 text(question, imgX, 150); 212 213 imgX += imgVX; 214} 215 216// [Simple Particle System / Examples / Processing.org](https://processing.org/examples/simpleparticlesystem.html) 217// をベースに小改造(文字列を一文字ずつばらばらに四散させる)運動する粒子で表現される事象 218class ParticleSystem { 219 ArrayList<Particle> particles = new ArrayList<Particle>(); 220 void addParticle(PVector position, String str) { 221 for (char c : str.toCharArray()) { 222 particles.add(new Particle(position, c)); 223 } 224 } 225 void run() { 226 for (int i = particles.size() - 1; i >= 0; i--) { 227 Particle p = particles.get(i); 228 p.run(); 229 if (p.isDead()) { 230 particles.remove(i); 231 } 232 } 233 } 234} 235class Particle { 236 PVector position; 237 PVector velocity = PVector.random3D().mult(10); 238 float lifespan = 255; 239 char c; 240 Particle(PVector l, char c) { 241 position = l.copy(); 242 this.c = c; 243 } 244 void run() { 245 update(); 246 display(); 247 } 248 void update() { 249 position.add(velocity); 250 lifespan -= 2; 251 } 252 void display() { 253 push(); 254 translate(position.x, position.y); 255 rotate(radians(position.z)); 256 fill(0, lifespan); 257 textAlign(CENTER, CENTER); 258 text(c, 0, 0); 259 pop(); 260 } 261 boolean isDead() { 262 return lifespan < 0.0; 263 } 264}class Button {float x,y; 265 float sizeX,sizeY; 266 int state; 267 268 color basecol; 269 float nb; 270 float sb; 271 float pb; 272 273 274 String str; 275 276 Button(float x,float y,float sizeX,float sizeY, 277 color baseCol,String str){ 278 this.x=x; 279 this.y=y; 280 this.sizeY=sizeY; 281 this.sizeX=sizeX; 282 this.baseCol= baseCol; 283 this.str=str; 284 285 nb=1; 286 sb=0.8; 287 pb=0.6; 288 } 289 290 void run0(){ 291 rogic(); 292 display0; 293 } 294 295 void display0(){ 296 noStroke(); 297 changeColor(); 298 rect(x,y,sizeX,sizeY); 299 300 fill(0,0,100); 301 textSize(30); 302 text(str,x,y); 303 } 304 305 void rogic(){ 306 state=checkState(); 307 } 308 309 310 boolean isPush(){ 311 if(checkState()==2) 312 return true; 313 return false; 314 } 315 316 int checkState(){ 317 if (!checkInMouse()) 318 return 0; 319 320 if(!mousePressed) 321 return 1; 322 return 2; 323 } 324 325boolean checkInMouse(){ 326 if (mouseX>x-sizeX/2 && mouseX <x+sizeX/2){ 327 if (mouseY>y-sizeY/2 && mouseY< y+sizeY/2) 328 { return true; 329 } 330 } 331 return false; 332} 333 334void changeColor() { 335 switch(state) { 336 case 0; 337 fill(hue(baseCol),saturation(baseCol),brightness(baseCol)*nb); 338 339 break; 340 341 case 1; 342 fill(hue(baseCol),saturation(baseCol),brightness(baseCol)*pb); 343 344 345 346 case 2; 347 348 fill(hue(baseCol),saturation(baseCol),brightness(baseCol)*pb); 349 350 351 352 break; 353 354 default; 355 fill(0,0,0); 356 break; 357 } 358 } 359 360 361 362
![guest](/img/icon/icnUserSample.jpg)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/26 03:17
2022/06/26 03:30
2022/06/26 03:56
2022/07/03 07:42