-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcatch01.js
39 lines (33 loc) · 832 Bytes
/
catch01.js
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
// Create the canvas
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = 512;
canvas.height = 480;
document.body.appendChild(canvas);
// Background image
var bgReady = false;
var bgImage = new Image(); //we have an image object
bgImage.src = "chpaper.png";
bgImage.onload = function () {
//different way to create a function
bgReady = true;
};
// Draw everything
var render = function () {
{
ctx.drawImage(bgImage, 0, 0);
}
var symbolCaught = 0
// Score
ctx.fillStyle = "rgb(250, 250, 250)";
ctx.font = "24px serif";
ctx.textAlign = "left";
ctx.textBaseline = "top";
ctx.fillText("Symbols collected: " + symbolCaught , 32, 32);
};
// The main game loop
var main = function () {
render();
};
// Let's play this game!
setInterval(main, 1); // Execute as fast as possible