script.js 608 B

123456789101112131415161718192021222324
  1. const dino = document.getElementById('dino');
  2. const cactus = document.getElementById('cactus');
  3. document.addEventListener('keydown', function(event){
  4. jump();
  5. });
  6. function jump(){
  7. if(dino.classList != 'jump'){
  8. dino.classList.add('jump');
  9. }
  10. setTimeout(function(){
  11. dino.classList.remove('jump');
  12. }, 300)
  13. }
  14. let isAlive = setInterval(function(){
  15. let dinoTop = parseInt(window.getComputedStyle(dino).getPropertyValue('top'));
  16. let cactusLeft = parseInt(window.getComputedStyle(cactus).getPropertyValue('left'));
  17. if(cactusLeft < 50 && cactusLeft > 0 && dinoTop >= 140){
  18. alert('GAME OVER');
  19. }
  20. },10)