I would be very grateful for any help, trying to code Space Invaders in JS, managed to move aliens in functions to shift the board right left and down in Intervals, the laser shoot is also in another Interval moving it up.
The problem that sometimes when the laser hits the exact time aliens are shifting it shoots two aliens, and my alien counter on the screen doesn’t match the actual seen on the game, and cant finish the game, i finish the game according to the global var aliens counter, is it a problem of Intervals, or handleHit function I am not sure.
https://github.com/Farhan-Ganayim/Space-Invaders
https://farhan-ganayim.github.io/Space-Invaders/
I managed to shoot aliens and the score is fine, that happens when play game with slow aliens and shoot them accurately, but when setting the interval to 1 sec, sometimes the problem of shooting two aliens happens.
function handleAlienHit(pos) {
// clearInterval(laserInterval)
// updateCell(pos,null)
gGame.alienCount--
updateScore()
gHero.isShoot=false
}
function blinkLaser(pos) {
// var cellGameObject=gBoard[pos.i][pos.j].gameObject
updateCell(pos, LASER)
setTimeout(() => {
updateCell(pos, null)
}, 80)
}