Changeset 92 for pycodeshooter
- Timestamp:
- 01/12/11 18:39:31 (14 years ago)
- Location:
- pycodeshooter/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/index.html
r84 r92 25 25 "shotinterval": parseInt(document.getElementById("shotinterval").value), 26 26 "shotspeed": parseInt(document.getElementById("shotspeed").value), 27 "shotlevel": parseInt(document.getElementById("shotlevel").value) 27 "shotlevel": parseInt(document.getElementById("shotlevel").value), 28 "numbombs": parseInt(document.getElementById("numbombs").value) 28 29 }; 29 30 … … 110 111 èä¹ 111 112 æ§: <input type="text" value="15" size="3" id="hitpoint" /> 113 ãã æ°: <input type="text" value="2" size="3" id="numbombs" /> 112 114 <br /> 113 115 <canvas id="screen" width="320" height="480"></canvas> … … 138 140 <dt>â ã·ã§ãã:</dt> 139 141 <dd>z</dd> 142 <dt>â ãã :</dt> 143 <dd>a</dd> 140 144 <dt>â 移åé床é 141 145 延:</dt> -
pycodeshooter/trunk/shooter/action.js
r81 r92 21 21 const ACTION_DELAY = 32; 22 22 const SWITCH_BULLET = 1; 23 const SWITCH_BOMB = 2; 23 24 var currentAction = 0; 24 25 var currentSwitch = 0; … … 57 58 function getSwitchByCharCode(charCode) { 58 59 switch(charCode) { 60 case 97: // a 61 return SWITCH_BOMB; 59 62 case 99: // c 60 63 return SWITCH_BULLET; … … 106 109 this.index = 0; 107 110 unsetSwitch(SWITCH_BULLET); 111 } 112 if (isSetSwitch(SWITCH_BOMB)) { 113 trooper.addBomb(); 114 unsetSwitch(SWITCH_BOMB); 108 115 } 109 116 if (isInAction(ACTION_SHOT)) -
pycodeshooter/trunk/shooter/system.js
r84 r92 233 233 playerData.hitpoint, 234 234 playerData.speed, 235 playerData.numbombs, 235 236 [new LinerBarrage(YExtendBullet, 236 237 playerData.shotsize, … … 313 314 bossData.hitpoint, 314 315 Math.log(bossData.agility + 0.1) * 3, 316 0, 315 317 brrgs 316 318 ); -
pycodeshooter/trunk/shooter/trooper.js
r81 r92 14 14 */ 15 15 16 function touch(x1, y1, s1, x2, y2, s2) { 17 var dx = Math.pow(x2 - x1, 2); 18 var dy = Math.pow(y2 - y1, 2); 19 if (Math.sqrt(dx + dy) < s1 + s2) 20 return true; 21 return false; 22 } 23 24 var Bomb = function(x, y, w, h, size, speed, colors) { 25 this.x = x; 26 this.y = y; 27 this.w = w; 28 this.h = h; 29 this.size = size; 30 this.speed = speed; 31 this.colors = colors; 32 this.colIdx = 0; 33 34 this.update = function(enemy) { 35 this.size += this.speed; 36 37 // judge bullet 38 var delIdx = new Array(); 39 for (i = 0; i < enemy.bullets.length; i++) { 40 if (touch(this.x, this.y, this.size, 41 enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 42 delIdx.push(i); 43 } 44 enemy.delBullet(delIdx); 45 46 // judge enemy 47 if (touch(this.x, this.y, this.size, enemy.x, enemy.y, enemy.size) && enemy.life > 0) 48 enemy.life--; 49 }; 50 51 this.draw = function(ctx) { 52 ctx.beginPath(); 53 ctx.fillStyle = this.colors[this.colIdx]; 54 ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2.0, true); 55 ctx.fill(); 56 ctx.closePath(); 57 58 if (++this.colIdx >= this.colors.length) 59 this.colIdx = 0; 60 }; 61 62 this.vanished = function() { 63 if (this.size > this.w && this.size > this.h) 64 return true; 65 return false; 66 }; 67 }; 68 16 69 var Trooper = function(name, actList, size, color, x, y, w, h, 17 life, speed, barrages) {70 life, speed, numBombs, barrages) { 18 71 19 72 this.bullets = new Array(); 73 this.bomb = null; 20 74 this.name = name; 21 75 this.actList = actList; … … 28 82 this.life = life; 29 83 this.speed = speed; 84 this.numBombs = numBombs; 30 85 this.barrages = barrages; 31 86 … … 66 121 this.actList.update(this, enemy); 67 122 123 // update bomb 124 if (this.bomb) { 125 this.bomb.update(enemy); 126 if (this.bomb.vanished()) 127 this.bomb = null; 128 } 129 68 130 // update/delete my bullets 69 131 delIdx = new Array(); … … 79 141 delIdx = new Array(); 80 142 for (i = 0; i < enemy.bullets.length; i++) { 81 var dx = Math.pow(enemy.bullets[i].x - this.x, 2); 82 var dy = Math.pow(enemy.bullets[i].y - this.y, 2); 83 84 if (Math.sqrt(dx + dy) < this.size + enemy.bullets[i].size) 143 if (touch(this.x, this.y, this.size, 144 enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 85 145 delIdx.push(i); 86 146 } 87 enemy.delBullet(delIdx) 147 enemy.delBullet(delIdx); 88 148 89 149 // update life … … 93 153 94 154 this.draw = function(ctx) { 155 // draw bomb 156 if (this.bomb) 157 this.bomb.draw(ctx); 158 95 159 // draw trooper 96 160 ctx.beginPath(); … … 125 189 this.bullets = newBullets; 126 190 }; 191 192 this.addBomb = function() { 193 if (!this.bomb && this.numBombs > 0) { 194 this.bomb = new Bomb(this.x, this.y, this.w, this.h, this.size * 2, 10, 195 ["rgba(255,0,0,0.3)", "rgba(0,0,255,0.3)"]); 196 this.numBombs--; 197 } 198 }; 127 199 }
Note: See TracChangeset
for help on using the changeset viewer.