-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.js
More file actions
45 lines (32 loc) · 1.09 KB
/
Action.js
File metadata and controls
45 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let collispeCactus= (dino, cactus, ctx, animation, canvas)=>{
let xGap = cactus.x - (dino.x+dino.width);
let yGap = cactus.y -(dino.y +dino.height);
if(xGap <0 && yGap <0){
cancelAnimationFrame(animation);
ctx.clearRect(0, 0, canvas.width, canvas.height);
return true;
}
return false;
}
function collispeRocket(dino, rocket, ctx, animation, canvas){
let xGap = rocket.x - (dino.x+dino.width);
let yGap = (rocket.y+rocket.height) -(dino.y);
if(xGap <0 && yGap >0){
cancelAnimationFrame(animation);
ctx.clearRect(0,0,canvas.width, canvas.height);
return true;
}
return false;
}
function collispeCoin(dino, coin, ctx,coinScore){
let xGap = coin.x - (dino.x+dino.width);
let yGap = (coin.y+coin.height) -(dino.y);
if(xGap <0 && yGap >0){
console.log(coinScore);
coinScore+=1;
ctx.clearRect(coin.x,coin.y ,coin.width, coin.height);
return coinScore;
}
return coinScore;
}
export {collispeCactus, collispeRocket, collispeCoin};