Changeset 106 for pycodeshooter/trunk/shooter/bullet.js
- Timestamp:
- 01/26/11 02:40:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/shooter/bullet.js
r105 r106 14 14 */ 15 15 16 var Bullet = function(size, color, x, y, dir, speed) {16 var Bullet = function(size, color, frame, x, y, dir, speed) { 17 17 this.size = size; 18 18 this.color = color; 19 this.frame = frame; 19 20 this.x = x; 20 21 this.y = y; … … 22 23 this.speed = speed; 23 24 25 this.getSize = function() { 26 return this.size; 27 }; 28 this.getColor = function() { 29 return this.color; 30 }; 31 this.next = function() { 32 var pos = this.calcNext(); 33 this.x = pos[0]; 34 this.y = pos[1]; 35 }; 36 this.vanished = function(width, height) { 37 return (width < this.x || height < this.y || this.x < 0 || this.y < 0); 38 }; 24 39 this.draw = function(ctx) { 40 if (this.frame) { 41 var pos = this.calcNext(); 42 var dir = Math.atan2(pos[0] - this.x, this.y - pos[1]); 43 44 ctx.save(); 45 46 if (this.frame.style == "rect") { 47 ctx.beginPath(); 48 ctx.strokeStyle = this.frame.color; 49 ctx.translate(this.x, this.y); 50 ctx.rotate(dir); 51 ctx.rect(-this.frame.width / 2, -this.frame.height / 2, 52 this.frame.width, this.frame.height); 53 ctx.stroke(); 54 ctx.closePath(); 55 } 56 57 ctx.restore(); 58 } 59 25 60 ctx.beginPath(); 26 61 ctx.fillStyle = this.getColor(); … … 29 64 ctx.closePath(); 30 65 }; 31 this.vanished = function(width, height) {32 return (width < this.x || height < this.y || this.x < 0 || this.y < 0);33 };34 this.getSize = function() {35 return this.size;36 };37 this.getColor = function() {38 return this.color;39 };40 66 }; 41 67 42 var LinerBullet = function(size, color, x, y, dir, speed) {43 var that = new Bullet(size, color, x, y, dir, speed);68 var LinerBullet = function(size, color, frame, x, y, dir, speed) { 69 var that = new Bullet(size, color, frame, x, y, dir, speed); 44 70 45 71 that.deltaBaseX = Math.cos(that.dir); 46 72 that.deltaBaseY = Math.sin(that.dir); 47 73 48 that.next = function() { 49 this.x += this.getDeltaX(); 50 this.y += this.getDeltaY(); 74 that.calcNext = function() { 75 return [this.x + this.getDeltaX(), this.y + this.getDeltaY()]; 51 76 }; 52 77 that.getDeltaX = function() { … … 60 85 }; 61 86 62 var AxisExtendBullet = function(size, color, x, y, dir, speed) {63 var that = new LinerBullet(size, color, x, y, dir, speed);87 var AxisExtendBullet = function(size, color, frame, x, y, dir, speed) { 88 var that = new LinerBullet(size, color, frame, x, y, dir, speed); 64 89 65 90 that.dx = that.speed * that.deltaBaseX / 1.5; … … 80 105 }; 81 106 82 var XYExtendBullet = function(size, color, x, y, dir, speed) {83 var that = new AxisExtendBullet(size, color, x, y, dir, speed);107 var XYExtendBullet = function(size, color, frame, x, y, dir, speed) { 108 var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 84 109 85 110 that.i = 1; … … 94 119 }; 95 120 96 var XExtendBullet = function(size, color, x, y, dir, speed) {97 var that = new AxisExtendBullet(size, color, x, y, dir, speed);121 var XExtendBullet = function(size, color, frame, x, y, dir, speed) { 122 var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 98 123 99 124 that.i = 1; … … 108 133 }; 109 134 110 var YExtendBullet = function(size, color, x, y, dir, speed) {111 var that = new AxisExtendBullet(size, color, x, y, dir, speed);135 var YExtendBullet = function(size, color, frame, x, y, dir, speed) { 136 var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 112 137 113 138 that.i = 1; … … 122 147 }; 123 148 124 var CurveBullet = function(size, color, x, y, dir, speed) {125 var that = new Bullet(size, color, x, y, dir, speed);149 var CurveBullet = function(size, color, frame, x, y, dir, speed) { 150 var that = new Bullet(size, color, frame, x, y, dir, speed); 126 151 127 152 that.delta = 1 / (that.speed * 100); 128 153 that.i = 1; 129 154 130 that. next = function() {131 this.x +=Math.cos(this.dir) * this.i;132 this.y +=Math.sin(this.dir) * this.i;155 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; 133 158 this.dir += (this.delta / this.i) * this.getSign(); 134 159 this.i += (this.delta / this.i); 160 return [x, y]; 135 161 }; 136 162 … … 138 164 }; 139 165 140 var LeftCurveBullet = function(size, color, x, y, dir, speed) {141 var that = new CurveBullet(size, color, x, y, dir, speed);166 var LeftCurveBullet = function(size, color, frame, x, y, dir, speed) { 167 var that = new CurveBullet(size, color, frame, x, y, dir, speed); 142 168 143 169 that.getSign = function() { … … 148 174 }; 149 175 150 var RightCurveBullet = function(size, color, x, y, dir, speed) {151 var that = new CurveBullet(size, color, x, y, dir, speed);176 var RightCurveBullet = function(size, color, frame, x, y, dir, speed) { 177 var that = new CurveBullet(size, color, frame, x, y, dir, speed); 152 178 153 179 that.getSign = function() {
Note: See TracChangeset
for help on using the changeset viewer.