Hi I’m trying to say that whenever the enemy sprite leaves the screen a mini sprite will be spawned. I already managed to ensure that mini sprites are spawn when enemy leaves the screen but it spawns all eight mini sprite immediately. My thought logic is whenever enemy sprite i plus one but does not increase to the max of 8. However, I tried many ways and still unable to do so. Can anyone help me out thx.
if (enemyexit == true) {
for (int i = 0; i<Mcnum; i++) {
minicreature(mouseX+Mpos[i][0], mouseY+Mpos[i][1]);
float XDofMDetection = mouseX+Mpos[i][0]-x; // x point difference between 2 of the detection circle
float YDofMDetection = mouseY+Mpos[i][1]-y; // y point difference between 2 of the detection circle
float RofMDetection = 40+55; // total radius of both circle
if (XDofMDetection * XDofMDetection + YDofMDetection * YDofMDetection <= RofMDetection *RofMDetection) { //XDofMDetection * XDofMDetection + YDofMDetection * YDofMDetection code is the distance between centre point of enemny and mini detection circle
fill(255, 0, 0);
textSize(80);
text("GAMEOVER", 250, 450);
noLoop();
}
}
Mcnum++;
}
if (Mcnum > 8) {
Mcnum = 8;
}
}
void MassignV() {
for (int i = 0; i < 8; i++) {
Mpos[0][0]= random(120, 150);
Mpos[0][1]= random(-150, 120);
Mpos[1][0]= random(-120, -150);
Mpos[1][1]= random(-150, 120);
Mpos[2][0]= random(-150, 150);
Mpos[2][1]= random(120, 150);
Mpos[3][0]= random(-150, 150);
Mpos[3][1]= random(-150, -120);
Mpos[4][0]= random(120, 150);
Mpos[4][1]= random(-150, 120);
Mpos[5][0]= random(-120, -150);
Mpos[5][1]= random(-150, 120);
Mpos[6][0]= random(-150, 150);
Mpos[6][1]= random(120, 150);
Mpos[7][0]= random(-150, 150);
Mpos[7][1]= random(-150, -120);
}
}
Then we would have here: Mpos[0] = new PVector (random(120, 150), random(-150, 120) );
Much better.
Remark 2
for this line:
if (XDofMDetection * XDofMDetection + YDofMDetection * YDofMDetection <= RofMDetection *RofMDetection) { //XDofMDetection * XDofMDetection + YDofMDetection * YDofMDetection code is the distance between centre point of enemny and mini detection circle
Hi actually wat I want to achieve is whenever the enemy sprite leaves only one mini sprite appears. If the enemy leaves for the second time, another one appear but the first one still remains. I would like this effect to be achieved the most 8 times. How should I change my code to achieve this effect?
Thx. The way I’m thinking of now is whenever enemy sprite leave the value of i increase by one to affect the array. But this only occurs one if I change my code like this. Where did I go wrong?
int i = -1;
if (enemyexit == true) {
i++;
if (i >7){
i =7;
}
minicreature(mouseX+Mpos[i][0], mouseY+Mpos[i][1]);
}
Hi I understood what you are trying to tell me and hv tried to apply it but now whenever enemy sprite leaves the screen it spawns 8 mini sprite in a flickering motion and all the mini sprite immediately disappear. Where did I go wrong?
if (enemyexit == true) {
int i = Mcnum;
if (Mcnum < 8){
minicreature(mouseX+Mpos[i][0], mouseY+Mpos[i][1]);
}
Mcnum = Mcnum+1;
}