Ignore:
Timestamp:
01/18/12 00:01:24 (12 years ago)
Author:
atzm
Message:

imaging support

Location:
pycodeshooter/trunk/shooter
Files:
2 edited

Legend:

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

    r108 r109  
    2222    }, 
    2323    "message":          null, 
     24    "enemyImages":      new Array(), 
    2425    "enemies":          new Array(), 
    2526    "players":          new Array(), 
     
    194195} 
    195196 
     197function addEnemyImage(image) { 
     198    System.enemyImages.push(image); 
     199} 
     200 
    196201function addEnemy(enemyData) { 
    197202    var actList = EnemyActionLists[enemyData.mtime % EnemyActionLists.length]; 
     
    242247        enemyData.name, 
    243248        new actList(acts), 
     249        System.enemyImages[enemyData.hitpoint % System.enemyImages.length], 
    244250        size, 
    245251        size, 
     
    373379        playerData.name, 
    374380        new ActionList([new ManualAction(new ManualShot())]), 
     381        playerData.image, 
    375382        playerData.size, 
    376383        playerData.hitsize, 
  • pycodeshooter/trunk/shooter/trooper.js

    r108 r109  
    7171}; 
    7272 
    73 var Trooper = function(name, actList, size, hitSize, color, hitColor, 
     73var Trooper = function(name, actList, image, size, hitSize, color, hitColor, 
    7474                       x, y, w, h, life, speed, numBombs, bombColors, barrages) { 
    7575 
     
    7878    this.name       = name; 
    7979    this.actList    = actList; 
     80    this.image      = image; 
    8081    this.size       = size; 
    8182    this.hitSize    = hitSize; 
     
    185186 
    186187        // draw trooper 
    187         ctx.beginPath(); 
    188         ctx.fillStyle = this.color; 
    189         ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2.0, true); 
    190         ctx.fill(); 
    191         ctx.closePath(); 
    192  
     188        if (this.image) { 
     189            var w = this.image.width * (this.size / this.image.height); 
     190            var h = this.size; 
     191            var x = this.x - (w / 2); 
     192            var y = this.y - (h / 2); 
     193            ctx.drawImage(this.image, x, y, w, h); 
     194        } 
     195        else { 
     196            ctx.beginPath(); 
     197            ctx.fillStyle = this.color; 
     198            ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2.0, true); 
     199            ctx.fill(); 
     200            ctx.closePath(); 
     201        } 
     202 
     203        // draw hit area 
    193204        if (this.color != this.hitColor || this.size != this.hitSize) { 
    194205            ctx.beginPath(); 
Note: See TracChangeset for help on using the changeset viewer.