Q&A
processingでこのようなコードを打ち込んだのですが、
エラーが出ます。
どこが悪いのか教えてください。
ちなみにエラーはunexpected token : voidとでます。
import processing.sound.*;
PFont myFont;
PImage doorImg, wallImg, floorImg, clockImg, keyImg;
SoundFile jiggleSound, clankSound, openSound;
Item door, clock, theKey;
boolean solvedFlg = false;
boolean searchFlg = false;
boolean keyFlg = false;
String message = "";
int stat=0; //画面状態を表す状態変数
int x1=0, y1;
void setup() {
size(480, 480);
background(255, 255, 255);
fill(0, 0, 0);
noStroke();
frameRate(40);
myFont = createFont("YuGothic", 24, true);
textFont(myFont);
y1=height;
doorImg = loadImage("sign_door.jpg"); wallImg = loadImage("01murocrep512.jpg"); floorImg = loadImage("metal_s01.png"); clockImg = loadImage("BlackAndWhite2_S.png"); keyImg = loadImage("key.png"); jiggleSound = new SoundFile(this, "LockedDoorHandleJiggle.wav"); clankSound = new SoundFile(this, "dropmetalthing.ogg"); openSound = new SoundFile(this, "closing door.ogg"); door = new Item(doorImg, 150, 133, 6); clock = new Item(clockImg, 350, 100, 50); theKey = new Item(keyImg, 350, 310, 7);
}
void draw() {
background(200);
switch(stat) {
case 0: //状態変数が0(つまり画面がTitle)のときの動作 fill(0); textSize(48); text("脱出せよ", 160, 240); textSize(24); text("click to the screan", 150, 300); break;
case 1: //ゲーム画面
image(wallImg, 0, 0, 480, 300); image(floorImg, 0, 300, 480, 150); door.draw(); clock.draw(); if (searchFlg && !keyFlg) { theKey.draw(); } if (solvedFlg) { fill(0); textSize(48); text("CLEAR!", 100, 240); } fill(255); text(message, 10, 475);
}
}
void draw() {
int imgWidth = img.width / scale;
int imgHeight = img.height / scale;
image(img, xpos, ypos, imgWidth, imgHeight);
}
boolean isIn(int x, int y) {
if (x >= xpos && x <= xpos + img.width / scale &&
y >= ypos && y <= ypos + img.height / scale) {
return true;
} else {
return false;
}
class Item {
PImage img;
int xpos;
int ypos;
int scale;
Item(PImage _img, int _xpos, int _ypos, int _scale) { img = _img; xpos = _xpos; ypos = _ypos; scale = _scale; } void draw() { int imgWidth = img.width / scale; int imgHeight = img.height / scale; image(img, xpos, ypos, imgWidth, imgHeight); } boolean isIn(int x, int y) { if (x >= xpos && x <= xpos + img.width / scale && y >= ypos && y <= ypos + img.height / scale) { return true; } else { return false; } }
}
void mousePressed()
{
switch(stat) {
case 0:
if (mouseX<width) {
x1=0; //次の状態で必要な変数の初期化
stat=1;//ゲーム画面1状態に移る
}
break;
case 1:
message = "";
if (solvedFlg) {
return;
}
if (door.isIn(mouseX, mouseY)) { if (keyFlg) { solvedFlg = true; openSound.play(); } else { jiggleSound.play(); message = "鍵がかかっている。"; } } if (clock.isIn(mouseX, mouseY)) { if (!searchFlg) { searchFlg = true; clankSound.play(); message = "何かが落ちたようだ…"; } } if (theKey.isIn(mouseX, mouseY)) { if (searchFlg && !keyFlg) { keyFlg = true; message = "鍵を見つけた!"; } }
}
}
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。