-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
69 lines (61 loc) · 1.38 KB
/
common.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
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
var context;
var canvas;
var gameWidth = window.innerWidth;
var gameHeight = window.innerHeight;
function loadImage(filename)
{
var ctemp = new Image();
ctemp.src = filename;
ctemp.onerror = function()
{
alert("common.js: cannot load image "+this.src);
};
return(ctemp);
}
function drawImage(img, x, y, w, h, a)
{
//Needed for Opera
w++;
if (img.complete && img.width > 0 && img.height > 0)
{
ct++;
context.save();
context.translate(x+w/2, y+h/2);
context.rotate(a);
context.drawImage(img, -w/2, -h/2, w, h);
context.restore();
}
}
function drawImageEx(img, sx, sy, sw, sh, x, y, w, h, a)
{
if (img.complete && img.width > 0 && img.height > 0)
{
ct++;
context.save();
context.translate(x+w/2, y+h/2);
context.rotate(a);
context.drawImage(img, sx, sy, sw, sh, -w/2, -h/2, w, h);
context.restore();
}
}
function testCollision(x, y, w, h, x2, y2, w2, h2, ex)
{
return(y+h+ex > y2 && y < y2+h2+ex && x+w+ex > x2 && x < x2+w2+ex);
}
function loadSound(filename)
{
name = filename.substring(0, filename.indexOf("."));
document.getElementById("musicbox").innerHTML += "<audio src=\""+filename+"\" id=\"snd_"+name+"\"></audio>";
}
function getDL(x1, y1, x2, y2)
{
return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
function playSound(name)
{
document.getElementById("snd_"+name).play();
}
function getDL(x, y, x2, y2)
{
return(Math.sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2)));
}