Ignore:
Timestamp:
01/17/12 01:34:00 (12 years ago)
Author:
atzm
Message:
  • multi enemies support
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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; 
Note: See TracChangeset for help on using the changeset viewer.