-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
128 lines (112 loc) · 2.97 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
let speed = 6;
let time = "s";
changeSpeed = (gearValue) => {
if (speed <= 1 && time == "s") {
speed = 999;
time = "ms";
}
if (speed > 999 && time == "ms") {
speed = 1;
time = "s";
}
if (gearValue < 0) {
if (time == "ms") {
if (speed < 100) speed += 10;
else speed += 300;
} else {
speed += 5;
}
} else {
if (time == "ms") {
if (speed < 100) speed -= 10;
else speed -= 300;
} else {
speed -= 5;
}
}
if (speed < 0 && time == "ms") {
alert("Brake failed!! Please refresh the game.");
}
if (speed > 20 && time == "s") {
alert("Too Slow to Move. Please increase the speed Or refresh the game.");
}
document.getElementById("road").style.animation =
"moving " + speed + "" + time + " linear infinite";
document.getElementById("speedometer").innerHTML = speed + "" + time;
};
brake = (ev) => {
changeSpeed(-1);
};
accelerate = (ev) => {
changeSpeed(1);
};
</script>
<head>
<style>
body {
margin: 0;
padding: 0;
}
.background {
height: 100vh;
background: url(https://i.postimg.cc/k4G4fPVb/background-Copy.png);
background-position: bottom left;
animation: moving 3s linear infinite;
}
.car {
position: absolute;
left: 200px;
bottom: -50px;
width: 200px;
}
@keyframes moving {
from {
background-position: bottom right;
}
to {
background-position: bottom left;
}
}
#rotateMode {
border-radius: 50%;
width: 125px;
height: 125px;
background-color: blue;
color: white;
position: absolute;
top: 80%;
left: 80%;
}
#left {
position: absolute;
top: 50%;
left: 0px;
transform: translateY(-50%);
}
#right {
position: absolute;
top: 50%;
right: 0px;
transform: translateY(-50%);
}
</style>
</head>
<div class="background" id="road">
<img src="https://i.postimg.cc/26DGZT3M/car.png" class="car" alt="">
<div class='circleBase' id='rotateMode'>
<table>
<tr>
<td>
<button id="left" onclick="brake();" class="btn btn-default btn-sm"><span
class="glyphicon glyphicon-arrow-left"></span></button>
</td>
<td> <button id="right" onclick="accelerate ();" class="btn btn-default btn-sm"><span
class="glyphicon glyphicon-arrow-right"></span></button> </td>
</tr>
</table>
</div>
</div>