Révision | 755aa619f6519a1a4db4174569a45284f7dedf93 (tree) |
---|---|
l'heure | 2016-12-16 21:38:41 |
Auteur | Yu Hayashi <yu011301@teca...> |
Commiter | Yu Hayashi |
600x600
@@ -30,8 +30,8 @@ | ||
30 | 30 | } |
31 | 31 | |
32 | 32 | function Ship() { |
33 | - this.cx = 400; | |
34 | - this.cy = 400; | |
33 | + this.cx = 300; | |
34 | + this.cy = 300; | |
35 | 35 | this.w = 90; |
36 | 36 | this.h = 60; |
37 | 37 | this.dx = 0; |
@@ -52,13 +52,18 @@ | ||
52 | 52 | getX: function() { return (this.cx - this.w / 2); }, |
53 | 53 | getY: function() { return (this.cy - this.h / 2); }, |
54 | 54 | isHit: function(o) { |
55 | - return !(((o.getX() + o.w) < this.getX()) || ((this.getX() + this.w) < o.getX()) || ((o.getY() + o.h) < this.getY()) || ((this.getY() + this.h) < o.getY())); | |
55 | + return !(((o.getX() + o.w) < this.getX()) | |
56 | + || ((this.getX() + this.w) < o.getX()) | |
57 | + || ((o.getY() + o.h) < this.getY()) | |
58 | + || ((this.getY() + this.h) < o.getY())); | |
56 | 59 | }, |
57 | 60 | update: function() { |
58 | - this.cx = (this.cx + this.dx + 800) % 800; | |
59 | - this.cy = (this.cy + this.dy + 800) % 800; | |
61 | + this.cx = (this.cx + this.dx + 600) % 600; | |
62 | + this.cy = (this.cy + this.dy + 600) % 600; | |
60 | 63 | } |
61 | 64 | } |
65 | + | |
66 | + function rand(r) { return Math.floor(Math.random() *r) } | |
62 | 67 | |
63 | 68 | function init() { |
64 | 69 | ctx = document.getElementById('canvas').getContext('2d'); |
@@ -103,7 +108,7 @@ | ||
103 | 108 | |
104 | 109 | // 岩の初期化 |
105 | 110 | for (var i=0; i < level; i++) { |
106 | - var x = rand(800), y = rand(800); | |
111 | + var x = rand(600), y = rand(600); | |
107 | 112 | while(true) { |
108 | 113 | var r = new Rock(x, y, 64); |
109 | 114 | if (!r.isHit(ship)) { |
@@ -138,8 +143,8 @@ | ||
138 | 143 | ship.dy = Math.sin(ship.rotate) * ship.poower; |
139 | 144 | ship.update(); |
140 | 145 | |
141 | - bgX = (bgX + ship.dx / 2 + 1600) % 800; | |
142 | - bgY = (bgY + ship.dy / 2 + 1600) % 800; | |
146 | + bgX = (bgX + ship.dx / 2 + 1200) % 600; | |
147 | + bgY = (bgY + ship.dy / 2 + 1200) % 600; | |
143 | 148 | |
144 | 149 | // 弾丸の位置を更新 |
145 | 150 | var fire = false; |
@@ -204,7 +209,8 @@ | ||
204 | 209 | |
205 | 210 | function draw() { |
206 | 211 | // 背景を描画 |
207 | - ctx.drawImage(bg, bgX, bgY, 400, 400, 0, 0, 800, 800); | |
212 | + var bg = document.getElementById("bg"); | |
213 | + ctx.drawImage(bg, bgX, bgY, 300, 300, 0, 0, 600, 600); | |
208 | 214 | |
209 | 215 | // 弾丸の描画 |
210 | 216 | ctx.fillStyle = 'rgb(0,255,255)'; |
@@ -241,9 +247,9 @@ | ||
241 | 247 | } |
242 | 248 | </script> |
243 | 249 | </head> |
244 | - <body onload="iniit()"> | |
250 | + <body onload="init()"> | |
245 | 251 | <div> |
246 | - <canvas id="canvas" width="800" height="800"></canvas> | |
252 | + <canvas id="canvas" width="600" height="600"></canvas> | |
247 | 253 | </div> |
248 | 254 | <img id="ship" src="ship90x60.png" style="display:none" /> |
249 | 255 | <img id="bg" src="bg.png" style="display:none" /> |