-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathlodeRunner.misc.js
213 lines (185 loc) · 4.85 KB
/
lodeRunner.misc.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//============
// MISC
//============
var DEBUG = 0;
var demoSoundOff = 1;
function debug(string) {
if(DEBUG) console.log(string);
}
function assert(expression, msg)
{
if(DEBUG) console.assert(expression, msg);
}
function getScreenSize()
{
var x, y;
//----------------------------------------------------------------------
// Window size and scrolling:
// URL: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
//----------------------------------------------------------------------
if (typeof (window.innerWidth) == 'number') {
//Non-IE
x = window.innerWidth;
y = window.innerHeight;
} else if ((document.documentElement) &&
(document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards compliant mode'
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 compatible
x = document.body.clientWidth;
y = document.body.clientHeight;
}
return {x:x, y:y};
}
//==============================
// Too many user created Levels
//==============================
var editWarningText = null;
function editWarningMsg(hidden)
{
var x, y, width, height;
if(editWarningText == null)
editWarningText = new createjs.Text("Too many user created levels !",
"bold " + (64*tileScale) + "px Helvetica", "#fc5c1c");
width = editWarningText.getBounds().width;
height = editWarningText.getBounds().height;
x = editWarningText.x = (NO_OF_TILES_X*(tileW+EDIT_PADDING) - width) / 2 | 0;
y = editWarningText.y = (NO_OF_TILES_Y*tileH - height) / 2 | 0;
editWarningText.shadow = new createjs.Shadow("white", 2, 2, 1);
if(hidden) {
mainStage.removeChild(editWarningText);
} else {
mainStage.addChild(editWarningText);
}
mainStage.update();
}
//================================
// show tips messgae
//===============================
function showTipsMsg(_tipsTxt, _stage, _scale)
{
var TEXT_SIZE = 72* _scale;
var TEXT_COLOR = "#ff2020";
var tipsText = new createjs.Text(_tipsTxt, "bold " + TEXT_SIZE + "px Helvetica", TEXT_COLOR);
var screenX1 = _stage.canvas.width;
var screenY1 = _stage.canvas.height;
tipsText.x = (screenX1) / 2 | 0;
tipsText.y = screenY1/2 - tipsText.getBounds().height*5/4 | 0;
tipsText.shadow = new createjs.Shadow("white", 3, 3, 2);
tipsText.textAlign = "center";
_stage.addChild(tipsText);
createjs.Tween.get(tipsText).set({alpha:1}).wait(50).to({scaleX:1.2, scaleY:1.2, alpha:0}, 2000)
.call(function(){_stage.removeChild(tipsText);});
}
//==========================================
// move z-index to top for a child of stage
//==========================================
function moveChild2Top(stage, obj)
{
stage.setChildIndex(obj, stage.getNumChildren() - 1);
}
//==========================
// BEGIN for Sound function
//==========================
var soundOff = 0;
function soundPlay(name)
{
if(soundOff || playMode == PLAY_AUTO || (playMode == PLAY_DEMO && demoSoundOff)) return;
if(typeof name == "string") {
return createjs.Sound.play(name);
} else {
name.stop(); //12/21/2014 , for support soundJS 0.6.0
name.play();
}
}
function soundStop(name)
{
if(soundOff || playMode == PLAY_AUTO || (playMode == PLAY_DEMO && demoSoundOff)) return;
if(typeof name == "string") {
return createjs.Sound.stop(name);
} else {
name.stop();
}
}
function soundPause(name)
{
if(soundOff || playMode == PLAY_AUTO || (playMode == PLAY_DEMO && demoSoundOff)) return;
if(typeof name == "string") {
return createjs.Sound.pause(name);
} else {
name.pause();
}
}
function soundResume(name)
{
if(soundOff || playMode == PLAY_AUTO || (playMode == PLAY_DEMO && demoSoundOff)) return;
if(typeof name == "string") {
return createjs.Sound.resume(name);
} else {
name.resume();
}
}
//===============
// Random Object
//===============
function rangeRandom(minValue, maxValue, seedValue)
{
var rndList, idx, items;
var min, max;
var reset;
var seed = 0;
function rndStart()
{
var swapId, tmp;
rndList = [];
for(var i = 0; i < items; i++) rndList[i] = min + i;
for(var i = 0; i < items; i++) {
if(seedValue > 0) {
seed = seedValue;
swapId = (seedRandom() * items) | 0;
} else {
swapId = (Math.random() * items) | 0;
}
tmp = rndList[i];
rndList[i] = rndList[swapId];
rndList[swapId] = tmp;
}
idx = 0;
//debug(rndList);
}
function seedRandom()
{
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
this.get = function ()
{
if( idx >= items) {
rndStart();
reset = 1;
} else {
reset = 0;
}
return rndList[idx++];
}
this.rndReset = function ()
{
return reset;
}
//---------
// initial
//---------
reset = 0;
min = minValue;
max = maxValue;
if(min > max) { //swap
var tmp;
tmp = min;
min = max;
max = tmp;
}
items = max - min + 1;
rndStart();
}