Changeset 130


Ignore:
Timestamp:
05/02/12 20:56:24 (12 years ago)
Author:
atzm
Message:
  • add power-up items
Location:
pycodeshooter/trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/index.html

    r129 r130  
    3434 
    3535        // register sounds to system 
    36         registerSound("bgm_title", document.getElementById("bgm_title")); 
    37         registerSound("bgm_stage1", document.getElementById("bgm_stage1")); 
    38         registerSound("bgm_stage2", document.getElementById("bgm_stage2")); 
    39         registerSound("bgm_stage3", document.getElementById("bgm_stage3")); 
    40         registerSound("bgm_stage4", document.getElementById("bgm_stage4")); 
    41         registerSound("bgm_stage5", document.getElementById("bgm_stage5")); 
    42         registerSound("se_start", document.getElementById("se_start")); 
    43         registerSound("se_encounter", document.getElementById("se_encounter")); 
    44         registerSound("se_damage", document.getElementById("se_damage")); 
    45         registerSound("se_bomb", document.getElementById("se_bomb")); 
    46         registerSound("se_destroy", document.getElementById("se_destroy")); 
     36        var audios = document.getElementsByTagName("audio"); 
     37        for (var i = 0; i < audios.length; i++) 
     38            registerSound(audios[i].id, audios[i]); 
    4739 
    4840        // sound on/off (default off) 
     
    157149                <input type="hidden" value="5"  id="shotspeed" /> 
    158150                <input type="hidden" value="5"  id="shotinterval" /> 
    159                 <input type="hidden" value="3"  id="shotlevel" /> 
     151                <input type="hidden" value="1"  id="shotlevel" /> 
    160152                <input type="hidden" value="/etc/pycodebattler/?mode=json" id="api" /> 
    161153                <img src="images/logo.png" style="visibility: hidden;" id="logoimg" /> 
     
    172164                <audio src="sounds/se_zusyunzusyun.ogg", id="se_bomb" preload="auto" /> 
    173165                <audio src="sounds/se_zugan.ogg", id="se_destroy" preload="auto" /> 
     166                <audio src="sounds/se_breakout_2.ogg", id="se_item_score" preload="auto" /> 
     167                <audio src="sounds/se_coinget_1.ogg", id="se_item_shot" preload="auto" /> 
     168                <audio src="sounds/se_coinget_1.ogg", id="se_item_bomb" preload="auto" /> 
     169                <audio src="sounds/se_byuin.ogg", id="se_item_life" preload="auto" /> 
    174170 
    175171                <img src="images/ma1s.gif"  style="visibility: hidden;" id="p_img0"  /> 
     
    240236        <p>TODO</p> 
    241237        <ul style="font-size: small;"> 
     238          <li>実裠
     239がやっ぀けすぎるので曞き盎す</li> 
    242240          <li>動䜜パタヌンを増やす</li> 
    243241          <li>匟幕パタヌンを増やす</li> 
    244           <li>パワヌアップアむテム</li> 
    245242          <li>動䜜を凝る</li> 
    246243        </ul> 
  • pycodeshooter/trunk/shooter/bullet.js

    r115 r130  
    3939        return (width < this.x || height < this.y || this.x < 0 || this.y < 0); 
    4040    }; 
    41     this.draw = function(ctx) { 
     41    this.draw = function(ctx, func) { 
    4242        if (this.frame) { 
    4343            var pos = this.calcNext(); 
     
    6161 
    6262        ctx.beginPath(); 
    63         ctx.fillStyle = this.getColor(); 
    64         ctx.arc(this.x, this.y, this.getSize(), 0, Math.PI * 2.0, true); 
    65         ctx.fill(); 
     63        if (func) { 
     64            func(this, ctx); 
     65        } 
     66        else { 
     67            ctx.fillStyle = this.getColor(); 
     68            ctx.arc(this.x, this.y, this.getSize(), 0, Math.PI * 2.0, true); 
     69            ctx.fill(); 
     70        } 
    6671        ctx.closePath(); 
    6772    }; 
  • pycodeshooter/trunk/shooter/system.js

    r129 r130  
    3030    "backgroundObject": new Array(), 
    3131    "deathPieces":      new Array(), 
     32    "items":            new Array(), 
    3233    "mainIntervalId":   0 
    3334}; 
     
    9596 
    9697    System.deathPieces = newObjs; 
     98} 
     99 
     100 
     101/* 
     102 *  Item Utilities 
     103 */ 
     104function addItem(x, y, angle, size, color, speed, attrs) { 
     105    var frame = {"style": "rect", "color": attrs.color, "width": size * 2, "height": size * 2}; 
     106    var item  = new YExtendBullet(size, color, frame, 
     107                                  System.screen.width, System.screen.height, 
     108                                  x, y, angle * Math.PI, speed); 
     109    item.attrs = attrs; 
     110    System.items.push(item); 
     111} 
     112 
     113function updateItems(ctx, width, height, troopers) { 
     114    var newObjs = new Array(); 
     115 
     116  ITEMLOOP: 
     117    for (var i = 0; i < System.items.length; i++) { 
     118        var item = System.items[i]; 
     119 
     120        item.next(); 
     121        item.draw(ctx, function(bullet, ctx) { 
     122            drawString( 
     123                ctx, "source-over", item.attrs.symbol, 
     124                bullet.x, bullet.y, 
     125                item.attrs.color, item.size + "pt monospace", "center" 
     126            ); 
     127        }); 
     128 
     129        for (var j = 0; j < troopers.length; j++) { 
     130            var trooper = troopers[j]; 
     131 
     132            if (touch(trooper.x, trooper.y, trooper.size, item.x, item.y, item.size)) { 
     133                switch (item.attrs.type) { 
     134                case "score": 
     135                    playSound("se_item_score"); 
     136                    if (System.score[trooper.name] !== undefined) 
     137                        System.score[trooper.name] += item.attrs.quantity; 
     138                    break; 
     139                case "shot": 
     140                    playSound("se_item_shot"); 
     141                    for (var k = 0; k < trooper.barrages.length; k++) { 
     142                        trooper.barrages[k].way += item.attrs.quantity; 
     143                        if (trooper.barrages[k].way >= 10) 
     144                            trooper.barrages[k].way = 10; 
     145                    } 
     146                    break; 
     147                case "bomb": 
     148                    playSound("se_item_bomb"); 
     149                    trooper.numBombs += item.attrs.quantity; 
     150                    break; 
     151                case "life": 
     152                    playSound("se_item_life"); 
     153                    trooper.life += item.attrs.quantity; 
     154                    break; 
     155                } 
     156 
     157                continue ITEMLOOP; 
     158            } 
     159        } 
     160 
     161        if (!item.vanished(width, height)) 
     162            newObjs.push(item); 
     163    } 
     164 
     165    System.items = newObjs; 
    97166} 
    98167 
     
    355424                [6, 8, 10], ["#F55", "#FAA"], 3, 8 
    356425            ); 
     426 
     427            var itemAttr; 
     428            var itemRand = Math.floor(Math.random() * 100); 
     429            if (itemRand < 40) { 
     430                // nothing 
     431            } 
     432            else if (itemRand < 75) { 
     433                itemAttr = {"color": "#AAF", "symbol": "S", "type": "score", "quantity": enemy.maxLife * 200}; 
     434            } 
     435            else if (itemRand < 95) { 
     436                itemAttr = {"color": "#FAA", "symbol": "P", "type": "shot", "quantity": 1}; 
     437            } 
     438            else if (itemRand < 98) { 
     439                itemAttr = {"color": "#FFA", "symbol": "B", "type": "bomb", "quantity": 1}; 
     440            } 
     441            else { 
     442                itemAttr = {"color": "#AFA", "symbol": "L", "type": "life", "quantity": 1}; 
     443            } 
     444 
     445            if (itemAttr) 
     446                addItem(enemy.x, enemy.y, 0.5, 5, "#AFA", 1, itemAttr); 
    357447        } 
    358448        else { 
     
    396486        "STAGE " + getStageNumber(), 
    397487        System.screen.width - 10, 
    398         System.screen.height - 15, 
     488        15, 
    399489        "#ACF", "9pt monospace", "right" 
    400490    ); 
     
    409499            name + " SCORE " + System.score[name], 
    410500            (System.screen.width - 10), 
    411             i * 16 + 15, 
     501            i * 16 + 30, 
    412502            "#ACF", "9pt monospace", "right" 
    413503        ); 
    414504    } 
     505 
     506    // update/draw items 
     507    updateItems(System.screen.ctx, 
     508                System.screen.width, 
     509                System.screen.height, 
     510                System.players); 
    415511 
    416512    // update/draw troopers 
     
    436532            (System.screen.height - 23) - (i * 33), 
    437533            "#ACF", "9pt monospace", "left" 
     534        ); 
     535 
     536        drawString( 
     537            System.screen.ctx, 
     538            "source-over", 
     539            "BOMB " + player.numBombs, 
     540            (System.screen.width - 10), 
     541            (System.screen.height - 23) - (i * 33), 
     542            "#ACF", "9pt monospace", "right" 
    438543        ); 
    439544    } 
     
    522627                          playerData.shotlevel, 
    523628                          -0.5), 
    524          new LinerBarrage(YExtendBullet, 
     629         new LinerBarrage(LinerBullet, 
    525630                          playerData.shotsize, 
    526631                          "rgba(64,64,128,0.7)", 
     
    529634                          playerData.shotspeed, 
    530635                          playerData.shotlevel, 
    531                           0.5), 
    532          new CircularBarrage(LinerBullet, 
    533                           playerData.shotsize, 
    534                           "rgba(64,64,128,0.7)", 
    535                           null, 
    536                           playerData.shotinterval, 
    537                           playerData.shotspeed, 
    538                           playerData.shotlevel + 2, 
    539636                          -0.5)] 
    540637    ); 
     
    554651        trooper.x = System.screen.width / 2; 
    555652        trooper.y = System.screen.height - System.screen.height / 7; 
     653        trooper.numBombs = playerData.numbombs; 
     654        trooper.barrages = [ 
     655            new LinerBarrage(YExtendBullet, 
     656                             playerData.shotsize, 
     657                             "rgba(64,64,128,0.7)", 
     658                             null, 
     659                             playerData.shotinterval, 
     660                             playerData.shotspeed, 
     661                             playerData.shotlevel, 
     662                             -0.5), 
     663            new LinerBarrage(LinerBullet, 
     664                             playerData.shotsize, 
     665                             "rgba(64,64,128,0.7)", 
     666                             null, 
     667                             playerData.shotinterval, 
     668                             playerData.shotspeed, 
     669                             playerData.shotlevel, 
     670                             -0.5) 
     671        ]; 
    556672    }); 
    557673 
Note: See TracChangeset for help on using the changeset viewer.