Changeset 108 for pycodeshooter
- Timestamp:
- 01/17/12 01:34:00 (13 years ago)
- Location:
- pycodeshooter/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/index.html
r106 r108 15 15 var titleIntervalId = 0; 16 16 17 function start (id, list) {17 function startGame() { 18 18 var msg = document.getElementById("message"); 19 19 var player = { … … 39 39 } 40 40 41 if (titleIntervalId) {42 clearInterval(titleIntervalId);43 titleIntervalId = 0;44 }45 46 41 document.onkeydown = function (ev) { setKeyDown(ev.keyCode); }; 47 42 document.onkeyup = function (ev) { setKeyUp(ev.keyCode); }; 48 43 document.onkeypress = function (ev) { setKeyPress(ev.charCode); }; 49 44 50 initGame(document.getElementById("screen"), msg, id, list[id],player);45 initGame(document.getElementById("screen"), msg, player); 51 46 } 52 47 53 48 function initControlPanel(list) { 54 49 var cp = document.getElementById("controlpanel"); 55 var sel = "<select id=\" bossSelection\">";50 var sel = "<select id=\"enemySelection\">"; 56 51 57 52 for (var id in list) { … … 61 56 cp.innerHTML = sel + "</select>"; 62 57 63 document.getElementById("bossSelection").onchange = function (ev) { 64 start(this[this.selectedIndex].value, list); 58 document.getElementById("enemySelection").onchange = function (ev) { 59 if (titleIntervalId) { 60 clearInterval(titleIntervalId); 61 titleIntervalId = 0; 62 startGame(); 63 } 64 addEnemy(list[this[this.selectedIndex].value]); 65 65 }; 66 66 } … … 71 71 var logoimg = document.getElementById("logoimg"); 72 72 73 var x = (screen.width - logoimg.width) / 2; 74 var y = -1 - logoimg.height; 75 var titlePos = screen.height / 2 - logoimg.height / 2; 73 var x = (screen.width - logoimg.width) / 2; 74 var y = -1 - logoimg.height; 75 var titlePos = screen.height / 2 - logoimg.height / 2; 76 76 77 titleIntervalId = setInterval(function() { 77 78 drawScreen(ctx, "source-over", "rgba(8,8,8,0.5)", screen.width, screen.height); … … 111 112 åå: <input type="text" value="Player" size="8" id="name" /> 112 113 èä¹ 113 æ§: <input type="text" value=" 15" size="3" id="hitpoint" />114 æ§: <input type="text" value="5" size="3" id="hitpoint" /> 114 115 ãã æ°: <input type="text" value="2" size="3" id="numbombs" /> 115 116 <br /> -
pycodeshooter/trunk/shooter/action.js
r103 r108 104 104 105 105 that.index = 0; 106 that.shot = function(trooper, enem y) {106 that.shot = function(trooper, enemies) { 107 107 if (isSetSwitch(SWITCH_BULLET)) { 108 108 if (++this.index >= trooper.barrages.length) … … 115 115 } 116 116 if (isInAction(ACTION_SHOT)) 117 trooper.barrages[this.index].update(trooper, enem y);117 trooper.barrages[this.index].update(trooper, enemies); 118 118 }; 119 119 … … 125 125 126 126 that.index = 0; 127 that.shot = function(trooper, enem y) {128 if (trooper.barrages[this.index].update(trooper, enem y))127 that.shot = function(trooper, enemies) { 128 if (trooper.barrages[this.index].update(trooper, enemies)) 129 129 this.index = Math.floor(Math.random() * trooper.barrages.length); 130 130 }; … … 140 140 141 141 that.i = 0; 142 that.shot = function(trooper, enem y) {143 if (trooper.barrages[this.index].update(trooper, enem y)) {142 that.shot = function(trooper, enemies) { 143 if (trooper.barrages[this.index].update(trooper, enemies)) { 144 144 if (++this.i > count) { 145 145 this.index++; … … 169 169 var Action = function(shot) { 170 170 this.shot = shot; 171 this.update = function(trooper, enem y) {171 this.update = function(trooper, enemies) { 172 172 if (trooper.isDead()) 173 173 return; 174 this.shot.shot(trooper, enem y);175 return this.move(trooper, enem y);176 }; 177 this.move = function(trooper, enem y) {174 this.shot.shot(trooper, enemies); 175 return this.move(trooper, enemies); 176 }; 177 this.move = function(trooper, enemies) { 178 178 return true; 179 179 }; … … 183 183 var that = new Action(shot); 184 184 185 that.move = function(trooper, enem y) {185 that.move = function(trooper, enemies) { 186 186 var x = 0; 187 187 var y = 0; … … 216 216 that.resolution = 0; 217 217 218 that.move = function(trooper, enem y) {218 that.move = function(trooper, enemies) { 219 219 if (this.count >= this.resolution) { 220 220 this.count = 0; 221 221 this.resolution = resolution / trooper.speed; 222 222 223 this.p0 = this.getPoint0(trooper, enem y);224 this.p1 = this.getPoint1(trooper, enem y);225 this.p2 = this.getPoint2(trooper, enem y);226 this.p3 = this.getPoint3(trooper, enem y);223 this.p0 = this.getPoint0(trooper, enemies); 224 this.p1 = this.getPoint1(trooper, enemies); 225 this.p2 = this.getPoint2(trooper, enemies); 226 this.p3 = this.getPoint3(trooper, enemies); 227 227 } 228 228 … … 254 254 var that = new BezierAction(shot, resolution); 255 255 256 that.getPoint0 = function(trooper, enem y) {256 that.getPoint0 = function(trooper, enemies) { 257 257 return [trooper.x, trooper.y]; 258 258 }; 259 that.getPoint1 = function(trooper, enem y) {259 that.getPoint1 = function(trooper, enemies) { 260 260 return [trooper.x - (trooper.speed * 10), 261 261 trooper.y + (trooper.speed * 10)]; 262 262 }; 263 that.getPoint2 = function(trooper, enem y) {263 that.getPoint2 = function(trooper, enemies) { 264 264 return [trooper.x + (trooper.speed * 10), 265 265 trooper.y + (trooper.speed * 10)]; 266 266 }; 267 that.getPoint3 = function(trooper, enem y) {267 that.getPoint3 = function(trooper, enemies) { 268 268 return [trooper.x, trooper.y]; 269 269 }; … … 275 275 var that = new BezierAction(shot, resolution); 276 276 277 that.getPoint0 = function(trooper, enem y) {277 that.getPoint0 = function(trooper, enemies) { 278 278 return [trooper.x, trooper.y]; 279 279 }; 280 that.getPoint1 = function(trooper, enem y) {280 that.getPoint1 = function(trooper, enemies) { 281 281 return [Math.floor(Math.random() * trooper.w), 282 282 Math.floor(Math.random() * trooper.h)]; 283 283 }; 284 that.getPoint2 = function(trooper, enem y) {284 that.getPoint2 = function(trooper, enemies) { 285 285 return [Math.floor(Math.random() * trooper.w), 286 286 Math.floor(Math.random() * trooper.h)]; 287 287 }; 288 that.getPoint3 = function(trooper, enem y) {288 that.getPoint3 = function(trooper, enemies) { 289 289 return [Math.floor(Math.random() * trooper.w), 290 290 Math.floor(Math.random() * trooper.h)]; … … 297 297 var that = new RandomAction(shot, resolution); 298 298 299 that.getPoint3 = function(trooper, enem y) {299 that.getPoint3 = function(trooper, enemies) { 300 300 return [Math.floor(Math.random() * trooper.w), trooper.y]; 301 301 }; … … 307 307 var that = new RandomAction(shot, resolution); 308 308 309 that.getPoint3 = function(trooper, enemy) { 310 return [enemy.x, Math.floor(Math.random() * trooper.h)]; 309 that.getPoint3 = function(trooper, enemies) { 310 var x = enemies.length ? enemies[0].x : 0; 311 return [x, Math.floor(Math.random() * trooper.h)]; 311 312 }; 312 313 … … 317 318 var that = new RandomAction(shot, resolution); 318 319 319 that.getPoint3 = function(trooper, enemy) { 320 return [enemy.x, trooper.y]; 320 that.getPoint3 = function(trooper, enemies) { 321 var x = enemies.length ? enemies[0].x : 0; 322 return [x, trooper.y]; 321 323 }; 322 324 … … 332 334 this.list = list; 333 335 this.index = 0; 334 this.update = function(trooper, enem y) {335 this.updateIdx(this.list[this.index].update(trooper, enem y),336 trooper, enem y);337 }; 338 this.updateIdx = function(end, trooper, enem y) {336 this.update = function(trooper, enemies) { 337 this.updateIdx(this.list[this.index].update(trooper, enemies), 338 trooper, enemies); 339 }; 340 this.updateIdx = function(end, trooper, enemies) { 339 341 this.index = 0; 340 342 }; … … 344 346 var that = new ActionList(list); 345 347 346 that.updateIdx = function(end, trooper, enem y) {348 that.updateIdx = function(end, trooper, enemies) { 347 349 if (end) 348 350 this.index = Math.floor(Math.random() * this.list.length); … … 359 361 360 362 that.i = 0; 361 that.updateIdx = function(end, trooper, enem y) {363 that.updateIdx = function(end, trooper, enemies) { 362 364 if (end) { 363 365 if (++this.i > count) { … … 385 387 386 388 that.life = 0; 387 that.updateIdx = function(end, trooper, enem y) {389 that.updateIdx = function(end, trooper, enemies) { 388 390 if (!this.life) 389 391 this.life = trooper.life; … … 402 404 403 405 that.life = 0; 404 that.updateIdx = function(end, trooper, enem y) {406 that.updateIdx = function(end, trooper, enemies) { 405 407 if (!this.life) 406 408 this.life = trooper.life; -
pycodeshooter/trunk/shooter/barrage.js
r106 r108 25 25 26 26 this.aim = function(trooper, enemy) { 27 if (!trooper || !enemy) 28 return 0.5 * Math.PI; 27 29 var dx = enemy.x - trooper.x; 28 30 var dy = enemy.y - trooper.y; … … 34 36 return this.aim(trooper, enemy) / Math.PI; 35 37 }; 36 this.update = function(trooper, enem y) {38 this.update = function(trooper, enemies) { 37 39 return false; 38 40 }; … … 49 51 50 52 that.state = 0; 51 that.update = function(trooper, enem y) {53 that.update = function(trooper, enemies) { 52 54 if (++this.state < this.interval) 53 55 return false; 54 56 55 var dir = this.angle(trooper, enem y);57 var dir = this.angle(trooper, enemies[0]); 56 58 57 59 trooper.addBullet(this.bullet, this.size, this.color, … … 91 93 92 94 that.state = 0; 93 that.update = function(trooper, enem y) {95 that.update = function(trooper, enemies) { 94 96 if (++this.state < this.interval) 95 97 return false; 96 98 97 var angle = this.angle(trooper, enem y) - (this.delta * (this.way - 1) / 2);99 var angle = this.angle(trooper, enemies[0]) - (this.delta * (this.way - 1) / 2); 98 100 99 101 for (var i = 0; i < this.way; i++) { … … 135 137 that.curAngle = null; 136 138 137 that.update = function(trooper, enem y) {139 that.update = function(trooper, enemies) { 138 140 if (++this.state < this.interval) 139 141 return false; 140 142 141 143 if (this.curAngle == null) 142 this.curAngle = this.angle(trooper, enem y) -144 this.curAngle = this.angle(trooper, enemies[0]) - 143 145 this.delta * (this.way - 1) / 2; 144 146 … … 268 270 }; 269 271 270 this.update = function(trooper, enem y) {272 this.update = function(trooper, enemies) { 271 273 for (var i = 0; i < this.brrg.length; i++) { 272 274 if (!this.flag[i]) 273 this.flag[i] = this.brrg[i].update(trooper, enem y);275 this.flag[i] = this.brrg[i].update(trooper, enemies); 274 276 } 275 277 for (var i = 0; i < this.flag.length; i++) { -
pycodeshooter/trunk/shooter/system.js
r106 r108 22 22 }, 23 23 "message": null, 24 " boss": null,25 "player ": null,24 "enemies": new Array(), 25 "players": new Array(), 26 26 "backgroundObject": new Array(), 27 27 "deathPieces": new Array(), 28 "gameOver": false,29 28 "mainIntervalId": 0 30 29 }; … … 32 31 33 32 /* 34 * Tiun Tiun 33 * Tiun Tiun Utilities 35 34 */ 36 35 var DeathPiece = function(sizes, colors, x, y, dir, speed) { … … 55 54 }; 56 55 56 function addDeathPieces(x, y, sizes, colors, speed, way) { 57 if (way % 2) 58 way++; 59 60 var pieces = new Array(); 61 var angle = 0; 62 var delta = 2 / way; 63 64 for(var i = 0; i < way; i++) { 65 pieces.push(new DeathPiece(sizes, colors, x, y, angle * Math.PI, speed)); 66 angle += delta; 67 } 68 69 System.deathPieces.push(pieces); 70 } 71 72 function updateDeathPieces(ctx, width, height) { 73 var newObjs = new Array(); 74 75 for (var i = 0; i < System.deathPieces.length; i++) { 76 var pieces = System.deathPieces[i]; 77 var newPieces = new Array(); 78 79 for (var k = 0; k < pieces.length; k++) { 80 pieces[k].next(); 81 pieces[k].draw(ctx); 82 if (!pieces[k].vanished(width, height)) 83 newPieces.push(pieces[k]); 84 } 85 86 if (newPieces.length) 87 newObjs.push(newPieces); 88 } 89 90 System.deathPieces = newObjs; 91 } 92 57 93 58 94 /* 59 95 * Utility Functions 60 96 */ 97 function setMessage(elem, msg) { 98 if (elem) 99 elem.innerHTML = msg; 100 } 101 102 function addMessage(elem, msg) { 103 if (elem) 104 elem.innerHTML += msg; 105 } 106 61 107 function updateBackground(ctx, width, height, size, color, max) { 62 108 if (System.backgroundObject.length < max) { … … 68 114 69 115 var newObjs = new Array(); 116 70 117 for (var i = 0; i < System.backgroundObject.length; i++) { 71 118 System.backgroundObject[i].next(); … … 74 121 newObjs.push(System.backgroundObject[i]); 75 122 } 123 76 124 System.backgroundObject = newObjs; 77 }78 79 function updateDeathPieces(ctx, width, height, x, y, sizes, colors, speed, way) {80 if (System.deathPieces.length <= 0) {81 if (way % 2)82 way++;83 84 var angle = 0;85 var delta = 2 / way;86 87 for(i = 0; i < way; i++) {88 System.deathPieces.push(89 new DeathPiece(sizes, colors, x, y, angle * Math.PI, speed));90 angle += delta;91 }92 }93 94 var newObjs = new Array();95 for (var i = 0; i < System.deathPieces.length; i++) {96 System.deathPieces[i].next();97 System.deathPieces[i].draw(ctx);98 if (!System.deathPieces[i].vanished(width, height))99 newObjs.push(System.deathPieces[i]);100 }101 System.deathPieces = newObjs;102 103 return !System.deathPieces.length;104 125 } 105 126 … … 151 172 } 152 173 153 function updateTrooper(trooper, enemy) { 154 if (System.gameOver) { 155 trooper.clearBullet(); 156 enemy.clearBullet(); 157 158 drawString( 159 System.screen.ctx, "source-over", 160 "GAME OVER", 161 System.screen.width / 2, 162 System.screen.height / 2, 163 "#ACF", "24pt monospace", "center" 164 ); 165 } 166 else if (trooper.isDead()) { 167 trooper.clearBullet(); 168 enemy.clearBullet(); 169 170 System.gameOver = updateDeathPieces( 171 System.screen.ctx, 172 System.screen.width, 173 System.screen.height, 174 trooper.x, 175 trooper.y, 176 [6, 8, 10], ["#55F", "#AAF"], 3, 8 177 ); 178 } 179 else if (enemy.isDead()) { 180 trooper.draw(System.screen.ctx); 181 } 182 else { 183 trooper.update(enemy); 184 trooper.draw(System.screen.ctx); 185 } 186 } 187 188 function setMessage(elem, msg) { 189 if (elem) 190 elem.innerHTML = msg; 191 } 192 193 function addMessage(elem, msg) { 194 if (elem) 195 elem.innerHTML += msg; 174 function updateTrooper(trooper, enemyKey) { 175 trooper.update(System[enemyKey]); 176 177 var aliveEnemies = new Array(); 178 for (var i = 0; i < System[enemyKey].length; i++) { 179 var enemy = System[enemyKey][i]; 180 181 if (enemy.isDead()) { 182 addDeathPieces( 183 enemy.x, enemy.y, 184 [6, 8, 10], ["#55F", "#AAF"], 3, 8 185 ); 186 } 187 else { 188 aliveEnemies.push(enemy); 189 } 190 } 191 System[enemyKey] = aliveEnemies; 192 193 trooper.draw(System.screen.ctx); 194 } 195 196 function addEnemy(enemyData) { 197 var actList = EnemyActionLists[enemyData.mtime % EnemyActionLists.length]; 198 var shot = EnemyShots[enemyData.hitpoint % EnemyShots.length]; 199 var numAct = enemyData.agility % (EnemyActions.length - 1) + 1; 200 var numBlt = enemyData.skills.length % (EnemyBullets.length - 1) + 1; 201 var numBrrg = enemyData.skills.length % (EnemyBarrages.length - 1) + 1; 202 var acts = new Array(); 203 var brrgs = new Array(); 204 205 var bulletWay = Math.ceil(enemyData.concentration / 10); 206 var bulletInterval = Math.round(50 * 1 / Math.log(enemyData.skillpoint + 0.1)); 207 var bulletSize = Math.round(Math.log(enemyData.luck + 1)); 208 var bulletFrameWidth = (bulletSize + 5) * 2; 209 var bulletFrameHeight = (bulletSize + 5) * 4; 210 var bulletSpeed = enemyData.strength / 15; 211 212 bulletSpeed = Math.log(bulletSpeed < 1.5 ? 1.5 : bulletSpeed); 213 214 for (var i = 0; i < numAct; i++) { 215 var idx = (enemyData.agility + i) % EnemyActions.length; 216 acts.push(new EnemyActions[idx](new shot())); 217 } 218 219 for (var i = 0; i < numBrrg; i++) { 220 var idx = (enemyData.skillpoint + i * (enemyData.skills.length + 1)) % EnemyBarrages.length; 221 var brrgCls = EnemyBarrages[idx]; 222 223 for (var k = 0; k < numBlt; k++) { 224 var iidx = (enemyData.skills.length + i + k) % EnemyBullets.length; 225 brrgs.push( 226 new brrgCls( 227 EnemyBullets[iidx], 228 bulletSize, 229 "#FF3", 230 {"style": "rect", "color": "rgba(128,32,32,0.5)", 231 "width": bulletFrameWidth, "height": bulletFrameHeight}, 232 bulletInterval, 233 bulletSpeed, 234 bulletWay 235 ) 236 ); 237 } 238 } 239 240 var size = Math.ceil((System.screen.width / 2) * (1 / enemyData.defense)); 241 var enemy = new Trooper( 242 enemyData.name, 243 new actList(acts), 244 size, 245 size, 246 "#F33", 247 "#F33", 248 System.screen.width / 2, 249 System.screen.height / 7, 250 System.screen.width, 251 System.screen.height, 252 enemyData.hitpoint, 253 Math.log(enemyData.agility + 0.1) * 3, 254 0, 255 ["rgba(255,0,0,0.3)", "rgba(0,0,255,0.3)"], 256 brrgs 257 ); 258 259 System.enemies.push(enemy); 196 260 } 197 261 … … 219 283 220 284 // update/draw troopers 221 updateTrooper(System.player, System.boss); 222 updateTrooper(System.boss, System.player); 223 224 // draw player name/life 225 drawString( 226 System.screen.ctx, 227 "source-over", 228 System.player.name, 229 10, System.screen.height - 25, 230 "#ACF", "9pt monospace", "left" 231 ); 232 drawLifeGauge( 233 System.screen.ctx, 234 "lighter", 235 System.player, 236 10, 237 System.screen.height - 20, 238 System.screen.width 239 ); 240 241 // draw boss name/life 242 drawString( 243 System.screen.ctx, 244 "source-over", 245 System.boss.name, 10, 35, 246 "#FCA", "9pt monospace", "left" 247 ); 248 drawLifeGauge( 249 System.screen.ctx, 250 "lighter", 251 System.boss, 252 10, 253 10, 254 System.screen.width 255 ); 285 for (var i = 0; i < System.players.length; i++) { 286 var player = System.players[i]; 287 288 updateTrooper(player, "enemies"); 289 290 drawLifeGauge( 291 System.screen.ctx, 292 "lighter", 293 player, 294 10, 295 (System.screen.height - 20) - (i * 33), 296 System.screen.width 297 ); 298 299 drawString( 300 System.screen.ctx, 301 "source-over", 302 player.name, 303 10, 304 (System.screen.height - 23) - (i * 33), 305 "#ACF", "9pt monospace", "left" 306 ); 307 } 308 309 // update/draw enemies 310 for (var i = 0; i < System.enemies.length; i++) { 311 var enemy = System.enemies[i]; 312 313 updateTrooper(enemy, "players"); 314 315 drawLifeGauge( 316 System.screen.ctx, 317 "lighter", 318 enemy, 10, i * 33 + 10, 319 System.screen.width 320 ); 321 322 drawString( 323 System.screen.ctx, 324 "source-over", 325 enemy.name, 10, i * 33 + 33, 326 "#FCA", "9pt monospace", "left" 327 ); 328 } 329 330 updateDeathPieces(System.screen.ctx, 331 System.screen.width, 332 System.screen.height); 333 334 if (!System.players.length) { 335 drawString( 336 System.screen.ctx, "source-over", 337 "GAME OVER", 338 System.screen.width / 2, 339 System.screen.height / 2, 340 "#ACF", "24pt monospace", "center" 341 ); 342 } 256 343 } 257 344 … … 260 347 * Initializer 261 348 */ 262 function initGame(canvas, msg, bossId, bossData,playerData) {349 function initGame(canvas, msg, playerData) { 263 350 System.screen.canvas = canvas; 264 351 System.message = msg; … … 283 370 ); 284 371 285 System.player =new Trooper(372 System.players.push(new Trooper( 286 373 playerData.name, 287 374 new ActionList([new ManualAction(new ManualShot())]), … … 322 409 playerData.shotlevel + 2, 323 410 -0.5)] 324 ); 325 326 var actList = EnemyActionLists[bossData.mtime % EnemyActionLists.length]; 327 var shot = EnemyShots[bossData.hitpoint % EnemyShots.length]; 328 var numAct = bossData.agility % (EnemyActions.length - 1) + 1; 329 var numBlt = bossData.skills.length % (EnemyBullets.length - 1) + 1; 330 var numBrrg = bossData.skills.length % (EnemyBarrages.length - 1) + 1; 331 var acts = new Array(); 332 var brrgs = new Array(); 333 334 var bulletWay = Math.ceil(bossData.concentration / 10); 335 var bulletInterval = Math.round(50 * 1 / Math.log(bossData.skillpoint + 0.1)); 336 var bulletSize = Math.round(Math.log(bossData.luck + 1)); 337 var bulletFrameWidth = (bulletSize + 5) * 2; 338 var bulletFrameHeight = (bulletSize + 5) * 4; 339 var bulletSpeed = bossData.strength / 15; 340 bulletSpeed = Math.log(bulletSpeed < 1.5 ? 1.5 : bulletSpeed); 341 342 setMessage(System.message, ""); 343 addMessage(System.message, " bulletWay:" + String(bulletWay) + "<br>"); 344 addMessage(System.message, " bulletInterval:" + String(bulletInterval) + "<br>"); 345 addMessage(System.message, " bulletSize:" + String(bulletSize) + "<br>"); 346 addMessage(System.message, " bulletSpeed:" + String(bulletSpeed) + "<br>"); 347 348 addMessage(System.message, "ActionsIdx:"); 349 350 for (var i = 0; i < numAct; i++) { 351 var idx = (bossData.agility + i) % EnemyActions.length; 352 acts.push(new EnemyActions[idx](new shot())); 353 354 addMessage(System.message, String(idx) + "(" + 355 String(bossData.hitpoint % EnemyShots.length) + "),"); 356 } 357 358 addMessage(System.message, "<br>"); 359 360 for (var i = 0; i < numBrrg; i++) { 361 var idx = (bossData.skillpoint + i * (bossData.skills.length + 1)) % EnemyBarrages.length; 362 var brrgCls = EnemyBarrages[idx]; 363 364 addMessage(System.message, 365 "BarragesIdx:" + String(idx) + " / BulletsIdx:"); 366 367 for (var k = 0; k < numBlt; k++) { 368 var iidx = (bossData.skills.length + i + k) % EnemyBullets.length; 369 brrgs.push( 370 new brrgCls( 371 EnemyBullets[iidx], 372 bulletSize, 373 "#FF3", 374 {"style": "rect", "color": "rgba(128,32,32,0.5)", 375 "width": bulletFrameWidth, "height": bulletFrameHeight}, 376 bulletInterval, 377 bulletSpeed, 378 bulletWay 379 ) 380 ); 381 382 addMessage(System.message, String(iidx) + ","); 383 } 384 385 addMessage(System.message, "<br>"); 386 } 387 388 var size = Math.ceil((System.screen.width / 2) * (1 / bossData.defense)); 389 size = size < playerData.size ? playerData.size : size; 390 System.boss = new Trooper( 391 bossData.name, 392 new actList(acts), 393 size, 394 size, 395 "#F33", 396 "#F33", 397 System.screen.width / 2, 398 System.screen.height / 7, 399 System.screen.width, 400 System.screen.height, 401 bossData.hitpoint, 402 Math.log(bossData.agility + 0.1) * 3, 403 0, 404 ["rgba(255,0,0,0.3)", "rgba(0,0,255,0.3)"], 405 brrgs 406 ); 411 )); 407 412 408 413 System.backgroundObject = new Array(); -
pycodeshooter/trunk/shooter/trooper.js
r106 r108 32 32 this.colIdx = 0; 33 33 34 this.update = function(enem y) {34 this.update = function(enemies) { 35 35 this.size += this.speed; 36 36 37 // judge bullet 38 var delIdx = new Array(); 39 for (var 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--; 37 for (var ei = 0; ei < enemies.length; ei++) { 38 var enemy = enemies[ei]; 39 var delIdx = new Array(); 40 41 // judge bullet 42 for (var i = 0; i < enemy.bullets.length; i++) { 43 if (touch(this.x, this.y, this.size, 44 enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 45 delIdx.push(i); 46 } 47 enemy.delBullet(delIdx); 48 49 // judge enemy 50 if (touch(this.x, this.y, this.size, enemy.x, enemy.y, enemy.size) && enemy.life > 0) 51 enemy.life--; 52 } 49 53 }; 50 54 … … 121 125 }; 122 126 123 this.update = function(enemy) { 124 var delIdx = null; 125 127 this.update = function(enemies) { 126 128 // update my action 127 this.actList.update(this, enem y);129 this.actList.update(this, enemies); 128 130 129 131 // update bomb 130 132 if (this.bomb) { 131 this.bomb.update(enem y);133 this.bomb.update(enemies); 132 134 if (this.bomb.vanished()) 133 135 this.bomb = null; … … 135 137 136 138 // update/delete my bullets 137 delIdx = new Array(); 138 for (var i = 0; i < this.bullets.length; i++) { 139 this.bullets[i].next(); 140 141 if (this.bullets[i].vanished()) 142 delIdx.push(i); 143 } 144 this.delBullet(delIdx); 145 146 // judge/delete hit bullets 147 delIdx = new Array(); 148 for (var i = 0; i < enemy.bullets.length; i++) { 149 if (touch(this.x, this.y, this.hitSize, 150 enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 151 delIdx.push(i); 152 } 153 enemy.delBullet(delIdx); 154 155 // update life 156 if (delIdx.length > 0 && this.life > 0) 157 this.life--; 139 { 140 var delIdx = new Array(); 141 for (var i = 0; i < this.bullets.length; i++) { 142 this.bullets[i].next(); 143 144 if (this.bullets[i].vanished()) 145 delIdx.push(i); 146 } 147 this.delBullet(delIdx); 148 } 149 150 // update/delete enemies' bullets 151 { 152 var hit = false; 153 154 for (var ei = 0; ei < enemies.length; ei++) { 155 var enemy = enemies[ei]; 156 var delIdx = new Array(); 157 158 // judge/delete hit bullets 159 for (var i = 0; i < enemy.bullets.length; i++) { 160 if (touch(this.x, this.y, this.hitSize, 161 enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 162 delIdx.push(i); 163 } 164 165 enemy.delBullet(delIdx); 166 167 if (delIdx.length > 0) 168 hit = true; 169 } 170 171 // update my life 172 if (hit && this.life > 0) 173 this.life--; 174 } 158 175 }; 159 176
Note: See TracChangeset
for help on using the changeset viewer.