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 | SnailBait.prototype = { ... createSnailSprites: function () { var snail, snailArtist = new SpriteSheetArtist(this.spritesheet, this.snailCells); for (var i = 0; i < this.snailData.length; ++i) { snail = new Sprite('snail', snailArtist, [ this.paceBehavior, this.snailShootBehavior, new CycleBehavior(300, // 300ms per image 1500) // 1.5 seconds between sequences ]); snail.width = this.SNAIL_CELLS_WIDTH; snail.height = this.SNAIL_CELLS_HEIGHT; snail.velocityX = this.SNAIL_PACE_VELOCITY; snail.direction = this.RIGHT; this.snails.push(snail); // Push snail onto snails array } }, }; |
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 | SnailBait.prototype = { ... armSnails: function () { var snail, snailBombArtist = new SpriteSheetArtist(this.spritesheet, this.snailBombCells); for (var i=0; i < this.snails.length; ++i) { snail = this.snails; snail.bomb = new Sprite('snail bomb', snailBombArtist, [ this.snailBombMoveBehavior ]); snail.bomb.width = snailBait.SNAIL_BOMB_CELLS_WIDTH; snail.bomb.height = snailBait.SNAIL_BOMB_CELLS_HEIGHT; snail.bomb.top = snail.top + snail.bomb.height/2; snail.bomb.left = snail.left + snail.bomb.width/2; snail.bomb.visible = false; this.sprites.push(snail.bomb); } }, }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | SnailBait.prototype = { ... this.snailShootBehavior = { // sprite is the snail execute: function (sprite, time, fps) { var bomb = sprite.bomb; if (! bomb.visible && sprite.artist.cellIndex === 2) { bomb.left = sprite.left; bomb.visible = true; } } }, }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | SnailBait = function () { this.SNAIL_BOMB_VELOCITY = 450, ... }; SnailBait.prototype = { this.snailBombMoveBehavior = { execute: function(sprite, time, fps) { // sprite is the bomb if (sprite.visible && snailBait.spriteInView(sprite)) { sprite.left -= snailBait.SNAIL_BOMB_VELOCITY / fps; } if (!snailBait.spriteInView(sprite)) { sprite.visible = false; } } }, |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |