Changeset 92 for pycodeshooter


Ignore:
Timestamp:
01/12/11 18:39:31 (13 years ago)
Author:
atzm
Message:

bomb support

Location:
pycodeshooter/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/index.html

    r84 r92  
    2525            "shotinterval": parseInt(document.getElementById("shotinterval").value), 
    2626            "shotspeed":    parseInt(document.getElementById("shotspeed").value), 
    27             "shotlevel":    parseInt(document.getElementById("shotlevel").value) 
     27            "shotlevel":    parseInt(document.getElementById("shotlevel").value), 
     28            "numbombs":     parseInt(document.getElementById("numbombs").value) 
    2829        }; 
    2930 
     
    110111                耐习
    111112性: <input type="text" value="15" size="3" id="hitpoint" /> 
     113                ボム数: <input type="text" value="2" size="3" id="numbombs" /> 
    112114                <br /> 
    113115                <canvas id="screen" width="320" height="480"></canvas> 
     
    138140          <dt>■ ショット:</dt> 
    139141          <dd>z</dd> 
     142          <dt>■ ボム:</dt> 
     143          <dd>a</dd> 
    140144          <dt>■ 移動速床遠
    141145延:</dt> 
  • pycodeshooter/trunk/shooter/action.js

    r81 r92  
    2121const ACTION_DELAY  = 32; 
    2222const SWITCH_BULLET = 1; 
     23const SWITCH_BOMB   = 2; 
    2324var   currentAction = 0; 
    2425var   currentSwitch = 0; 
     
    5758function getSwitchByCharCode(charCode) { 
    5859    switch(charCode) { 
     60    case 97:  // a 
     61        return SWITCH_BOMB; 
    5962    case 99:  // c 
    6063        return SWITCH_BULLET; 
     
    106109                this.index = 0; 
    107110            unsetSwitch(SWITCH_BULLET); 
     111        } 
     112        if (isSetSwitch(SWITCH_BOMB)) { 
     113            trooper.addBomb(); 
     114            unsetSwitch(SWITCH_BOMB); 
    108115        } 
    109116        if (isInAction(ACTION_SHOT)) 
  • pycodeshooter/trunk/shooter/system.js

    r84 r92  
    233233        playerData.hitpoint, 
    234234        playerData.speed, 
     235        playerData.numbombs, 
    235236        [new LinerBarrage(YExtendBullet, 
    236237                          playerData.shotsize, 
     
    313314        bossData.hitpoint, 
    314315        Math.log(bossData.agility + 0.1) * 3, 
     316        0, 
    315317        brrgs 
    316318    ); 
  • pycodeshooter/trunk/shooter/trooper.js

    r81 r92  
    1414 */ 
    1515 
     16function touch(x1, y1, s1, x2, y2, s2) { 
     17    var dx = Math.pow(x2 - x1, 2); 
     18    var dy = Math.pow(y2 - y1, 2); 
     19    if (Math.sqrt(dx + dy) < s1 + s2) 
     20        return true; 
     21    return false; 
     22} 
     23 
     24var Bomb = function(x, y, w, h, size, speed, colors) { 
     25    this.x      = x; 
     26    this.y      = y; 
     27    this.w      = w; 
     28    this.h      = h; 
     29    this.size   = size; 
     30    this.speed  = speed; 
     31    this.colors = colors; 
     32    this.colIdx = 0; 
     33 
     34    this.update = function(enemy) { 
     35        this.size += this.speed; 
     36 
     37        // judge bullet 
     38        var delIdx = new Array(); 
     39        for (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--; 
     49    }; 
     50 
     51    this.draw = function(ctx) { 
     52        ctx.beginPath(); 
     53        ctx.fillStyle = this.colors[this.colIdx]; 
     54        ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2.0, true); 
     55        ctx.fill(); 
     56        ctx.closePath(); 
     57 
     58        if (++this.colIdx >= this.colors.length) 
     59            this.colIdx = 0; 
     60    }; 
     61 
     62    this.vanished = function() { 
     63        if (this.size > this.w && this.size > this.h) 
     64            return true; 
     65        return false; 
     66    }; 
     67}; 
     68 
    1669var Trooper = function(name, actList, size, color, x, y, w, h, 
    17                        life, speed, barrages) { 
     70                       life, speed, numBombs, barrages) { 
    1871 
    1972    this.bullets  = new Array(); 
     73    this.bomb     = null; 
    2074    this.name     = name; 
    2175    this.actList  = actList; 
     
    2882    this.life     = life; 
    2983    this.speed    = speed; 
     84    this.numBombs = numBombs; 
    3085    this.barrages = barrages; 
    3186 
     
    66121        this.actList.update(this, enemy); 
    67122 
     123        // update bomb 
     124        if (this.bomb) { 
     125            this.bomb.update(enemy); 
     126            if (this.bomb.vanished()) 
     127                this.bomb = null; 
     128        } 
     129 
    68130        // update/delete my bullets 
    69131        delIdx = new Array(); 
     
    79141        delIdx = new Array(); 
    80142        for (i = 0; i < enemy.bullets.length; i++) { 
    81             var dx = Math.pow(enemy.bullets[i].x - this.x, 2); 
    82             var dy = Math.pow(enemy.bullets[i].y - this.y, 2); 
    83  
    84             if (Math.sqrt(dx + dy) < this.size + enemy.bullets[i].size) 
     143            if (touch(this.x, this.y, this.size, 
     144                      enemy.bullets[i].x, enemy.bullets[i].y, enemy.bullets[i].size)) 
    85145                delIdx.push(i); 
    86146        } 
    87         enemy.delBullet(delIdx) 
     147        enemy.delBullet(delIdx); 
    88148 
    89149        // update life 
     
    93153 
    94154    this.draw = function(ctx) { 
     155        // draw bomb 
     156        if (this.bomb) 
     157            this.bomb.draw(ctx); 
     158 
    95159        // draw trooper 
    96160        ctx.beginPath(); 
     
    125189        this.bullets = newBullets; 
    126190    }; 
     191 
     192    this.addBomb = function() { 
     193        if (!this.bomb && this.numBombs > 0) { 
     194            this.bomb = new Bomb(this.x, this.y, this.w, this.h, this.size * 2, 10, 
     195                                 ["rgba(255,0,0,0.3)", "rgba(0,0,255,0.3)"]); 
     196            this.numBombs--; 
     197        } 
     198    }; 
    127199} 
Note: See TracChangeset for help on using the changeset viewer.