Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
loeasy68
GitHub Repository: loeasy68/loeasy68.github.io
Path: blob/main/website/GAUSS/js/test-manager.js
2941 views
1
var testRoomsList;
2
var testCharactersList;
3
var testAnimsList;
4
var testInvItemsList;
5
var testMapIdRoom;
6
var testMapIdItem;
7
var testMapIdInvItem;
8
var testMapIdAnim;
9
var testMapIdEvent;
10
var testMapIdDialog;
11
var testMapIdWb;
12
var currentCharacter;
13
var testCurrentRoom;
14
var testGameActions;
15
var testCurrentAction;
16
var testCurrentSentence;
17
var testInventory;
18
var testMapIdAudio;
19
var testMapIdWalkbox;
20
var gameCanvas;
21
var gameCtx;
22
var gameVars;
23
var guiObj;
24
var pathfinder;
25
var activeAnims;
26
var sentence;
27
var gameScripts = {};
28
var sceneSentences;
29
var hovering = false;
30
var DEBUG_ON = false;
31
var actionSelected;
32
var targetObj1;
33
var targetObj2;
34
var viewport;
35
var scrollIntLR;
36
var scrollIntUD;
37
var walkCycleMillisecs = 20;
38
var scrollingMillisecs = 30;
39
var scrollingAmount = 10;
40
var mouseDownTimer = 300;
41
var mouseDown;
42
var guiStyle = 'CMI';
43
var drawInterval;
44
var mousePos;
45
var MAX_SLOPE = 1.5;
46
var MIN_SLOPE = -MAX_SLOPE;
47
var DEFAULT_WALK_SPEED = 7;
48
var scaleFactor = { x : 1, y : 1};
49
50
var initTest = function()
51
{
52
viewport = { left : 0, right : 0, top : 0, bottom : 0 };
53
clearInterval(scrollIntLR);
54
clearInterval(scrollIntUD);
55
scrollIntLR = null;
56
scrollIntUD = null;
57
actionSelected = WALK_TO_ID;
58
targetObj1 = null;
59
targetObj2 = null;
60
mouseDown = false;
61
gameVars = owl.deepCopy(editorGameVars);
62
testRoomsList = owl.deepCopy(editorRoomsList);
63
testMapIdRoom = {};
64
testMapIdAnim = {};
65
testMapIdEvent = {};
66
testMapIdAudio = {};
67
testMapIdWalkbox = {};
68
testMapIdDialog = owl.deepCopy(editorMapIdDialog);
69
testMapIdInvItem = owl.deepCopy(editorMapIdInvItem);
70
testMapIdItem = owl.deepCopy(editorMapIdItem);
71
testGameActions = owl.deepCopy(editorActionsList);
72
testCharactersList = owl.deepCopy(editorCharactersList);
73
testAnimsList = owl.deepCopy(editorAnimsList);
74
testInvItemsList = owl.deepCopy(editorInvItemList);
75
testMapIdWb = owl.deepCopy(editorMapIdWb);
76
for(var key in activeAnims)
77
clearInterval(activeAnims[key]);
78
activeAnims = {};
79
//================================================= SCRIPT COMPILATION ===========================================//
80
gameScripts = {};
81
for(var i = 0; i < editorActionsList.length; i++)
82
gameScripts[editorActionsList[i].id] = {};
83
for(var key in editorScriptList)
84
scriptInterpreter(editorScriptList[key], gameScripts);
85
for(var key in gameScripts)
86
{
87
if(key === 'Events')
88
continue;
89
for (var item in testMapIdItem)
90
if(key !== COMBINE_ID)
91
{
92
if (gameScripts[key][item] === undefined)
93
gameScripts[key][item] = { 'code': defaultReactions[key] };
94
}
95
else break;
96
97
//gameScripts[key][item] = { 'code' : getDefaultReaction(key, item) };
98
//createDefaultScript('item', [key, item]);
99
for (var item in testMapIdInvItem)
100
if(key !== COMBINE_ID)
101
{
102
if (gameScripts[key][item] === undefined)
103
gameScripts[key][item] = { 'code': defaultReactions[key] };
104
}
105
else
106
{
107
if (gameScripts[key][item] === undefined)
108
gameScripts[key][item] = {};
109
for(var item2 in testMapIdItem)
110
{
111
if (gameScripts[key][item][item2] === undefined)
112
gameScripts[key][item][item2] = { 'code': defaultReactions[key] };
113
}
114
for(var item2 in testMapIdInvItem)
115
{
116
if(item === item2)
117
break;
118
if (gameScripts[key][item][item2] === undefined)
119
gameScripts[key][item][item2] = { 'code': defaultReactions[key] };
120
}
121
}
122
//createDefaultScript('inv', [key, item]);
123
}
124
125
for(var key1 in testMapIdDialog)
126
{
127
for(var key2 in testMapIdDialog[key1].subdialogs)
128
{
129
var subD = testMapIdDialog[key1].subdialogs[key2];
130
for(var i = 0; i < subD.length; i++)
131
if(subD[i].script)
132
gameScripts[subD[i].script] = scriptInterpreter(editorScriptList[subD[i].script], gameScripts);
133
}
134
}
135
136
for(var key in gameScripts['Events'])
137
{
138
$(document).off(key);
139
(function(key)
140
{
141
$(document).on(key, function()
142
{
143
eval(gameScripts['Events'][key]);
144
});
145
})(key);
146
}
147
//============================================= END OF SCRIPT COMPILATION ======================================//
148
149
for (var i in testRoomsList)
150
{
151
testMapIdRoom[testRoomsList[i].id] = testRoomsList[i];
152
153
testRoomsList[i].walkBehindList = [];
154
////////////////////////////
155
computeWalkboxNeighbors(testMapIdRoom);
156
////////////////////////////
157
var items = testRoomsList[i].items;
158
for (var j = 1; j < items.length; j++) {
159
delete items[j].hideFromCanvas;
160
items[j].img = new Image();
161
if (items[j].defaultAnims.default != null && items[j].centralPerspectiveWalkBehind != null)
162
testRoomsList[i].walkBehindList.push({'walkBehind': items[j].centralPerspectiveWalkBehind, 'itemId': items[j].id});
163
if (items[j].hotspot != null) {
164
items[j].onClick = testMapIdItem[items[j].id].onClick;
165
items[j].onHover = testMapIdItem[items[j].id].onHover;
166
items[j].onWalk = testMapIdItem[items[j].id].onWalk;
167
testMapIdItem[items[j].id] = items[j];
168
}
169
}
170
for(var j in testRoomsList[i].walkBoxes)
171
{
172
testMapIdWalkbox[j] = testRoomsList[i].walkBoxes[j];
173
}
174
testRoomsList[i].walkBehinds = qSort(testRoomsList[i].walkBehinds, orderWalkBehinds);
175
176
for(var j = 0; j < testRoomsList[i].walkBehinds.length; j++)
177
{
178
var img = new Image();
179
img.src = testRoomsList[i].walkBehinds[j].image;
180
testRoomsList[i].walkBehinds[j].image = img;
181
}
182
}
183
184
for(var i = 0; i < testAnimsList.length; i++)
185
testMapIdAnim[testAnimsList[i].id] = testAnimsList[i];
186
187
for (var i = 0; i < testCharactersList.length; i++)
188
{
189
testCharactersList[i].scaleFactor = 1;
190
testMapIdItem[testCharactersList[i].id] = testCharactersList[i];
191
}
192
193
for(var key in editorMapIdAudio)
194
{
195
var audio = new Audio();
196
audio.src = editorMapIdAudio[key].audioData;
197
testMapIdAudio[key] = audio;
198
}
199
if(!editorPlayerCharacter)
200
{
201
alert('No player character found. Aborting.');
202
return;
203
}
204
setCurrentCharacter(editorPlayerCharacter);
205
206
currentCharacter.inventory = [];
207
//setObjectLocation(currentCharacter.id, currentCharacter.locationId);
208
testCurrentAction = testGameActions[0].description;
209
testCurrentSentence = testCurrentAction;
210
testInventory = new Array();
211
212
currentCharacter.path = [];
213
if(currentCharacter.walkInt)
214
clearInterval(currentCharacter.walkInt);
215
currentCharacter.walkInt = null;
216
217
sceneSentences = {};
218
pathfinder = new PathFinder();
219
guiObj = initGUI(resolution, guiStyle);
220
221
var $gameCanvas = $('#game-canvas');
222
$gameCanvas.css({'background' : 'black', 'cursor' : 'none', 'border' : '1px solid black' });
223
gameCanvas = $gameCanvas[0];
224
gameCanvas.width = resolution.width;
225
gameCanvas.height = resolution.height;
226
setCanvasResolution(gameCanvas, 640, 480);
227
228
gameCtx = gameCanvas.getContext('2d');
229
230
231
gameCtx.font = '30px LEC';
232
gameCtx.fillStyle = 'white';
233
gameCtx.strokeStyle = 'black';
234
235
mousePos = { x: 0, y: 0};
236
237
$(gameCanvas).mousedown(function(e)
238
{
239
e.preventDefault();
240
e.stopImmediatePropagation();
241
var BUTTON_RIGHT = 3;
242
243
if(e.which == BUTTON_RIGHT && guiObj.listening)
244
{
245
if(!guiObj.inventoryOpen)
246
{
247
hovering = null;
248
guiObj.hovering = null;
249
stopPath(currentCharacter);
250
currentCharacter.path = [];
251
}
252
guiObj.inventoryOpen = !guiObj.inventoryOpen;
253
guiObj.setCursor('default');
254
guiObj.onScreen = false;
255
guiObj.sentence = '';
256
return;
257
}
258
259
var offset = $(this).offset();
260
var rect = gameCanvas.getBoundingClientRect();
261
var relX = Math.round((e.clientX - rect.left) / scaleFactor.x);
262
var relY = Math.round((e.clientY - rect.top) / scaleFactor.y);
263
264
if(guiObj.actionSelected) // Mousedown occurred over a GUI button
265
{
266
if(guiObj.actionSelected !== COMBINE_ID)
267
{
268
var action = guiObj.actionSelected;
269
var obj = guiObj.hovering;
270
if(gameScripts[guiObj.actionSelected][guiObj.hovering])
271
{
272
if(obj in testMapIdInvItem)
273
try
274
{
275
eval(gameScripts[action][obj].code);
276
}
277
catch (err)
278
{
279
alert(err);
280
}
281
else
282
try
283
{
284
walkToObj(currentCharacter.id, guiObj.hovering, null, function ()
285
{
286
setDirection(currentCharacter.id, testMapIdItem[obj].faceDir);
287
eval(gameScripts[action][obj].code);
288
});
289
290
}
291
catch (err)
292
{
293
alert(err);
294
}
295
}
296
}
297
else if(guiObj.inventoryOpen === true)
298
{
299
var img = testMapIdAnim[testMapIdInvItem[guiObj.hovering].anim].frames[0].img;
300
guiObj.setCursor(guiObj.hovering, img, -img.width / 2, 0);
301
}
302
guiObj.sentence = '';
303
guiObj.hovering = null;
304
guiObj.onScreen = false;
305
guiObj.actionSelected = null;
306
$gameCanvas.trigger('mousemove');
307
308
return;
309
}
310
if(!guiObj.inventoryOpen)
311
{
312
if(guiObj.dialogOpen)
313
{
314
var dialog = testMapIdDialog[guiObj.dialogOpen];
315
if(dialog.hidden === true)
316
return;
317
var dialogChoices = dialog.subdialogs[dialog.currentSubDialog];
318
for(var i = 0; i < dialogChoices.length; i++)
319
if(dialogChoices[i].hovering)
320
{
321
dialogChoices[i].hovering = false;
322
for(var j = 0; j < dialogChoices.length; j++)
323
{
324
if(dialogChoices[j].showOnce === true)
325
dialogChoices[j].hidden = true;
326
}
327
//alert(dialogChoices[i].sentence);
328
var choice = dialogChoices[i];
329
if (choice.script)
330
try
331
{
332
if(choice.chooseOnce)
333
choice.hidden = true;
334
if(choice.open)
335
{
336
dialog.currentSubDialog = choice.open;
337
hideDialog();
338
}
339
else closeDialog();
340
disableInput();
341
eval(gameScripts[dialogChoices[i].script].code.concat());
342
}
343
catch (err) { alert(err); }
344
else
345
{
346
closeDialog();
347
enableInput();
348
}
349
return;
350
}
351
return;
352
}
353
if(!hovering) // Mousedown occurred outside of any hotspot and the inventory is closed
354
{
355
if (guiObj.onScreen) // Clear GUI if still present on screen
356
{
357
guiObj.sentence = '';
358
guiObj.hovering = null;
359
guiObj.onScreen = false;
360
guiObj.item = null;
361
return;
362
}
363
364
// User is dragging an inventory object and clicked a non-interactive zone
365
if(guiObj.cursor.state !== 'default')
366
{
367
guiObj.setCursor('default');
368
return;
369
}
370
371
// No verb coin present, the cursor is default, so the user tried to walk
372
relX += viewport.left;
373
relY += viewport.top;
374
if (actionSelected == WALK_TO_ID && guiObj.listening)
375
{
376
if (DEBUG_ON)
377
console.log('click on ' + relX + ', ' + relY);
378
walkToPos(currentCharacter.id, relX, relY, [], null);
379
}
380
return;
381
}
382
383
// Mousedown occurred over a hotspot
384
if(guiObj.cursor.state == 'default')
385
{
386
guiObj.setPivot(relX, relY);
387
if (guiObj.onScreen)
388
{
389
guiObj.onScreen = false;
390
var ev = new jQuery.Event('mousemove');
391
ev.pageX = e.pageX;
392
ev.pageY = e.pageY;
393
$(gameCanvas).trigger(ev);
394
}
395
guiObj.onScreen = true
396
guiObj.item = null;
397
guiObj.hovering = hovering;
398
}
399
else if(guiObj.cursor.state === 'exit')
400
{
401
var obj = testMapIdItem[hovering];
402
if(!mouseDown)
403
{
404
e.stopImmediatePropagation();
405
mouseDown = true;
406
walkToObj(currentCharacter.id, obj.id, null, function ()
407
{
408
//setDirection(currentCharacter.id, testMapIdItem[hovering].faceDir);
409
setPosition(currentCharacter.id, obj.exitTo.room, obj.exitTo.xPos, obj.exitTo.yPos);
410
});
411
setTimeout(function() { mouseDown = false; }, mouseDownTimer);
412
}
413
else
414
{
415
stopPath(currentCharacter);
416
setPosition(currentCharacter.id, obj.exitTo.room, obj.exitTo.xPos, obj.exitTo.yPos);
417
}
418
return;
419
}
420
else
421
{
422
var obj1 = guiObj.cursor.state;
423
var obj2 = hovering;
424
425
try
426
{
427
walkToObj(currentCharacter.id, obj2, null, function ()
428
{
429
setDirection(currentCharacter.id, testMapIdItem[obj2].faceDir);
430
eval(gameScripts[COMBINE_ID][obj1][obj2].code);
431
});
432
433
}
434
catch (err) { }
435
hovering = null;
436
guiObj.sentence = '';
437
guiObj.hovering = null;
438
guiObj.setCursor('default');
439
return;
440
441
//alert('combine ' + testMapIdInvItem[guiObj.cursor.state].description + ' with ' + testMapIdItem[hovering].description);
442
}
443
stopPath(currentCharacter);
444
}
445
else if(!guiObj.dialogOpen)
446
{
447
var hoveredInvItem = guiObj.getHoveredInvItem();
448
if(!hoveredInvItem)
449
{
450
var invMargin = guiObj.getInvMargin();
451
if(mousePos.x < invMargin || mousePos.x > resolution.width - invMargin
452
|| mousePos.y < invMargin || mousePos.y > resolution.height - invMargin)
453
{
454
guiObj.inventoryOpen = false;
455
}
456
guiObj.onScreen = false;
457
guiObj.setCursor('default');
458
return;
459
}
460
if(guiObj.cursor.state !== 'default')
461
{
462
if(guiObj.cursor.state !== hoveredInvItem.id)
463
{
464
eval(gameScripts[COMBINE_ID][guiObj.cursor.state][hoveredInvItem.id].code);
465
guiObj.setCursor('default');
466
}
467
return;
468
}
469
guiObj.setPivot(relX, relY);
470
guiObj.onScreen = true;
471
guiObj.hovering = hovering;
472
}
473
});
474
$(gameCanvas).mousemove(function(e)
475
{
476
e.preventDefault();
477
e.stopImmediatePropagation();
478
479
var offset = $(this).offset();
480
var relX = Math.round((e.pageX - offset.left) / scaleFactor.x);
481
var relY = Math.round((e.pageY - offset.top) / scaleFactor.y);
482
483
484
if(!isNaN(relX) && !isNaN(relY))
485
{
486
mousePos.x = relX;
487
mousePos.y = relY;
488
}
489
490
if(guiObj.onScreen === true)
491
{
492
var btnHovering = false;
493
hovering = null;
494
if(getDistanceBetweenPoints(mousePos, guiObj.magnifierButtonCenter) < guiObj.getButtonRadius())
495
{
496
guiObj.setActionSelected(EYES_ID);
497
btnHovering = true;
498
}
499
else if(getDistanceBetweenPoints(mousePos, guiObj.handButtonCenter) < guiObj.getButtonRadius())
500
{
501
guiObj.setActionSelected(HAND_ID);
502
btnHovering = true;
503
504
}
505
else if(getDistanceBetweenPoints(mousePos, guiObj.mouthButtonCenter) < guiObj.getButtonRadius())
506
{
507
guiObj.setActionSelected(MOUTH_ID);
508
btnHovering = true;
509
}
510
else if(guiObj.inventoryOpen === true && getDistanceBetweenPoints(mousePos, guiObj.cogwheelButtonCenter) < guiObj.getButtonRadius())
511
{
512
guiObj.setActionSelected(COMBINE_ID);
513
btnHovering = true;
514
}
515
516
if(btnHovering)
517
{
518
var sentence = null;
519
//if(guiObj.actionSelected !== 'Combine')
520
{
521
if (gameScripts[guiObj.actionSelected][guiObj.hovering])
522
sentence = gameScripts[guiObj.actionSelected][guiObj.hovering].sentence;
523
524
if (guiObj.hovering in testMapIdItem)
525
guiObj.sentence = sentence ? sentence : editorMapIdAction[guiObj.actionSelected].description + ' ' + testMapIdItem[guiObj.hovering].description;
526
else if (guiObj.hovering in testMapIdInvItem)
527
guiObj.sentence = sentence ? sentence : editorMapIdAction[guiObj.actionSelected].description + ' ' + testMapIdInvItem[guiObj.hovering].description;
528
else
529
guiObj.sentence = 'Combine ' + testMapIdInvItem[guiObj.hovering].description;
530
}
531
532
return;
533
534
}
535
536
guiObj.setActionSelected(null);
537
return;
538
}
539
540
relX += viewport.left;
541
relY += viewport.top;
542
543
if(guiObj.dialogOpen)
544
{
545
var dialogTopLeft = guiObj.getDialogMargin();
546
var x = dialogTopLeft.left;
547
var y = dialogTopLeft.top - 20;
548
549
var dialog = testMapIdDialog[guiObj.dialogOpen];
550
var dialogChoices = dialog.subdialogs[dialog.currentSubDialog];
551
552
for(var i = 0; i < dialogChoices.length; i++)
553
{
554
if(dialogChoices[i].hidden === true)
555
continue;
556
dialogChoices[i].hovering = false;
557
if(mousePos.x >= x && mousePos.y >= y && mousePos.y <= y + 20)
558
{
559
dialogChoices[i].hovering = true;
560
}
561
y += 40;
562
}
563
return;
564
}
565
if(!guiObj.listening)
566
return;
567
568
if(!guiObj.inventoryOpen)
569
{
570
var reverseLayers = [];
571
for (var i in testCurrentRoom.zOrderMap)
572
reverseLayers.unshift(i);
573
for(var i = 0; i < testCharactersList.length; i++)
574
{
575
if(testCharactersList[i].id === currentCharacter.id)
576
continue;
577
var character = testCharactersList[i] ;
578
if (character.visible && character.hotspot && isPointInPoly(character.hotspot.points, { x: relX, y: relY }) == true)
579
{
580
hovering = character.id;
581
if (!guiObj.onScreen)
582
{
583
if(guiObj.cursor.state === 'default')
584
guiObj.sentence = character.description;
585
else
586
{
587
var sentence = 'Combine ' + testMapIdInvItem[guiObj.cursor.state].description + ' with ' + testMapIdItem[hovering].description;
588
try
589
{
590
sentence = (gameScripts[COMBINE_ID][guiObj.cursor.state][hovering].sentence) ? gameScripts[COMBINE_ID][guiObj.cursor.state][hovering].sentence : sentence;
591
}
592
catch(err) {}
593
guiObj.sentence = sentence;
594
}
595
}
596
return;
597
}
598
}
599
600
for (var i = 0; i < reverseLayers.length; i++)
601
{
602
var items = testCurrentRoom.zOrderMap[reverseLayers[i]];
603
for (var j = 0; j < items.length; j++)
604
{
605
var item = testMapIdItem[items[j]];
606
if (item.visible && item.hotspot && isPointInPoly(item.hotspot.points, { x: relX, y: relY }) == true)
607
{
608
hovering = item.id;
609
if (!guiObj.onScreen)
610
{
611
if(item.exitTo.room)
612
{
613
if(guiObj.cursor.state === 'default')
614
guiObj.setCursor('exit');
615
else if(guiObj.cursor.state !== 'exit')
616
{
617
hovering = null;
618
return;
619
}
620
}
621
else if(guiObj.cursor.state === 'default')
622
guiObj.sentence = item.description;
623
else if(guiObj.cursor.state !== 'exit')
624
{
625
var sentence = 'Combine ' + testMapIdInvItem[guiObj.cursor.state].description + ' with ' + testMapIdItem[hovering].description;
626
try
627
{
628
sentence = (gameScripts[COMBINE_ID][guiObj.cursor.state][hovering].sentence) ? gameScripts[COMBINE_ID][guiObj.cursor.state][hovering].sentence : sentence;
629
}
630
catch(err) {}
631
guiObj.sentence = sentence;
632
}
633
}
634
return;
635
}
636
}
637
}
638
if (!guiObj.onScreen)
639
guiObj.sentence = '';
640
hovering = null;
641
if(guiObj.cursor.state === 'exit')
642
guiObj.setCursor('default');
643
}
644
// Inventory management
645
else
646
{
647
if(!guiObj.actionSelected)
648
if(guiObj.cursor.state != 'default')
649
{
650
var invMargin = guiObj.getInvMargin();
651
652
// If the cursor is moved outside the inventory GUI bounds, close inventory
653
if (mousePos.x < invMargin || mousePos.x > resolution.width - invMargin
654
|| mousePos.y < invMargin || mousePos.y > resolution.height - invMargin)
655
{
656
guiObj.inventoryOpen = false;
657
return;
658
}
659
}
660
var hoveredItem = guiObj.getHoveredInvItem();
661
if(!hoveredItem || hoveredItem.id == guiObj.cursor.state)
662
return;
663
hovering = hoveredItem.id;
664
if (!guiObj.onScreen)
665
{
666
if(guiObj.cursor.state === 'default')
667
guiObj.sentence = testMapIdInvItem[hoveredItem.id].description;
668
else
669
{
670
var sentence = 'Combine ' + testMapIdInvItem[guiObj.cursor.state].description + ' with ' + testMapIdInvItem[hoveredItem.id].description;
671
try
672
{
673
sentence = (gameScripts[COMBINE_ID][guiObj.cursor.state][hoveredItem.id].sentence) ? gameScripts[COMBINE_ID][guiObj.cursor.state][hoveredItem.id].sentence : sentence;
674
}
675
catch (err) {}
676
guiObj.sentence = sentence;
677
}
678
}
679
}
680
681
});
682
$(gameCanvas).contextmenu(function(e)
683
{
684
e.preventDefault();
685
});
686
setCurrentRoom(testRoomsList[0].id);
687
drawInterval = setInterval(function() { drawScene(); }, 1000/30);
688
};
689
690
691
var drawScene = function()
692
{
693
694
var bg = testCurrentRoom.items[0].img;
695
gameCtx.clearRect(0, 0, resolution.width, resolution.height);
696
gameCtx.drawImage(bg, viewport.left, viewport.top, Math.min(gameCanvas.width, bg.width), Math.min(gameCanvas.height, bg.height), 0, 0, Math.min(gameCanvas.width, bg.width), Math.min(gameCanvas.height, bg.height));
697
698
var charactersIndexes = [];
699
for(var i = 0; i < testCharactersList.length; i++) {
700
var character = testCharactersList[i];
701
if (character.parentRoomId !== testCurrentRoom.id)
702
continue;
703
charactersIndexes[i] = getItemZIndex(character.id);
704
character.setLayer(charactersIndexes[i], true);
705
}
706
707
for(var key in testCurrentRoom.zOrderMap)
708
{
709
var layer = testCurrentRoom.zOrderMap[key];
710
711
if(parseInt(key) % 2 === 1)
712
{
713
layer = qSort(layer, function(c1, c2) { return testMapIdItem[c1].position.y < testMapIdItem[c2].position.y; });
714
}
715
716
for(var i = 0; i < layer.length; i++)
717
{
718
var item = testMapIdItem[layer[i]];
719
if(item.visible)
720
drawSprite(testMapIdItem[layer[i]]);
721
}
722
}
723
724
if(DEBUG_ON)
725
{
726
DEBUG_drawWalkBoxes();
727
if(currentCharacter.path.length > 0)
728
{
729
var tmp = gameCtx.strokeStyle;
730
var sprite = getItemPlaceHolder(currentCharacter);
731
var currPos = new Point(currentCharacter.position.x,
732
currentCharacter.position.y);
733
734
var path = currentCharacter.path;
735
gameCtx.strokeStyle = 'yellow';
736
gameCtx.beginPath();
737
for(var i = 0; i < path.length; i++)
738
{
739
var tmp = new Point(path[i].x, path[i].y);
740
gameCtx.moveTo(currPos.x - viewport.left, currPos.y - viewport.top);
741
gameCtx.lineTo(tmp.x - viewport.left , tmp.y - viewport.top);
742
currPos = tmp;
743
}
744
gameCtx.closePath();
745
gameCtx.stroke();
746
gameCtx.strokeStyle = tmp;
747
gameCtx.strokeStyle = 'black';
748
}
749
}
750
//if(!currentCharacter.onScreen)
751
// drawSprite(currentCharacter);
752
drawInventory();
753
drawSentences();
754
drawGUI();
755
drawGUISentence();
756
drawCursor();
757
758
};
759
760
var drawGUISentence = function()
761
{
762
var textMargin = 10;
763
var startX = guiObj.onScreen ? guiObj.pivot.x : mousePos.x;
764
var startY = guiObj.onScreen ? guiObj.magnifierButtonCenter.y - guiObj.getButtonRadius() - textMargin : mousePos.y;
765
gameCtx.lineWidth = 5;
766
var textSize = gameCtx.measureText(guiObj.sentence);
767
var destX = startX - textSize.width / 2 < 0 ? 0 : (startX + textSize.width / 2 > resolution.width ? resolution.width - textSize.width : startX - textSize.width / 2);
768
gameCtx.strokeText(guiObj.sentence, destX, startY - 20);
769
gameCtx.lineWidth = 3;
770
gameCtx.fillStyle = 'white';
771
gameCtx.fillText(guiObj.sentence, destX, startY - 20);
772
};
773
774
var drawSentences = function ()
775
{
776
var maxWidth = 500;
777
for(var key in sceneSentences)
778
{
779
gameCtx.lineWidth = 5;
780
wrapText(gameCtx, sceneSentences[key].text, sceneSentences[key].pos.x, sceneSentences[key].pos.y, maxWidth, 40, testMapIdItem[key].speechColor);
781
}
782
783
};
784
785
var drawInventory = function()
786
{
787
if(guiObj.inventoryOpen)
788
{
789
var inv = currentCharacter.inventory;
790
var invGUIMargin = guiObj.getInvMargin();
791
var MAX_ROWS = guiObj.getInvRows();
792
var MAX_COLUMNS = guiObj.getInvColumns();
793
var cellMargin = guiObj.getInvCellMargin();
794
var cellSize = guiObj.getInvCellSize();
795
796
gameCtx.fillStyle = 'rgba(255, 127, 127, 0.5)';
797
gameCtx.fillRect(invGUIMargin, invGUIMargin, resolution.width - 2 * invGUIMargin, resolution.height - 2 * invGUIMargin);
798
799
for(var i = 0; i < MAX_ROWS; i++)
800
for(var j = 0; j < MAX_COLUMNS; j++)
801
{
802
var idx = j + (MAX_COLUMNS * i);
803
if(idx == inv.length)
804
return;
805
var img = testMapIdAnim[testMapIdInvItem[inv[idx]].anim].frames[0].img;
806
img.width = img.height = cellSize;
807
gameCtx.drawImage(img, invGUIMargin + cellMargin + j * (cellMargin + cellSize), invGUIMargin + cellMargin + i * (cellMargin + cellSize));
808
gameCtx.lineWidth = 1;
809
gameCtx.strokeRect(invGUIMargin + cellMargin + j * (cellMargin + cellSize), invGUIMargin + cellMargin + i * (cellMargin + cellSize), cellSize, cellSize);
810
}
811
}
812
};
813
814
var drawGUI = function()
815
{
816
if(guiObj.onScreen === true)
817
{
818
var radius = guiObj.getButtonRadius();
819
var diameter = 2 * radius;
820
//gameCtx.fillStyle = 'black';
821
//gameCtx.fillRect(guiObj.position.x - guiObj.size.width / 2, guiObj.position.y, guiObj.size.width, guiObj.size.height);
822
gameCtx.drawImage(guiObj.actions[0], guiObj.magnifierButtonCenter.x - radius, guiObj.magnifierButtonCenter.y - radius, diameter, diameter);
823
gameCtx.drawImage(guiObj.actions[1], guiObj.handButtonCenter.x - radius, guiObj.handButtonCenter.y - radius, diameter, diameter);
824
gameCtx.drawImage(guiObj.actions[2], guiObj.mouthButtonCenter.x - radius, guiObj.mouthButtonCenter.y - radius, diameter, diameter);
825
if(guiObj.inventoryOpen === true)
826
gameCtx.drawImage(guiObj.actions[3], guiObj.cogwheelButtonCenter.x - radius, guiObj.cogwheelButtonCenter.y - radius, diameter, diameter);
827
828
return;
829
}
830
831
if(guiObj.dialogOpen)
832
{
833
var dialog = testMapIdDialog[guiObj.dialogOpen];
834
if(dialog.hidden === true)
835
return;
836
var dialogChoices = dialog.subdialogs[dialog.currentSubDialog];
837
var dialogMargin = guiObj.getDialogMargin();
838
var y = dialogMargin.top;
839
840
841
for (var i = 0; i < dialogChoices.length; i++)
842
{
843
if(dialogChoices[i].hidden)
844
continue;
845
if(dialogChoices[i].open)
846
{
847
var subdialog = dialog.subdialogs[dialogChoices[i].open];
848
var allHidden = true;
849
for(var j = 0; j < subdialog.length; j++)
850
{
851
if(subdialog[j].hidden === false)
852
{
853
allHidden = false;
854
break;
855
}
856
}
857
if(allHidden === true)
858
{
859
dialogChoices[i].hidden = true;
860
continue;
861
}
862
};
863
if(dialogChoices[i].hovering)
864
gameCtx.fillStyle = 'yellow';
865
else
866
gameCtx.fillStyle = 'lightgreen';
867
gameCtx.lineWidth = 5;
868
gameCtx.strokeText(dialogChoices[i].sentence, dialogMargin.left, y);
869
gameCtx.lineWidth = 3;
870
gameCtx.fillText(dialogChoices[i].sentence, dialogMargin.left, y);
871
y += 40;
872
}
873
}
874
};
875
876
var drawCursor = function()
877
{
878
gameCtx.drawImage(guiObj.cursor.img, mousePos.x + guiObj.cursor.offset.x, mousePos.y + guiObj.cursor.offset.y);
879
};
880
881
var initGUI = function(gameResolution, guiStyle)
882
{
883
var guiObj;
884
885
switch (guiStyle)
886
{
887
case 'MI2':
888
break;
889
case 'CMI':
890
var imgWidth = 75;
891
var margin = 5;
892
var dialogMargin = { left: 25, top: resolution.height - 200 };
893
894
var defaultCursorId = 'default';
895
var defaultCursorPath = 'icons/cursor-small.png';
896
var defaultCursor = new Image();
897
defaultCursor.src = defaultCursorPath;
898
899
var defaultCursorOffset = { x : -23, y : -1 };
900
901
var MAX_ROWS = 5;
902
var MAX_COLUMNS = 5;
903
var invGUIMargin = 100;
904
var invCellMargin = 50;
905
var invCellSize = 100;
906
907
var exitCursorId = 'exit';
908
var exitCursorPath = 'icons/exit.png';
909
var exitCursor = new Image();
910
exitCursor.src = exitCursorPath;
911
var exitCursorOffset = { x : -19, y : -1 };
912
913
var magnifier_img = new Image();
914
var hand_img = new Image();
915
var mouth_img = new Image();
916
var cogwheel_img = new Image();
917
var magnifier_hover_img = new Image();
918
var hand_hover_img = new Image();
919
var mouth_hover_img = new Image();
920
var cogwheel_hover_img = new Image();
921
922
var magnifier_icon = 'icons/occhi.png';
923
var magnifier_hover_icon = 'icons/occhi-hover.png';
924
var hand_icon = 'icons/mano.png';
925
var hand_hover_icon = 'icons/mano-hover.png';
926
var mouth_icon = 'icons/bocca.png';
927
var mouth_hover_icon = 'icons/bocca-hover.png';
928
var cogwheel_icon = 'icons/cogwheel.png';
929
var cogwheel_hover_icon = 'icons/cogwheel-hover.png';
930
931
var magnifier_img_offset = { x : 0, y : -79};
932
var hand_img_offset = {x :-50, y : 0};
933
var mouth_img_offset = {x : 50, y : 0};
934
var cogwheel_img_offset = {x : 0, y : 79};
935
magnifier_img.src = magnifier_icon;
936
hand_img.src = hand_icon;
937
mouth_img.src = mouth_icon;
938
cogwheel_img.src = cogwheel_icon;
939
magnifier_hover_img.src = magnifier_hover_icon;
940
hand_hover_img.src = hand_hover_icon;
941
mouth_hover_img.src = mouth_hover_icon;
942
cogwheel_hover_img.src = cogwheel_hover_icon;
943
944
945
var guiObject = function()
946
{
947
this.type = 'CMI';
948
this.listening = true;
949
this.onScreen = false;
950
this.inventoryOpen = false;
951
this.dialogOpen = null;
952
this.cursor = { state : defaultCursorId, img : defaultCursor, offset : defaultCursorOffset};
953
this.listening = true;
954
this.actionSelected = null;
955
this.sentence = '';
956
this.pivot = { x : null, y : null };
957
this.size = {width : 250, height : 100 };
958
this.magnifierButtonCenter = null;
959
this.handButtonCenter = null;
960
this.mouthButtonCenter = null;
961
this.cogwheelButtonCenter = null;
962
this.hovering = null;
963
this.actions = [];
964
this.actions[0] = magnifier_img;
965
this.actions[1] = hand_img;
966
this.actions[2] = mouth_img;
967
this.actions[3] = cogwheel_img;
968
969
this.getButtonDiameter = function()
970
{
971
return imgWidth;
972
};
973
this.getButtonRadius = function()
974
{
975
return imgWidth / 2;
976
};
977
this.getInvRows = function()
978
{
979
return MAX_ROWS;
980
};
981
this.getInvColumns = function()
982
{
983
return MAX_COLUMNS;
984
};
985
this.getInvMargin = function()
986
{
987
return invGUIMargin;
988
};
989
this.getInvCellMargin = function()
990
{
991
return invCellMargin;
992
};
993
this.getInvCellSize = function()
994
{
995
return invCellSize;
996
};
997
this.getMargin = function()
998
{
999
return margin;
1000
};
1001
this.getDialogMargin = function()
1002
{
1003
return dialogMargin;
1004
};
1005
this.setPivot = function(x, y)
1006
{
1007
var size = this.size;
1008
x - size.width / 2 < 0 ? this.pivot.x = size.width / 2 : (x + size.width / 2 > resolution.width ? this.pivot.x = resolution.width - size.width : this.pivot.x = x);
1009
y + size.height > resolution.height ? this.pivot.y = resolution.height - size.height : this.pivot.y = y;
1010
//this.magnifierButtonCenter = { x : this.pivot.x, y : this.pivot.y + imgWidth / 2 + margin};
1011
this.magnifierButtonCenter = { x : this.pivot.x + magnifier_img_offset.x, y : this.pivot.y + magnifier_img_offset.y };
1012
//this.handButtonCenter = { x : this.pivot.x - imgWidth / 2 - margin, y : this.pivot.y + imgWidth + 2 * margin + imgWidth / 2};
1013
this.handButtonCenter = { x : this.pivot.x + hand_img_offset.x, y : this.pivot.y + hand_img_offset.y};
1014
//this.mouthButtonCenter = { x : this.pivot.x + imgWidth / 2 + margin, y : this.pivot.y + imgWidth + 2 * margin + imgWidth / 2 };
1015
this.mouthButtonCenter = { x : this.pivot.x + mouth_img_offset.x, y : this.pivot.y + mouth_img_offset.y };
1016
//this.cogwheelButtonCenter = { x : this.pivot.x, y : this.pivot.y + 2 * imgWidth + 3 * margin + imgWidth / 2};
1017
this.cogwheelButtonCenter = { x : this.pivot.x + cogwheel_img_offset.x, y : this.pivot.y + cogwheel_img_offset.y};
1018
};
1019
this.setActionSelected = function(action)
1020
{
1021
this.actionSelected = action;
1022
switch(action)
1023
{
1024
case EYES_ID:
1025
this.actions[0] = magnifier_hover_img;
1026
break;
1027
case HAND_ID:
1028
this.actions[1] = hand_hover_img;
1029
break;
1030
case MOUTH_ID:
1031
this.actions[2] = mouth_hover_img;
1032
break;
1033
case COMBINE_ID:
1034
this.actions[3] = cogwheel_hover_img;
1035
break;
1036
default:
1037
this.actionSelected = null;
1038
this.actions[0] = magnifier_img;
1039
this.actions[1] = hand_img;
1040
this.actions[2] = mouth_img;
1041
this.actions[3] = cogwheel_img;
1042
break;
1043
}
1044
};
1045
this.disableListening = function()
1046
{
1047
hovering = null;
1048
this.sentence = '';
1049
this.hovering = null;
1050
this.listening = false;
1051
};
1052
this.enableListening = function()
1053
{
1054
this.listening = true;
1055
};
1056
this.inventoryPush = function(invItemId)
1057
{
1058
1059
};
1060
1061
this.show = function(x, y)
1062
{
1063
1064
this.onScreen = true;
1065
};
1066
this.hide = function()
1067
{
1068
this.onScreen = false;
1069
};
1070
this.drawSentence = function(x, y, sentence, zIndex)
1071
{
1072
};
1073
this.openInventory = function()
1074
{
1075
1076
};
1077
this.closeInventory = function()
1078
{
1079
1080
};
1081
this.setCursor = function(id, path, offsetX, offsetY)
1082
{
1083
if(id === 'default')
1084
{
1085
this.cursor = { state : defaultCursorId, img : defaultCursor, offset : defaultCursorOffset };
1086
return;
1087
}
1088
if(id === 'exit')
1089
{
1090
this.cursor = { state : exitCursorId, img : exitCursor, offset : exitCursorOffset };
1091
return;
1092
}
1093
this.cursor.state = id;
1094
this.cursor.img = path;
1095
this.cursor.offset = { x: offsetX, y: offsetY };
1096
1097
};
1098
this.getHoveredInvItem = function()
1099
{
1100
var inv = currentCharacter.inventory;
1101
1102
for(var i = 0; i < MAX_ROWS; i++)
1103
for(var j = 0; j < MAX_COLUMNS; j++)
1104
{
1105
var idx = j + (MAX_ROWS * i);
1106
if(idx == inv.length)
1107
{
1108
hovering = null;
1109
this.sentence = '';
1110
return null;
1111
}
1112
var left = invGUIMargin + invCellMargin + j * (invCellSize + invCellMargin);
1113
var top = invGUIMargin + invCellMargin + i * (invCellSize + invCellMargin);
1114
var right = left + invCellSize;
1115
var bottom = top + invCellSize;
1116
1117
if(mousePos.x >= left && mousePos.x < right && mousePos.y >= top && mousePos.y < bottom)
1118
return { id: inv[idx], left : left, top : top, right : right, bottom : bottom };
1119
}
1120
};
1121
};
1122
guiObj = new guiObject();
1123
break;
1124
}
1125
return guiObj;
1126
};
1127
1128
1129
var drawSprite = function(item, drawAbsolute)
1130
{
1131
var anim = null;
1132
//if(item.type === 'character')
1133
//{
1134
if (item.anim_state in item.defaultAnims)
1135
{
1136
if(item.type === 'character')
1137
anim = testMapIdAnim[item.defaultAnims[item.anim_state][item.dir]];
1138
else anim = testMapIdAnim[item.defaultAnims[item.anim_state]];
1139
}
1140
else if (item.anim_state in item.customAnims)
1141
anim = testMapIdAnim[item.customAnims[item.anim_state]];
1142
//}
1143
//else
1144
// anim = testMapIdAnim[item.defaultAnims[item.anim_state]];
1145
if(!anim)
1146
return;
1147
anim.play();
1148
1149
var sprite = anim.frames[anim.current_frame].img;
1150
1151
var pos = item.position;
1152
var currWBox = getWalkboxFromPoint(testCurrentRoom.walkBoxes, pos);
1153
if(!currWBox)
1154
currWBox = getNearestWalkBox(testCurrentRoom.walkBoxes, pos);
1155
var width = sprite.width;
1156
var height = sprite.height;
1157
var scrollLeft = drawAbsolute !== true ? viewport.left : 0;
1158
var scrollTop = drawAbsolute !== true ? viewport.top : 0;
1159
1160
if(item.type === 'character')
1161
{
1162
interpolateScaleAndSpeed(item, currWBox.polygon.top, currWBox.minScaleFactor, currWBox.polygon.bottom, currWBox.maxScaleFactor);
1163
width *= item.scaleFactor;
1164
height *= item.scaleFactor;
1165
}
1166
1167
gameCtx.drawImage(sprite, pos.x - width / 2 - scrollLeft, pos.y - height - scrollTop, width, height);
1168
};
1169
1170
var getBottomMiddlePos = function(itemId)
1171
{
1172
var item = testMapIdItem[itemId];
1173
var anim;
1174
if(item.type == 'character')
1175
anim = testMapIdAnim[item.defaultAnims[item.anim_state][item.dir]];
1176
else anim = testMapIdAnim[item.defaultAnims[item.anim_state]];
1177
if(!anim)
1178
return null;
1179
var sprite = anim.frames[anim.current_frame];
1180
return new paper.Point(item.position.x + sprite.img.width / 2, item.position.y + sprite.img.height);
1181
};
1182
1183
var setCurrentCharacter = function(characterId)
1184
{
1185
currentCharacter = testMapIdItem[characterId];
1186
currentCharacter.path = [];
1187
};
1188
1189
var setObjectLocation = function(objectId, roomId)
1190
{
1191
testMapIdItem[objectId].parentRoomId = roomId;
1192
//drawScene();
1193
};
1194
var getItemZIndex = function(itemId)
1195
{
1196
var walkBehindList = testCurrentRoom.walkBehindList;
1197
var item = testMapIdItem[itemId];
1198
1199
for (var i = 0; i < walkBehindList.length; i++)
1200
if (item.position.y < walkBehindList[i].walkBehind)
1201
{
1202
return testMapIdItem[walkBehindList[i].itemId].layer - 1;
1203
}
1204
1205
return 2000;
1206
};
1207
1208
var atomicEffects = {
1209
setDirection: setDirection,
1210
egoSetDirection : egoSetDirection,
1211
setPosition: setPosition,
1212
setRoom : setCurrentRoom,
1213
inventoryAdd: inventoryAdd,
1214
inventoryRemove: inventoryRemove,
1215
show: show,
1216
hide: hide,
1217
varSet : varSet,
1218
varIncr : varIncr,
1219
setState : setState,
1220
egoSetState : egoSetState,
1221
enableInput : enableInput,
1222
disableInput : disableInput,
1223
openDialog : openDialog,
1224
playAudio : playAudio
1225
};
1226
1227
var interruptibleEffects = {
1228
delay: delay,
1229
sayLine: sayLine,
1230
egoSayLine: egoSayLine,
1231
walkToPos: walkToPos,
1232
egoWalkToPos: egoWalkToPos,
1233
walkToObj: walkToObj,
1234
egoWalkToObj: egoWalkToObj
1235
};
1236
1237
1238
1239
var throwError = function(errMsg)
1240
{
1241
return function() { alert(errMsg); throw errMsg; }
1242
};
1243
1244
var startPath = function(item, dfd)
1245
{
1246
currentCharacter.anim_state = 'walk';
1247
//drawSprite(currentCharacter);
1248
currentCharacter.walkInt = setInterval(function() {updatePath(item, dfd)}, walkCycleMillisecs);
1249
};
1250
1251
var updatePath = function(item, dfd)
1252
{
1253
var length = item.path.length;
1254
if(length == 0)
1255
{
1256
stopPath(item, dfd);
1257
return;
1258
}
1259
var sprite = item.getCurrentFrame();
1260
var viewCoords = { x : item.position.x - viewport.left, y : item.position.y - viewport.top };
1261
var scrollCamera = function (dir)
1262
{
1263
var stop = false;
1264
var scroll = item.walkSpeed + 3;
1265
switch(dir)
1266
{
1267
case 'left':
1268
case 'right':
1269
if(dir == 'right')
1270
scroll *= -1;
1271
1272
if (dir == 'left' && viewport.left + resolution.width + scroll > testCurrentRoom.items[0].boundingBox.width)
1273
{
1274
scroll = - (viewport.left + resolution.width - testCurrentRoom.items[0].boundingBox.width);
1275
stop = true;
1276
}
1277
else if(dir == 'right' && viewport.left + scroll < 0)
1278
{
1279
scroll = -viewport.left;
1280
stop = true;
1281
}
1282
viewport.left += scroll;
1283
1284
var left = item.position.x - viewport.left;
1285
if (stop)
1286
{
1287
clearInterval(scrollIntLR);
1288
scrollIntLR = null;
1289
return;
1290
}
1291
1292
if (dir == 'left' && left + sprite.img.width / 2 < resolution.width / 2)
1293
{
1294
clearInterval(scrollIntLR);
1295
scrollIntLR = null;
1296
return;
1297
}
1298
1299
if (dir == 'right' && left + sprite.img.width / 2 > resolution.width / 2)
1300
{
1301
clearInterval(scrollIntLR);
1302
scrollIntLR = null;
1303
return;
1304
}
1305
break;
1306
case 'up':
1307
case 'down':
1308
if(dir == 'up')
1309
scroll *= -1;
1310
1311
if (dir == 'down' && viewport.top + resolution.height + scroll > testCurrentRoom.items[0].boundingBox.height)
1312
{
1313
scroll = - (viewport.top + resolution.height - testCurrentRoom.items[0].boundingBox.height);
1314
stop = true;
1315
}
1316
else if(dir == 'up' && viewport.top + scroll < 0)
1317
{
1318
scroll = -viewport.top;
1319
stop = true;
1320
}
1321
viewport.top += scroll;
1322
1323
var top = item.position.y - viewport.top;
1324
if (stop)
1325
{
1326
clearInterval(scrollIntUD);
1327
scrollIntUD = null;
1328
return;
1329
}
1330
1331
if (dir == 'down' && top + sprite.img.height / 2 < (resolution.height - (guiStyle == 'MI2' ? guiHeights[resolution.height] : 0))/ 2)
1332
{
1333
clearInterval(scrollIntUD);
1334
scrollIntUD = null;
1335
return;
1336
}
1337
1338
if (dir == 'up' && top + sprite.img.height / 2 > (resolution.height - (guiStyle == 'MI2' ? guiHeights[resolution.height] : 0)) / 2)
1339
{
1340
clearInterval(scrollIntUD);
1341
scrollIntUD = null;
1342
return;
1343
}
1344
break;
1345
}
1346
1347
};
1348
if(item.id === currentCharacter.id)
1349
cameraCenterItem(item.id);
1350
/*if((viewCoords.x) >= (resolution.width / 3) * 2 && scrollIntLR == null)
1351
{
1352
1353
if(viewport.left + resolution.width < testCurrentRoom.items[0].boundingBox.width)
1354
{
1355
scrollIntLR = setInterval(function() { scrollCamera('left'); }, scrollingMillisecs);
1356
}
1357
}
1358
else if((viewCoords.x) < (resolution.width / 3) && scrollIntLR == null)
1359
{
1360
if(viewport.left > 0)
1361
{
1362
scrollIntLR = setInterval(function() { scrollCamera('right'); }, scrollingMillisecs);
1363
}
1364
}
1365
if((viewCoords.y) >= ((resolution.height - (guiStyle == 'MI2' ? guiHeights[resolution.height] : 0))/ 3) && scrollIntUD == null)
1366
{
1367
if(viewport.top + resolution.height < testCurrentRoom.items[0].boundingBox.height)
1368
{
1369
scrollIntUD = setInterval(function() { scrollCamera('down'); }, scrollingMillisecs);
1370
}
1371
}
1372
else if((viewCoords.y) < ((resolution.height - (guiStyle == 'MI2' ? guiHeights[resolution.height] : 0)) / 3) * 0.4 && scrollIntUD == null)
1373
{
1374
if(viewport.top > 0)
1375
{
1376
scrollIntUD = setInterval(function() { scrollCamera('up'); }, scrollingMillisecs);
1377
}
1378
}*/
1379
var path = item.path;
1380
var currPos = item.position;
1381
var nextPoint = getNextPointInLine(currPos, path[0], item.walkSpeed);
1382
1383
1384
if(Math.abs(nextPoint.x - path[0].x) < 1 && Math.abs(nextPoint.y - path[0].y) < 0.1)
1385
{
1386
path.splice(0, 1);
1387
if(path.length > 0)
1388
{
1389
var slope = getLineSlope(currPos, path[0]);
1390
var nextToNextPoint = getNextPointInLine(currPos, path[0], item.walkSpeed);
1391
//console.log('Slope is ' + slope);
1392
if (slope <= MAX_SLOPE && slope >= MIN_SLOPE )
1393
{
1394
if (nextToNextPoint.x > currPos.x)
1395
setDirection(item.id, 'right');
1396
else
1397
setDirection(item.id, 'left');
1398
}
1399
else if(nextToNextPoint.y > currPos.y)
1400
setDirection(item.id, 'front');
1401
else
1402
setDirection(item.id, 'back');
1403
}
1404
}
1405
var nextWBox = getWalkboxFromPoint(testCurrentRoom.walkBoxes, nextPoint, true);
1406
if(nextWBox && nextWBox.visible === false)
1407
{
1408
item.path = [];
1409
stopPath(item, dfd);
1410
return;
1411
}
1412
setPosition(item.id, item.parentRoomId, nextPoint.x, nextPoint.y);
1413
//setItemZIndex(currentCharacter.id);
1414
1415
for(var i = 0; i < testCurrentRoom.items.length; i++)
1416
{
1417
var itm = testCurrentRoom.items[i];
1418
if(itm.hotspot)
1419
{
1420
if(itm.onWalk && isPointInPoly(itm[i].hotspot.points, getBottomMiddlePos(item.id)))
1421
{
1422
try { eval(itm.onWalk.code); }
1423
catch(err) { alert(err); }
1424
}
1425
}
1426
}
1427
};
1428
1429
var stopPath = function(item, dfd)
1430
{
1431
clearInterval(item.walkInt);
1432
item.anim_state = 'stand';
1433
//drawSprite(currentCharacter);
1434
item.callback = null;
1435
if(dfd && dfd.hasOwnProperty('resolve'))
1436
dfd.resolve();
1437
else if(dfd)
1438
dfd();
1439
};
1440
1441
var interpolateScaleAndSpeed = function(item, minY, minScale, maxY, maxScale)
1442
{
1443
item.scaleFactor = (maxScale + (minScale - maxScale) * ((item.position.y - maxY) / (minY - maxY))) / 100;
1444
item.walkSpeed = DEFAULT_WALK_SPEED * item.scaleFactor;
1445
};
1446