至急!助けてください!
processingで脱出 緑の四角を押した時にゲームができるようにしたいです
processingで脱出ゲームをつくっています。助けて欲しいです!
緑の四角を押した時にゲームができるようにしたいです。またイカを押すことが出来なくなっているので、改善策コード欲しいです。クリアした時に、アイテムが出てくるようにもしたいです。
解決方法を教えて下さい。
発生している問題・エラー
出ているエラーメッセージを入力
NameError (uninitialized constant World)
または、問題・エラーが起きている画像をここにドラッグアンドドロップ
該当するソースコード
ソースコードを入力
boolean hasKey= false;
boolean door= false;
PImage door1;
PImage door2;
PImage table;
PImage key1;
PImage tokei;
int scale = 0;
int scene = 0;
int myPositionX;
int myPositionY;
int cnt = 0;
void setup() {
size(480, 480);
background(250, 250, 250);
textFont(createFont("SansSerif", 15, true));
}
void heya1() {
fill(255, 255, 255);
fill(148, 149, 162);
rect(100, 70, 380, 300);
quad(0, 0, 100, 70, 100, 370, 0, 480);
door1= loadImage("door_close.png");
door2= loadImage("door_open.png");
table= loadImage("table_syoumen_wood.png");
key1= loadImage("key.png");
tokei =loadImage("clock_0800.png");
image(door1, 250, 170, door1.width0.28, door1.height0.28);
fill(255, 0, 0);
triangle(380, 200, 380, 130, 440, 170);
fill(255, 0, 0);
triangle(190, 80, 270, 80, 230, 30);
}
void heya2() {
fill(148, 149, 162);
rect(0, 70, 380, 300);
quad(380, 70, 480, 0, 480, 480, 380, 370);
fill(255, 0, 0);
triangle(80, 200, 80, 130, 40, 170);
image(table, 80, 350, table.width0.22, table.height0.22);
image(tokei, 300, 10, tokei.width0.15, tokei.height0.15);
if (hasKey ==false) {
image(key1, 130, 360, key1.width0.08, key1.height0.08);
}
}
void draw() {
background(255, 255, 255);
if (scale == 0) {
fill(0, 0, 0);
text("スペースキーを押してゲームスタートだ!", 100, 240);
text("この家から脱出せよ!", 240, 300);
} else if (scale == 1) {
heya1();
} else if (scale == 2) {
heya2();
} else if (scale == 3) {
heya3();
} else if (scale == 4) {
heya4();
} else if (scale == 5) {
heya5();
}
if (scene == 1) {
gamestart();
print(scale);
print(scene);
} else if (scene == 2) {
gameplay();
} else if (scene == 3) {
gameclear();
}
}
void heya3() {
fill(255, 255, 255);
fill(148, 149, 162);
rect(100, 70, 380, 300);
quad(0, 0, 100, 70, 100, 370, 0, 480);
image(door2, 250, 170, door1.width0.28, door1.height0.28);
fill(255, 0, 0);
rect(50, 100, 50, 50);
fill(0, 0, 0);
text("reset", 60, 125);
fill(255, 0, 0);
triangle(190, 80, 270, 80, 230, 30);
}
void heya4() {
fill(255, 0, 0);
rect(100, 70, 380, 300);
}
void heya5() {
fill(255, 255, 255);
fill(148, 149, 162);
rect(100, 70, 380, 300);
quad(380, 70, 480, 0, 480, 480, 380, 370);
quad(0, 0, 100, 70, 100, 370, 0, 480);
fill(0, 255, 0);
rect(310, 80, 60, 60);
}
void mousePressed() {
//scale1の時
if (scale==1) {
if (mouseX >=380 && mouseX <440 && mouseY >= 130 && mouseY < 200) {
scale=2;
}
if (mouseX >=250 && mouseX <380 && mouseY >= 170 && mouseY < 370) {
if (hasKey ==true) {
scale = 3;
}
}
} else if (scale == 2) {
if ((mouseX >=50 && mouseX < 100 && mouseY >= 100 && mouseY < 200)) {
scale = 1;
}
if (mouseX >= 130 && mouseX < 210 && mouseY >= 360 && mouseY < 420) {
hasKey=true;
}
} else if (scale == 3) {
if (mouseX >=50 && mouseX < 100 && mouseY >= 100 && mouseY < 200) {
scale = 4;
hasKey = false;
} else if (scale == 3) {
println("aaaaaaaaaa");
println(scale);
if (mouseX >=190 && mouseX < 270 && mouseY >= 30 && mouseY < 80) {
scale = 5;
}
println("bbbbbbbbbbb");
if ( mouseX >=310 && mouseX < 370 && mouseY >= 60 && mouseY < 140) {
scene = 1;
println("cccccccc");
println(scene);
}
if (scene == 3) {
scene = 1;
//カウントリセット
cnt = 0;
}
}
//クリック判定 rectで使っているxyにランダム関数を入れているから毎回位置が変わっても押せるようになる
if (myPositionX - 10 <= mouseX && myPositionX + 10 >= mouseX && myPositionY - 10 <= mouseY && myPositionY + 10 >= mouseY) {
//カウント
cnt = cnt + 1;
//モグラの位置替え
myPositionX = int(random(10, 470));
myPositionY = int(random(10, 470));
}
}
//クリア判定
if (cnt == 10) {
scene = 3;
}
println("x:" + mouseX);
println("y:" + mouseY);
}
void keyPressed() {
if (key == ' ' && scale == 0) {
scale = 1;
} else if (key == ' ' && scale == 3) {
scale = 0;
}
if (scene == 1 && keyCode == ' ') {
scene = 2;
//モグラの初期位置ランダム
myPositionX = int(random(10, 470));
myPositionY = int(random(10, 470));
}
}
void gamestart() {
textSize(30);
fill(0);
text("Press Space key to start", 90, 200);
}
void gameplay() {
noStroke();
fill(19, 37, 150);
triangle(myPositionX-20, myPositionY-10, myPositionX, myPositionY-30, myPositionX+20, myPositionY-10);
triangle(myPositionX-20, myPositionY-10, myPositionX, myPositionY, myPositionX+20, myPositionY-10);
ellipse(myPositionX, myPositionY, 25, 40);
fill(19, 37, 150);
ellipse(myPositionX-9, myPositionY+15, 4, 35);
ellipse(myPositionX-3, myPositionY+15, 4, 35);
ellipse(myPositionX+9, myPositionY+15, 4, 35);
ellipse(myPositionX+3, myPositionY+15, 4, 35);
fill(255, 255, 255);
ellipse(myPositionX-5, myPositionY-5, 11, 15);
ellipse(myPositionX+5, myPositionY-5, 11, 15);
fill(0, 0, 0);
ellipse(myPositionX-5, myPositionY-8, 5, 5);
ellipse(myPositionX+5, myPositionY-8, 5, 5);
textSize(25);
fill(0);
text(cnt + "/" + "10", 390, 30);
myPositionX = myPositionX +1;
myPositionY = myPositionY +1;
myPositionX = myPositionX % 480;
myPositionY = myPositionY % 480;
}
void gameclear() {
textSize(25);
fill(0);
text(cnt + "/" + "10", 390, 30);
textSize(30);
fill(255, 0, 0);
text("congratulations!!", 140, 240);
}
自分で試したこと
ここに問題・エラーに対して試したことを記載してください。
緑の四角を押した時にスペースキーを押してくださいの文字が出てきて、押したらいかのゲームができるようにしたい!イカを押すことも出来なくなっているので、改善策コード欲しいです。