-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay-window.html
70 lines (70 loc) · 1.42 KB
/
play-window.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
<!DOCTYPE html>
<html>
<head>
<title>Play Window - 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 = 300;
this.canvas.height = 300;
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(10, 10, "yellow", 0, 290);
game.start();
}
var step=0;
var item=0;
function update() {
if(item > 18) {
step++;
item=0;
loading.x=step * 15;
loading.y=290;
}
if(step > 18) {
game.clear();
}
loading.x += 15;
loading.y -= 15;
item++;
loading.update();
}
window.addEventListener("load", function() {
start();
});
</script>
</body>
</html>