forked from github/game-off-2013
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainloop.js
81 lines (66 loc) · 2.13 KB
/
mainloop.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
"use strict";
define(['inventory', 'arscene', 'ui', 'imagesource', 'level', 'hud', 'audio', 'tween.min', 'three.min'],
function( Inventory, arscene, ui, imagesource, level, hud, audio ) {
var source = new imagesource.VideoSource( { width:480, height:360 } );
var scene, hudView;
var currentLevel;
var inventory;
var score = 0;
function animate() {
requestAnimationFrame( animate );
currentLevel.update();
TWEEN.update();
source.update();
scene.update();
scene.render();
hudView.render();
}
function onFailure(message) {
var color = {
background: "#FF0000",
foreground: "#FFFFFF"
};
ui.flash( message, color );
score = score === 0 ? score : score-1;
hudView.setScore(score);
}
function onWin() {
var color = {
background: "#FFFFFF",
foreground: "#000000"
};
score++;
hudView.setScore(score);
}
function onGameComplete() {
ui.theEnd();
}
function start() {
inventory = new Inventory.Inventory();
scene = new arscene.Scene( document.getElementById("scene"), source );
hudView = new hud.HUD( document.getElementById("scene"), inventory );
currentLevel = new level.Level( onPlaceChanged, onFailure, onWin, onGameComplete, inventory, hudView );
ui.addToolListener( changeTool );
ui.addPlacePreviousListener( previousPlace );
ui.addPlaceNextListener( nextPlace );
scene.setView( currentLevel.currentFilter().getView() );
source.setVideo( currentLevel.currentPlace().getVideo() );
requestAnimationFrame( animate );
}
function changeTool() {
inventory.previousItem();
}
function previousPlace() {
currentLevel.previousPlace();
}
function nextPlace() {
currentLevel.nextPlace();
}
function onPlaceChanged() {
source.setVideo( currentLevel.currentPlace().getVideo() );
scene.setView( currentLevel.currentFilter().getView() );
}
return {
start: start,
};
});