CodingTrain / CodingTrain/Suggestion-Box

my flower aint deleting

Offen
#979 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Keine Sprachdaten
Sterne
570
Forks
85
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.
![space](https://user-images.githubusercontent.com/39027318/40280530-eb811628-5c22-11e8-9fea-f2a26ddd5905.png)

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Reproduziere das Spiel und untersuche den im Issue enthaltenen Flower-Code und die Löschschleifen, insbesondere, wie die Arrays durchlaufen werden, nachdem ein Objekt zur Löschung markiert wurde. Bestätige, dass jede Blume von einem Geschoss entfernt werden kann und dass die verbleibenden Objekte und das Bewegungsverhalten korrekt bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
game-dev
Issue-Typ
Bug
Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.