Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualPatriarch K

Posted 04 March 2013 - 04:03 PM

I have detected the problem myself, but I don't know what to do about it. If I remove the line that I've marked in the code in my collision detection method, then the boss will spawn without problems. I have two of this and I suppose it is something about a loop in a loop in a loop which have to loop multiple times. But I don't really understand how to solve that problem.

 

Jet.prototype.collision = function() {
   
 for (var i = 0; i < this.bullets.length; i++) {
   
  // Bullet with boss
    if(kills >= 50){    
if(this.bullets[i].drawX > bossX && this.bullets[i].drawX < bossX+100 && this.bullets[i].drawY > bossY && this.bullets[i].drawY < bossY+90 && this.bullets[i].bulletLife > 0 && this.bossLife > 0){
    this.collisiontest = true;
    if(this.collisiontest == true){
   this.bullets[i].bulletLife--; <<<<<<<<<<<<<<<<<<< THIS LINE MAKES IT SLOW!!
   this.bossLife--;
   this.collisiontest = false;
 }
}
}
    for (var j = 0; j < this.enemies.length; j++) {
        // Minuspoäng när fiender är utanför skärmen
            if(this.enemies[j].drawX > -10 && this.enemies[j].drawX < 0 && this.enemies[j].outScreen == false){
kills--;
this.enemies[j].outScreen = true;
            }

// Bullet with enemy
            if(this.bullets[i].drawX > this.enemies[j].drawX && this.bullets[i].drawX < this.enemies[j].drawX+50 && this.bullets[i].drawY+30 > this.enemies[j].drawY && this.bullets[i].drawY < this.enemies[j].drawY+25 && this.bullets[i].bulletLife > 0 && this.enemies[j].life > 0 ){
                this.enemies[j].life--;
                if(this.enemies[j].life < 1){
                    kills++;
                }
                 this.collisiontest = true;
                 if(this.collisiontest == true){
                this.bullets[i].bulletLife--;
                this.collisiontest = false;
              }
            }
        }
      } 
}

#1Patriarch K

Posted 04 March 2013 - 04:02 PM

I have detected the problem myself, but I don't know what to do about it. If I remove the line that I've marked in the code in my collision detection method, then the boss will spawn without problems. I have two of this and I suppose it is something about a loop in a loop in a loop which have to loop multiple times. But I don't really understand how to solve that problem.

 

Jet.prototype.collision = function() {
   
 for (var i = 0; i < this.bullets.length; i++) {
   
  // Bullet with boss
    if(kills >= 50){    
if(this.bullets[i].drawX > bossX && this.bullets[i].drawX < bossX+100 && this.bullets[i].drawY > bossY && this.bullets[i].drawY < bossY+90 && this.bullets[i].bulletLife > 0 && this.bossLife > 0){
    this.collisiontest = true;
    if(this.collisiontest == true){
   this.bullets[i].bulletLife--; <<<<<<<<<<<<<<<<<<< THIS LINE MAKES IT SLOW!!
   this.bossLife--;
   this.collisiontest = false;
 }
}
}
    for (var j = 0; j < this.enemies.length; j++) {
        // Minuspoäng när fiender är utanför skärmen
            if(this.enemies[j].drawX > -10 && this.enemies[j].drawX < 0 && this.enemies[j].outScreen == false){
kills--;
this.enemies[j].outScreen = true;
            }

// Bullet with enemy
            if(this.bullets[i].drawX > this.enemies[j].drawX && this.bullets[i].drawX < this.enemies[j].drawX+50 && this.bullets[i].drawY+30 > this.enemies[j].drawY && this.bullets[i].drawY < this.enemies[j].drawY+25 && this.bullets[i].bulletLife > 0 && this.enemies[j].life > 0 ){
                this.enemies[j].life--;
                if(this.enemies[j].life < 1){
                    kills++;
                }
                 this.collisiontest = true;
                 if(this.collisiontest == true){
                this.bullets[i].bulletLife--;
                this.collisiontest = false;
              }
            }
        }
      } 
}

PARTNERS