Changeset 122 for pycodeshooter/trunk
- Timestamp:
- 01/22/12 19:47:14 (13 years ago)
- Location:
- pycodeshooter/trunk
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/index.html
r119 r122 14 14 <script type="text/javascript"> 15 15 window.onload = function () { 16 // load enemies 16 17 var req = new XMLHttpRequest(); 17 18 req.open("GET", document.getElementById("api").value, false); … … 26 27 var enemyList = JSON.parse(req.responseText).result; 27 28 29 // system message clear 30 setMessage(msg, "<br />"); 31 32 // register sounds to system 28 33 registerSound("bgm_title", document.getElementById("bgm_title")); 29 34 registerSound("bgm_stage1", document.getElementById("bgm_stage1")); 35 registerSound("bgm_stage2", document.getElementById("bgm_stage2")); 36 registerSound("bgm_stage3", document.getElementById("bgm_stage3")); 37 registerSound("bgm_stage4", document.getElementById("bgm_stage4")); 38 registerSound("bgm_stage5", document.getElementById("bgm_stage5")); 30 39 registerSound("se_start", document.getElementById("se_start")); 31 40 registerSound("se_encounter", document.getElementById("se_encounter")); … … 34 43 registerSound("se_bomb", document.getElementById("se_bomb")); 35 44 registerSound("se_destroy", document.getElementById("se_destroy")); 36 setMessage(msg, "<br />"); 37 38 // sound on/off 45 46 // sound on/off (default off) 39 47 soundCheck.onclick = function() { 40 48 toggleSound(soundCheck.checked); 41 49 }; 42 50 soundCheck.click(); 51 playSound("bgm_title"); 43 52 44 53 // title screen set 45 var titlebgm = document.getElementById("bgm_title");46 54 var logoimg = document.getElementById("logoimg"); 47 55 var x = (screen.width - logoimg.width) / 2; … … 64 72 }, 20); 65 73 66 playSound("bgm_title");67 68 74 // start game 69 75 screen.onclick = function() { … … 72 78 } 73 79 74 titlebgm.pause(); 80 clearInterval(titleIntervalId); 81 titleIntervalId = 0; 82 83 pauseSound("bgm_title", true) 75 84 playSound("se_start"); 76 85 77 86 setTimeout(function() { 78 clearInterval(titleIntervalId);79 titleIntervalId = 0;80 81 87 var player = { 82 88 "name": document.getElementById("name").value, … … 109 115 } 110 116 111 document.onkeydown = function (ev) { setKeyDown(ev.keyCode); };112 document.onkeyup = function (ev) { setKeyUp(ev.keyCode); };113 document.onkeypress = function (ev) { setKeyPress(ev.charCode); };114 115 playSound("bgm_stage1");116 117 initGame(document.getElementById("screen"), msg, player); 117 118 119 // auto enemy encounter 118 120 var enemyIntervalId = setInterval(function() { 119 121 if (numEnemies() < parseInt(document.getElementById("numenemies").value)) { … … 124 126 } 125 127 }, 1500); 126 }, 1 400);128 }, 1500); 127 129 }; 128 130 }; … … 166 168 <audio src="sounds/bgm_sht_a01.mp3", id="bgm_title" loop="true" preload="auto" /> 167 169 <audio src="sounds/bgm_sht_a02.mp3", id="bgm_stage1" loop="true" preload="auto" /> 170 <audio src="sounds/bgm_sht_a03.mp3", id="bgm_stage2" loop="true" preload="auto" /> 171 <audio src="sounds/bgm_sht_a04.mp3", id="bgm_stage3" loop="true" preload="auto" /> 172 <audio src="sounds/bgm_sht_a05.mp3", id="bgm_stage4" loop="true" preload="auto" /> 173 <audio src="sounds/bgm_sht_a06.mp3", id="bgm_stage5" loop="true" preload="auto" /> 168 174 <audio src="sounds/se_coinin_1.mp3", id="se_start" preload="auto" /> 169 175 <audio src="sounds/se_denshion_1.mp3", id="se_encounter" preload="auto" /> -
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.