-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxi-style.html
74 lines (74 loc) · 1.46 KB
/
taxi-style.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
<!DOCTYPE html>
<html>
<head>
<title>Taxi Style - Canvas Excersice</title>
<style>
* {
padding: 0px;
margin: 0px;
}
canvas {
border: 1px solid gray;
background: black;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var loading;
var game = {
canvas: document.querySelector("#canvas"),
start: function() {
this.canvas.width = 400;
this.canvas.height = 400;
this.context = this.canvas.getContext("2d");
this.interval = setInterval(update, 20);
},
clear: function() {
this.context.fillStyle = '#ff6';
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
// this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}
function shape(width, height, color, x, y) {
this.width = width;
this.height = height;
this.x = x;
this.y = y;
this.update = function(){
game.context.fillStyle = color;
game.context.fillRect(this.x, this.y, this.width, this.height);
}
}
function start() {
loading = new shape(20, 20, "yellow", 0, 0);
game.start();
}
var step=0;
var item=0;
function update() {
loading.update();
loading.x += 40;
item++;
if(item > 20) {
item=0;
if(step % 2 == 0) {
loading.x=20;
}
else {
loading.x=0;
}
loading.y+=20;
step++;
}
if(step > 20) {
game.clear();
}
}
window.addEventListener("load", function() {
start();
});
</script>
</body>
</html>