-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
93 lines (70 loc) · 2.38 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="Canvas.js"></script>
<script src="Dino.js"></script>
<script src="Cactus.js"></script>
<script src="Background.js"></script>
<style type="text/css">
body {
background-color: #d2d1d1;
}
.canvasDiv{
width: 90%;
background-color: white;
}
</style>
</head>
<body>
<h1>Dino Game</h1>
<br>
<div class="canvasDiv">
<canvas id="viewport" height="300"></canvas>
</div>
<br><br><br><br>
<h1 id="count">0</h1>
//2404 130
<img id="sprite" src="images/sprite.png">
<script>
window.onload = function() {
var canvas = new Canvas(document.getElementById("viewport"));
canvas.width = document.body.clientWidth * 0.9;
var image = document.getElementById("sprite");
var dino = new Dino(canvas, image);
var background = new Background(canvas, image);
var sec = 0;
var speed = 10;
var myFunction = function(){
clearInterval(interval);
var quantity = (speed >= 0 ? 2 : 2 + (-1 * speed));
for(var i = 0; i < quantity; i++) {
canvas.clear();
dino.draw();
background.draw();
}
interval = setInterval(myFunction, speed);
}
var interval = setInterval(myFunction, 0);
setInterval(function() {
sec++;
if(sec % 1 == 0) {
speed = 10 - (sec * 0.12);
}
}, 1000)
window.onkeydown = function (event) {
let key = event.code;
switch (key) {
case "Space":
dino.jump();
break;
}
}
};
</script>
</body>
</html>