-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimon.js
124 lines (111 loc) · 3.06 KB
/
simon.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
var game = new Phaser.Game(480, 320, Phaser.CANVAS, '', {
preload: preload,
create: create,
update: update,
render: render
});
var simonSez = false; // sez == says
var currentCount = 0;
var N = 1;
var userCount = 0;
var sequence;
var loser, winner;
function preload() {
game.load.spritesheet('item', 'assets/number-buttons2.png', 160, 160);
}
function create() {
simon = game.add.group();
// 上段
for (var i = 0; i < 6; i++) {
var item = simon.create((160 * (i % 3)), Math.floor((i / 3)) * 160 + 0, 'item', i);
item.inputEnabled = true;
item.input.start(0, true);
item.events.onInputDown.add(onInputDown);
item.events.onInputUp.add(onInputUp);
item.events.onInputOut.add(onInputOut);
simon.getAt(i).alpha = 0.25;
}
// blinkAnimation();
// create sequence.
sequence = Array.from({length: 16}, (v, k) =>game.rnd.integerInRange(0, 5));
/*
setTimeout(function() {
console.log('simonSequence');
simonSequence();
intro = false;
}, 6000); // 6秒
*/
simonSequence();
}
function simonSequence() {
simonSez = true;
litSquare = sequence[currentCount]; // lit 点灯
simon.getAt(litSquare).alpha = 1;
timeCheck = game.time.now;
currentCount++;
}
//
function blinkAnimation() {
intro = true;
simon.forEach(o => {
var flashing = game.add.tween(o).to({ alpha: 1 }, 500, Phaser.Easing.Linear.None, true, 0, 4, true);
var final = game.add.tween(o).to({ alpha: .25 }, 500, Phaser.Easing.Linear.None, true);
flashing.chain(final);
flashing.start();
});
};
function update() {
if (simonSez) {
console.log('update')
if (game.time.now - timeCheck > 700 - N * 40) {
simon.getAt(litSquare).alpha = 0.25;
game.paused = true;
setTimeout(function () {
if (currentCount < N) {
simonSequence();
} else {
simonSez = false;
}
game.paused = false;
}, 400 - N * 20);
}
}
}
function render() {
// タイトル
// ゲーム終了時
}
function onInputDown(item, pointer) {
!simonSez && (item.alpha = 1);
}
function onInputUp(item, pointer) {
if (!simonSez) {
item.alpha = 0.25;
playerSequence(item);
}
}
function playerSequence(selected) {
correctSquare = sequence[userCount++];
console.log(selected);
thisSquare = simon.getIndex(selected);
if (correctSquare == thisSquare) {
if (userCount === N) {
// 全てのステージクリア
if (N === sequence.length) {
console.log('you win');
// todo restart.
} else {
userCount = 0;
currentCount = 0;
N++;
simonSez = true;
}
}
} else {
// todo gameover and reset.
console.log('todo gameover!');
}
}
function onInputOut(item, pointer) {
!simonSez && (item.alpha = 0.25);
}