-1

我的代码中的这个函数使一个精灵在接触另一个精灵时做一些事情。但是当它这样做时,会弹出错误消息。我对它进行了多次测试,但它一直在做同样的事情。我已经尝试移动我现在拥有的功能,但它仍然显示错误消息。这是我的代码:

// Create your variables here
var baconLives = 5;
var evilwaffleLives = 5;

// Create your sprites here
var miniEggs = createSprite(190, 355);
miniEggs.setAnimation("face_friedegg_1");
miniEggs.scale = 0.15;
var fryPan = createSprite(200, 370);
fryPan.setAnimation("fried_egg_2");
fryPan.scale = 0.25;
var cuteBacon = createSprite(192, 355);
cuteBacon.setAnimation("face_bacon_1");
cuteBacon.scale = 0.18;
var miniEvilWaffle = createSprite(200, 40);
miniEvilWaffle.setAnimation("face_waffle_1");
miniEvilWaffle.scale = 0.15;
var evilWaffleKing = createSprite(200, 40);
evilWaffleKing.setAnimation("face_waffle_1");
evilWaffleKing.scale = 0.2;
var blueMixer = createSprite(50, 37);
blueMixer.setAnimation("mixer_1");
blueMixer.scale = 0.6;
var goldCrown = createSprite(170, 25);
goldCrown.setAnimation("gameplay_crown_1");
goldCrown.scale = 0.1;
goldCrown.rotation = 310;
var miniEggs2 = createSprite(30, 365);
miniEggs2.setAnimation("face_egg_1");
miniEggs2.scale = 0.15;

function draw() {
miniEggs.rotationSpeed = 5;
miniEvilWaffle.rotationSpeed = -5;
// draw background
if (baconLives < 1) {
background("black");
} else {
background("lightgray");
noStroke();
fill("gray");
rect(0, 330, 400, 200);
fill(rgb(239, 196, 125));
rect(0, 0, 400, 75);
}
if (evilwaffleLives < 1) {
background("black");
} else {
background("lightgray");
noStroke();
fill("gray");
rect(0, 330, 400, 200);
fill(rgb(239, 196, 125));
rect(0, 0, 400, 75);
}

// update sprites
showLives();
setAttack();
spriteMovement();

drawSprites();
}

// Create your functions here
function showLives() {
fill("black");
textSize(20);
text("Bacon Lives: ", 5, 320);
text(baconLives, 125, 320);
text("Evil Waffle Lives: ", 5, 95);
text(evilwaffleLives, 160, 95);
}
function spriteMovement() {
if (keyDown("right")) {
cuteBacon.x = cuteBacon.x + 3;
fryPan.x = fryPan.x + 3;
miniEggs.x = miniEggs.x + 3;
}
if (keyDown("left")) {
cuteBacon.x = cuteBacon.x + -3;
fryPan.x = fryPan.x + -3;
miniEggs.x = miniEggs.x + -3;
}
if (keyDown("up")) {
miniEggs.velocityY = -3;
miniEggs.velocityX = 0;
}
}
function setAttack() {
if (miniEvilWaffle.isTouching(cuteBacon)) {
cuteBacon = cuteBacon - 1;
miniEvilWaffle.x = 200;
miniEvilWaffle.y = 40;
miniEvilWaffle.velocityY = 0;
}
if (miniEggs.isTouching(evilWaffleKing)) {
evilWaffleKing = evilWaffleKing - 1;
miniEggs.x = 190;
miniEggs.y = 355;
miniEggs.velocityY = 0;

} }

4

0 回答 0