forked from nkhalsa/top-down-pong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
218 lines (183 loc) · 6.86 KB
/
index.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<title>PONG</title>
<script src="jspsych-6.0.3/jspsych.js"></script>
<script src="jspsych-6.0.3/plugins/jspsych-survey-text.js"></script>
<script src="jspsych-6.0.3/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.0.3/plugins/jspsych-html-slider-response.js"></script>
<script src="jspsych-6.0.3/plugins/jspsych-html-button-response.js"></script>
<script src="pong.js"></script>
<link href="jspsych-6.0.3/css/jspsych.css" rel="stylesheet" type="text/css"></link>
<style>
html, body { background-color: black; }
</style>
</head>
<body>
</body>
<script>
var timeStarted = new Date().valueOf()
var gameDuration = 15*60*1000
var gameWidth = 960, gameHeight = 600
var numTrials = 0
var maxTrials = 30 //make sure this is divisible by 3 for paddle size randomization!
var timeline = []
var colorBlindSafeColorPairs = [['white', 'grey'], ['white', 'red'], ['white', 'green'], ['white', 'blue'], ['white', 'pink'], ['grey', 'white'], ['grey', 'red'], ['grey', 'blue'], ['red', 'white'], ['red', 'blue'], ['green', 'white'], ['green', 'blue'], ['blue', 'white'], ['blue', 'white'], ['blue', 'red'], ['blue', 'pink'], ['blue', 'grey'], ['chartreuse', 'grey'], ['chartreuse', 'yellow'], ['chartreuse', 'white'], ['chartreuse', 'blue'], ['chartreuse', 'grey'], ['magenta', 'white'], ['magenta', 'grey'], ['magenta', 'yellow'], ['magenta', 'red'], ['cyan', 'grey'], ['cyan', 'white'], ['white', 'cyan'], ['grey', 'cyan'], ['grey', 'chartreuse'], ['yellow', 'chartreuse'], ['white', 'chartreuse'], ['blue', 'chartreuse'], ['white', 'magenta'], ['grey', 'magenta'], ['yellow', 'magenta'], ['red', 'magenta']]
var paddleSizes = [0.5, 1.2, 1.9]
var usedPaddleSizes = []
var ballSpeeds = [13, 15, 17]
//these have similar levels of contrast as each other, to a black background. Because of this, they don't appear to be moving different speeds.
var goodColors = [['#3077FF', 'mediumorchid'], ['mediumorchid', '#3077FF'], ['#00AAAA', '#BB00BB'], ['#AA00AA', '#00AAAA'], ['#a1a69f', '#1eabf6'], ['#1eabf6', '#a1a69f']]
function getRandomColorPair(){
return goodColors[Math.floor(Math.random()*goodColors.length)]
}
//returns a random paddle size, but each subject only gets only numTrials/3 of each paddle
function getRandomPaddleSize(){
var generate = true
var numGenerates = 0
while(generate){
console.log(usedPaddleSizes)
numGenerates++
var paddleSize = paddleSizes[Math.floor(Math.random()*paddleSizes.length)]
var timesSizeUsed = 0
//count number of times it's been used yet:
for(var i = 0; i < usedPaddleSizes.length; i++){
if(usedPaddleSizes[i] == paddleSize){timesSizeUsed++}
}
console.log(timesSizeUsed)
//stop condition:
if(timesSizeUsed < maxTrials/3 || numGenerates > 400){
console.log('d')
generate = false
usedPaddleSizes.push(paddleSize)
return paddleSize
}
}
}
var welcome = {
type:"html-keyboard-response",
stimulus:"<img src='welcome.png' height='" + gameHeight + "' style='position: absolute; top: 50%; left: 50%; margin-right:50%; transform: translate(-50%, -50%);></img>'<br />",
on_finish: function(){//gameMusic.load()
/*gameMusic.play()*/}
}
var genericLevel = {
type:"pong",
stimulus:"<p>test</p>",
ballSpeed: function() { return ballSpeeds[Math.floor(Math.random()*ballSpeeds.length)] },
ballColors: getRandomColorPair,
humanPaddleSize: getRandomPaddleSize,
aiPaddleSize:1,
gameWidth:500,
gameHeight:400,
randomBackgroundBallMotion: false,
keyboardControl: false,
mouseControl: true
}
var tutorialLevel1 = {
type:"pong",
stimulus:"<p>test</p>",
ballSpeed: ballSpeeds[Math.floor(Math.random()*ballSpeeds.length)],
ballColors: getRandomColorPair(),
humanPaddleSize:paddleSizes[Math.floor(Math.random()*paddleSizes.length)], //don't use getRandomPaddleSize
aiPaddleSize:1,
gameWidth:500,
gameHeight:400,
randomBackgroundBallMotion: false,
keyboardControl: false,
mouseControl: true
}
var tutorialLevel2 = {
type:"pong",
stimulus:"<p>test</p>",
ballSpeed: ballSpeeds[Math.floor(Math.random()*ballSpeeds.length)],
ballColors: getRandomColorPair(),
humanPaddleSize:paddleSizes[Math.floor(Math.random()*paddleSizes.length)], //don't use getRandomPaddleSize
aiPaddleSize:1,
gameWidth:500,
gameHeight:400,
randomBackgroundBallMotion: false,
keyboardControl: false,
mouseControl: true
}
var firstLevel = {
type:"pong",
stimulus:"<p>test</p>",
ballSpeed: ballSpeeds[0],
ballColors: getRandomColorPair(),
humanPaddleSize:paddleSizes[1],
aiPaddleSize:1,
gameWidth:500,
gameHeight:400,
randomBackgroundBallMotion: false,
keyboardControl: false,
mouseControl: true,
tutorial: true
}
var postTutorialPrompt = {
type:"html-keyboard-response",
stimulus: "<p style='color:white'>Tutorial over. Press any key for the first level</p>"
}
var nextTutorialPrompt = {
type:"html-keyboard-response",
stimulus: "<p style='color:white'>Good, let's do a practice level. Press any key to continue (remember: the target is the ball to play with).</p>"
}
/*
var response = {
type: 'html-button-response',
stimulus: '',
choices: ['Background', 'Target', 'Neither'],
prompt: "<p style='color:white'>Which ball was faster?</p>"
}
*/
var lengthResponse = {
type: 'html-button-response',
stimulus: '',
choices: ['10', '15', '20'],
prompt: "<p style='color:white'>How long did this trial feel? (in seconds)</p>"
}
var fluffQ = {
type: 'html-button-response',
stimulus: '',
choices: ['Easy', 'Medium', 'Difficult'],
prompt: "<p style='color:white'>How hard was the trial?</p>"
}
var performanceQ = {
type: 'html-slider-response',
stimulus: '<p style="color:white"></p>',
labels: ['<p style="color:white">One of my worst runs</p>', '<p style="color:white">One of my best</p>'],
prompt: "<p style='color:white'>How well do you think you did?</p>"
}
var hypothesisGuess = {
type: 'survey-text',
questions: [{prompt: "<p style='color:white'>What do you think this experiment is about? What's your best guess of the hypothesis?</p>", rows: 5, columns: 40}],
}
var thankerScreen = {
type: 'html-keyboard-response',
stimulus: "<p style='color:white'>Thank you for playing! Please return to Prolific now to finish the study: </p>"
}
var loop = {timeline: [genericLevel, lengthResponse, fluffQ, performanceQ],
repetitions: maxTrials
}
timeline.push(welcome)
timeline.push(firstLevel)
timeline.push(nextTutorialPrompt)
timeline.push(tutorialLevel1)
timeline.push(nextTutorialPrompt)
timeline.push(tutorialLevel2)
timeline.push(postTutorialPrompt)
timeline.push(loop)
timeline.push(hypothesisGuess)
timeline.push(thankerScreen)
/*timeline.push(level)
timeline.push(response)
timeline.push(lengthResponse)
timeline.push(favoriteBall)
timeline.push(performanceQ)*/
jsPsych.init({
timeline: timeline,
on_finish: function(){
jsPsych.data.displayData();
}
})
</script>
</html>