Changeset 114 for pycodeshooter


Ignore:
Timestamp:
01/21/12 04:46:57 (13 years ago)
Author:
atzm
Message:
  • add bullet patterns, xreflect series
Location:
pycodeshooter/trunk/shooter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/shooter/bullet.js

    r106 r114  
    1414 */ 
    1515 
    16 var Bullet = function(size, color, frame, x, y, dir, speed) { 
     16var Bullet = function(size, color, frame, w, h, x, y, dir, speed) { 
    1717    this.size  = size; 
    1818    this.color = color; 
    1919    this.frame = frame; 
     20    this.w     = w; 
     21    this.h     = h; 
    2022    this.x     = x; 
    2123    this.y     = y; 
     
    6668}; 
    6769 
    68 var LinerBullet = function(size, color, frame, x, y, dir, speed) { 
    69     var that = new Bullet(size, color, frame, x, y, dir, speed); 
     70var LinerBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     71    var that = new Bullet(size, color, frame, w, h, x, y, dir, speed); 
    7072 
    7173    that.deltaBaseX = Math.cos(that.dir); 
     
    8587}; 
    8688 
    87 var AxisExtendBullet = function(size, color, frame, x, y, dir, speed) { 
    88     var that = new LinerBullet(size, color, frame, x, y, dir, speed); 
     89var XReflectLinerBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     90    var that  = new LinerBullet(size, color, frame, w, h, x, y, dir, speed); 
     91    var count = 0; 
     92 
     93    that.calcNext = function() { 
     94        var x = this.x + this.getDeltaX(); 
     95        var y = this.y + this.getDeltaY(); 
     96 
     97        if ((0 >= x || x >= this.w) && count < 5) { 
     98            count++; 
     99            this.dir += (2 - this.dir) - (this.dir - 1); 
     100            this.deltaBaseX = Math.cos(this.dir); 
     101            this.deltaBaseY = Math.sin(this.dir); 
     102            x = this.x + this.getDeltaX(); 
     103            y = this.y + this.getDeltaY(); 
     104        } 
     105 
     106        return [x, y]; 
     107    }; 
     108 
     109    return that; 
     110} 
     111 
     112var AxisExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     113    var that = new LinerBullet(size, color, frame, w, h, x, y, dir, speed); 
    89114 
    90115    that.dx = that.speed * that.deltaBaseX / 1.5; 
     
    105130}; 
    106131 
    107 var XYExtendBullet = function(size, color, frame, x, y, dir, speed) { 
    108     var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 
     132var XYExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     133    var that = new AxisExtendBullet(size, color, frame, w, h, x, y, dir, speed); 
    109134 
    110135    that.i = 1; 
     
    119144}; 
    120145 
    121 var XExtendBullet = function(size, color, frame, x, y, dir, speed) { 
    122     var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 
     146var XExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     147    var that = new AxisExtendBullet(size, color, frame, w, h, x, y, dir, speed); 
    123148 
    124149    that.i = 1; 
     
    133158}; 
    134159 
    135 var YExtendBullet = function(size, color, frame, x, y, dir, speed) { 
    136     var that = new AxisExtendBullet(size, color, frame, x, y, dir, speed); 
     160var YExtendBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     161    var that = new AxisExtendBullet(size, color, frame, w, h, x, y, dir, speed); 
    137162 
    138163    that.i = 1; 
     
    147172}; 
    148173 
    149 var CurveBullet = function(size, color, frame, x, y, dir, speed) { 
    150     var that = new Bullet(size, color, frame, x, y, dir, speed); 
     174var CurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     175    var that = new Bullet(size, color, frame, w, h, x, y, dir, speed); 
    151176 
    152177    that.delta = 1 / (that.speed * 100); 
    153178    that.i     = 1; 
    154179 
     180    that.getDir = function() { 
     181        return this.dir; 
     182    }; 
    155183    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; 
     184        var d = this.getDir(); 
     185        var x = this.x + Math.cos(d) * this.i; 
     186        var y = this.y + Math.sin(d) * this.i; 
    158187        this.dir += (this.delta / this.i) * this.getSign(); 
    159188        this.i   += (this.delta / this.i); 
     
    164193}; 
    165194 
    166 var LeftCurveBullet = function(size, color, frame, x, y, dir, speed) { 
    167     var that = new CurveBullet(size, color, frame, x, y, dir, speed); 
     195var LeftCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     196    var that = new CurveBullet(size, color, frame, w, h, x, y, dir, speed); 
    168197 
    169198    that.getSign = function() { 
     
    174203}; 
    175204 
    176 var RightCurveBullet = function(size, color, frame, x, y, dir, speed) { 
    177     var that = new CurveBullet(size, color, frame, x, y, dir, speed); 
     205var RightCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     206    var that = new CurveBullet(size, color, frame, w, h, x, y, dir, speed); 
    178207 
    179208    that.getSign = function() { 
     
    184213}; 
    185214 
     215var XReflectLeftCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     216    var that  = new LeftCurveBullet(size, color, frame, w, h, x, y, dir, speed); 
     217    var count = 0; 
     218 
     219    that.getDir = function() { 
     220        var x = this.x + Math.cos(this.dir) * this.i; 
     221        var y = this.y + Math.sin(this.dir) * this.i; 
     222 
     223        if ((0 >= x || x >= this.w) && count < 5) { 
     224            count++; 
     225            this.dir += (2 - this.dir) - (this.dir - 1); 
     226        } 
     227 
     228        return this.dir; 
     229    }; 
     230 
     231    return that; 
     232}; 
     233 
     234var XReflectRightCurveBullet = function(size, color, frame, w, h, x, y, dir, speed) { 
     235    var that  = new RightCurveBullet(size, color, frame, w, h, x, y, dir, speed); 
     236    var count = 0; 
     237 
     238    that.getDir = function() { 
     239        var x = this.x + Math.cos(this.dir) * this.i; 
     240        var y = this.y + Math.sin(this.dir) * this.i; 
     241 
     242        if ((0 >= x || x >= this.w) && count < 5) { 
     243            count++; 
     244            this.dir += (2 - this.dir) - (this.dir - 1); 
     245        } 
     246 
     247        return this.dir; 
     248    }; 
     249 
     250    return that; 
     251}; 
    186252 
    187253var EnemyBullets = [LinerBullet, 
     254                    XReflectLinerBullet, 
    188255                    XYExtendBullet, 
    189256                    XExtendBullet, 
    190257                    YExtendBullet, 
    191258                    LeftCurveBullet, 
    192                     RightCurveBullet]; 
     259                    RightCurveBullet, 
     260                    XReflectLeftCurveBullet, 
     261                    XReflectRightCurveBullet]; 
  • pycodeshooter/trunk/shooter/system.js

    r112 r114  
    3636 */ 
    3737var DeathPiece = function(sizes, colors, x, y, dir, speed) { 
    38     var that = new LinerBullet(sizes[0], colors[0], null, x, y, dir, speed); 
     38    var that = new LinerBullet(sizes[0], colors[0], null, 
     39                               System.screen.width, System.screen.height, 
     40                               x, y, dir, speed); 
    3941 
    4042    var sizeIdx  = -1; 
     
    112114        var s = Math.ceil(Math.random() * 5); 
    113115        System.backgroundObject.push( 
    114             new LinerBullet(size, color, null, x, 0, 0.5 * Math.PI, s)); 
     116            new LinerBullet(size, color, null, 
     117                            System.screen.width, System.screen.height, 
     118                            x, 0, 0.5 * Math.PI, s)); 
    115119    } 
    116120 
  • pycodeshooter/trunk/shooter/trooper.js

    r113 r114  
    214214    this.addBullet = function(bulletType, size, color, frame, x, y, dir, speed) { 
    215215        this.bullets.push( 
    216             new bulletType(size, color, frame, this.x + x, this.y + y, dir, speed)); 
     216            new bulletType(size, color, frame, this.w, this.h, this.x + x, this.y + y, dir, speed)); 
    217217    }; 
    218218 
Note: See TracChangeset for help on using the changeset viewer.