修订版 | 4bbd83f4ad6ad85537bfd943d8016dc7d98bab4d (tree) |
---|---|
时间 | 2016-12-13 21:33:32 |
作者 | Yu Hayashi <yu011301@teca...> |
Commiter | Yu Hayashi |
FIX: Bombs
@@ -15,6 +15,7 @@ | ||
15 | 15 | function Missile() { |
16 | 16 | this.maxCount = 500; |
17 | 17 | this.interval = 1000; |
18 | + | |
18 | 19 | this.reload = function() { |
19 | 20 | this.sX = rand(800); |
20 | 21 | this.eX = rand(800); |
@@ -26,14 +27,14 @@ | ||
26 | 27 | }; |
27 | 28 | |
28 | 29 | this.draw = function(ctx) { |
29 | - ctx.strokeStyle = ctx.fillStyle = rgb(0,255,255); | |
30 | + ctx.strokeStyle = ctx.fillStyle = 'rgb(0,255,255)'; | |
30 | 31 | |
31 | 32 | // 軌跡の描画 |
32 | 33 | line(ctx, this.sX, 0, this.x, this.y); |
33 | 34 | |
34 | 35 | // 爆発 |
35 | 36 | if (this.r > 0) { |
36 | - circle(ctx, this.x, this.y, this.r < 50 ? this.r : (100 - this.r)); | |
37 | + circle(ctx, this.x, this.y, (this.r < 50 ? this.r : (100 - this.r))); | |
37 | 38 | } |
38 | 39 | }; |
39 | 40 |
@@ -51,14 +52,15 @@ | ||
51 | 52 | this.shotR = 0; |
52 | 53 | this.fire = false; |
53 | 54 | this.draw = function (ctx) { |
54 | - ctx.strokeStyle = ctx.fillStyle = rgb(0,255,0); | |
55 | + ctx.strokeStyle = ctx.fillStyle = 'rgb(0,255,0)'; | |
55 | 56 | |
56 | 57 | // 照準器の描画 |
57 | - ctx.drawImage(this.image, this.scopeX - this.scopeW / 2, this.scopeY - thisscopeW / 2); | |
58 | + ctx.drawImage(this.image, this.scopeX - this.scopeW / 2, this.scopeY - this.scopeW / 2); | |
58 | 59 | if (!this.fire) { |
59 | 60 | return; |
60 | 61 | } |
61 | - if (this.shotR == 0 && this.count < 100) { | |
62 | + | |
63 | + if ((this.shotR == 0) && (this.count < 100)) { | |
62 | 64 | // 軌跡の描画 |
63 | 65 | var ratio = this.count / 100; |
64 | 66 | var y = 600 - (600 - this.shotY) * ratio; |
@@ -77,11 +79,11 @@ | ||
77 | 79 | } |
78 | 80 | |
79 | 81 | function rand(r) { |
80 | - return Math.floor(Math.random() * r) | |
82 | + return Math.floor(Math.random() * r); | |
81 | 83 | } |
82 | 84 | |
83 | 85 | function explodeSound() { |
84 | - documeent.getElementById('explode').play(); | |
86 | + document.getElementById('explode').play(); | |
85 | 87 | } |
86 | 88 | |
87 | 89 | function line(ctx, x0, y0, x1, y1) { |
@@ -96,15 +98,15 @@ | ||
96 | 98 | if (r <= 0) { |
97 | 99 | return; |
98 | 100 | } |
99 | - ctx.biginPath(); | |
101 | + ctx.beginPath(); | |
100 | 102 | ctx.arc(x, y, r, 0, Math.PI * 2, true); |
101 | 103 | ctx.fill(); |
102 | 104 | } |
103 | 105 | |
104 | 106 | function init() { |
105 | - shoot = new shoot(); | |
107 | + shoot = new Shoot(); | |
106 | 108 | var canvas = document.getElementById('canvas'); |
107 | - ctx. = canvas.getContext('2d'); | |
109 | + ctx = canvas.getContext('2d'); | |
108 | 110 | ctx.font = "20pt Arial"; |
109 | 111 | canvas.addEventListener('mousemove', mousemove); |
110 | 112 | canvas.addEventListener('mousedown', mousedown); |
@@ -133,19 +135,19 @@ | ||
133 | 135 | if (shoot.fire) { |
134 | 136 | shoot.count++; |
135 | 137 | |
136 | - if (100 <= shoot.count && shoot.count < 200) { | |
138 | + if ((100 <= shoot.count) && (shoot.count < 200)) { | |
137 | 139 | shoot.shotR++; |
138 | 140 | } |
139 | - else if (200 <= shoot.count && shoot.count < 300) { | |
141 | + else if ((200 <= shoot.count) && (shoot.count < 300)) { | |
140 | 142 | shoot.shotR--; |
141 | 143 | } |
142 | - else if (300 <= shot.count) { | |
144 | + else if (300 <= shoot.count) { | |
143 | 145 | shoot.fire = false; |
144 | 146 | } |
145 | 147 | } |
146 | 148 | |
147 | 149 | // ミサイルの状態を更新 |
148 | - missile.forEach(function(m) { | |
150 | + missiles.forEach(function(m) { | |
149 | 151 | var c = count - m.firetime; |
150 | 152 | if (c < 0) { |
151 | 153 | return; |
@@ -158,7 +160,7 @@ | ||
158 | 160 | } |
159 | 161 | else { |
160 | 162 | // ミサイルの場所更新 |
161 | - m.x = (m.eX - x.sX) * c / m.maxCount + m.sX; | |
163 | + m.x = (m.eX - m.sX) * c / m.maxCount + m.sX; | |
162 | 164 | m.y = 600 * c / m.maxCount; |
163 | 165 | |
164 | 166 | // 自分の迎撃ミサイルとの衝突判定 |
@@ -182,9 +184,7 @@ | ||
182 | 184 | } |
183 | 185 | }); |
184 | 186 | |
185 | - if (houses.every(function(house) { | |
186 | - return house.hit; | |
187 | - })) { | |
187 | + if (houses.every(function(house) { return house.hit; })) { | |
188 | 188 | clearInterval(timer); |
189 | 189 | timer = NaN; |
190 | 190 | } |
@@ -204,7 +204,7 @@ | ||
204 | 204 | } |
205 | 205 | |
206 | 206 | function mousedown(e) { |
207 | - if (shot.fire == false) { | |
207 | + if (shoot.fire == false) { | |
208 | 208 | shoot.shotX = e.clientX; |
209 | 209 | shoot.shotY = e.clientY; |
210 | 210 | shoot.shotR = 0; |
@@ -213,7 +213,7 @@ | ||
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - function dwaw() { | |
216 | + function draw() { | |
217 | 217 | // 背景を塗りつぶし |
218 | 218 | ctx.fillStyle = 'rgb(0,0,0)'; |
219 | 219 | ctx.fillRect(0, 0, 800, 600); |
@@ -244,8 +244,8 @@ | ||
244 | 244 | </head> |
245 | 245 | <body onload="init();"> |
246 | 246 | <canvas id="canvas" width="800" height="600"></canvas> |
247 | - <img id="strip" src="strip.png" style="display:none;" /> | |
248 | - <img id="scope" src="scope.png" style="display:none;" /> | |
247 | + <img id="strip" src="house.png" style="display:none;" /> | |
248 | + <img id="scope" src="scope.png" style="display:none;" /> | |
249 | 249 | <audio id="explode" src="bomb.mp3"></audio> |
250 | 250 | </body> |
251 | 251 | </html> |
\ No newline at end of file |