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 | SnailBait.prototype = { ... this.RUNNER_JUMP_HEIGHT = 120, // pixels this.RUNNER_JUMP_DURATION = 1000, // milliseconds equipRunnerForJumping: function () { this.runner.JUMP_HEIGHT = this.RUNNER_JUMP_HEIGHT; this.runner.JUMP_DURATION = this.RUNNER_JUMP_DURATION; this.runner.jumping = false; this.runner.ascendStopwatch = new Stopwatch(this.runner.JUMP_DURATION/2); this.runner.descendStopwatch = new Stopwatch(this.runner.JUMP_DURATION/2); this.runner.jump = function () { if (this.jumping) // 'this' is the runner return; this.jumping = true; this.runAnimationRate = 0; // Freeze the runner while jumping this.verticalLaunchPosition = this.top; this.ascendStopwatch.start(); }; }, equipRunner: function () { ... this.equipRunnerForJumping(); }, ... }; |
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 | var SnailBait = function () { this.jumpBehavior = { ... execute: function(sprite, context, time, fps) { if ( ! sprite.jumping) { return; } if (this.isJumpOver(sprite)) { sprite.jumping = false; return; } if (this.isAscending(sprite)) { if ( ! this.isDoneAscending(sprite)) this.ascend(sprite); else this.finishAscent(sprite); } else if (this.isDescending(sprite)) { if ( ! this.isDoneDescending(sprite)) this.descend(sprite); else this.finishDescent(sprite); } } }, ... |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |