Reputation: 1
Im writing a webapp for a space invaders game and am getting this error when trying to write a function to get my Ship to shoot. "TypeError: can't define property "moveLaser": Object is not extensible" This is my code below.
Game.shoot = function(inv, invRem, sq, csi, w) {
let laserId;
let cli = csi;
Game.moveLaser = function() {
sq[cli].classList.remove('laser');
cli -= w;
if (! 20 < cli < 421 ) {
sq[cli].classList.add('laser');
if (sq[cli].classList.contains('invader')) {
sq[cli].classList.remove('laser');
sq[cli].classList.remove('invader');
sq[cli].classList.add('collision');
setTimeout(() => sq[cli].classList.remove('collision'), 300)
clearInterval(laserId);
let invaderRemoval = inv.indexOf(cli);
invRem.push(invaderRemoval);
results++;
resultsDisplay.innerHTML = results;
}
} else {
return;
}
}
laserId = setInterval(Game.moveLaser(), 100);
return[inv, invRem, sq, csi, w];
Upvotes: 0
Views: 186