Changeset 106 for pycodeshooter/trunk


Ignore:
Timestamp:
01/26/11 02:40:22 (13 years ago)
Author:
atzm
Message:
  • fixed small bug
  • add bullet frame
  • parameter adjust
Location:
pycodeshooter/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/index.html

    r97 r106  
    120120                <input type="hidden" value="7"  id="shotsize" /> 
    121121                <input type="hidden" value="5"  id="shotspeed" /> 
    122                 <input type="hidden" value="10" id="shotinterval" /> 
     122                <input type="hidden" value="5" id="shotinterval" /> 
    123123                <input type="hidden" value="3"  id="shotlevel" /> 
    124124                <input type="hidden" value="/etc/pycodebattler/?mode=json" id="api" /> 
  • pycodeshooter/trunk/shooter/barrage.js

    r96 r106  
    1414 */ 
    1515 
    16 var Barrage = function(bullet, size, color, interval, speed, way, dir) { 
     16var Barrage = function(bullet, size, color, frame, interval, speed, way, dir) { 
    1717    this.bullet   = bullet; 
    1818    this.size     = size; 
    1919    this.color    = color; 
     20    this.frame    = frame; 
    2021    this.interval = interval; 
    2122    this.speed    = speed; 
     
    4445}; 
    4546 
    46 var LinerBarrage = function(bullet, size, color, interval, speed, way, dir) { 
    47     var that = new Barrage(bullet, size, color, interval, speed, way, dir); 
     47var LinerBarrage = function(bullet, size, color, frame, interval, speed, way, dir) { 
     48    var that = new Barrage(bullet, size, color, frame, interval, speed, way, dir); 
    4849 
    4950    that.state  = 0; 
     
    5556 
    5657        trooper.addBullet(this.bullet, this.size, this.color, 
    57                           this.posX(), this.posY(), 
     58                          this.frame, this.posX(), this.posY(), 
    5859                          dir * Math.PI, this.speed); 
    5960 
     
    6263 
    6364            trooper.addBullet(this.bullet, this.size, this.color, 
    64                               this.posX(), this.posY(), 
     65                              this.frame, this.posX(), this.posY(), 
    6566                              (dir - d) * Math.PI, this.speed); 
    6667            trooper.addBullet(this.bullet, this.size, this.color, 
    67                               this.posX(), this.posY(), 
     68                              this.frame, this.posX(), this.posY(), 
    6869                              (dir + d) * Math.PI, this.speed); 
    6970        } 
     
    7677}; 
    7778 
    78 var ArchBarrage = function(bullet, size, color, 
     79var ArchBarrage = function(bullet, size, color, frame, 
    7980                           interval, speed, way, dir, delta) { 
    8081 
    81     var that = new Barrage(bullet, size, color, interval, speed, way, dir); 
     82    var that = new Barrage(bullet, size, color, frame, interval, speed, way, dir); 
    8283 
    8384    that.delta = delta; 
    8485 
    85     if (that.way % 2) 
     86    if (!(that.way % 2)) 
    8687        that.way++; 
    8788 
     
    9495            return false; 
    9596 
    96         var angle = this.angle(trooper, enemy) - (this.delta * this.way / 2); 
     97        var angle = this.angle(trooper, enemy) - (this.delta * (this.way - 1) / 2); 
    9798 
    9899        for (var i = 0; i < this.way; i++) { 
    99100            trooper.addBullet(this.bullet, this.size, this.color, 
    100                               this.posX(), this.posY(), 
     101                              this.frame, this.posX(), this.posY(), 
    101102                              angle * Math.PI, this.speed); 
    102103            angle += this.delta; 
     
    110111}; 
    111112 
    112 var CircularBarrage = function(bullet, size, color, 
     113var CircularBarrage = function(bullet, size, color, frame, 
    113114                               interval, speed, way, dir) { 
    114     if (way % 2) 
    115         way++; 
    116  
    117     var that = new ArchBarrage(bullet, size, color, 
     115    var that = new ArchBarrage(bullet, size, color, frame, 
    118116                               interval, speed, way, dir, 2 / way); 
    119117    return that; 
    120 } 
    121  
    122 var DelayedArchBarrage = function(bullet, size, color, 
     118}; 
     119 
     120var DelayedArchBarrage = function(bullet, size, color, frame, 
    123121                                  interval, speed, way, dir, delta) { 
    124122 
    125     var that = new Barrage(bullet, size, color, interval, speed, way, dir); 
     123    var that = new Barrage(bullet, size, color, frame, interval, speed, way, dir); 
    126124 
    127125    that.delta = delta; 
    128126 
    129     if (that.way % 2) 
     127    if (!(that.way % 2)) 
    130128        that.way++; 
    131129 
     
    143141        if (this.curAngle == null) 
    144142            this.curAngle = this.angle(trooper, enemy) - 
    145                 this.delta * (this.way / 2); 
     143                this.delta * (this.way - 1) / 2; 
    146144 
    147145        trooper.addBullet(this.bullet, this.size, this.color, 
    148                           this.posX(), this.posY(), 
     146                          this.frame, this.posX(), this.posY(), 
    149147                          this.curAngle * Math.PI, this.speed); 
    150  
    151         this.curAngle += this.delta; 
    152148 
    153149        if (--this.remain <= 0) { 
    154150            return this.reset(); 
    155151        } 
     152 
     153        this.curAngle += this.delta; 
    156154 
    157155        return false; 
     
    167165}; 
    168166 
    169 var DelayedCircularBarrage = function(bullet, size, color, 
     167var DelayedCircularBarrage = function(bullet, size, color, frame, 
    170168                                      interval, speed, way, dir) { 
    171     if (way % 2) 
    172         way++; 
    173  
    174     var that = new DelayedArchBarrage(bullet, size, color, 
     169    var that = new DelayedArchBarrage(bullet, size, color, frame, 
    175170                                      interval, speed, way, dir, 2 / way); 
    176171    return that; 
    177172}; 
    178173 
    179 var DelayedRecursiveArchBarrage = function(bullet, size, color, 
     174var DelayedRecursiveArchBarrage = function(bullet, size, color, frame, 
    180175                                           interval, speed, way, dir, cnt) { 
    181176 
    182     var that = new DelayedArchBarrage(bullet, size, color, 
     177    var that = new DelayedArchBarrage(bullet, size, color, frame, 
    183178                                      interval, speed, way, dir); 
    184179 
     
    204199}; 
    205200 
    206 var DelayedRecursiveCircularBarrage = function(bullet, size, color, 
     201var DelayedRecursiveCircularBarrage = function(bullet, size, color, frame, 
    207202                                               interval, speed, way, dir, cnt) { 
    208203 
    209     var that = new DelayedCircularBarrage(bullet, size, color, 
     204    var that = new DelayedCircularBarrage(bullet, size, color, frame, 
    210205                                          interval, speed, way, dir); 
    211206 
     
    230225}; 
    231226 
    232 var MultiRounderBarrage = function(bullet, size, color, 
     227var MultiRounderBarrage = function(bullet, size, color, frame, 
    233228                                   interval, speed, way, dir, 
    234229                                   klass, radius, num) { 
     230    if (way < 3) 
     231        way = 3; 
     232 
    235233    if (radius == null) { 
    236         radius = size * way; 
     234        radius = size * way * 3; 
    237235        if (radius > 50) 
    238236            radius = 50; 
     
    240238 
    241239    if (num == null) 
    242         num = Math.ceil((1 / way) * 50); 
     240        num = Math.ceil((1 / way) * 5); 
    243241 
    244242    var start = 0.25; 
     
    251249 
    252250        for (var i = 0; i < num; i++) { 
    253             var b = new klass(bullet, size, color, 
     251            var b = new klass(bullet, size, color, frame, 
    254252                              interval, speed, w, dir); 
    255253 
     
    286284}; 
    287285 
    288 var MultiRounderArchBarrage = function(bullet, size, color, 
     286var MultiRounderArchBarrage = function(bullet, size, color, frame, 
    289287                                       interval, speed, way, dir) { 
    290     var that = new MultiRounderBarrage(bullet, size, color, interval, speed, 
    291                                        way, dir, ArchBarrage); 
    292     return that; 
    293 }; 
    294  
    295 var MultiRounderCircularBarrage = function(bullet, size, color, 
    296                                            interval, speed, way, dir) { 
    297     var that = new MultiRounderBarrage(bullet, size, color, interval, speed, 
    298                                        way, dir, CircularBarrage); 
    299     return that; 
    300 }; 
    301  
    302 var MultiRounderDelayedArchBarrage = function(bullet, size, color, 
     288    var that = new MultiRounderBarrage(bullet, size, color, frame, 
     289                                       interval, speed, way, dir, ArchBarrage); 
     290    return that; 
     291}; 
     292 
     293var MultiRounderDelayedArchBarrage = function(bullet, size, color, frame, 
    303294                                              interval, speed, way, dir) { 
    304     var that = new MultiRounderBarrage(bullet, size, color, interval, speed, 
    305                                        way, dir, DelayedArchBarrage); 
    306     return that; 
    307 }; 
    308  
    309 var MultiRounderDelayedCircularBarrage = function(bullet, size, color, 
    310                                                   interval, speed, way, dir) { 
    311     var that = new MultiRounderBarrage(bullet, size, color, interval, speed, 
    312                                        way, dir, DelayedCircularBarrage); 
    313     return that; 
    314 }; 
    315  
    316 var MultiRounderDelayedRecursiveArchBarrage = function(bullet, size, color, 
     295    var that = new MultiRounderBarrage(bullet, size, color, frame, 
     296                                       interval, speed, way, dir, DelayedArchBarrage); 
     297    return that; 
     298}; 
     299 
     300var MultiRounderDelayedRecursiveArchBarrage = function(bullet, size, color, frame, 
    317301                                                       interval, speed, way, dir) { 
    318     var that = new MultiRounderBarrage(bullet, size, color, interval, speed, 
    319                                        way, dir, DelayedRecursiveArchBarrage); 
    320     return that; 
    321 }; 
    322  
    323 var MultiRounderDelayedRecursiveCircularBarrage = function(bullet, size, color, 
    324                                                            interval, speed, way, dir) { 
    325     var that = new MultiRounderBarrage(bullet, size, color, interval, speed, 
    326                                        way, dir, DelayedRecursiveCircularBarrage); 
     302    var that = new MultiRounderBarrage(bullet, size, color, frame, 
     303                                       interval, speed, way, dir, DelayedRecursiveArchBarrage); 
    327304    return that; 
    328305}; 
     
    337314                     DelayedRecursiveCircularBarrage, 
    338315                     MultiRounderArchBarrage, 
    339                      MultiRounderCircularBarrage, 
    340316                     MultiRounderDelayedArchBarrage, 
    341                      MultiRounderDelayedCircularBarrage, 
    342                      MultiRounderDelayedRecursiveArchBarrage, 
    343                      MultiRounderDelayedRecursiveCircularBarrage]; 
     317                     MultiRounderDelayedRecursiveArchBarrage] 
  • pycodeshooter/trunk/shooter/bullet.js

    r105 r106  
    1414 */ 
    1515 
    16 var Bullet = function(size, color, x, y, dir, speed) { 
     16var Bullet = function(size, color, frame, x, y, dir, speed) { 
    1717    this.size  = size; 
    1818    this.color = color; 
     19    this.frame = frame; 
    1920    this.x     = x; 
    2021    this.y     = y; 
     
    2223    this.speed = speed; 
    2324 
     25    this.getSize = function() { 
     26        return this.size; 
     27    }; 
     28    this.getColor = function() { 
     29        return this.color; 
     30    }; 
     31    this.next = function() { 
     32        var pos = this.calcNext(); 
     33        this.x = pos[0]; 
     34        this.y = pos[1]; 
     35    }; 
     36    this.vanished = function(width, height) { 
     37        return (width < this.x || height < this.y || this.x < 0 || this.y < 0); 
     38    }; 
    2439    this.draw = function(ctx) { 
     40        if (this.frame) { 
     41            var pos = this.calcNext(); 
     42            var dir = Math.atan2(pos[0] - this.x, this.y - pos[1]); 
     43 
     44            ctx.save(); 
     45 
     46            if (this.frame.style == "rect") { 
     47                ctx.beginPath(); 
     48                ctx.strokeStyle = this.frame.color; 
     49                ctx.translate(this.x, this.y); 
     50                ctx.rotate(dir); 
     51                ctx.rect(-this.frame.width / 2, -this.frame.height / 2, 
     52                         this.frame.width, this.frame.height); 
     53                ctx.stroke(); 
     54                ctx.closePath(); 
     55            } 
     56 
     57            ctx.restore(); 
     58        } 
     59 
    2560        ctx.beginPath(); 
    2661        ctx.fillStyle = this.getColor(); 
     
    2964        ctx.closePath(); 
    3065    }; 
    31     this.vanished = function(width, height) { 
    32         return (width < this.x || height < this.y || this.x < 0 || this.y < 0); 
    33     }; 
    34     this.getSize = function() { 
    35         return this.size; 
    36     }; 
    37     this.getColor = function() { 
    38         return this.color; 
    39     }; 
    4066}; 
    4167 
    42 var LinerBullet = function(size, color, x, y, dir, speed) { 
    43     var that = new Bullet(size, color, x, y, dir, speed); 
     68var LinerBullet = function(size, color, frame, x, y, dir, speed) { 
     69    var that = new Bullet(size, color, frame, x, y, dir, speed); 
    4470 
    4571    that.deltaBaseX = Math.cos(that.dir); 
    4672    that.deltaBaseY = Math.sin(that.dir); 
    4773 
    48     that.next = function() { 
    49         this.x += this.getDeltaX(); 
    50         this.y += this.getDeltaY(); 
     74    that.calcNext = function() { 
     75        return [this.x + this.getDeltaX(), this.y + this.getDeltaY()]; 
    5176    }; 
    5277    that.getDeltaX = function() { 
     
    6085}; 
    6186 
    62 var AxisExtendBullet = function(size, color, x, y, dir, speed) { 
    63     var that = new LinerBullet(size, color, x, y, dir, speed); 
     87var AxisExtendBullet = function(size, color, frame, x, y, dir, speed) { 
     88    var that = new LinerBullet(size, color, frame, x, y, dir, speed); 
    6489 
    6590    that.dx = that.speed * that.deltaBaseX / 1.5; 
     
    80105}; 
    81106 
    82 var XYExtendBullet = function(size, color, x, y, dir, speed) { 
    83     var that = new AxisExtendBullet(size, color, x, y, dir, speed); 
     107var XYExtendBullet = function(size, color, frame, x, y, dir, speed) { 
     108    var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 
    84109 
    85110    that.i = 1; 
     
    94119}; 
    95120 
    96 var XExtendBullet = function(size, color, x, y, dir, speed) { 
    97     var that = new AxisExtendBullet(size, color, x, y, dir, speed); 
     121var XExtendBullet = function(size, color, frame, x, y, dir, speed) { 
     122    var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 
    98123 
    99124    that.i = 1; 
     
    108133}; 
    109134 
    110 var YExtendBullet = function(size, color, x, y, dir, speed) { 
    111     var that = new AxisExtendBullet(size, color, x, y, dir, speed); 
     135var YExtendBullet = function(size, color, frame, x, y, dir, speed) { 
     136    var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 
    112137 
    113138    that.i = 1; 
     
    122147}; 
    123148 
    124 var CurveBullet = function(size, color, x, y, dir, speed) { 
    125     var that = new Bullet(size, color, x, y, dir, speed); 
     149var CurveBullet = function(size, color, frame, x, y, dir, speed) { 
     150    var that = new Bullet(size, color, frame, x, y, dir, speed); 
    126151 
    127152    that.delta = 1 / (that.speed * 100); 
    128153    that.i     = 1; 
    129154 
    130     that.next = function() { 
    131         this.x   += Math.cos(this.dir) * this.i; 
    132         this.y   += Math.sin(this.dir) * this.i; 
     155    that.calcNext = function() { 
     156        var x = this.x + Math.cos(this.dir) * this.i; 
     157        var y = this.y + Math.sin(this.dir) * this.i; 
    133158        this.dir += (this.delta / this.i) * this.getSign(); 
    134159        this.i   += (this.delta / this.i); 
     160        return [x, y]; 
    135161    }; 
    136162 
     
    138164}; 
    139165 
    140 var LeftCurveBullet = function(size, color, x, y, dir, speed) { 
    141     var that = new CurveBullet(size, color, x, y, dir, speed); 
     166var LeftCurveBullet = function(size, color, frame, x, y, dir, speed) { 
     167    var that = new CurveBullet(size, color, frame, x, y, dir, speed); 
    142168 
    143169    that.getSign = function() { 
     
    148174}; 
    149175 
    150 var RightCurveBullet = function(size, color, x, y, dir, speed) { 
    151     var that = new CurveBullet(size, color, x, y, dir, speed); 
     176var RightCurveBullet = function(size, color, frame, x, y, dir, speed) { 
     177    var that = new CurveBullet(size, color, frame, x, y, dir, speed); 
    152178 
    153179    that.getSign = function() { 
  • pycodeshooter/trunk/shooter/system.js

    r104 r106  
    3535 */ 
    3636var DeathPiece = function(sizes, colors, x, y, dir, speed) { 
    37     var that = new LinerBullet(sizes[0], colors[0], x, y, dir, speed); 
     37    var that = new LinerBullet(sizes[0], colors[0], null, x, y, dir, speed); 
    3838 
    3939    var sizeIdx  = -1; 
     
    6464        var s = Math.ceil(Math.random() * 5); 
    6565        System.backgroundObject.push( 
    66             new LinerBullet(size, color, x, 0, 0.5 * Math.PI, s)); 
     66            new LinerBullet(size, color, null, x, 0, 0.5 * Math.PI, s)); 
    6767    } 
    6868 
     
    205205        System.screen.ctx, 
    206206        "source-over", 
    207         "rgba(8,8,8,0.5)", 
     207        "rgba(8,8,8,0.8)", 
    208208        System.screen.width, 
    209209        System.screen.height 
     
    300300        [new LinerBarrage(YExtendBullet, 
    301301                          playerData.shotsize, 
    302                           "#3FF", 
     302                          "rgba(64,64,128,0.7)", 
     303                          null, 
    303304                          playerData.shotinterval, 
    304305                          playerData.shotspeed, 
     
    307308         new LinerBarrage(YExtendBullet, 
    308309                          playerData.shotsize, 
    309                           "#3FF", 
     310                          "rgba(64,64,128,0.7)", 
     311                          null, 
    310312                          playerData.shotinterval, 
    311313                          playerData.shotspeed, 
     
    314316         new CircularBarrage(LinerBullet, 
    315317                          playerData.shotsize, 
    316                           "#3FF", 
     318                          "rgba(64,64,128,0.7)", 
     319                          null, 
    317320                          playerData.shotinterval, 
    318321                          playerData.shotspeed, 
     
    329332    var brrgs   = new Array(); 
    330333 
    331     setMessage(System.message, "ActionsIdx:"); 
     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:"); 
    332349 
    333350    for (var i = 0; i < numAct; i++) { 
     
    350367        for (var k = 0; k < numBlt; k++) { 
    351368            var iidx = (bossData.skills.length + i + k) % EnemyBullets.length; 
    352             var ss   = Math.log(bossData.luck * 15); 
    353             var sp   = bossData.strength / 15; 
    354             sp = sp < 1.5 ? 1.5 : sp; 
    355369            brrgs.push( 
    356370                new brrgCls( 
    357371                    EnemyBullets[iidx], 
    358                     ss < 3 ? 3 : ss, 
     372                    bulletSize, 
    359373                    "#FF3", 
    360                     200 * 1 / Math.log(bossData.skillpoint + 0.1), 
    361                     Math.log(sp), 
    362                     Math.ceil(bossData.concentration / 5) 
     374                    {"style": "rect", "color": "rgba(128,32,32,0.5)", 
     375                     "width": bulletFrameWidth, "height": bulletFrameHeight}, 
     376                    bulletInterval, 
     377                    bulletSpeed, 
     378                    bulletWay 
    363379                ) 
    364380            ); 
     
    370386    } 
    371387 
    372     var size = Math.ceil(50 * (1 / bossData.defense)); 
     388    var size = Math.ceil((System.screen.width / 2) * (1 / bossData.defense)); 
    373389    size = size < playerData.size ? playerData.size : size; 
    374390    System.boss = new Trooper( 
  • pycodeshooter/trunk/shooter/trooper.js

    r103 r106  
    163163            this.bomb.draw(ctx); 
    164164 
     165        // draw bullets 
     166        for (var i = 0; i < this.bullets.length; i++) 
     167            this.bullets[i].draw(ctx); 
     168 
    165169        // draw trooper 
    166170        ctx.beginPath(); 
     
    177181            ctx.closePath(); 
    178182        } 
    179  
    180         // draw bullets 
    181         for (var i = 0; i < this.bullets.length; i++) 
    182             this.bullets[i].draw(ctx); 
    183     }; 
    184  
    185     this.addBullet = function(bulletType, size, color, x, y, dir, speed) { 
     183    }; 
     184 
     185    this.addBullet = function(bulletType, size, color, frame, x, y, dir, speed) { 
    186186        this.bullets.push( 
    187             new bulletType(size, color, this.x + x, this.y + y, dir, speed)); 
     187            new bulletType(size, color, frame, this.x + x, this.y + y, dir, speed)); 
    188188    }; 
    189189 
Note: See TracChangeset for help on using the changeset viewer.