1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var SnailBait = function (canvasId) { // constructor ... this.bats = [], this.bees = [], this.buttons = [], this.coins = [], this.platforms = [], this.rubies = [], this.sapphires = [], this.snails = [], this.runner = new Sprite('runner', this.runnerArtist); this.sprites = [ this.runner ]; // Add other sprites later ... }; |
1 2 3 4 5 6 7 8 9 | SnailBait.prototype = { // methods ... start: function () { this.createSprites(); this.initializeImages(); this.equipRunner(); this.splashToast('Good Luck!'); }, }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | SnailBait.prototype = { // methods ... createSprites: function() { this.createPlatformSprites(); this.createBatSprites(); this.createBeeSprites(); this.createButtonSprites(); this.createCoinSprites(); this.createRubySprites(); this.createSapphireSprites(); this.createSnailSprites(); this.initializeSprites(); this.addSpritesToSpriteArray(); }, |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | SnailBait.prototype = { // methods ... createBatSprites: function () { var bat, batArtist = new SpriteSheetArtist(this.spritesheet, this.batCells), redEyeBatArtist = new SpriteSheetArtist(this.spritesheet, this.batRedEyeCells); for (var i = 0; i < this.batData.length; ++i) { if (i % 2 === 0) bat = new Sprite('bat', batArtist); else bat = new Sprite('bat', redEyeBatArtist); bat.width = this.BAT_CELLS_WIDTH; bat.height = this.BAT_CELLS_HEIGHT; this.bats.push(bat); } }, createBeeSprites: function () { var bee, beeArtist = new SpriteSheetArtist(this.spritesheet, this.beeCells); for (var i = 0; i < this.beeData.length; ++i) { bee = new Sprite('bee', beeArtist); bee.width = this.BEE_CELLS_WIDTH; bee.height = this.BEE_CELLS_HEIGHT; this.bees.push(bee); } }, createButtonSprites: function () { var button, buttonArtist = new SpriteSheetArtist(this.spritesheet, this.buttonCells), goldButtonArtist = new SpriteSheetArtist(this.spritesheet, this.goldButtonCells); for (var i = 0; i < this.buttonData.length; ++i) { if (i === this.buttonData.length - 1) { button = new Sprite('button', goldButtonArtist); } else { button = new Sprite('button', buttonArtist); } button.width = this.BUTTON_CELLS_WIDTH; button.height = this.BUTTON_CELLS_HEIGHT; button.velocityX = this.BUTTON_PACE_VELOCITY; button.direction = this.RIGHT; this.buttons.push(button); } }, createCoinSprites: function () { var coin, coinArtist = new SpriteSheetArtist(this.spritesheet, this.coinCells); for (var i = 0; i < this.coinData.length; ++i) { coin = new Sprite('coin', coinArtist); coin.width = this.COIN_CELLS_WIDTH; coin.height = this.COIN_CELLS_HEIGHT; this.coins.push(coin); } }, createPlatformSprites: function () { var sprite, pd; // Sprite, Platform data for (var i=0; i < this.platformData.length; ++i) { pd = this.platformData; sprite = new Sprite('platform-' + i, this.platformArtist); sprite.left = pd.left; sprite.width = pd.width; sprite.height = pd.height; sprite.fillStyle = pd.fillStyle; sprite.opacity = pd.opacity; sprite.track = pd.track; sprite.button = pd.button; sprite.pulsate = pd.pulsate; sprite.power = pd.power; sprite.top = this.calculatePlatformTop(pd.track); this.platforms.push(sprite); } }, createSapphireSprites: function () { // Listing omitted for brevity. Discussed in the next article in this series. }, createRubySprites: function () { // Listing omitted for brevity. Discussed in the next article in this series. }, createSnailSprites: function () { // Listing omitted for brevity. Discussed in the next article in this series. }, }; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |