scoreが5ずつ増えるたびにcountDownが+10秒増えるようにしたい。
if(score==5){
countDown+=10;
textSize(70);
text("15秒増加",50,100);
}
このコードをかいても、countDownは反応しませんでした。誰か教えてください。
また、textを5秒間だけウインドウ上に表示する機能も教えてください。
後、日本語の文字化けを治したい。
processing
1コード 2String question; 3String answer; 4String input; 5int score; 6float imgX=900; 7float imgVX=1; 8PImage img; 9PImage[] imgs; 10int timeLimit=60; 11int countDown; 12PImage imm; 13PImage imm1; 14PImage imm2; 15PImage imm3; 16 17 18Scene scene= Scene.TITLE;//現在のシーン 19 20 21enum Scene { 22 TITLE, PLAY, GAMEOVER 23}; 24 25Button button; 26void setup() { 27 size(800, 800); 28 textSize(48); 29 /* パネルの大きさ*/ 30 31 colorMode(HSB, 360, 100, 100); 32 textAlign(CENTER, CENTER); 33 34 button=new Button(width/2, height/2, 200, 100, color(190, 100, 70), "PUSH!!"); 35 imm=loadImage("brain.png"); 36 imm1=loadImage("fishing.png"); 37 imm2=loadImage("umi.png"); 38 imm3=loadImage("umi1.jpg"); 39 40 imgs=new PImage[]{ 41 loadImage("ika.png"), 42 loadImage("sake.png"), 43 loadImage("tako.png"), 44 loadImage("maguro.png"), 45 loadImage("haze.png"), 46 loadImage("tai.png"), 47 loadImage("karei.png"), 48 }; 49 imgVX=random(1, 5); 50 float f = random(imgs.length); // 0以上2未満のfloat値(1.234のような) 51 int i = int(f); // 0か1(小数点以下を切り捨てる) 52 img = imgs[i]; 53} 54 55void draw() { 56 57 background(127); 58 59 switch(scene) { 60 case TITLE: 61 62 button.run(); 63 if (button.isPush()) { 64 65 66 scene= Scene.PLAY; 67 68 } 69 image(imm,100,500,200,200); 70 image(imm1,500,500,200,200); 71 72 textSize(90); 73 text("Brain Fishing",400,200); 74 break; 75 76 case PLAY: 77 78 image(imm2,0,0,800,300); 79 80 int ms = millis()/1000; 81 println(ms); 82 83 fill(0); 84 countDown = timeLimit - ms; 85 fill(255); 86 textSize(50); 87 textAlign(RIGHT,TOP); 88 text("COUNT DOWN : "+countDown, 500, 50); 89 if (countDown<=0) { 90 scene= Scene.GAMEOVER; 91 } 92 93if(score==5){ 94 countDown+=10; 95 textSize(70); 96 text("15秒増加",50,100); 97 } 98 99 100 101 showPanel(); // パネルの表示 102 103 mato(); 104 105 textAlign(LEFT, BASELINE); 106 text("SCORE: " + score, 10, 50); 107 //textAlign(LEFT, BOTTOM); 108 //text(answer, 10, 250); 109 textAlign(CENTER, BOTTOM); 110 text(input, 0, 0, width, 250); 111 112 ps.run(); 113 114 115 break; 116 117 case GAMEOVER: 118 image(imm3,0,0,800,800); 119 textAlign(CENTER, CENTER); 120 text(" TIME OVER", 0, 0, width, height); 121 break; 122 } 123} 124int reg = 0, val = 0; 125String op = "="; 126 127void calc(int id) { 128 switch(id) { 129 case 0: // 0以外の数字を入力した場合 130 case 1: 131 case 2: 132 case 4: 133 case 5: 134 case 6: 135 case 8: 136 case 9: 137 case 10: 138 if (disp == "0") { // "0" で始まる文字列にならないようにする 139 disp = ""; 140 } 141 disp = disp+label[id]; // dispの後ろに1文字つなぐ 142 break; 143 case 12: // "0" 144 if (disp != "0") { 145 disp = disp + "0"; 146 } 147 break; 148 case 3: // "+/-" プラスマイナス符号の入れ替え 149 if (disp == "0") { 150 } else if (disp.substring(0,1).equals("-")) { 151 // 文字列 disp の最初の文字がマイナスのとき 152 // マイナスを取り去った文字列をdispに代入 153 disp = disp.substring(1); 154 } else { // 先頭にマイナスをつける 155 disp = "-" + disp; 156 } 157 break; 158 case 11: // "+" 159 reg = int(disp); // dispの文字列を整数値にしてしまっておく 160 disp = "0"; 161 op = "+"; // 次にイコールがきたら足し算する 162 break; 163 case 7: // "-" 164 reg = int(disp); 165 disp = "0"; 166 op = "-"; // 次いイコールがきたら引き算する 167 break; 168 case 13: // "=" 計算して結果を文字列として disp に代入 169 val = int(disp); 170 if (op == "+") { 171 op = "="; 172 val = reg + val; 173 disp = str(val); 174 } else if (op == "-") { 175 op = "="; 176 val = reg - val; 177 disp = str(val); 178 } 179 break; 180 default: 181 break; 182 } 183} 184 185String disp = "0"; 186final float x = 20; 187final float y = 300; 188final float w = 800 - 40; 189final float h = 400; 190final String[] label = { 191 "7", "8", "9", 192 "4", "5", "6", 193 "1", "2", "3", 194 "0", "", "C" }; 195final ParticleSystem ps = new ParticleSystem(); 196 197void mousePressed() { 198 switch(scene) { 199 case TITLE: 200 break; 201 202 case PLAY: 203 204 if (mouseX < x || mouseX > x + w) return; 205 if (mouseY < y || mouseY > y + h) return; 206 207 int i = int(3 * (mouseX - x) / w); 208 int j = int(4 * (mouseY - y) / h); 209 String s = label[getID(i, j)]; 210 211 if (s.equals("C")) { // クリア 212 input = ""; 213 214 return; 215 216 217 218} 219 220 input += s; 221 if (input.equals(answer)) { // 正解 222 score++; 223 ps.addParticle(new PVector(imgX, 150), question); 224 imgX = 1000; // 範囲外に飛ばすことで、matoでの再設定を誘発させる 225 } 226 break; 227 228 case GAMEOVER: 229 scene = Scene.TITLE; 230 exit(); 231 232 break; 233 } 234} 235 236void showPanel() { 237 rect(x, y, w, h); 238 239 for (int i = 0; i < label.length; i++) { 240 showLabel(i); 241 } 242} 243 244void showLabel(int i) { 245 float bw = w / 3; 246 float bh = h / 4; 247 float bx = x + (i % 3) * bw; 248 float by = y + (i / 3) * bh; 249 250 fill(200); 251 rect(bx, by, bw, bh); 252 fill(0); 253 textAlign(CENTER, CENTER); 254 text(label[i], bx, by, bw, bh); 255} 256 257int getID(int i, int j) { 258 return j * 3 + i; 259} 260 261 262 263 264 void mato() { 265 if (width < imgX) { 266 imgX = 0; 267 int a = int(random(1, 100)); 268 int b = int(random(1, 100)); 269 question = a + "+" + b; // 問題を文字列化 270 answer = str(a + b); // 答えも文字列化 271 input = ""; 272 273 imgVX = random(1, 5); 274 img = imgs[int(random(imgs.length))];//画像がランダムで選ばれる。 275 } 276 277 image(img, imgX, 150, 100, 100);//X軸を等速直線に動く 278 textAlign(LEFT, BASELINE); 279 text(question, imgX, 150); 280 281 imgX += imgVX; 282} 283 284// [Simple Particle System / Examples / Processing.org](https://processing.org/examples/simpleparticlesystem.html) 285// をベースに小改造(文字列を一文字ずつばらばらに四散させる)運動する粒子で表現される事象 286class ParticleSystem { 287 ArrayList<Particle> particles = new ArrayList<Particle>(); 288 void addParticle(PVector position, String str) { 289 for (char c : str.toCharArray()) { 290 particles.add(new Particle(position, c)); 291 } 292 } 293 void run() { 294 for (int i = particles.size() - 1; i >= 0; i--) { 295 Particle p = particles.get(i); 296 p.run(); 297 if (p.isDead()) { 298 particles.remove(i); 299 } 300 } 301 } 302} 303class Particle { 304 PVector position; 305 PVector velocity = PVector.random3D().mult(10); 306 float lifespan = 255; 307 char c; 308 Particle(PVector l, char c) { 309 position = l.copy(); 310 this.c = c; 311 } 312 void run() { 313 update(); 314 display(); 315 } 316 void update() { 317 position.add(velocity); 318 lifespan -= 2; 319 } 320 void display() { 321 push(); 322 translate(position.x, position.y); 323 rotate(radians(position.z)); 324 fill(0, lifespan); 325 textAlign(CENTER, CENTER); 326 text(c, 0, 0); 327 pop(); 328 } 329 boolean isDead() { 330 return lifespan < 0.0; 331 } 332} 333 334 335 336 class Button { 337 float x, y; 338 float sizeX, sizeY; 339 int state; 340 341 color baseCol; 342 float nb; 343 float sb; 344 float pb; 345 346 347 String str; 348 349 Button(float x, float y, float sizeX, float sizeY, 350 color baseCol, String str) { 351 this.x=x; 352 this.y=y; 353 this.sizeY=sizeY; 354 this.sizeX=sizeX; 355 this.baseCol=baseCol; 356 this.str=str; 357 358 nb=1; 359 sb=0.8; 360 pb=0.6; 361 } 362 363 void run() { 364 rogic(); 365 display(); 366 } 367 368 void display() { 369 push(); 370 371 rectMode(CENTER); 372 colorMode(HSB, 360, 100, 100); 373 textAlign(CENTER, CENTER); 374 375 noStroke(); 376 changeColor(); 377 rect(x, y, sizeX, sizeY); 378 379 fill(0, 0, 100); 380 textSize(30); 381 text(str, x, y); 382 383 pop(); 384 } 385 386 void rogic() { 387 state=checkState(); 388 } 389 390 391 boolean isPush() { 392 if (checkState()==2) 393 return true; 394 return false; 395 } 396 397 int checkState() { 398 if (!checkInMouse()) 399 return 0; 400 401 if (!mousePressed) 402 return 1; 403 return 2; 404 } 405 406 boolean checkInMouse() { 407 if (mouseX>x-sizeX/2 && mouseX <x+sizeX/2) { 408 if (mouseY>y-sizeY/2 && mouseY< y+sizeY/2) 409 { 410 return true; 411 } 412 } 413 return false; 414 } 415 416 void changeColor() { 417 switch(state) { 418 case 0: 419 fill(hue(baseCol), saturation(baseCol), brightness(baseCol)*nb); 420 421 break; 422 423 case 1: 424 fill(hue(baseCol), saturation(baseCol), brightness(baseCol)*pb); 425 426 427 428 case 2: 429 430 fill(hue(baseCol), saturation(baseCol), brightness(baseCol)*pb); 431 432 433 434 break; 435 436 default: 437 fill(0, 0, 0); 438 break; 439 } 440 } 441} 442 443 444 445 446
遠回しな表現では伝わらないようなので、はっきりお伝えしておきます(別に怒っているわけではないです)
* 参考コードは出典を明示してください
先方にも失礼ですし、自分で書いたコードと他人のコードの区別がつかないと質問者のスキル感が推測できないです。
* (使用していない関数等)不要なコードは載せないでください
(実際には使っているとしても)提示コード内で使っていなければ、行数の無駄ですし読む時間も無駄に取られてしまいます。
* 解決したら速やかに解決済にしてください
動作確認も取れ内容も理解でき疑問もなければ、その時に「解決済」にしてください。
新たに質問をする時に、前の質問を「解決済」にするような対応は不誠実に感じます。

回答1件
あなたの回答
tips
プレビュー