Changeset 122 for pycodeshooter/trunk/shooter
- Timestamp:
- 01/22/12 19:47:14 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/shooter/system.js
r121 r122 207 207 } 208 208 209 function switchStageBgm() { 210 var sum = 0; 211 var stage = 1; 212 var stages = new Array(); 213 var base = 50000; 214 var score = 0; 215 var scores = Object.keys(System.score); 216 217 for (var i = 0; i < scores.length; i++) { 218 sum += System.score[scores[i]]; 219 } 220 score = Math.round(sum / scores.length); 221 222 for (var name in System.sound) { 223 if (!name.match(/^bgm_stage/)) continue; 224 stages.push(name); 225 } 226 stage = Math.floor((score % (stages.length * base)) / base) + 1; 227 228 for (var i = 0; i < stages.length; i++) { 229 if (("bgm_stage" + stage) == stages[i]) { 230 playSound(stages[i]); 231 } 232 else { 233 pauseSound(stages[i], true); 234 } 235 } 236 } 237 209 238 function toggleSound(val) { 210 239 for (var name in System.sound) … … 219 248 if (System.sound[name]) 220 249 System.sound[name].play(); 250 } 251 252 function pauseSound(name, stop) { 253 if (System.sound[name]) { 254 System.sound[name].pause(); 255 if (stop) 256 System.sound[name].currentTime = 0; 257 } 221 258 } 222 259 … … 331 368 ); 332 369 370 switchStageBgm(); 371 333 372 // draw score 334 373 var scoreNames = Object.keys(System.score).sort(); … … 422 461 if (System.mainIntervalId) { 423 462 clearInterval(System.mainIntervalId); 424 System.mainIntervalId = 0; 425 } 426 427 drawScreen( 428 System.screen.ctx, 429 "source-over", 430 "rgba(0,0,0,1)", 431 System.screen.width, 432 System.screen.height 433 ); 463 System.mainIntervalId = 0; 464 System.players = new Array(); 465 System.enemies = new Array(); 466 System.backgroundObject = new Array(); 467 System.deathPieces = new Array(); 468 } 434 469 435 470 var trooper = new Trooper( … … 474 509 -0.5)] 475 510 ); 476 trooper.registerCallback("addBomb", function() 477 trooper.registerCallback("damaged", function() 511 trooper.registerCallback("addBomb", function(){playSound("se_bomb")}); 512 trooper.registerCallback("damaged", function(){playSound("se_damage_player")}); 478 513 479 514 System.players.push(trooper); … … 483 518 } 484 519 485 System.backgroundObject = new Array(); 486 System.mainIntervalId = setInterval(mainLoop, 20); 487 } 520 drawScreen( 521 System.screen.ctx, 522 "source-over", 523 "rgba(0,0,0,1)", 524 System.screen.width, 525 System.screen.height 526 ); 527 528 document.onkeydown = function (ev) { setKeyDown(ev.keyCode); }; 529 document.onkeyup = function (ev) { setKeyUp(ev.keyCode); }; 530 document.onkeypress = function (ev) { setKeyPress(ev.charCode); }; 531 532 System.mainIntervalId = setInterval(mainLoop, 20); 533 }
Note: See TracChangeset
for help on using the changeset viewer.