/
instructions.js
134 lines (109 loc) · 3.91 KB
/
instructions.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
//instructions.js
Instructions = function (text, params, parent) {
this.text = text;
this.params = params;
this.count = 0;
this.parent = parent;
this.complete = false;
if (parent.mobile == true) {
cont = 'press here to continue'
} else {
cont = 'press space to continue'
}
ins_style = {font:'24px Arial', fill:'#FFFFFF', align:'center', backgroundColor: 'rgba(0,0,0,0.5)'};
this.ins_text = parent.game.add.text(parent.game.world.centerX, 50, text[0], ins_style);
this.ins_text.anchor.x = 0.5;
this.ins_text.wordWrap = true;
this.ins_text.wordWrapWidth = 800;
ins_style['backgroundColor'] = 'rgba(25, 25, 25, 1)';
ins_style['font'] = '24px Arial';
this.continue_button = text_button(parent.game, this, function () {this.next();},
parent.game.world.centerX, parent.game.world.centerY + 200,
cont, ins_style);
this.space = this.parent.game.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR);
this.space.onDown.addOnce(function() {this.next();}, this);
this.next = function () {
//hide initial text
this.continue_button.destroy();
//get the next stimulus params and set these properties
trial_params = this.params[this.count];
for (var k in trial_params) {
//set the values of the trial parameters
this.parent[k] = trial_params[k];
}
//clear the stimuli
this.parent.signal.dispatch('ISI');
//update the instructions label
this.ins_text.setText(this.text[this.count + 1]);
//show the stimuli
this.parent.signal.dispatch('stimulus');
this.count += 1;
this.space.onDown.removeAll();
};
this.check = function () {
//don't sum up the easyness
this.parent.avg_easyness = undefined;
console.log('begin instructions check');
console.log('continue :' + this.continue());
//handle the appropriate behavior when in instructions mode
if (this.continue() == false) {
//mark the instructions as complete
console.log('Continue Instructions');
this.complete = true;
if (this.parent.grader.ACC == 1) {
console.log('ins: correct')
console.log('move on to practice...');
//remove practice text
this.ins_text.destroy();
//clear ye stimuli
this.ins_text.destroy();
this.parent.signal.dispatch('ISI');
//now, fire up practice...
this.parent.practice.begin();
} else {
console.log('incorrect, try again');
this.complete = false;
this.parent.signal.dispatch('stimulus');
this.incorrect();
}
} else {
if (this.parent.grader.ACC == 1) {
console.log('ins: correct!');
this.parent.signal.dispatch('stimulus');
if (this.continue() == true) {
this.next();
}
} else {
this.complete = false;
//gotta call this to reset the one-shot event handlers
this.parent.signal.dispatch('stimulus');
this.incorrect();
}
}
console.log('end instructions check');
};
this.incorrect = function () {
//fun little animation to show they got it wrong...
//this.parent.game.add.tween(this.ins_text).to({angle:2}, 100, Phaser.Easing.Cubic.InOut, true);
t = this.parent.game.add.tween(this.ins_text);
t.to({ x: this.ins_text.position.x + 5, angle:this.ins_text.angle + 5}, 150, function (k) {
return wiggle(k, .5, .5);
}, true, 0, 2);
//t.start();
};
this.continue = function () {
//check if we've completed the instructions
console.log(this.params.length);
console.log(this.count);
if (this.params.length > this.count) {
return true;
} else {
return false;
}
};
}
function wiggle(aProgress, aPeriod1, aPeriod2) {
var current1 = aProgress * Math.PI * 2 * aPeriod1;
var current2 = aProgress * (Math.PI * 2 * aPeriod2 + Math.PI / 2);
return Math.sin(current1) * Math.cos(current2);
}