我正在尝试制作一个向您发送方块的游戏,您必须通过移动控制它们周围的圆圈的鼠标来避免它们。
我添加了一个生命值来为游戏添加更多,并设置碰撞检测,以便从圆的中心到正方形的距离小于圆的半径,它就带走了一个生命。这个碰撞检测有效,只是在我检测碰撞的 if 语句中我添加了“lives = living - 1;”,但是一旦它们发生碰撞,生命值立即下降到 0。
float centerY = 250;
float centerX = 175;
float lives = 3;
float rectY1 = random(0,500);
float rectX1 = random(0,500);
float rectY2 = random(0,500);
float rectX2 = random(0,500);
float rectY3 = random(0,500);
float rectX3 = random(0,500);
float rectY4 = random(0,500);
float rectX4 = random(0,500);
float rectY5 = random(0,500);
float rectX5 = random(0,500);
float rectY6 = random(0,500);
float rectX6 = random(0,500);
int score = 0;
int squareRadius = 15;
void setup(){
size(500,500);
background(155);
}
void draw(){
boolean gameOver = false;
boolean lifeLost = false;
background(155);
fill(149,185,215);
ellipse(centerX,centerY,30,30);
centerX = mouseX;
centerY = mouseY;
fill(0);
rect(rectX1,rectY1,30,30);
rect(rectX2,rectY2,30,30);
rect(rectX3,rectY3,30,30);
rect(rectX4,rectY4,30,30);
rectX1 = rectX1 - 5;
rectX2 = rectX2 - 5;
rectX3 = rectX3 - 5;
rectX4 = rectX4 - 5;
rectX5 = rectX5 - 5;
if(rectX1 + 30 < 0){
rectX1 = 500;
rectY1 = random(0,600);
score = score + 1;
}
if(rectX2 + 30 < 0){
rectX2 = 500;
rectY2 = random(0,600);
score = score + 1;
}
if(rectX3 + 30 < 0){
rectX3 = 500;
rectY3 = random(0,600);
score = score + 1;
}
if(rectX4 + 30 < 0){
rectX4 = 500;
rectY4 = random(0,600);
score = score + 1;
}
if(rectX5 + 30 < 0){
rectX5 = 500;
rectY5 = random(0,600);
score = score + 1;
}
if(dist(mouseX,mouseY,rectX1,rectY1) < 30){
lifeLost = true;
}
if(dist(mouseX,mouseY,rectX2,rectY2) < 30){
lifeLost = true;
}
if(dist(mouseX,mouseY,rectX3,rectY3) < 30){
lifeLost = true;
}
if(dist(mouseX,mouseY,rectX4,rectY4) < 30){
lifeLost = true;
}
if(lifeLost == true){
lifeLost = false;
lives = lives - 1;
}
if(lives == 0 || lives < 0){
gameOver = true;
}
陪伴而非守候
白板的微信
相关分类