Skip to content

Instantly share code, notes, and snippets.

@Srushtika
Created June 9, 2020 20:15
Show Gist options
  • Save Srushtika/a659d69b0273e0f50b99eebbd4ce63f0 to your computer and use it in GitHub Desktop.
Save Srushtika/a659d69b0273e0f50b99eebbd4ce63f0 to your computer and use it in GitHub Desktop.
Code snippet 16 - For multiplayer space invaders article
function startDownwardMovement(playerId) {
let interval = setInterval(() => {
if (players[playerId] && players[playerId].isAlive) {
players[playerId].y += PLAYER_VERTICAL_INCREMENT;
players[playerId].score += PLAYER_SCORE_INCREMENT;
if (players[playerId].y > SHIP_PLATFORM) {
finishGame(playerId);
clearInterval(interval);
}
} else {
clearInterval(interval);
}
}, PLAYER_VERTICAL_MOVEMENT_UPDATE_INTERVAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment