forked from Ezharjan/Web-basedRacerGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
74 lines (62 loc) · 1.42 KB
/
util.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
70
71
72
73
74
var Util = {};
Util.getRandomIntBetweenInterval = function (min, max) {
var value = Math.floor(Math.random() * (max - min + 1)) + min;
return value;
};
Util.drawGuidelines = function (context) {
var initialPosition = 100;
// Horizontal lines
for (var i = 0; i < 5; i++) {
context.beginPath();
context.moveTo(0, initialPosition);
context.lineTo(800, initialPosition);
context.stroke();
initialPosition += 100;
}
initialPosition = 160;
// Vertical lines
for (var i = 0; i < 5; i++) {
context.beginPath();
context.moveTo(initialPosition, 0);
context.lineTo(initialPosition, 600);
context.stroke();
initialPosition += GameConfig.scenario.lanesSize;
}
};
Util.drawLog = function (context, text) {
context.fillText(text, 680, 50);
};
Util.drawTextWithShadow = function (
context,
text,
x,
y,
textColor,
shadowOffsetX,
shadowOffsetY,
shadowColor
) {
context.save();
context.fillStyle = shadowColor;
context.fillText(text, x + shadowOffsetX, y + shadowOffsetY);
context.fillStyle = textColor;
context.fillText(text, x, y);
context.restore();
};
Util.drawPressAnyKey = function (context) {
context.save();
context.globalAlpha = 0.5;
context.fillRect(185, 470, 430, 40);
context.globalAlpha = 1;
Util.drawTextWithShadow(
context,
"PRESS ANY KEY TO START!",
200,
500,
"yellow",
2,
2,
"red"
);
context.restore();
};