scoreが5ずつ増えるたびにcountDownが+10秒増えるようにしたい。

processing

コード String question;String answer;String input;int score;float imgX=900;float imgVX=1;PImage img;PImage[] imgs;int timeLimit=60;int countDown;PImage imm;PImage imm1;PImage imm2;PImage imm3; Scene scene= Scene.TITLE;//現在のシーン enum Scene { TITLE, PLAY, GAMEOVER}; Button button;void setup() { size(800, 800); textSize(48); /* パネルの大きさ*/ colorMode(HSB, 360, 100, 100); textAlign(CENTER, CENTER); button=new Button(width/2, height/2, 200, 100, color(190, 100, 70), "PUSH!!"); imm=loadImage("brain.png"); imm1=loadImage("fishing.png"); imm2=loadImage("umi.png"); imm3=loadImage("umi1.jpg"); imgs=new PImage[]{ loadImage("ika.png"), loadImage("sake.png"), loadImage("tako.png"), loadImage("maguro.png"), loadImage("haze.png"), loadImage("tai.png"), loadImage("karei.png"), }; imgVX=random(1, 5); float f = random(imgs.length); // 0以上2未満のfloat値(1.234のような) int i = int(f); // 0か1(小数点以下を切り捨てる) img = imgs[i];} void draw() { background(127); switch(scene) { case TITLE: button.run(); if (button.isPush()) { scene= Scene.PLAY; } image(imm,100,500,200,200); image(imm1,500,500,200,200); textSize(90); text("Brain Fishing",400,200); break; case PLAY: image(imm2,0,0,800,300); int ms = millis()/1000; println(ms); fill(0); countDown = timeLimit - ms; fill(255); textSize(50); textAlign(RIGHT,TOP); text("COUNT DOWN : "+countDown, 500, 50); if (countDown<=0) { scene= Scene.GAMEOVER; } if(score==5){ countDown+=10; textSize(70); text("15秒増加",50,100); } showPanel(); // パネルの表示 mato(); textAlign(LEFT, BASELINE); text("SCORE: " + score, 10, 50); //textAlign(LEFT, BOTTOM); //text(answer, 10, 250); textAlign(CENTER, BOTTOM); text(input, 0, 0, width, 250); ps.run(); break; case GAMEOVER: image(imm3,0,0,800,800); textAlign(CENTER, CENTER); text(" TIME OVER", 0, 0, width, height); break; }}int reg = 0, val = 0;String op = "="; void calc(int id) { switch(id) { case 0: // 0以外の数字を入力した場合 case 1: case 2: case 4: case 5: case 6: case 8: case 9: case 10: if (disp == "0") { // "0" で始まる文字列にならないようにする disp = ""; } disp = disp+label[id]; // dispの後ろに1文字つなぐ break; case 12: // "0" if (disp != "0") { disp = disp + "0"; } break; case 3: // "+/-" プラスマイナス符号の入れ替え if (disp == "0") { } else if (disp.substring(0,1).equals("-")) { // 文字列 disp の最初の文字がマイナスのとき // マイナスを取り去った文字列をdispに代入 disp = disp.substring(1); } else { // 先頭にマイナスをつける disp = "-" + disp; } break; case 11: // "+" reg = int(disp); // dispの文字列を整数値にしてしまっておく disp = "0"; op = "+"; // 次にイコールがきたら足し算する break; case 7: // "-" reg = int(disp); disp = "0"; op = "-"; // 次いイコールがきたら引き算する break; case 13: // "=" 計算して結果を文字列として disp に代入 val = int(disp); if (op == "+") { op = "="; val = reg + val; disp = str(val); } else if (op == "-") { op = "="; val = reg - val; disp = str(val); } break; default: break; }} String disp = "0";final float x = 20;final float y = 300;final float w = 800 - 40;final float h = 400;final String[] label = { "7", "8", "9", "4", "5", "6", "1", "2", "3", "0", "", "C" };final ParticleSystem ps = new ParticleSystem(); void mousePressed() { switch(scene) { case TITLE: break; case PLAY: if (mouseX < x || mouseX > x + w) return; if (mouseY < y || mouseY > y + h) return; int i = int(3 * (mouseX - x) / w); int j = int(4 * (mouseY - y) / h); String s = label[getID(i, j)]; if (s.equals("C")) { // クリア input = ""; return; } input += s; if (input.equals(answer)) { // 正解 score++; ps.addParticle(new PVector(imgX, 150), question); imgX = 1000; // 範囲外に飛ばすことで、matoでの再設定を誘発させる } break; case GAMEOVER: scene = Scene.TITLE; exit(); break; }} void showPanel() { rect(x, y, w, h); for (int i = 0; i < label.length; i++) { showLabel(i); }} void showLabel(int i) { float bw = w / 3; float bh = h / 4; float bx = x + (i % 3) * bw; float by = y + (i / 3) * bh; fill(200); rect(bx, by, bw, bh); fill(0); textAlign(CENTER, CENTER); text(label[i], bx, by, bw, bh);} int getID(int i, int j) { return j * 3 + i;} void mato() { if (width < imgX) { imgX = 0; int a = int(random(1, 100)); int b = int(random(1, 100)); question = a + "+" + b; // 問題を文字列化 answer = str(a + b); // 答えも文字列化 input = ""; imgVX = random(1, 5); img = imgs[int(random(imgs.length))];//画像がランダムで選ばれる。 } image(img, imgX, 150, 100, 100);//X軸を等速直線に動く textAlign(LEFT, BASELINE); text(question, imgX, 150); imgX += imgVX;} // [Simple Particle System / Examples / Processing.org](https://processing.org/examples/simpleparticlesystem.html)// をベースに小改造(文字列を一文字ずつばらばらに四散させる)運動する粒子で表現される事象class ParticleSystem { ArrayList<Particle> particles = new ArrayList<Particle>(); void addParticle(PVector position, String str) { for (char c : str.toCharArray()) { particles.add(new Particle(position, c)); } } void run() { for (int i = particles.size() - 1; i >= 0; i--) { Particle p = particles.get(i); p.run(); if (p.isDead()) { particles.remove(i); } } }}class Particle { PVector position; PVector velocity = PVector.random3D().mult(10); float lifespan = 255; char c; Particle(PVector l, char c) { position = l.copy(); this.c = c; } void run() { update(); display(); } void update() { position.add(velocity); lifespan -= 2; } void display() { push(); translate(position.x, position.y); rotate(radians(position.z)); fill(0, lifespan); textAlign(CENTER, CENTER); text(c, 0, 0); pop(); } boolean isDead() { return lifespan < 0.0; }} class Button { float x, y; float sizeX, sizeY; int state; color baseCol; float nb; float sb; float pb; String str; Button(float x, float y, float sizeX, float sizeY, color baseCol, String str) { this.x=x; this.y=y; this.sizeY=sizeY; this.sizeX=sizeX; this.baseCol=baseCol; this.str=str; nb=1; sb=0.8; pb=0.6; } void run() { rogic(); display(); } void display() { push(); rectMode(CENTER); colorMode(HSB, 360, 100, 100); textAlign(CENTER, CENTER); noStroke(); changeColor(); rect(x, y, sizeX, sizeY); fill(0, 0, 100); textSize(30); text(str, x, y); pop(); } void rogic() { state=checkState(); } boolean isPush() { if (checkState()==2) return true; return false; } int checkState() { if (!checkInMouse()) return 0; if (!mousePressed) return 1; return 2; } boolean checkInMouse() { if (mouseX>x-sizeX/2 && mouseX <x+sizeX/2) { if (mouseY>y-sizeY/2 && mouseY< y+sizeY/2) { return true; } } return false; } void changeColor() { switch(state) { case 0: fill(hue(baseCol), saturation(baseCol), brightness(baseCol)*nb); break; case 1: fill(hue(baseCol), saturation(baseCol), brightness(baseCol)*pb); case 2: fill(hue(baseCol), saturation(baseCol), brightness(baseCol)*pb); break; default: fill(0, 0, 0); break; } }}

コメントを投稿

0 コメント