function cycle(){
  myContext.clearRect(0,0,myCanvas.width,myCanvas.height);
  resolveKeys();
  players.forEach(function(player){
    player.gravity();
    player.move();
    myContext.fillStyle=player.c;
    myContext.fillRect(player.x,player.y,player.w,player.h);
  })
  
  //Step 10: Make your looping function also draw the attacks
  attacks.forEach(function(attack){
    attack.display();
    myContext.fillStyle="green";
    myContext.strokeStyle="green";
    if(attack.fill){
      myContext.fillRect(attack.x,attack.y,attack.w,attack.h);
    } else {
      myContext.strokeRect(attack.x,attack.y,attack.w,attack.h);
    }
    attack.nextFrame();
    
    //Additional Challenges: Make it so if two attacks collide, both players get knocked away.
    attacks.forEach(function(otherAttack){
      if(attack.player !== otherAttack.player){
      if(hitDetect(attack,otherAttack)!==0){
        
        players.forEach(function(player){
          player.xAccel=player.xAccel*-1;
          player.move();
        })
      }
      }
    })
    
    //Step 12: Make your looping function detect if an Attack is colliding with a Player, and if so, stop the loop and show an alert.
    players.forEach(function(enemy){
      if(enemy !== attack.player){
        if(hitDetect(attack,enemy)!==0 || hitDetect(enemy,attack)!==0){
          clearInterval(loop);
          alert(attack.player.name + " wins!");
        }
      }
    })
  })
}
//Step 4:Create a function that loops ~30 times a second
Step 4:Create a function that loops ~30 times a second
Step 4 : Create a function that loops ~30 times a second
function cycle(){
  myContext.clearRect(0,0,myCanvas.width,myCanvas.height);
  resolveKeys();
  players.forEach(function(player){
    player.gravity();
    player.move();
    myContext.fillStyle=player.c;
    myContext.fillRect(player.x,player.y,player.w,player.h);
  })
  attacks.forEach(function(attack){
    attack.display();
    myContext.fillStyle="green";
    myContext.strokeStyle="green";
    if(attack.fill){
      myContext.fillRect(attack.x,attack.y,attack.w,attack.h);
    } else {
      myContext.strokeRect(attack.x,attack.y,attack.w,attack.h);
    }
    attack.nextFrame();
    attacks.forEach(function(otherAttack){
      if(attack.player !== otherAttack.player){
      if(hitDetect(attack,otherAttack)!==0){
        players.forEach(function(player){
          player.xAccel=player.xAccel*-1;
          player.move();
        })
      }
      }
    })
    players.forEach(function(enemy){
      if(enemy !== attack.player){
        if(hitDetect(attack,enemy)!==0 || hitDetect(enemy,attack)!==0){
          clearInterval(loop);
          alert(attack.player.name + " wins!");
        }
      }
    })
  })
}
function cycle ( ) { myContext . clearRect ( 0 , 0 , myCanvas . width , myCanvas . height ) ; resolveKeys ( ) ; players . forEach ( function ( player ) { player . gravity ( ) ; player . move ( ) ; myContext . fillStyle = player . c ; myContext . fillRect ( player . x , player . y , player . w , player . h ) ; } ) attacks . forEach ( function ( attack ) { attack . display ( ) ; myContext . fillStyle = "green" ; myContext . strokeStyle = "green" ; if ( attack . fill ) { myContext . fillRect ( attack . x , attack . y , attack . w , attack . h ) ; } else { myContext . strokeRect ( attack . x , attack . y , attack . w , attack . h ) ; } attack . nextFrame ( ) ; attacks . forEach ( function ( otherAttack ) { if ( attack . player !== otherAttack . player ) { if ( hitDetect ( attack , otherAttack ) !== 0 ) { players . forEach ( function ( player ) { player . xAccel = player . xAccel * - 1 ; player . move ( ) ; } ) } } } ) players . forEach ( function ( enemy ) { if ( enemy !== attack . player ) { if ( hitDetect ( attack , enemy ) !== 0 || hitDetect ( enemy , attack ) !== 0 ) { clearInterval ( loop ) ; alert ( attack . player . name + " wins!" ) ; } } } ) } ) }
Step 4:Create a function that loops ~30 times a second
Step 4 : Create a function that loops ~30 times a second
//Step 10: Make your looping function also draw the attacks //Additional Challenges: Make it so if two attacks collide, both players get knocked away. //Step 12: Make your looping function detect if an Attack is colliding with a Player, and if so, stop the loop and show an alert.