質問編集履歴
9
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,10 @@
|
|
20
20
|
|
21
21
|
SyntaxError: [stdin]:8:18: unexpected ,
|
22
22
|
|
23
|
+
↓
|
24
|
+
|
25
|
+
エラー直りました!
|
26
|
+
|
23
27
|
###ソースコード
|
24
28
|
|
25
29
|
```
|
@@ -355,17 +359,3 @@
|
|
355
359
|
###その他
|
356
360
|
|
357
361
|
本文が決められている文字数を超えるのでもとのjsのコードは載せれませんでした。[以前の質問に載せてあります](https://teratail.com/questions/63808)
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
###追記
|
362
|
-
|
363
|
-
今度はstylesheetがおかしいと言われました(特に触っていない)
|
364
|
-
|
365
|
-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> ←赤く光っています
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
app/assets/stylesheetsには
|
370
|
-
|
371
|
-
application.cssとhome.scssしかありません。
|
8
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -242,16 +242,20 @@
|
|
242
242
|
|
243
243
|
frame++
|
244
244
|
|
245
|
-
if !(frame % 10)
|
245
|
+
if !(frame % 10)
|
246
|
+
|
246
|
-
|
247
|
+
mobMove()
|
248
|
+
|
247
|
-
|
249
|
+
for i in [0..balls.length-1]
|
248
250
|
|
249
251
|
balls[i].draw()
|
250
252
|
|
251
|
-
|
253
|
+
while i = schottBalls.length
|
252
254
|
|
253
255
|
schottBalls[i].draw()
|
254
256
|
|
257
|
+
i--
|
258
|
+
|
255
259
|
|
256
260
|
|
257
261
|
SchottBall =(x, y, w)->
|
@@ -278,26 +282,18 @@
|
|
278
282
|
|
279
283
|
this.y -= 3
|
280
284
|
|
281
|
-
break
|
282
|
-
|
283
285
|
when 'right'
|
284
286
|
|
285
287
|
this.x += 3
|
286
288
|
|
287
|
-
break
|
288
|
-
|
289
289
|
when 'left'
|
290
290
|
|
291
291
|
this.x -= 3
|
292
292
|
|
293
|
-
break
|
294
|
-
|
295
293
|
when 'bottom'
|
296
294
|
|
297
295
|
this.y += 3
|
298
296
|
|
299
|
-
break
|
300
|
-
|
301
297
|
if this.x >= canvas.width + 5 ||
|
302
298
|
|
303
299
|
this.x <= -5 ||
|
@@ -316,7 +312,7 @@
|
|
316
312
|
|
317
313
|
balls.push(new Ball('user', direction[rand(0, 4)]))
|
318
314
|
|
319
|
-
for i in [0..
|
315
|
+
for i in [0..2]
|
320
316
|
|
321
317
|
balls.push(new Ball('', direction[rand(0, 4)]))
|
322
318
|
|
@@ -354,10 +350,6 @@
|
|
354
350
|
|
355
351
|
schottBalls.push(new SchottBall(ball.x + ball.r, ball.y, 'right'))
|
356
352
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
353
|
```
|
362
354
|
|
363
355
|
###その他
|
7
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,16 +38,18 @@
|
|
38
38
|
|
39
39
|
ctx = canvas.getContext('2d')
|
40
40
|
|
41
|
+
start=0
|
42
|
+
|
43
|
+
end=0
|
44
|
+
|
41
45
|
balls=[]
|
42
46
|
|
43
47
|
schottBalls=[]
|
44
48
|
|
45
|
-
start
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
49
|
direction=['top','right','left','bottom']
|
50
50
|
|
51
|
+
|
52
|
+
|
51
53
|
rand = (min,max)->
|
52
54
|
|
53
55
|
return min+Math.floor(Math.random()*(max-min+1))
|
@@ -78,24 +80,26 @@
|
|
78
80
|
|
79
81
|
end = 250
|
80
82
|
|
81
|
-
|
83
|
+
else if this.direction == 'left'
|
82
84
|
|
83
85
|
start = 200
|
84
86
|
|
85
87
|
end = 160
|
86
88
|
|
87
|
-
|
89
|
+
else if this.direction == 'bottom'
|
88
90
|
|
89
91
|
start = 110
|
90
92
|
|
91
93
|
end = 70
|
92
94
|
|
93
|
-
else this.direction == 'right'
|
95
|
+
else if this.direction == 'right'
|
94
96
|
|
95
97
|
start = 20
|
96
98
|
|
97
99
|
end = 340
|
98
100
|
|
101
|
+
|
102
|
+
|
99
103
|
ctx.beginPath()
|
100
104
|
|
101
105
|
ctx.arc(this.x, this.y, this.r, start / 180 * Math.PI, end / 180 * Math.PI)
|
@@ -104,21 +108,21 @@
|
|
104
108
|
|
105
109
|
|
106
110
|
|
107
|
-
|
111
|
+
checkPosition =(x, y, r, ball) ->
|
108
112
|
|
109
113
|
if x - r < 0
|
110
114
|
|
111
115
|
ball.x = r
|
112
116
|
|
113
|
-
|
117
|
+
else if x + r > canvas.width
|
114
118
|
|
115
119
|
ball.x = canvas.width - r
|
116
120
|
|
117
|
-
|
121
|
+
else if y - r < 0
|
118
122
|
|
119
123
|
ball.y = r
|
120
124
|
|
121
|
-
|
125
|
+
else if y + r > canvas.height
|
122
126
|
|
123
127
|
ball.y = canvas.height - r
|
124
128
|
|
@@ -128,19 +132,27 @@
|
|
128
132
|
|
129
133
|
switch a
|
130
134
|
|
135
|
+
when 1
|
136
|
+
|
131
|
-
|
137
|
+
return msg = if (b - c) < 0 then 5 else -5
|
138
|
+
|
132
|
-
|
139
|
+
when 2
|
140
|
+
|
133
|
-
|
141
|
+
return msg = if (b + c) > canvas.width then -5 else 5
|
142
|
+
|
134
|
-
|
143
|
+
when 3
|
144
|
+
|
135
|
-
|
145
|
+
return msg = if (b - c) < 0 then 5 else -5
|
146
|
+
|
136
|
-
|
147
|
+
when 4
|
148
|
+
|
137
|
-
|
149
|
+
return msg = if (b + c) > canvas.height then -5 else 5
|
138
|
-
|
139
|
-
|
140
|
-
|
150
|
+
|
151
|
+
|
152
|
+
|
141
|
-
|
153
|
+
mobMove = ->
|
142
|
-
|
154
|
+
|
143
|
-
|
155
|
+
for i in [1..balls.length-1]
|
144
156
|
|
145
157
|
enemyBall = balls[i]
|
146
158
|
|
@@ -148,41 +160,41 @@
|
|
148
160
|
|
149
161
|
a = rand(1, 4)
|
150
162
|
|
151
|
-
|
163
|
+
switch a
|
152
|
-
|
164
|
+
|
153
|
-
|
165
|
+
when 1
|
154
|
-
|
166
|
+
|
155
|
-
|
167
|
+
enemyBall.direction = 'left'
|
156
|
-
|
168
|
+
|
157
|
-
|
169
|
+
enemyBall.x += stop(1, enemyBall.x, enemyBall.r)
|
158
|
-
|
170
|
+
|
159
|
-
|
171
|
+
break
|
160
|
-
|
172
|
+
|
161
|
-
|
173
|
+
when 2
|
162
|
-
|
174
|
+
|
163
|
-
|
175
|
+
enemyBall.direction = 'right'
|
164
|
-
|
176
|
+
|
165
|
-
|
177
|
+
enemyBall.x += stop(2, enemyBall.x, enemyBall.r)
|
166
|
-
|
178
|
+
|
167
|
-
|
179
|
+
break
|
168
|
-
|
180
|
+
|
169
|
-
|
181
|
+
when 3
|
170
|
-
|
182
|
+
|
171
|
-
|
183
|
+
enemyBall.direction = 'top'
|
172
|
-
|
184
|
+
|
173
|
-
|
185
|
+
enemyBall.y += stop(3, enemyBall.y, enemyBall.r)
|
174
|
-
|
186
|
+
|
175
|
-
|
187
|
+
break
|
176
|
-
|
188
|
+
|
177
|
-
|
189
|
+
when 4
|
178
|
-
|
190
|
+
|
179
|
-
|
191
|
+
enemyBall.direction = 'bottom'
|
180
|
-
|
192
|
+
|
181
|
-
|
193
|
+
enemyBall.y += stop(4, enemyBall.y, enemyBall.r)
|
182
|
-
|
194
|
+
|
183
|
-
|
195
|
+
break
|
184
|
-
|
196
|
+
|
185
|
-
checkPosition(enemyBall.x, enemyBall.y, enemyBall.r, enemyBall)
|
197
|
+
checkPosition(enemyBall.x, enemyBall.y, enemyBall.r, enemyBall)
|
186
198
|
|
187
199
|
|
188
200
|
|
@@ -194,29 +206,27 @@
|
|
194
206
|
|
195
207
|
if k == 37
|
196
208
|
|
197
|
-
userBall.x -= 5
|
209
|
+
userBall.x -= 5
|
198
|
-
|
210
|
+
|
199
|
-
userBall.direction = 'left'
|
211
|
+
userBall.direction = 'left'
|
200
|
-
|
212
|
+
|
201
|
-
else k ==
|
213
|
+
else if k == 38
|
202
|
-
|
214
|
+
|
203
|
-
userBall.y -= 5
|
215
|
+
userBall.y -= 5
|
204
|
-
|
216
|
+
|
205
|
-
userBall.direction = 'top'
|
217
|
+
userBall.direction = 'top'
|
206
|
-
|
218
|
+
|
207
|
-
else k ==
|
219
|
+
else if k == 39
|
208
|
-
|
220
|
+
|
209
|
-
userBall.x += 5
|
221
|
+
userBall.x += 5
|
210
|
-
|
222
|
+
|
211
|
-
userBall.direction = 'right'
|
223
|
+
userBall.direction = 'right'
|
212
|
-
|
224
|
+
|
213
|
-
else k ==
|
225
|
+
else if k == 40
|
214
|
-
|
226
|
+
|
215
|
-
userBall.y += 5
|
227
|
+
userBall.y += 5
|
216
|
-
|
228
|
+
|
217
|
-
userBall.direction = 'bottom'
|
229
|
+
userBall.direction = 'bottom'
|
218
|
-
|
219
|
-
|
220
230
|
|
221
231
|
checkPosition(userBall.x, userBall.y, userBall.r, userBall)
|
222
232
|
|
@@ -232,13 +242,13 @@
|
|
232
242
|
|
233
243
|
frame++
|
234
244
|
|
235
|
-
if
|
245
|
+
if !(frame % 10) mobMove()
|
236
|
-
|
246
|
+
|
237
|
-
for i
|
247
|
+
for i in [0..balls.length-1]
|
238
248
|
|
239
249
|
balls[i].draw()
|
240
250
|
|
241
|
-
for i
|
251
|
+
for i in [0..schottBalls.length-1]
|
242
252
|
|
243
253
|
schottBalls[i].draw()
|
244
254
|
|
@@ -264,32 +274,30 @@
|
|
264
274
|
|
265
275
|
switch this.w
|
266
276
|
|
267
|
-
|
277
|
+
when 'top'
|
268
278
|
|
269
279
|
this.y -= 3
|
270
280
|
|
271
281
|
break
|
272
282
|
|
273
|
-
|
283
|
+
when 'right'
|
274
284
|
|
275
285
|
this.x += 3
|
276
286
|
|
277
287
|
break
|
278
288
|
|
279
|
-
|
289
|
+
when 'left'
|
280
290
|
|
281
291
|
this.x -= 3
|
282
292
|
|
283
293
|
break
|
284
294
|
|
285
|
-
|
295
|
+
when 'bottom'
|
286
296
|
|
287
297
|
this.y += 3
|
288
298
|
|
289
299
|
break
|
290
300
|
|
291
|
-
|
292
|
-
|
293
301
|
if this.x >= canvas.width + 5 ||
|
294
302
|
|
295
303
|
this.x <= -5 ||
|
@@ -308,7 +316,7 @@
|
|
308
316
|
|
309
317
|
balls.push(new Ball('user', direction[rand(0, 4)]))
|
310
318
|
|
311
|
-
for i
|
319
|
+
for i in [0..3]
|
312
320
|
|
313
321
|
balls.push(new Ball('', direction[rand(0, 4)]))
|
314
322
|
|
@@ -324,25 +332,25 @@
|
|
324
332
|
|
325
333
|
if e.keyCode == 32
|
326
334
|
|
327
|
-
for i
|
335
|
+
for i in [0..balls.length-1]
|
328
336
|
|
329
337
|
ball = balls[i]
|
330
338
|
|
331
339
|
if ball.name == 'user'
|
332
340
|
|
333
|
-
if ball.direction ==
|
341
|
+
if ball.direction == 'top'
|
334
342
|
|
335
343
|
schottBalls.push(new SchottBall(ball.x, ball.y - ball.r, 'top'))
|
336
344
|
|
337
|
-
else ball.direction ==
|
345
|
+
else if ball.direction == 'left'
|
338
346
|
|
339
347
|
schottBalls.push(new SchottBall(ball.x - ball.r, ball.y, 'left'))
|
340
348
|
|
341
|
-
else ball.direction ==
|
349
|
+
else if ball.direction == 'bottom'
|
342
350
|
|
343
351
|
schottBalls.push(new SchottBall(ball.x, ball.y + ball.r, 'bottom'))
|
344
352
|
|
345
|
-
else ball.direction ==
|
353
|
+
else if ball.direction == 'right'
|
346
354
|
|
347
355
|
schottBalls.push(new SchottBall(ball.x + ball.r, ball.y, 'right'))
|
348
356
|
|
6
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -355,3 +355,17 @@
|
|
355
355
|
###その他
|
356
356
|
|
357
357
|
本文が決められている文字数を超えるのでもとのjsのコードは載せれませんでした。[以前の質問に載せてあります](https://teratail.com/questions/63808)
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
###追記
|
362
|
+
|
363
|
+
今度はstylesheetがおかしいと言われました(特に触っていない)
|
364
|
+
|
365
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> ←赤く光っています
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
app/assets/stylesheetsには
|
370
|
+
|
371
|
+
application.cssとhome.scssしかありません。
|
5
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,9 +38,15 @@
|
|
38
38
|
|
39
39
|
ctx = canvas.getContext('2d')
|
40
40
|
|
41
|
+
balls=[]
|
42
|
+
|
41
|
-
|
43
|
+
schottBalls=[]
|
44
|
+
|
42
|
-
|
45
|
+
start
|
46
|
+
|
47
|
+
end
|
48
|
+
|
43
|
-
|
49
|
+
direction=['top','right','left','bottom']
|
44
50
|
|
45
51
|
rand = (min,max)->
|
46
52
|
|
@@ -50,15 +56,15 @@
|
|
50
56
|
|
51
57
|
Ball = (name, direction) ->
|
52
58
|
|
53
|
-
this.x = rand(100, 300)
|
59
|
+
this.x = rand(100, 300)
|
54
|
-
|
60
|
+
|
55
|
-
this.y = rand(100, 200)
|
61
|
+
this.y = rand(100, 200)
|
56
|
-
|
62
|
+
|
57
|
-
this.r = 10
|
63
|
+
this.r = 10
|
58
|
-
|
64
|
+
|
59
|
-
this.name = name
|
65
|
+
this.name = name
|
60
|
-
|
66
|
+
|
61
|
-
this.direction = direction
|
67
|
+
this.direction = direction
|
62
68
|
|
63
69
|
if name == '' then this.name = 'enemy'
|
64
70
|
|
@@ -68,27 +74,27 @@
|
|
68
74
|
|
69
75
|
if this.direction == 'top'
|
70
76
|
|
71
|
-
start = 290
|
77
|
+
start = 290
|
72
|
-
|
78
|
+
|
73
|
-
end = 250
|
79
|
+
end = 250
|
74
80
|
|
75
81
|
else this.direction == 'left'
|
76
82
|
|
77
|
-
start = 200
|
83
|
+
start = 200
|
78
|
-
|
84
|
+
|
79
|
-
end = 160
|
85
|
+
end = 160
|
80
86
|
|
81
87
|
else this.direction == 'bottom'
|
82
88
|
|
83
|
-
start = 110
|
89
|
+
start = 110
|
84
|
-
|
90
|
+
|
85
|
-
end = 70
|
91
|
+
end = 70
|
86
92
|
|
87
93
|
else this.direction == 'right'
|
88
94
|
|
89
|
-
start = 20
|
95
|
+
start = 20
|
90
|
-
|
96
|
+
|
91
|
-
end = 340
|
97
|
+
end = 340
|
92
98
|
|
93
99
|
ctx.beginPath()
|
94
100
|
|
@@ -134,7 +140,7 @@
|
|
134
140
|
|
135
141
|
mobMove = ->
|
136
142
|
|
137
|
-
for i = 1
|
143
|
+
for i = 1; l = balls.length; i < l; i++
|
138
144
|
|
139
145
|
enemyBall = balls[i]
|
140
146
|
|
@@ -228,7 +234,7 @@
|
|
228
234
|
|
229
235
|
if (!(frame % 10)) mobMove()
|
230
236
|
|
231
|
-
for i = 0
|
237
|
+
for i = 0; l = balls.length; i < l; i++
|
232
238
|
|
233
239
|
balls[i].draw()
|
234
240
|
|
@@ -342,6 +348,8 @@
|
|
342
348
|
|
343
349
|
|
344
350
|
|
351
|
+
|
352
|
+
|
345
353
|
```
|
346
354
|
|
347
355
|
###その他
|
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
↓
|
18
18
|
|
19
|
-
今はこんなエラーが出ています。
|
19
|
+
(追記)今はこんなエラーが出ています。
|
20
20
|
|
21
21
|
SyntaxError: [stdin]:8:18: unexpected ,
|
22
22
|
|
3
ソースの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,6 +14,12 @@
|
|
14
14
|
|
15
15
|
SyntaxError: [stdin]:7:1: unexpected indentation このようなエラーが出ていました
|
16
16
|
|
17
|
+
↓
|
18
|
+
|
19
|
+
今はこんなエラーが出ています。
|
20
|
+
|
21
|
+
SyntaxError: [stdin]:8:18: unexpected ,
|
22
|
+
|
17
23
|
###ソースコード
|
18
24
|
|
19
25
|
```
|
@@ -28,7 +34,7 @@
|
|
28
34
|
|
29
35
|
canvas = document.getElementById('canvas')
|
30
36
|
|
31
|
-
if !canvas || !canvas.getContext then return false
|
37
|
+
if !canvas || !canvas.getContext then return false
|
32
38
|
|
33
39
|
ctx = canvas.getContext('2d')
|
34
40
|
|
@@ -36,220 +42,220 @@
|
|
36
42
|
|
37
43
|
start,end,direction=['top','right','left','bottom']
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
return min+Math.floor(Math.random()*(max-min+1))
|
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
|
-
|
45
|
+
rand = (min,max)->
|
46
|
+
|
47
|
+
return min+Math.floor(Math.random()*(max-min+1))
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
Ball = (name, direction) ->
|
52
|
+
|
53
|
+
this.x = rand(100, 300);
|
54
|
+
|
55
|
+
this.y = rand(100, 200);
|
56
|
+
|
57
|
+
this.r = 10;
|
58
|
+
|
59
|
+
this.name = name;
|
60
|
+
|
61
|
+
this.direction = direction;
|
62
|
+
|
63
|
+
if name == '' then this.name = 'enemy'
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
Ball.prototype.draw = ->
|
68
|
+
|
69
|
+
if this.direction == 'top'
|
70
|
+
|
71
|
+
start = 290;
|
72
|
+
|
73
|
+
end = 250;
|
74
|
+
|
75
|
+
else this.direction == 'left'
|
76
|
+
|
77
|
+
start = 200;
|
78
|
+
|
79
|
+
end = 160;
|
80
|
+
|
81
|
+
else this.direction == 'bottom'
|
82
|
+
|
83
|
+
start = 110;
|
84
|
+
|
85
|
+
end = 70;
|
86
|
+
|
87
|
+
else this.direction == 'right'
|
88
|
+
|
89
|
+
start = 20;
|
90
|
+
|
91
|
+
end = 340;
|
92
|
+
|
93
|
+
ctx.beginPath()
|
94
|
+
|
95
|
+
ctx.arc(this.x, this.y, this.r, start / 180 * Math.PI, end / 180 * Math.PI)
|
96
|
+
|
97
|
+
ctx.stroke()
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
checkPosition =(x, y, r, ball) ->
|
102
|
+
|
103
|
+
if x - r < 0
|
104
|
+
|
105
|
+
ball.x = r
|
106
|
+
|
107
|
+
else x + r > canvas.width
|
108
|
+
|
109
|
+
ball.x = canvas.width - r
|
110
|
+
|
111
|
+
else y - r < 0
|
112
|
+
|
113
|
+
ball.y = r
|
114
|
+
|
115
|
+
else y + r > canvas.height
|
116
|
+
|
117
|
+
ball.y = canvas.height - r
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
stop = (a, b, c) ->
|
122
|
+
|
123
|
+
switch a
|
124
|
+
|
125
|
+
when 1 then return msg = if (b - c) < 0 then 5 else -5
|
126
|
+
|
127
|
+
when 2 then return msg = if (b + c) > canvas.width then -5 else 5
|
128
|
+
|
129
|
+
when 3 then return msg = if (b - c) < 0 then 5 else -5
|
130
|
+
|
131
|
+
when 4 then return msg = if (b + c) > canvas.height then -5 else 5
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
mobMove = ->
|
136
|
+
|
137
|
+
for i = 1, l = balls.length; i < l; i++
|
138
|
+
|
139
|
+
enemyBall = balls[i]
|
140
|
+
|
141
|
+
if enemyBall.name == 'enemy'
|
142
|
+
|
143
|
+
a = rand(1, 4)
|
144
|
+
|
145
|
+
switch a
|
146
|
+
|
147
|
+
when 1
|
148
|
+
|
149
|
+
enemyBall.direction = 'left'
|
150
|
+
|
151
|
+
enemyBall.x += stop(1, enemyBall.x, enemyBall.r)
|
152
|
+
|
153
|
+
break
|
154
|
+
|
155
|
+
when 2
|
156
|
+
|
157
|
+
enemyBall.direction = 'right'
|
158
|
+
|
159
|
+
enemyBall.x += stop(2, enemyBall.x, enemyBall.r)
|
160
|
+
|
161
|
+
break
|
162
|
+
|
163
|
+
when 3
|
164
|
+
|
165
|
+
enemyBall.direction = 'top'
|
166
|
+
|
167
|
+
enemyBall.y += stop(3, enemyBall.y, enemyBall.r)
|
168
|
+
|
169
|
+
break
|
170
|
+
|
171
|
+
when 4
|
172
|
+
|
173
|
+
enemyBall.direction = 'bottom'
|
174
|
+
|
175
|
+
enemyBall.y += stop(4, enemyBall.y, enemyBall.r)
|
176
|
+
|
177
|
+
break
|
178
|
+
|
179
|
+
checkPosition(enemyBall.x, enemyBall.y, enemyBall.r, enemyBall)
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
window.onkeydown = ->
|
184
|
+
|
185
|
+
k = event.keyCode
|
186
|
+
|
187
|
+
userBall = balls[0]
|
188
|
+
|
189
|
+
if k == 37
|
190
|
+
|
191
|
+
userBall.x -= 5
|
192
|
+
|
193
|
+
userBall.direction = 'left'
|
194
|
+
|
195
|
+
else k === 38
|
196
|
+
|
197
|
+
userBall.y -= 5
|
198
|
+
|
199
|
+
userBall.direction = 'top'
|
200
|
+
|
201
|
+
else k === 39
|
202
|
+
|
203
|
+
userBall.x += 5
|
204
|
+
|
205
|
+
userBall.direction = 'right'
|
206
|
+
|
207
|
+
else k === 40
|
208
|
+
|
209
|
+
userBall.y += 5
|
210
|
+
|
211
|
+
userBall.direction = 'bottom'
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
checkPosition(userBall.x, userBall.y, userBall.r, userBall)
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
draw = ->
|
222
|
+
|
223
|
+
requestAnimationFrame(draw)
|
224
|
+
|
225
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
226
|
+
|
227
|
+
frame++
|
228
|
+
|
229
|
+
if (!(frame % 10)) mobMove()
|
230
|
+
|
231
|
+
for i = 0, l = balls.length; i < l; i++
|
232
|
+
|
233
|
+
balls[i].draw()
|
234
|
+
|
235
|
+
for i = schottBalls.length; i--
|
236
|
+
|
237
|
+
schottBalls[i].draw()
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
SchottBall =(x, y, w)->
|
242
|
+
|
243
|
+
this.x = x
|
244
|
+
|
245
|
+
this.y = y
|
246
|
+
|
247
|
+
this.w = w
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
SchottBall.prototype.draw = ->
|
86
252
|
|
87
253
|
ctx.beginPath()
|
88
254
|
|
89
|
-
ctx.arc(this.x, this.y,
|
255
|
+
ctx.arc(this.x, this.y, 5, 0, 2 * Math.PI)
|
90
256
|
|
91
257
|
ctx.stroke()
|
92
258
|
|
93
|
-
|
94
|
-
|
95
|
-
checkPosition =(x, y, r, ball) ->
|
96
|
-
|
97
|
-
if x - r < 0
|
98
|
-
|
99
|
-
ball.x = r
|
100
|
-
|
101
|
-
else x + r > canvas.width
|
102
|
-
|
103
|
-
ball.x = canvas.width - r
|
104
|
-
|
105
|
-
else y - r < 0
|
106
|
-
|
107
|
-
ball.y = r
|
108
|
-
|
109
|
-
else y + r > canvas.height
|
110
|
-
|
111
|
-
ball.y = canvas.height - r
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
stop = (a, b, c) ->
|
116
|
-
|
117
|
-
switch a
|
118
|
-
|
119
|
-
when 1 then return msg = if (b - c) < 0 then 5 else -5
|
120
|
-
|
121
|
-
when 2 then return msg = if (b + c) > canvas.width then -5 else 5
|
122
|
-
|
123
|
-
when 3 then return msg = if (b - c) < 0 then 5 else -5
|
124
|
-
|
125
|
-
when 4 then return msg = if (b + c) > canvas.height then -5 else 5
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
mobMove = ->
|
130
|
-
|
131
|
-
for i = 1, l = balls.length; i < l; i++
|
132
|
-
|
133
|
-
enemyBall = balls[i]
|
134
|
-
|
135
|
-
if enemyBall.name == 'enemy'
|
136
|
-
|
137
|
-
a = rand(1, 4)
|
138
|
-
|
139
|
-
switch a
|
140
|
-
|
141
|
-
when 1
|
142
|
-
|
143
|
-
enemyBall.direction = 'left'
|
144
|
-
|
145
|
-
enemyBall.x += stop(1, enemyBall.x, enemyBall.r)
|
146
|
-
|
147
|
-
break
|
148
|
-
|
149
|
-
when 2
|
150
|
-
|
151
|
-
enemyBall.direction = 'right'
|
152
|
-
|
153
|
-
enemyBall.x += stop(2, enemyBall.x, enemyBall.r)
|
154
|
-
|
155
|
-
break
|
156
|
-
|
157
|
-
when 3
|
158
|
-
|
159
|
-
enemyBall.direction = 'top'
|
160
|
-
|
161
|
-
enemyBall.y += stop(3, enemyBall.y, enemyBall.r)
|
162
|
-
|
163
|
-
break
|
164
|
-
|
165
|
-
when 4
|
166
|
-
|
167
|
-
enemyBall.direction = 'bottom'
|
168
|
-
|
169
|
-
enemyBall.y += stop(4, enemyBall.y, enemyBall.r)
|
170
|
-
|
171
|
-
break
|
172
|
-
|
173
|
-
checkPosition(enemyBall.x, enemyBall.y, enemyBall.r, enemyBall)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
window.onkeydown = ->
|
178
|
-
|
179
|
-
k = event.keyCode
|
180
|
-
|
181
|
-
userBall = balls[0]
|
182
|
-
|
183
|
-
if k == 37
|
184
|
-
|
185
|
-
userBall.x -= 5
|
186
|
-
|
187
|
-
userBall.direction = 'left'
|
188
|
-
|
189
|
-
else k === 38
|
190
|
-
|
191
|
-
userBall.y -= 5
|
192
|
-
|
193
|
-
userBall.direction = 'top'
|
194
|
-
|
195
|
-
else k === 39
|
196
|
-
|
197
|
-
userBall.x += 5
|
198
|
-
|
199
|
-
userBall.direction = 'right'
|
200
|
-
|
201
|
-
else k === 40
|
202
|
-
|
203
|
-
userBall.y += 5
|
204
|
-
|
205
|
-
userBall.direction = 'bottom'
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
checkPosition(userBall.x, userBall.y, userBall.r, userBall)
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
draw = ->
|
216
|
-
|
217
|
-
requestAnimationFrame(draw)
|
218
|
-
|
219
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
220
|
-
|
221
|
-
frame++
|
222
|
-
|
223
|
-
if (!(frame % 10)) mobMove()
|
224
|
-
|
225
|
-
for i = 0, l = balls.length; i < l; i++
|
226
|
-
|
227
|
-
balls[i].draw()
|
228
|
-
|
229
|
-
for i = schottBalls.length; i--;
|
230
|
-
|
231
|
-
schottBalls[i].draw()
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
SchottBall =(x, y, w)->
|
236
|
-
|
237
|
-
this.x = x
|
238
|
-
|
239
|
-
this.y = y
|
240
|
-
|
241
|
-
this.w = w
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
SchottBall.prototype.draw =->
|
246
|
-
|
247
|
-
ctx.beginPath()
|
248
|
-
|
249
|
-
ctx.arc(this.x, this.y, 5, 0, 2 * Math.PI)
|
250
|
-
|
251
|
-
ctx.stroke()
|
252
|
-
|
253
259
|
switch this.w
|
254
260
|
|
255
261
|
then 'top'
|
@@ -280,11 +286,11 @@
|
|
280
286
|
|
281
287
|
if this.x >= canvas.width + 5 ||
|
282
288
|
|
283
|
-
|
289
|
+
this.x <= -5 ||
|
284
|
-
|
290
|
+
|
285
|
-
|
291
|
+
this.y >= canvas.height + 5 ||
|
286
|
-
|
292
|
+
|
287
|
-
|
293
|
+
this.y <= -5
|
288
294
|
|
289
295
|
schottBalls.splice(schottBalls.indexOf(this), 1)
|
290
296
|
|
@@ -312,9 +318,9 @@
|
|
312
318
|
|
313
319
|
if e.keyCode == 32
|
314
320
|
|
315
|
-
for i = balls.length; i--
|
321
|
+
for i = balls.length; i--
|
316
|
-
|
322
|
+
|
317
|
-
|
323
|
+
ball = balls[i]
|
318
324
|
|
319
325
|
if ball.name == 'user'
|
320
326
|
|
2
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jsのコードを
|
1
|
+
jsのコードをCoffeeScriptにしたい
|
test
CHANGED
File without changes
|
1
見出しの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
SyntaxError: [stdin]:7:1: unexpected indentation このようなエラーが出ていました
|
16
16
|
|
17
|
-
|
17
|
+
###ソースコード
|
18
18
|
|
19
19
|
```
|
20
20
|
|