MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / gamePlay

Function gamePlay

assets/js/carAvoidanceGame.js:51–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49 })
50}
51function gamePlay(){
52 let car=document.querySelector('.car');
53 let road=gameArea.getBoundingClientRect();
54 if(player.start){
55 moveLines();
56 moveEnemy(car);
57 if(keys.ArrowUp && player.y>(road.top+140)){
58 player.y-=player.speed;
59 }
60 if(keys.ArrowDown && player.y<(road.bottom-100)){
61 player.y+=player.speed;
62 }
63 if(keys.ArrowLeft && player.x>0){
64 player.x-=player.speed;
65 }
66 if(keys.ArrowRight && player.x<(road.width-70)){
67 player.x+=player.speed;
68 }
69 car.style.top=player.y + "px";
70 car.style.left=player.x + "px";
71 window.requestAnimationFrame(gamePlay);
72 player.score++;
73 let ps=player.score-1;
74 score.innerText="Score: " + ps;
75 }
76}
77function start(){
78 startScreen.classList.add('hide');
79 gameArea.innerHTML="";

Callers

nothing calls this directly

Calls 2

moveLinesFunction · 0.85
moveEnemyFunction · 0.85

Tested by

no test coverage detected