我正在为一个学校项目制作这个游戏,并且我们有这个敌人向你猛冲,然后爆炸,如果你在爆炸范围内,你将重生,敌人被摧毁并且不会重生。< / p>
我们希望如果你已经重生,敌人也会重生
class Suicidebot{
float x, y, radius;
int clr;
float xVelocity;
//float topPolice, rightPolice, bottomPolice, leftPolice;
float startingX;
boolean movement;
int timer, timer2;
boolean isExploded, startExploding;
void init(float xInput, float yInput, float radiusInput1, float radiusInput2) {
x = xInput;
y = yInput;
radius = radiusInput1;
radius = radiusInput2;
clr = color(0,255,255);
xVelocity = 5;
startingX = x;
movement = false;
timer = 0;
isExploded = false;
timer2 = 0;
startExploding = false;
}
void update(Player player) {
if(!isExploded) {
movement();
if (player.x > x - 300){
movement = true;
} else {
movement = false;
}
if(timer > 40){
colourSuicidebot(255,0,0);
xVelocity = 0;
timer = 0;
startExploding = true;
}
if(startExploding == true){
timer2+= 2;
radius +=8;
}
if(timer2 >= 60){
isExploded = true;
}
if(player.rightHitbox > x - radius/2 && player.leftHitbox < x +radius/2 && player.bottomHitbox > y - radius /2&& player.topHitbox < y +radius/2){
player.init(player.xStart, player.yStart);
isExploded = true;
}
if(theCamera.cameraToggle){
x += theCamera.cameraMove;
startingX += theCamera.cameraMove;
}
}
}
void movement(){
if (movement == true){
if(!isExploded) {
timer++;
}
x -= xVelocity;
}
}
void colourSuicidebot(int kleur1, int kleur2, int kleur3) {
clr = color(kleur1, kleur2, kleur3);
}
void draw() {
if(!isExploded) {
fill(clr);
ellipse(x,y,radius, radius);
}
}
}
如果我在绘图中删除if(!isExploded),它将继续增长并且不会破坏自己。
到目前为止,我已经尝试了几项让敌人重生的事情,但到目前为止并不好。
答案 0 :(得分:0)
当您希望敌人重生时,您需要重置isExploded
变量。您应该可以使用Update
方法
void update(Player player) {
if(!isExploded) {
//...
}
else {
if (/*Your condition for respawning goes here*/){
isExploded=false; // and any other respawning code
}
}
}