Changeset 95 for pycodeshooter/trunk


Ignore:
Timestamp:
01/17/11 20:28:17 (13 years ago)
Author:
atzm
Message:

tiun tiun

Location:
pycodeshooter/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pycodeshooter/trunk/index.html

    r93 r95  
    175175          <li>敵/自機に画像ずか</li> 
    176176          <li>メニュヌを䜕ずかする</li> 
    177           <li>撃砎/ダメヌゞ/死亡時動䜜を凝る</li> 
     177          <li>ダメヌゞ時動䜜を凝る</li> 
    178178        </ul> 
    179179 
  • pycodeshooter/trunk/shooter/bullet.js

    r81 r95  
    2424    this.draw = function(ctx) { 
    2525        ctx.beginPath(); 
    26         ctx.fillStyle = this.color; 
    27         ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2.0, true); 
     26        ctx.fillStyle = this.getColor(); 
     27        ctx.arc(this.x, this.y, this.getSize(), 0, Math.PI * 2.0, true); 
    2828        ctx.fill(); 
    2929        ctx.closePath(); 
     
    3131    this.vanished = function(width, height) { 
    3232        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; 
    3339    }; 
    3440}; 
  • pycodeshooter/trunk/shooter/system.js

    r92 r95  
    2525    "player":           null, 
    2626    "backgroundObject": new Array(), 
     27    "deathPieces":      new Array(), 
     28    "gameOver":         false, 
    2729    "mainIntervalId":   0 
     30}; 
     31 
     32 
     33/* 
     34 *  Tiun Tiun 
     35 */ 
     36var DeathPiece = function(sizes, colors, x, y, dir, speed) { 
     37    var that = new LinerBullet(sizes[0], colors[0], x, y, dir, speed); 
     38 
     39    var sizeIdx  = -1; 
     40    var colorIdx = -1; 
     41 
     42    that.getSize = function() { 
     43        if (++sizeIdx >= sizes.length) 
     44            sizeIdx = 0; 
     45        return sizes[sizeIdx]; 
     46    }; 
     47 
     48    that.getColor = function() { 
     49        if (++colorIdx >= colors.length) 
     50            colorIdx = 0; 
     51        return colors[colorIdx]; 
     52    }; 
     53 
     54    return that; 
    2855}; 
    2956 
     
    4875    } 
    4976    System.backgroundObject = newObjs; 
     77} 
     78 
     79function 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 (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; 
    50104} 
    51105 
     
    97151} 
    98152 
     153function 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 
    99188function setMessage(elem, msg) { 
    100189    if (elem) 
     
    129218    ); 
    130219 
    131     // update troopers 
    132     System.player.update(System.boss); 
    133     System.boss.update(System.player); 
    134  
    135     // draw troopers 
    136     System.player.draw(System.screen.ctx); 
    137     System.boss.draw(System.screen.ctx); 
     220    // update/draw troopers 
     221    updateTrooper(System.player, System.boss); 
     222    updateTrooper(System.boss, System.player); 
    138223 
    139224    // draw player name/life 
     
    169254        System.screen.width 
    170255    ); 
    171  
    172     // is dead? 
    173     if (System.player.isDead()) { 
    174         drawString( 
    175             System.screen.ctx, "source-over", 
    176             "YOU LOST", 
    177             System.screen.width / 2, 
    178             System.screen.height / 2, 
    179             "#FCA", "24pt monospace", "center" 
    180         ); 
    181         clearInterval(System.mainIntervalId); 
    182         System.mainIntervalId = 0; 
    183     } 
    184  
    185     if (System.boss.isDead()) { 
    186         drawString( 
    187             System.screen.ctx, "source-over", 
    188             "YOU WON", 
    189             System.screen.width / 2, 
    190             System.screen.height / 2, 
    191             "#ACF", "24pt monospace", "center" 
    192         ); 
    193         clearInterval(System.mainIntervalId); 
    194         System.mainIntervalId = 0; 
    195     } 
    196256} 
    197257 
     
    206266    System.screen.width  = System.screen.canvas.width; 
    207267    System.screen.height = System.screen.canvas.height; 
     268    System.gameOver      = false; 
    208269 
    209270    System.screen.ctx.globalCompositeOperation = "lighter"; 
  • pycodeshooter/trunk/shooter/trooper.js

    r92 r95  
    190190    }; 
    191191 
     192    this.clearBullet = function() { 
     193        this.bullets = new Array(); 
     194    }; 
     195 
    192196    this.addBomb = function() { 
    193197        if (!this.bomb && this.numBombs > 0) { 
Note: See TracChangeset for help on using the changeset viewer.