Changeset 130 for pycodeshooter/trunk/shooter
- Timestamp:
- 05/02/12 20:56:24 (13 years ago)
- Location:
- pycodeshooter/trunk/shooter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/shooter/bullet.js
r115 r130 39 39 return (width < this.x || height < this.y || this.x < 0 || this.y < 0); 40 40 }; 41 this.draw = function(ctx ) {41 this.draw = function(ctx, func) { 42 42 if (this.frame) { 43 43 var pos = this.calcNext(); … … 61 61 62 62 ctx.beginPath(); 63 ctx.fillStyle = this.getColor(); 64 ctx.arc(this.x, this.y, this.getSize(), 0, Math.PI * 2.0, true); 65 ctx.fill(); 63 if (func) { 64 func(this, ctx); 65 } 66 else { 67 ctx.fillStyle = this.getColor(); 68 ctx.arc(this.x, this.y, this.getSize(), 0, Math.PI * 2.0, true); 69 ctx.fill(); 70 } 66 71 ctx.closePath(); 67 72 }; -
pycodeshooter/trunk/shooter/system.js
r129 r130 30 30 "backgroundObject": new Array(), 31 31 "deathPieces": new Array(), 32 "items": new Array(), 32 33 "mainIntervalId": 0 33 34 }; … … 95 96 96 97 System.deathPieces = newObjs; 98 } 99 100 101 /* 102 * Item Utilities 103 */ 104 function addItem(x, y, angle, size, color, speed, attrs) { 105 var frame = {"style": "rect", "color": attrs.color, "width": size * 2, "height": size * 2}; 106 var item = new YExtendBullet(size, color, frame, 107 System.screen.width, System.screen.height, 108 x, y, angle * Math.PI, speed); 109 item.attrs = attrs; 110 System.items.push(item); 111 } 112 113 function updateItems(ctx, width, height, troopers) { 114 var newObjs = new Array(); 115 116 ITEMLOOP: 117 for (var i = 0; i < System.items.length; i++) { 118 var item = System.items[i]; 119 120 item.next(); 121 item.draw(ctx, function(bullet, ctx) { 122 drawString( 123 ctx, "source-over", item.attrs.symbol, 124 bullet.x, bullet.y, 125 item.attrs.color, item.size + "pt monospace", "center" 126 ); 127 }); 128 129 for (var j = 0; j < troopers.length; j++) { 130 var trooper = troopers[j]; 131 132 if (touch(trooper.x, trooper.y, trooper.size, item.x, item.y, item.size)) { 133 switch (item.attrs.type) { 134 case "score": 135 playSound("se_item_score"); 136 if (System.score[trooper.name] !== undefined) 137 System.score[trooper.name] += item.attrs.quantity; 138 break; 139 case "shot": 140 playSound("se_item_shot"); 141 for (var k = 0; k < trooper.barrages.length; k++) { 142 trooper.barrages[k].way += item.attrs.quantity; 143 if (trooper.barrages[k].way >= 10) 144 trooper.barrages[k].way = 10; 145 } 146 break; 147 case "bomb": 148 playSound("se_item_bomb"); 149 trooper.numBombs += item.attrs.quantity; 150 break; 151 case "life": 152 playSound("se_item_life"); 153 trooper.life += item.attrs.quantity; 154 break; 155 } 156 157 continue ITEMLOOP; 158 } 159 } 160 161 if (!item.vanished(width, height)) 162 newObjs.push(item); 163 } 164 165 System.items = newObjs; 97 166 } 98 167 … … 355 424 [6, 8, 10], ["#F55", "#FAA"], 3, 8 356 425 ); 426 427 var itemAttr; 428 var itemRand = Math.floor(Math.random() * 100); 429 if (itemRand < 40) { 430 // nothing 431 } 432 else if (itemRand < 75) { 433 itemAttr = {"color": "#AAF", "symbol": "S", "type": "score", "quantity": enemy.maxLife * 200}; 434 } 435 else if (itemRand < 95) { 436 itemAttr = {"color": "#FAA", "symbol": "P", "type": "shot", "quantity": 1}; 437 } 438 else if (itemRand < 98) { 439 itemAttr = {"color": "#FFA", "symbol": "B", "type": "bomb", "quantity": 1}; 440 } 441 else { 442 itemAttr = {"color": "#AFA", "symbol": "L", "type": "life", "quantity": 1}; 443 } 444 445 if (itemAttr) 446 addItem(enemy.x, enemy.y, 0.5, 5, "#AFA", 1, itemAttr); 357 447 } 358 448 else { … … 396 486 "STAGE " + getStageNumber(), 397 487 System.screen.width - 10, 398 System.screen.height -15,488 15, 399 489 "#ACF", "9pt monospace", "right" 400 490 ); … … 409 499 name + " SCORE " + System.score[name], 410 500 (System.screen.width - 10), 411 i * 16 + 15,501 i * 16 + 30, 412 502 "#ACF", "9pt monospace", "right" 413 503 ); 414 504 } 505 506 // update/draw items 507 updateItems(System.screen.ctx, 508 System.screen.width, 509 System.screen.height, 510 System.players); 415 511 416 512 // update/draw troopers … … 436 532 (System.screen.height - 23) - (i * 33), 437 533 "#ACF", "9pt monospace", "left" 534 ); 535 536 drawString( 537 System.screen.ctx, 538 "source-over", 539 "BOMB " + player.numBombs, 540 (System.screen.width - 10), 541 (System.screen.height - 23) - (i * 33), 542 "#ACF", "9pt monospace", "right" 438 543 ); 439 544 } … … 522 627 playerData.shotlevel, 523 628 -0.5), 524 new LinerBarrage( YExtendBullet,629 new LinerBarrage(LinerBullet, 525 630 playerData.shotsize, 526 631 "rgba(64,64,128,0.7)", … … 529 634 playerData.shotspeed, 530 635 playerData.shotlevel, 531 0.5),532 new CircularBarrage(LinerBullet,533 playerData.shotsize,534 "rgba(64,64,128,0.7)",535 null,536 playerData.shotinterval,537 playerData.shotspeed,538 playerData.shotlevel + 2,539 636 -0.5)] 540 637 ); … … 554 651 trooper.x = System.screen.width / 2; 555 652 trooper.y = System.screen.height - System.screen.height / 7; 653 trooper.numBombs = playerData.numbombs; 654 trooper.barrages = [ 655 new LinerBarrage(YExtendBullet, 656 playerData.shotsize, 657 "rgba(64,64,128,0.7)", 658 null, 659 playerData.shotinterval, 660 playerData.shotspeed, 661 playerData.shotlevel, 662 -0.5), 663 new LinerBarrage(LinerBullet, 664 playerData.shotsize, 665 "rgba(64,64,128,0.7)", 666 null, 667 playerData.shotinterval, 668 playerData.shotspeed, 669 playerData.shotlevel, 670 -0.5) 671 ]; 556 672 }); 557 673
Note: See TracChangeset
for help on using the changeset viewer.