Ignore:
Timestamp:
01/22/12 03:41:27 (12 years ago)
Author:
atzm
Message:

bgm/se support

Location:
pycodeshooter/trunk/shooter
Files:
2 edited

Legend:

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

    r117 r119  
    2121        "height": 0 
    2222    }, 
     23    "sound":            {}, 
    2324    "message":          null, 
    2425    "enemyImages":      new Array(), 
     
    186187 
    187188        if (enemy.isDead()) { 
     189            playSound("se_destroy"); 
     190 
    188191            addDeathPieces( 
    189192                enemy.x, enemy.y, 
     
    202205 
    203206    trooper.draw(System.screen.ctx); 
     207} 
     208 
     209function toggleSound(val) { 
     210    for (var name in System.sound) 
     211        System.sound[name].muted = !val; 
     212} 
     213 
     214function registerSound(name, audio) { 
     215    System.sound[name] = audio; 
     216} 
     217 
     218function playSound(name) { 
     219    if (System.sound[name]) 
     220        System.sound[name].play(); 
    204221} 
    205222 
     
    287304        brrgs 
    288305    ); 
     306    enemy.registerCallback("damaged", function() {playSound("se_damage_enemy")}); 
    289307 
    290308    System.enemies.push(enemy); 
     
    415433    ); 
    416434 
    417     System.players.push(new Trooper( 
     435    var trooper = new Trooper( 
    418436        playerData.name, 
    419437        new ActionList([new ManualAction(new ManualShot())]), 
     
    455473                          playerData.shotlevel + 2, 
    456474                          -0.5)] 
    457     )); 
     475    ); 
     476    trooper.registerCallback("addBomb", function() {playSound("se_bomb")}); 
     477    trooper.registerCallback("damaged", function() {playSound("se_damage_player")}); 
     478 
     479    System.players.push(trooper); 
    458480 
    459481    for (var i = 0; i < System.players.length; i++) { 
  • pycodeshooter/trunk/shooter/trooper.js

    r114 r119  
    7575 
    7676    this.bullets    = new Array(); 
     77    this.callbacks  = {}; 
    7778    this.bomb       = null; 
    7879    this.name       = name; 
     
    172173 
    173174            // update my life 
    174             if (hit && this.life > 0) 
     175            if (hit && this.life > 0) { 
    175176                this.life--; 
     177 
     178                if (this.callbacks["damaged"]) 
     179                    this.callbacks["damaged"](this); 
     180            } 
    176181        } 
    177182    }; 
     
    215220        this.bullets.push( 
    216221            new bulletType(size, color, frame, this.w, this.h, this.x + x, this.y + y, dir, speed)); 
     222 
     223        if (this.callbacks["addBullet"]) 
     224            this.callbacks["addBullet"](this); 
    217225    }; 
    218226 
     
    242250                                 this.size * 2, 10, this.bombColors); 
    243251            this.numBombs--; 
    244         } 
     252 
     253            if (this.callbacks["addBomb"]) 
     254                this.callbacks["addBomb"](this); 
     255        } 
     256    }; 
     257 
     258    this.registerCallback = function(name, callback) { 
     259        this.callbacks[name] = callback; 
    245260    }; 
    246261} 
Note: See TracChangeset for help on using the changeset viewer.