CodingTrain / CodingTrain/Suggestion-Box
my flower aint deleting
- Dominant language
- No language data
- Stars
- 570
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
So I'm trying to create a javascript space invaders game I got flowers, a spaceship & some bullet, but for some reason 2 of my 6 flowers refuse to be deleted no matter how many bullets i send into them. It starts off with 6 flowers and only 4 of them will allow me to delete them.

here the flower code:
`function Flower(x,y) {
this.x = x;
this.y = y;
this.r = 15;
this.life = 1;
this.toDelete = false;
this.xdir = 1;
this.grow = function(){
this.life -= 1;
if (this.life <= 0){
this.toDelete = true;
}
}
this.shiftDown = function(){
this.xdir *= -1;
this.y += this.r*2;
}
this.move = function() {
this.x = this.x + this.xdir;
}
this.show = function(){
fill(255,0,200);
ellipse(this.x,this.y,this.r*2,this.r*2);
}
}`
here the place where it is shown and deleted on the main
`var edge = false;
for (var i = 0; i < flowers.length; i++){
flowers[i].show();
flowers[i].move();
if (flowers[i].x > width || flowers[i].x < 0){
edge = true;
}
}
if (edge) {
for (var i = 0; i < flowers.length; i++){
flowers[i].shiftDown();
}
}
for (var i = drops.length-1; i > 1; i--){
if (drops[i].toDelete){
drops.splice(i,1);
}
}
for (var i = flowers.length-1; i > 1; i--){
if (flowers[i].toDelete){
flowers.splice(i,1);
}
}`
can anyone tell me why the flowers wont delete like the other 4? if need to see anymore just asked I copied it from space invaders coding train with an added life.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.