gpt4 book ai didi

javascript - 如何在处理中重生敌人

转载 作者:行者123 更新时间:2023-11-28 07:46:27 25 4
gpt4 key购买 nike

我正在为一个学校项目制作这个游戏,我们有一个敌人会向你猛冲,然后爆炸,如果你在爆炸半径内,你就会重生,而敌人会被摧毁并且不会重生。

我们希望如果你重生了,敌人也会重生

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),它只会继续增长,不会自行破坏。

到目前为止,我已经尝试了几种方法来让敌人重生,但到目前为止效果不佳。

最佳答案

当您希望敌人重生时,您需要重置 isExploded 变量。您应该能够在 Update 方法中执行此操作

void update(Player player) {
if(!isExploded) {
//...
}
else {
if (/*Your condition for respawning goes here*/){
isExploded=false; // and any other respawning code
}
}
}

关于javascript - 如何在处理中重生敌人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27380507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com