Changeset 114 for pycodeshooter/trunk/shooter
- Timestamp:
- 01/21/12 04:46:57 (13 years ago)
- Location:
- pycodeshooter/trunk/shooter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/shooter/bullet.js
r106 r114 14 14 */ 15 15 16 var Bullet = function(size, color, frame, x, y, dir, speed) {16 var Bullet = function(size, color, frame, w, h, x, y, dir, speed) { 17 17 this.size = size; 18 18 this.color = color; 19 19 this.frame = frame; 20 this.w = w; 21 this.h = h; 20 22 this.x = x; 21 23 this.y = y; … … 66 68 }; 67 69 68 var LinerBullet = function(size, color, frame, x, y, dir, speed) {69 var that = new Bullet(size, color, frame, x, y, dir, speed);70 var LinerBullet = function(size, color, frame, w, h, x, y, dir, speed) { 71 var that = new Bullet(size, color, frame, w, h, x, y, dir, speed); 70 72 71 73 that.deltaBaseX = Math.cos(that.dir); … … 85 87 }; 86 88 87 var AxisExtendBullet = function(size, color, frame, x, y, dir, speed) { 88 var that = new LinerBullet(size, color, frame, x, y, dir, speed); 89 var XReflectLinerBullet = function(size, color, frame, w, h, x, y, dir, speed) { 90 var that = new LinerBullet(size, color, frame, w, h, x, y, dir, speed); 91 var count = 0; 92 93 that.calcNext = function() { 94 var x = this.x + this.getDeltaX(); 95 var y = this.y + this.getDeltaY(); 96 97 if ((0 >= x || x >= this.w) && count < 5) { 98 count++; 99 this.dir += (2 - this.dir) - (this.dir - 1); 100 this.deltaBaseX = Math.cos(this.dir); 101 this.deltaBaseY = Math.sin(this.dir); 102 x = this.x + this.getDeltaX(); 103 y = this.y + this.getDeltaY(); 104 } 105 106 return [x, y]; 107 }; 108 109 return that; 110 } 111 112 var AxisExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 113 var that = new LinerBullet(size, color, frame, w, h, x, y, dir, speed); 89 114 90 115 that.dx = that.speed * that.deltaBaseX / 1.5; … … 105 130 }; 106 131 107 var XYExtendBullet = function(size, color, frame, x, y, dir, speed) {108 var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed);132 var XYExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 133 var that = new AxisExtendBullet(size, color, frame, w, h, x, y, dir, speed); 109 134 110 135 that.i = 1; … … 119 144 }; 120 145 121 var XExtendBullet = function(size, color, frame, x, y, dir, speed) {122 var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed);146 var XExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 147 var that = new AxisExtendBullet(size, color, frame, w, h, x, y, dir, speed); 123 148 124 149 that.i = 1; … … 133 158 }; 134 159 135 var YExtendBullet = function(size, color, frame, x, y, dir, speed) {136 var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed);160 var YExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 161 var that = new AxisExtendBullet(size, color, frame, w, h, x, y, dir, speed); 137 162 138 163 that.i = 1; … … 147 172 }; 148 173 149 var CurveBullet = function(size, color, frame, x, y, dir, speed) {150 var that = new Bullet(size, color, frame, x, y, dir, speed);174 var CurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 175 var that = new Bullet(size, color, frame, w, h, x, y, dir, speed); 151 176 152 177 that.delta = 1 / (that.speed * 100); 153 178 that.i = 1; 154 179 180 that.getDir = function() { 181 return this.dir; 182 }; 155 183 that.calcNext = function() { 156 var x = this.x + Math.cos(this.dir) * this.i; 157 var y = this.y + Math.sin(this.dir) * this.i; 184 var d = this.getDir(); 185 var x = this.x + Math.cos(d) * this.i; 186 var y = this.y + Math.sin(d) * this.i; 158 187 this.dir += (this.delta / this.i) * this.getSign(); 159 188 this.i += (this.delta / this.i); … … 164 193 }; 165 194 166 var LeftCurveBullet = function(size, color, frame, x, y, dir, speed) {167 var that = new CurveBullet(size, color, frame, x, y, dir, speed);195 var LeftCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 196 var that = new CurveBullet(size, color, frame, w, h, x, y, dir, speed); 168 197 169 198 that.getSign = function() { … … 174 203 }; 175 204 176 var RightCurveBullet = function(size, color, frame, x, y, dir, speed) {177 var that = new CurveBullet(size, color, frame, x, y, dir, speed);205 var RightCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 206 var that = new CurveBullet(size, color, frame, w, h, x, y, dir, speed); 178 207 179 208 that.getSign = function() { … … 184 213 }; 185 214 215 var XReflectLeftCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 216 var that = new LeftCurveBullet(size, color, frame, w, h, x, y, dir, speed); 217 var count = 0; 218 219 that.getDir = function() { 220 var x = this.x + Math.cos(this.dir) * this.i; 221 var y = this.y + Math.sin(this.dir) * this.i; 222 223 if ((0 >= x || x >= this.w) && count < 5) { 224 count++; 225 this.dir += (2 - this.dir) - (this.dir - 1); 226 } 227 228 return this.dir; 229 }; 230 231 return that; 232 }; 233 234 var XReflectRightCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 235 var that = new RightCurveBullet(size, color, frame, w, h, x, y, dir, speed); 236 var count = 0; 237 238 that.getDir = function() { 239 var x = this.x + Math.cos(this.dir) * this.i; 240 var y = this.y + Math.sin(this.dir) * this.i; 241 242 if ((0 >= x || x >= this.w) && count < 5) { 243 count++; 244 this.dir += (2 - this.dir) - (this.dir - 1); 245 } 246 247 return this.dir; 248 }; 249 250 return that; 251 }; 186 252 187 253 var EnemyBullets = [LinerBullet, 254 XReflectLinerBullet, 188 255 XYExtendBullet, 189 256 XExtendBullet, 190 257 YExtendBullet, 191 258 LeftCurveBullet, 192 RightCurveBullet]; 259 RightCurveBullet, 260 XReflectLeftCurveBullet, 261 XReflectRightCurveBullet]; -
pycodeshooter/trunk/shooter/system.js
r112 r114 36 36 */ 37 37 var DeathPiece = function(sizes, colors, x, y, dir, speed) { 38 var that = new LinerBullet(sizes[0], colors[0], null, x, y, dir, speed); 38 var that = new LinerBullet(sizes[0], colors[0], null, 39 System.screen.width, System.screen.height, 40 x, y, dir, speed); 39 41 40 42 var sizeIdx = -1; … … 112 114 var s = Math.ceil(Math.random() * 5); 113 115 System.backgroundObject.push( 114 new LinerBullet(size, color, null, x, 0, 0.5 * Math.PI, s)); 116 new LinerBullet(size, color, null, 117 System.screen.width, System.screen.height, 118 x, 0, 0.5 * Math.PI, s)); 115 119 } 116 120 -
pycodeshooter/trunk/shooter/trooper.js
r113 r114 214 214 this.addBullet = function(bulletType, size, color, frame, x, y, dir, speed) { 215 215 this.bullets.push( 216 new bulletType(size, color, frame, this. x + x, this.y + y, dir, speed));216 new bulletType(size, color, frame, this.w, this.h, this.x + x, this.y + y, dir, speed)); 217 217 }; 218 218
Note: See TracChangeset
for help on using the changeset viewer.