Changeset 108


Ignore:
Timestamp:
01/17/12 01:34:00 (12 years ago)
Author:
atzm
Message:
  • multi enemies support
Location:
pycodeshooter/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/index.html

    r106 r108  
    1515    var titleIntervalId = 0; 
    1616 
    17     function start(id, list) { 
     17    function startGame() { 
    1818        var msg    = document.getElementById("message"); 
    1919        var player = { 
     
    3939        } 
    4040 
    41         if (titleIntervalId) { 
    42             clearInterval(titleIntervalId); 
    43             titleIntervalId = 0; 
    44         } 
    45  
    4641        document.onkeydown  = function (ev) { setKeyDown(ev.keyCode); }; 
    4742        document.onkeyup    = function (ev) { setKeyUp(ev.keyCode); }; 
    4843        document.onkeypress = function (ev) { setKeyPress(ev.charCode); }; 
    4944 
    50         initGame(document.getElementById("screen"), msg, id, list[id], player); 
     45        initGame(document.getElementById("screen"), msg, player); 
    5146    } 
    5247 
    5348    function initControlPanel(list) { 
    5449        var cp  = document.getElementById("controlpanel"); 
    55         var sel = "<select id=\"bossSelection\">"; 
     50        var sel = "<select id=\"enemySelection\">"; 
    5651 
    5752        for (var id in list) { 
     
    6156        cp.innerHTML = sel + "</select>"; 
    6257 
    63         document.getElementById("bossSelection").onchange = function (ev) { 
    64             start(this[this.selectedIndex].value, list); 
     58        document.getElementById("enemySelection").onchange = function (ev) { 
     59            if (titleIntervalId) { 
     60                clearInterval(titleIntervalId); 
     61                titleIntervalId = 0; 
     62                startGame(); 
     63            } 
     64            addEnemy(list[this[this.selectedIndex].value]); 
    6565        }; 
    6666    } 
     
    7171        var logoimg = document.getElementById("logoimg"); 
    7272 
    73         var x           = (screen.width - logoimg.width) / 2; 
    74         var y           = -1 - logoimg.height; 
    75         var titlePos    = screen.height / 2 - logoimg.height / 2; 
     73        var x        = (screen.width - logoimg.width) / 2; 
     74        var y        = -1 - logoimg.height; 
     75        var titlePos = screen.height / 2 - logoimg.height / 2; 
     76 
    7677        titleIntervalId = setInterval(function() { 
    7778            drawScreen(ctx, "source-over", "rgba(8,8,8,0.5)", screen.width, screen.height); 
     
    111112                名前: <input type="text" value="Player" size="8" id="name" /> 
    112113                耐习
    113 æ€§: <input type="text" value="15" size="3" id="hitpoint" /> 
     114性: <input type="text" value="5" size="3" id="hitpoint" /> 
    114115                ボム数: <input type="text" value="2" size="3" id="numbombs" /> 
    115116                <br /> 
  • pycodeshooter/trunk/shooter/action.js

    r103 r108  
    104104 
    105105    that.index = 0; 
    106     that.shot  = function(trooper, enemy) { 
     106    that.shot  = function(trooper, enemies) { 
    107107        if (isSetSwitch(SWITCH_BULLET)) { 
    108108            if (++this.index >= trooper.barrages.length) 
     
    115115        } 
    116116        if (isInAction(ACTION_SHOT)) 
    117             trooper.barrages[this.index].update(trooper, enemy); 
     117            trooper.barrages[this.index].update(trooper, enemies); 
    118118    }; 
    119119 
     
    125125 
    126126    that.index = 0; 
    127     that.shot  = function(trooper, enemy) { 
    128         if (trooper.barrages[this.index].update(trooper, enemy)) 
     127    that.shot  = function(trooper, enemies) { 
     128        if (trooper.barrages[this.index].update(trooper, enemies)) 
    129129            this.index = Math.floor(Math.random() * trooper.barrages.length); 
    130130    }; 
     
    140140 
    141141    that.i    = 0; 
    142     that.shot = function(trooper, enemy) { 
    143         if (trooper.barrages[this.index].update(trooper, enemy)) { 
     142    that.shot = function(trooper, enemies) { 
     143        if (trooper.barrages[this.index].update(trooper, enemies)) { 
    144144            if (++this.i > count) { 
    145145                this.index++; 
     
    169169var Action = function(shot) { 
    170170    this.shot   = shot; 
    171     this.update = function(trooper, enemy) { 
     171    this.update = function(trooper, enemies) { 
    172172        if (trooper.isDead()) 
    173173            return; 
    174         this.shot.shot(trooper, enemy); 
    175         return this.move(trooper, enemy); 
    176     }; 
    177     this.move = function(trooper, enemy) { 
     174        this.shot.shot(trooper, enemies); 
     175        return this.move(trooper, enemies); 
     176    }; 
     177    this.move = function(trooper, enemies) { 
    178178        return true; 
    179179    }; 
     
    183183    var that = new Action(shot); 
    184184 
    185     that.move = function(trooper, enemy) { 
     185    that.move = function(trooper, enemies) { 
    186186        var x = 0; 
    187187        var y = 0; 
     
    216216    that.resolution = 0; 
    217217 
    218     that.move = function(trooper, enemy) { 
     218    that.move = function(trooper, enemies) { 
    219219        if (this.count >= this.resolution) { 
    220220            this.count      = 0; 
    221221            this.resolution = resolution / trooper.speed; 
    222222 
    223             this.p0 = this.getPoint0(trooper, enemy); 
    224             this.p1 = this.getPoint1(trooper, enemy); 
    225             this.p2 = this.getPoint2(trooper, enemy); 
    226             this.p3 = this.getPoint3(trooper, enemy); 
     223            this.p0 = this.getPoint0(trooper, enemies); 
     224            this.p1 = this.getPoint1(trooper, enemies); 
     225            this.p2 = this.getPoint2(trooper, enemies); 
     226            this.p3 = this.getPoint3(trooper, enemies); 
    227227        } 
    228228 
     
    254254    var that = new BezierAction(shot, resolution); 
    255255 
    256     that.getPoint0 = function(trooper, enemy) { 
     256    that.getPoint0 = function(trooper, enemies) { 
    257257        return [trooper.x, trooper.y]; 
    258258    }; 
    259     that.getPoint1 = function(trooper, enemy) { 
     259    that.getPoint1 = function(trooper, enemies) { 
    260260        return [trooper.x - (trooper.speed * 10), 
    261261                trooper.y + (trooper.speed * 10)]; 
    262262    }; 
    263     that.getPoint2 = function(trooper, enemy) { 
     263    that.getPoint2 = function(trooper, enemies) { 
    264264        return [trooper.x + (trooper.speed * 10), 
    265265                trooper.y + (trooper.speed * 10)]; 
    266266    }; 
    267     that.getPoint3 = function(trooper, enemy) { 
     267    that.getPoint3 = function(trooper, enemies) { 
    268268        return [trooper.x, trooper.y]; 
    269269    }; 
     
    275275    var that = new BezierAction(shot, resolution); 
    276276 
    277     that.getPoint0 = function(trooper, enemy) { 
     277    that.getPoint0 = function(trooper, enemies) { 
    278278        return [trooper.x, trooper.y]; 
    279279    }; 
    280     that.getPoint1 = function(trooper, enemy) { 
     280    that.getPoint1 = function(trooper, enemies) { 
    281281        return [Math.floor(Math.random() * trooper.w), 
    282282                Math.floor(Math.random() * trooper.h)]; 
    283283    }; 
    284     that.getPoint2 = function(trooper, enemy) { 
     284    that.getPoint2 = function(trooper, enemies) { 
    285285        return [Math.floor(Math.random() * trooper.w), 
    286286                Math.floor(Math.random() * trooper.h)]; 
    287287    }; 
    288     that.getPoint3 = function(trooper, enemy) { 
     288    that.getPoint3 = function(trooper, enemies) { 
    289289        return [Math.floor(Math.random() * trooper.w), 
    290290                Math.floor(Math.random() * trooper.h)]; 
     
    297297    var that = new RandomAction(shot, resolution); 
    298298 
    299     that.getPoint3 = function(trooper, enemy) { 
     299    that.getPoint3 = function(trooper, enemies) { 
    300300        return [Math.floor(Math.random() * trooper.w), trooper.y]; 
    301301    }; 
     
    307307    var that = new RandomAction(shot, resolution); 
    308308 
    309     that.getPoint3 = function(trooper, enemy) { 
    310         return [enemy.x, Math.floor(Math.random() * trooper.h)]; 
     309    that.getPoint3 = function(trooper, enemies) { 
     310        var x = enemies.length ? enemies[0].x : 0; 
     311        return [x, Math.floor(Math.random() * trooper.h)]; 
    311312    }; 
    312313 
     
    317318    var that = new RandomAction(shot, resolution); 
    318319 
    319     that.getPoint3 = function(trooper, enemy) { 
    320         return [enemy.x, trooper.y]; 
     320    that.getPoint3 = function(trooper, enemies) { 
     321        var x = enemies.length ? enemies[0].x : 0; 
     322        return [x, trooper.y]; 
    321323    }; 
    322324 
     
    332334    this.list   = list; 
    333335    this.index  = 0; 
    334     this.update = function(trooper, enemy) { 
    335         this.updateIdx(this.list[this.index].update(trooper, enemy), 
    336                        trooper, enemy); 
    337     }; 
    338     this.updateIdx = function(end, trooper, enemy) { 
     336    this.update = function(trooper, enemies) { 
     337        this.updateIdx(this.list[this.index].update(trooper, enemies), 
     338                       trooper, enemies); 
     339    }; 
     340    this.updateIdx = function(end, trooper, enemies) { 
    339341        this.index = 0; 
    340342    }; 
     
    344346    var that = new ActionList(list); 
    345347 
    346     that.updateIdx = function(end, trooper, enemy) { 
     348    that.updateIdx = function(end, trooper, enemies) { 
    347349        if (end) 
    348350            this.index = Math.floor(Math.random() * this.list.length); 
     
    359361 
    360362    that.i         = 0; 
    361     that.updateIdx = function(end, trooper, enemy) { 
     363    that.updateIdx = function(end, trooper, enemies) { 
    362364        if (end) { 
    363365            if (++this.i > count) { 
     
    385387 
    386388    that.life      = 0; 
    387     that.updateIdx = function(end, trooper, enemy) { 
     389    that.updateIdx = function(end, trooper, enemies) { 
    388390        if (!this.life) 
    389391            this.life = trooper.life; 
     
    402404 
    403405    that.life      = 0; 
    404     that.updateIdx = function(end, trooper, enemy) { 
     406    that.updateIdx = function(end, trooper, enemies) { 
    405407        if (!this.life) 
    406408            this.life = trooper.life; 
  • pycodeshooter/trunk/shooter/barrage.js

    r106 r108  
    2525 
    2626    this.aim = function(trooper, enemy) { 
     27        if (!trooper || !enemy) 
     28            return 0.5 * Math.PI; 
    2729        var dx = enemy.x - trooper.x; 
    2830        var dy = enemy.y - trooper.y; 
     
    3436        return this.aim(trooper, enemy) / Math.PI; 
    3537    }; 
    36     this.update = function(trooper, enemy) { 
     38    this.update = function(trooper, enemies) { 
    3739        return false; 
    3840    }; 
     
    4951 
    5052    that.state  = 0; 
    51     that.update = function(trooper, enemy) { 
     53    that.update = function(trooper, enemies) { 
    5254        if (++this.state < this.interval) 
    5355            return false; 
    5456 
    55         var dir = this.angle(trooper, enemy); 
     57        var dir = this.angle(trooper, enemies[0]); 
    5658 
    5759        trooper.addBullet(this.bullet, this.size, this.color, 
     
    9193 
    9294    that.state  = 0; 
    93     that.update = function(trooper, enemy) { 
     95    that.update = function(trooper, enemies) { 
    9496        if (++this.state < this.interval) 
    9597            return false; 
    9698 
    97         var angle = this.angle(trooper, enemy) - (this.delta * (this.way - 1) / 2); 
     99        var angle = this.angle(trooper, enemies[0]) - (this.delta * (this.way - 1) / 2); 
    98100 
    99101        for (var i = 0; i < this.way; i++) { 
     
    135137    that.curAngle = null; 
    136138 
    137     that.update = function(trooper, enemy) { 
     139    that.update = function(trooper, enemies) { 
    138140        if (++this.state < this.interval) 
    139141            return false; 
    140142 
    141143        if (this.curAngle == null) 
    142             this.curAngle = this.angle(trooper, enemy) - 
     144            this.curAngle = this.angle(trooper, enemies[0]) - 
    143145                this.delta * (this.way - 1) / 2; 
    144146 
     
    268270    }; 
    269271 
    270     this.update = function(trooper, enemy) { 
     272    this.update = function(trooper, enemies) { 
    271273        for (var i = 0; i < this.brrg.length; i++) { 
    272274            if (!this.flag[i]) 
    273                 this.flag[i] = this.brrg[i].update(trooper, enemy); 
     275                this.flag[i] = this.brrg[i].update(trooper, enemies); 
    274276        } 
    275277        for (var i = 0; i < this.flag.length; i++) { 
  • pycodeshooter/trunk/shooter/system.js

    r106 r108  
    2222    }, 
    2323    "message":          null, 
    24     "boss":             null, 
    25     "player":           null, 
     24    "enemies":          new Array(), 
     25    "players":          new Array(), 
    2626    "backgroundObject": new Array(), 
    2727    "deathPieces":      new Array(), 
    28     "gameOver":         false, 
    2928    "mainIntervalId":   0 
    3029}; 
     
    3231 
    3332/* 
    34  *  Tiun Tiun 
     33 *  Tiun Tiun Utilities 
    3534 */ 
    3635var DeathPiece = function(sizes, colors, x, y, dir, speed) { 
     
    5554}; 
    5655 
     56function addDeathPieces(x, y, sizes, colors, speed, way) { 
     57    if (way % 2) 
     58        way++; 
     59 
     60    var pieces = new Array(); 
     61    var angle  = 0; 
     62    var delta  = 2 / way; 
     63 
     64    for(var i = 0; i < way; i++) { 
     65        pieces.push(new DeathPiece(sizes, colors, x, y, angle * Math.PI, speed)); 
     66        angle += delta; 
     67    } 
     68 
     69    System.deathPieces.push(pieces); 
     70} 
     71 
     72function updateDeathPieces(ctx, width, height) { 
     73    var newObjs = new Array(); 
     74 
     75    for (var i = 0; i < System.deathPieces.length; i++) { 
     76        var pieces    = System.deathPieces[i]; 
     77        var newPieces = new Array(); 
     78 
     79        for (var k = 0; k < pieces.length; k++) { 
     80            pieces[k].next(); 
     81            pieces[k].draw(ctx); 
     82            if (!pieces[k].vanished(width, height)) 
     83                newPieces.push(pieces[k]); 
     84        } 
     85 
     86        if (newPieces.length) 
     87            newObjs.push(newPieces); 
     88    } 
     89 
     90    System.deathPieces = newObjs; 
     91} 
     92 
    5793 
    5894/* 
    5995 *  Utility Functions 
    6096 */ 
     97function setMessage(elem, msg) { 
     98    if (elem) 
     99        elem.innerHTML = msg; 
     100} 
     101 
     102function addMessage(elem, msg) { 
     103    if (elem) 
     104        elem.innerHTML += msg; 
     105} 
     106 
    61107function updateBackground(ctx, width, height, size, color, max) { 
    62108    if (System.backgroundObject.length < max) { 
     
    68114 
    69115    var newObjs = new Array(); 
     116 
    70117    for (var i = 0; i < System.backgroundObject.length; i++) { 
    71118        System.backgroundObject[i].next(); 
     
    74121            newObjs.push(System.backgroundObject[i]); 
    75122    } 
     123 
    76124    System.backgroundObject = newObjs; 
    77 } 
    78  
    79 function updateDeathPieces(ctx, width, height, x, y, sizes, colors, speed, way) { 
    80     if (System.deathPieces.length <= 0) { 
    81         if (way % 2) 
    82             way++; 
    83  
    84         var angle = 0; 
    85         var delta = 2 / way; 
    86  
    87         for(i = 0; i < way; i++) { 
    88             System.deathPieces.push( 
    89                 new DeathPiece(sizes, colors, x, y, angle * Math.PI, speed)); 
    90             angle += delta; 
    91         } 
    92     } 
    93  
    94     var newObjs = new Array(); 
    95     for (var i = 0; i < System.deathPieces.length; i++) { 
    96         System.deathPieces[i].next(); 
    97         System.deathPieces[i].draw(ctx); 
    98         if (!System.deathPieces[i].vanished(width, height)) 
    99             newObjs.push(System.deathPieces[i]); 
    100     } 
    101     System.deathPieces = newObjs; 
    102  
    103     return !System.deathPieces.length; 
    104125} 
    105126 
     
    151172} 
    152173 
    153 function updateTrooper(trooper, enemy) { 
    154     if (System.gameOver) { 
    155         trooper.clearBullet(); 
    156         enemy.clearBullet(); 
    157  
    158         drawString( 
    159             System.screen.ctx, "source-over", 
    160             "GAME OVER", 
    161             System.screen.width / 2, 
    162             System.screen.height / 2, 
    163             "#ACF", "24pt monospace", "center" 
    164         ); 
    165     } 
    166     else if (trooper.isDead()) { 
    167         trooper.clearBullet(); 
    168         enemy.clearBullet(); 
    169  
    170         System.gameOver = updateDeathPieces( 
    171             System.screen.ctx, 
    172             System.screen.width, 
    173             System.screen.height, 
    174             trooper.x, 
    175             trooper.y, 
    176             [6, 8, 10], ["#55F", "#AAF"], 3, 8 
    177         ); 
    178     } 
    179     else if (enemy.isDead()) { 
    180         trooper.draw(System.screen.ctx); 
    181     } 
    182     else { 
    183         trooper.update(enemy); 
    184         trooper.draw(System.screen.ctx); 
    185     } 
    186 } 
    187  
    188 function setMessage(elem, msg) { 
    189     if (elem) 
    190         elem.innerHTML = msg; 
    191 } 
    192  
    193 function addMessage(elem, msg) { 
    194     if (elem) 
    195         elem.innerHTML += msg; 
     174function updateTrooper(trooper, enemyKey) { 
     175    trooper.update(System[enemyKey]); 
     176 
     177    var aliveEnemies = new Array(); 
     178    for (var i = 0; i < System[enemyKey].length; i++) { 
     179        var enemy = System[enemyKey][i]; 
     180 
     181        if (enemy.isDead()) { 
     182            addDeathPieces( 
     183                enemy.x, enemy.y, 
     184                [6, 8, 10], ["#55F", "#AAF"], 3, 8 
     185            ); 
     186        } 
     187        else { 
     188            aliveEnemies.push(enemy); 
     189        } 
     190    } 
     191    System[enemyKey] = aliveEnemies; 
     192 
     193    trooper.draw(System.screen.ctx); 
     194} 
     195 
     196function addEnemy(enemyData) { 
     197    var actList = EnemyActionLists[enemyData.mtime % EnemyActionLists.length]; 
     198    var shot    = EnemyShots[enemyData.hitpoint % EnemyShots.length]; 
     199    var numAct  = enemyData.agility       % (EnemyActions.length  - 1) + 1; 
     200    var numBlt  = enemyData.skills.length % (EnemyBullets.length  - 1) + 1; 
     201    var numBrrg = enemyData.skills.length % (EnemyBarrages.length - 1) + 1; 
     202    var acts    = new Array(); 
     203    var brrgs   = new Array(); 
     204 
     205    var bulletWay         = Math.ceil(enemyData.concentration / 10); 
     206    var bulletInterval    = Math.round(50 * 1 / Math.log(enemyData.skillpoint + 0.1)); 
     207    var bulletSize        = Math.round(Math.log(enemyData.luck + 1)); 
     208    var bulletFrameWidth  = (bulletSize + 5) * 2; 
     209    var bulletFrameHeight = (bulletSize + 5) * 4; 
     210    var bulletSpeed       = enemyData.strength / 15; 
     211 
     212    bulletSpeed = Math.log(bulletSpeed < 1.5 ? 1.5 : bulletSpeed); 
     213 
     214    for (var i = 0; i < numAct; i++) { 
     215        var idx = (enemyData.agility + i) % EnemyActions.length; 
     216        acts.push(new EnemyActions[idx](new shot())); 
     217    } 
     218 
     219    for (var i = 0; i < numBrrg; i++) { 
     220        var idx     = (enemyData.skillpoint + i * (enemyData.skills.length + 1)) % EnemyBarrages.length; 
     221        var brrgCls = EnemyBarrages[idx]; 
     222 
     223        for (var k = 0; k < numBlt; k++) { 
     224            var iidx = (enemyData.skills.length + i + k) % EnemyBullets.length; 
     225            brrgs.push( 
     226                new brrgCls( 
     227                    EnemyBullets[iidx], 
     228                    bulletSize, 
     229                    "#FF3", 
     230                    {"style": "rect", "color": "rgba(128,32,32,0.5)", 
     231                     "width": bulletFrameWidth, "height": bulletFrameHeight}, 
     232                    bulletInterval, 
     233                    bulletSpeed, 
     234                    bulletWay 
     235                ) 
     236            ); 
     237        } 
     238    } 
     239 
     240    var size  = Math.ceil((System.screen.width / 2) * (1 / enemyData.defense)); 
     241    var enemy = new Trooper( 
     242        enemyData.name, 
     243        new actList(acts), 
     244        size, 
     245        size, 
     246        "#F33", 
     247        "#F33", 
     248        System.screen.width / 2, 
     249        System.screen.height / 7, 
     250        System.screen.width, 
     251        System.screen.height, 
     252        enemyData.hitpoint, 
     253        Math.log(enemyData.agility + 0.1) * 3, 
     254        0, 
     255        ["rgba(255,0,0,0.3)", "rgba(0,0,255,0.3)"], 
     256        brrgs 
     257    ); 
     258 
     259    System.enemies.push(enemy); 
    196260} 
    197261 
     
    219283 
    220284    // update/draw troopers 
    221     updateTrooper(System.player, System.boss); 
    222     updateTrooper(System.boss, System.player); 
    223  
    224     // draw player name/life 
    225     drawString( 
    226         System.screen.ctx, 
    227         "source-over", 
    228         System.player.name, 
    229         10, System.screen.height - 25, 
    230         "#ACF", "9pt monospace", "left" 
    231     ); 
    232     drawLifeGauge( 
    233         System.screen.ctx, 
    234         "lighter", 
    235         System.player, 
    236         10, 
    237         System.screen.height - 20, 
    238         System.screen.width 
    239     ); 
    240  
    241     // draw boss name/life 
    242     drawString( 
    243         System.screen.ctx, 
    244         "source-over", 
    245         System.boss.name, 10, 35, 
    246         "#FCA", "9pt monospace", "left" 
    247     ); 
    248     drawLifeGauge( 
    249         System.screen.ctx, 
    250         "lighter", 
    251         System.boss, 
    252         10, 
    253         10, 
    254         System.screen.width 
    255     ); 
     285    for (var i = 0; i < System.players.length; i++) { 
     286        var player = System.players[i]; 
     287 
     288        updateTrooper(player, "enemies"); 
     289 
     290        drawLifeGauge( 
     291            System.screen.ctx, 
     292            "lighter", 
     293            player, 
     294            10, 
     295            (System.screen.height - 20) - (i * 33), 
     296            System.screen.width 
     297        ); 
     298 
     299        drawString( 
     300            System.screen.ctx, 
     301            "source-over", 
     302            player.name, 
     303            10, 
     304            (System.screen.height - 23) - (i * 33), 
     305            "#ACF", "9pt monospace", "left" 
     306        ); 
     307    } 
     308 
     309    // update/draw enemies 
     310    for (var i = 0; i < System.enemies.length; i++) { 
     311        var enemy = System.enemies[i]; 
     312 
     313        updateTrooper(enemy, "players"); 
     314 
     315        drawLifeGauge( 
     316            System.screen.ctx, 
     317            "lighter", 
     318            enemy, 10, i * 33 + 10, 
     319            System.screen.width 
     320        ); 
     321 
     322        drawString( 
     323            System.screen.ctx, 
     324            "source-over", 
     325            enemy.name, 10, i * 33 + 33, 
     326            "#FCA", "9pt monospace", "left" 
     327        ); 
     328    } 
     329 
     330    updateDeathPieces(System.screen.ctx, 
     331                      System.screen.width, 
     332                      System.screen.height); 
     333 
     334    if (!System.players.length) { 
     335        drawString( 
     336            System.screen.ctx, "source-over", 
     337            "GAME OVER", 
     338            System.screen.width / 2, 
     339            System.screen.height / 2, 
     340            "#ACF", "24pt monospace", "center" 
     341        ); 
     342    } 
    256343} 
    257344 
     
    260347 *  Initializer 
    261348 */ 
    262 function initGame(canvas, msg, bossId, bossData, playerData) { 
     349function initGame(canvas, msg, playerData) { 
    263350    System.screen.canvas = canvas; 
    264351    System.message       = msg; 
     
    283370    ); 
    284371 
    285     System.player = new Trooper( 
     372    System.players.push(new Trooper( 
    286373        playerData.name, 
    287374        new ActionList([new ManualAction(new ManualShot())]), 
     
    322409                          playerData.shotlevel + 2, 
    323410                          -0.5)] 
    324     ); 
    325  
    326     var actList = EnemyActionLists[bossData.mtime % EnemyActionLists.length]; 
    327     var shot    = EnemyShots[bossData.hitpoint % EnemyShots.length]; 
    328     var numAct  = bossData.agility       % (EnemyActions.length  - 1) + 1; 
    329     var numBlt  = bossData.skills.length % (EnemyBullets.length  - 1) + 1; 
    330     var numBrrg = bossData.skills.length % (EnemyBarrages.length - 1) + 1; 
    331     var acts    = new Array(); 
    332     var brrgs   = new Array(); 
    333  
    334     var bulletWay         = Math.ceil(bossData.concentration / 10); 
    335     var bulletInterval    = Math.round(50 * 1 / Math.log(bossData.skillpoint + 0.1)); 
    336     var bulletSize        = Math.round(Math.log(bossData.luck + 1)); 
    337     var bulletFrameWidth  = (bulletSize + 5) * 2; 
    338     var bulletFrameHeight = (bulletSize + 5) * 4; 
    339     var bulletSpeed       = bossData.strength / 15; 
    340     bulletSpeed = Math.log(bulletSpeed < 1.5 ? 1.5 : bulletSpeed); 
    341  
    342     setMessage(System.message, ""); 
    343     addMessage(System.message, " bulletWay:" + String(bulletWay) + "<br>"); 
    344     addMessage(System.message, " bulletInterval:" + String(bulletInterval) + "<br>"); 
    345     addMessage(System.message, " bulletSize:" + String(bulletSize) + "<br>"); 
    346     addMessage(System.message, " bulletSpeed:" + String(bulletSpeed) + "<br>"); 
    347  
    348     addMessage(System.message, "ActionsIdx:"); 
    349  
    350     for (var i = 0; i < numAct; i++) { 
    351         var idx = (bossData.agility + i) % EnemyActions.length; 
    352         acts.push(new EnemyActions[idx](new shot())); 
    353  
    354         addMessage(System.message, String(idx) + "(" + 
    355                    String(bossData.hitpoint % EnemyShots.length) + "),"); 
    356     } 
    357  
    358     addMessage(System.message, "<br>"); 
    359  
    360     for (var i = 0; i < numBrrg; i++) { 
    361         var idx     = (bossData.skillpoint + i * (bossData.skills.length + 1)) % EnemyBarrages.length; 
    362         var brrgCls = EnemyBarrages[idx]; 
    363  
    364         addMessage(System.message, 
    365                    "BarragesIdx:" + String(idx) + " / BulletsIdx:"); 
    366  
    367         for (var k = 0; k < numBlt; k++) { 
    368             var iidx = (bossData.skills.length + i + k) % EnemyBullets.length; 
    369             brrgs.push( 
    370                 new brrgCls( 
    371                     EnemyBullets[iidx], 
    372                     bulletSize, 
    373                     "#FF3", 
    374                     {"style": "rect", "color": "rgba(128,32,32,0.5)", 
    375                      "width": bulletFrameWidth, "height": bulletFrameHeight}, 
    376                     bulletInterval, 
    377                     bulletSpeed, 
    378                     bulletWay 
    379                 ) 
    380             ); 
    381  
    382             addMessage(System.message, String(iidx) + ","); 
    383         } 
    384  
    385         addMessage(System.message, "<br>"); 
    386     } 
    387  
    388     var size = Math.ceil((System.screen.width / 2) * (1 / bossData.defense)); 
    389     size = size < playerData.size ? playerData.size : size; 
    390     System.boss = new Trooper( 
    391         bossData.name, 
    392         new actList(acts), 
    393         size, 
    394         size, 
    395         "#F33", 
    396         "#F33", 
    397         System.screen.width / 2, 
    398         System.screen.height / 7, 
    399         System.screen.width, 
    400         System.screen.height, 
    401         bossData.hitpoint, 
    402         Math.log(bossData.agility + 0.1) * 3, 
    403         0, 
    404         ["rgba(255,0,0,0.3)", "rgba(0,0,255,0.3)"], 
    405         brrgs 
    406     ); 
     411    )); 
    407412 
    408413    System.backgroundObject = new Array(); 
  • pycodeshooter/trunk/shooter/trooper.js

    r106 r108  
    3232    this.colIdx = 0; 
    3333 
    34     this.update = function(enemy) { 
     34    this.update = function(enemies) { 
    3535        this.size += this.speed; 
    3636 
    37         // judge bullet 
    38         var delIdx = new Array(); 
    39         for (var i = 0; i < enemy.bullets.length; i++) { 
    40             if (touch(this.x, this.y, this.size, 
    41                       enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 
    42                 delIdx.push(i); 
    43         } 
    44         enemy.delBullet(delIdx); 
    45  
    46         // judge enemy 
    47         if (touch(this.x, this.y, this.size, enemy.x, enemy.y, enemy.size) && enemy.life > 0) 
    48             enemy.life--; 
     37        for (var ei = 0; ei < enemies.length; ei++) { 
     38            var enemy  = enemies[ei]; 
     39            var delIdx = new Array(); 
     40 
     41            // judge bullet 
     42            for (var i = 0; i < enemy.bullets.length; i++) { 
     43                if (touch(this.x, this.y, this.size, 
     44                          enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 
     45                    delIdx.push(i); 
     46            } 
     47            enemy.delBullet(delIdx); 
     48 
     49            // judge enemy 
     50            if (touch(this.x, this.y, this.size, enemy.x, enemy.y, enemy.size) && enemy.life > 0) 
     51                enemy.life--; 
     52        } 
    4953    }; 
    5054 
     
    121125    }; 
    122126 
    123     this.update = function(enemy) { 
    124         var delIdx = null; 
    125  
     127    this.update = function(enemies) { 
    126128        // update my action 
    127         this.actList.update(this, enemy); 
     129        this.actList.update(this, enemies); 
    128130 
    129131        // update bomb 
    130132        if (this.bomb) { 
    131             this.bomb.update(enemy); 
     133            this.bomb.update(enemies); 
    132134            if (this.bomb.vanished()) 
    133135                this.bomb = null; 
     
    135137 
    136138        // update/delete my bullets 
    137         delIdx = new Array(); 
    138         for (var i = 0; i < this.bullets.length; i++) { 
    139             this.bullets[i].next(); 
    140  
    141             if (this.bullets[i].vanished()) 
    142                 delIdx.push(i); 
    143         } 
    144         this.delBullet(delIdx); 
    145  
    146         // judge/delete hit bullets 
    147         delIdx = new Array(); 
    148         for (var i = 0; i < enemy.bullets.length; i++) { 
    149             if (touch(this.x, this.y, this.hitSize, 
    150                       enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 
    151                 delIdx.push(i); 
    152         } 
    153         enemy.delBullet(delIdx); 
    154  
    155         // update life 
    156         if (delIdx.length > 0 && this.life > 0) 
    157             this.life--; 
     139        { 
     140            var delIdx = new Array(); 
     141            for (var i = 0; i < this.bullets.length; i++) { 
     142                this.bullets[i].next(); 
     143 
     144                if (this.bullets[i].vanished()) 
     145                    delIdx.push(i); 
     146            } 
     147            this.delBullet(delIdx); 
     148        } 
     149 
     150        // update/delete enemies' bullets 
     151        { 
     152            var hit = false; 
     153 
     154            for (var ei = 0; ei < enemies.length; ei++) { 
     155                var enemy  = enemies[ei]; 
     156                var delIdx = new Array(); 
     157 
     158                // judge/delete hit bullets 
     159                for (var i = 0; i < enemy.bullets.length; i++) { 
     160                    if (touch(this.x, this.y, this.hitSize, 
     161                              enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 
     162                        delIdx.push(i); 
     163                } 
     164 
     165                enemy.delBullet(delIdx); 
     166 
     167                if (delIdx.length > 0) 
     168                    hit = true; 
     169            } 
     170 
     171            // update my life 
     172            if (hit && this.life > 0) 
     173                this.life--; 
     174        } 
    158175    }; 
    159176 
Note: See TracChangeset for help on using the changeset viewer.