-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
107 lines (91 loc) · 2.49 KB
/
main.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
window.onload = function () {
var canvas = document.getElementById("game");
var stage = new Stage(canvas);
var eventMan = eventManager();
var timer = metronome({
'event': eventMan,
'detail': 2,
});
var rhythms = [];
rhythms.push(rhythm({
'event': eventMan,
'metronome': timer,
'pattern': ". . . . ",
}));
var player1 = controller({
'event': eventMan,
'lenience': 200,
'name': "Player 1",
});
var player2 = controller({
'event': eventMan,
'lenience': 200,
'name': "Player 2",
});
//eventMan.subscribe('tick', function (data) {
// console.log("tick");
//});
eventMan.subscribe('beat', function (data) {
//console.log("beat");
player2.beat();
});
eventMan.subscribe('synchronised', function (data) {
console.log(data.controller+" synchronised");
});
var img = new Image();
img.onload = function () {
var sprite = new SpriteSheet({
'images': [img],
'frames': {
'width': 64,
'height': 64,
},
'animations': {
'still': [0,0,"still"],
'beat': [1,11,"still"],
},
});
var beat = new BitmapAnimation(sprite);
beat.x = 0;
beat.y = 0;
beat.gotoAndPlay('still');
stage.addChild(beat);
eventMan.subscribe('beat', function (data) {
if (data.rhythm.id() == 0) {
beat.gotoAndPlay('beat');
}
});
}
img.src = "Beat.png";
timer.start();
Ticker.addListener(stage);
document.onkeydown = function () {
player1.beat();
}
/*var start;
var sync = synchroniser({
'leniency': 0.2,
'rhythms': [
'. . ',
'. . . . '
],
});
sync.enable(1);
document.tick = function () {
start = new Date();
console.log(sync.endBar());
var t = setTimeout("document.tick()", 4000);
var t2 = setTimeout("document.flash(1)", 100);
}
document.flash = function (n) {
console.log(n);
if (n < 4) {
var t = setTimeout("document.flash("+(n+1)+")", 1000);
}
}
document.tick();
document.onkeydown = function () {
var now = new Date();
sync.beat((now.getTime() - start.getTime())/1000);
}*/
};