Ignore:
Timestamp:
01/22/12 19:47:14 (12 years ago)
Author:
atzm
Message:

add stage bgm rotation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/shooter/system.js

    r121 r122  
    207207} 
    208208 
     209function 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 
    209238function toggleSound(val) { 
    210239    for (var name in System.sound) 
     
    219248    if (System.sound[name]) 
    220249        System.sound[name].play(); 
     250} 
     251 
     252function pauseSound(name, stop) { 
     253    if (System.sound[name]) { 
     254        System.sound[name].pause(); 
     255        if (stop) 
     256            System.sound[name].currentTime = 0; 
     257    } 
    221258} 
    222259 
     
    331368    ); 
    332369 
     370    switchStageBgm(); 
     371 
    333372    // draw score 
    334373    var scoreNames = Object.keys(System.score).sort(); 
     
    422461    if (System.mainIntervalId) { 
    423462        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    } 
    434469 
    435470    var trooper = new Trooper( 
     
    474509                          -0.5)] 
    475510    ); 
    476     trooper.registerCallback("addBomb", function() {playSound("se_bomb")}); 
    477     trooper.registerCallback("damaged", function() {playSound("se_damage_player")}); 
     511    trooper.registerCallback("addBomb", function(){playSound("se_bomb")}); 
     512    trooper.registerCallback("damaged", function(){playSound("se_damage_player")}); 
    478513 
    479514    System.players.push(trooper); 
     
    483518    } 
    484519 
    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.