所以我对代码有很多初学者的知识,并且我正在尝试创建一个“森林”场景,用户可以点击5个小块的粘液模具,一旦他们点击它们就会消失。
现在有5块粘液霉菌在那里,但点击它们时什么也没发生。
我从其他人那里复制了很多这些代码,但没有看到他们所有的代码所以不知道我错过了什么。
我不知道该怎么做,但这是我的代码:
感谢任何帮助:)
var slimeMould1x = 210;
var slimeMould1y = 550;
var slimeMould2x = 400;
var slimeMould2y = 540;
var slimeMould3x = 650;
var slimeMould3y = 560;
var slimeMould4x = 930;
var slimeMould4y = 580;
var slimeMould5x = 1100;
var slimeMould5y = 565;
var slimeMouldx = [210, 400, 650, 930, 1100];
var slimeMouldy = [550, 540, 560, 580, 565];
var slimeMouldClicked = [slimeMould1Clicked, slimeMould2Clicked,
slimeMould3Clicked, slimeMould4Clicked, slimeMould5Clicked];
var slimeMould = [slimeMould1, slimeMould2, slimeMould3, slimeMould4,
slimeMould5];
var forest;
function preload () {
slimeMould1 = loadImage("assets/slimemould-01.png");
slimeMould2 = loadImage("assets/slimemould-01.png");
slimeMould3 = loadImage("assets/slimemould-01.png");
slimeMould4 = loadImage("assets/slimemould-01.png");
slimeMould5 = loadImage("assets/slimemould-01.png");
forest = loadImage("assets/forest-03.png");
}
function setup() {
createCanvas(1200, 800);
imageMode(CENTER);
}
function draw() {
background(10);
image(forest,width/2,height/2);
fill(255);
noStroke();
textAlign(CENTER, CENTER);
textSize(25);
text("collect all the slime mould!", width/2, height*0.97);
image(slimeMould1,slimeMould1x,slimeMould1y);
image(slimeMould2,slimeMould2x,slimeMould2y);
image(slimeMould3,slimeMould3x,slimeMould3y);
image(slimeMould4,slimeMould4x,slimeMould4y);
image(slimeMould5,slimeMould5x,slimeMould5y);
slimeMould1Click();
slimeMould2Click();
slimeMould3Click();
slimeMould4Click();
slimeMould5Click();
var noslimeMould = true;
for (i = 0; i < slimeMould.length; i++){
if (slimeMouldClicked[i] == false) {
image(slimeMould[i], slimeMouldx[i], slimeMouldy[i]);
noslimeMould = false;
}
}
}
function slimeMould1Click() {
if (slimeMouldClicked[0] == false) {
if ((mouseX > slimeMould1x) && (mouseX < (slimeMould1x+ 50)) &&
(mouseY > slimeMould1y) && (mouseY < (slimeMould1y+ 50))) {
slimeMouldClicked[0] = true;
}
}
}
function slimeMould2Click() {
if (slimeMouldClicked[1] == false) {
if ((mouseX > slimeMould2x) && (mouseX < (slimeMould2x+ 50)) &&
(mouseY > slimeMould2y) && (mouseY < (slimeMould2y+ 50))) {
slimeMouldClicked[1] = true;
}
}
}
function slimeMould3Click() {
if (slimeMouldClicked[2] == false) {
if ((mouseX > slimeMould3x) && (mouseX < (slimeMould3x+ 50)) &&
(mouseY > slimeMould3y) && (mouseY < (slimeMould3y+ 50))) {
slimeMouldClicked[2] = true;
}
}
}
function slimeMould4Click() {
if (slimeMouldClicked[3] == false) {
if ((mouseX > slimeMould4x) && (mouseX < (slimeMould4x+ 50)) &&
(mouseY > slimeMould4y) && (mouseY < (slimeMould4y+ 50))) {
slimeMouldClicked[3] = true;
}
}
}
function slimeMould5Click() {
if (slimeMouldClicked[4] == false) {
if ((mouseX > slimeMould5x) && (mouseX < (slimeMould5x+ 50)) &&
(mouseY > slimeMould5y) && (mouseY < (slimeMould5y+ 50))) {
slimeMouldClicked[4] = true;
}
}
}