-
Notifications
You must be signed in to change notification settings - Fork 0
/
nitro.html
68 lines (51 loc) · 1.8 KB
/
nitro.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var nitropress=new Date();
var nitroend=new Date();
var flagtime=false;
function gamePlay(){
console.log(car.status);
if(!car.status){
ctx.clearRect(0,0,canvas.width,canvas.height);
background();
drawCar();
// console.log(obstacle.status +" "+ obstacle.x_coordinate+" "+obstacle.y_coordinate+" "+obstacle.oldObject);
if(nitroPress)
{ dy=4;
drawNitro();
if(!flagtime)
{nitropress=Date.now();
flagtime++;
}
}
nitroend=Date.now();
if(Math.floor(((nitroend-nitropress)/1000)%60)>2)
{ nitroPress=false;
dy=2;
ctx.clearRect(car.x+15,car.y+145,70,45);
flagtime=0;
}
if(obstacle.y>canvas.height){
obstacle.status = false;
obstacle.oldObject=false;
obstacle.y = 0;
//obstacleGeneration(obstacle.x_coordinate,obstacle.y_coordinate,obstacle.width,obstacle.height,obstacle.status);
}
obstacle.y = obstacleMovement(obstacle.y,obstacle.speed);
detect(obstacle.x,obstacle.y,obstacle.width,obstacle.height);
drawObstacle(obstacle.x,obstacle.y,obstacle.width,obstacle.height,obstacle.status);
}
else{
ctx.drawImage(gameover,130,80,250,180);
ctx.beginPath();
ctx.rect(130,260,250,100);
ctx.fill();
ctx.font="bold 25px serif";
ctx.fillStyle="green";
ctx.fillText("Press enter to start",153,280);
ctx.fillStyle="black";
ctx.closePath();
}
requestAnimationFrame(gamePlay);
ctx.fillStyle="black";
if(enterPress==true)
document.location.reload();
}