| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 (function() { | 4 (function() { |
| 5 'use strict'; | 5 'use strict'; |
| 6 /** | 6 /** |
| 7 * T-Rex runner. | 7 * T-Rex runner. |
| 8 * @param {string} outerContainerId Outer containing element id. | 8 * @param {string} outerContainerId Outer containing element id. |
| 9 * @param {Object} opt_config | 9 * @param {Object} opt_config |
| 10 * @constructor | 10 * @constructor |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 this.status = Trex.status.WAITING; | 1489 this.status = Trex.status.WAITING; |
| 1490 | 1490 |
| 1491 this.jumping = false; | 1491 this.jumping = false; |
| 1492 this.ducking = false; | 1492 this.ducking = false; |
| 1493 this.jumpVelocity = 0; | 1493 this.jumpVelocity = 0; |
| 1494 this.reachedMinHeight = false; | 1494 this.reachedMinHeight = false; |
| 1495 this.speedDrop = false; | 1495 this.speedDrop = false; |
| 1496 this.jumpCount = 0; | 1496 this.jumpCount = 0; |
| 1497 this.jumpspotX = 0; | 1497 this.jumpspotX = 0; |
| 1498 | 1498 |
| 1499 this.count = 0; |
| 1500 |
| 1499 this.init(); | 1501 this.init(); |
| 1500 }; | 1502 }; |
| 1501 | 1503 |
| 1502 | 1504 |
| 1503 /** | 1505 /** |
| 1504 * T-rex player config. | 1506 * T-rex player config. |
| 1505 * @enum {number} | 1507 * @enum {number} |
| 1506 */ | 1508 */ |
| 1507 Trex.config = { | 1509 Trex.config = { |
| 1508 DROP_VELOCITY: -5, | 1510 DROP_VELOCITY: -5, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 this.currentFrame = 0; | 1628 this.currentFrame = 0; |
| 1627 this.msPerFrame = Trex.animFrames[opt_status].msPerFrame; | 1629 this.msPerFrame = Trex.animFrames[opt_status].msPerFrame; |
| 1628 this.currentAnimFrames = Trex.animFrames[opt_status].frames; | 1630 this.currentAnimFrames = Trex.animFrames[opt_status].frames; |
| 1629 | 1631 |
| 1630 if (opt_status == Trex.status.WAITING) { | 1632 if (opt_status == Trex.status.WAITING) { |
| 1631 this.animStartTime = getTimeStamp(); | 1633 this.animStartTime = getTimeStamp(); |
| 1632 this.setBlinkDelay(); | 1634 this.setBlinkDelay(); |
| 1633 } | 1635 } |
| 1634 } | 1636 } |
| 1635 | 1637 |
| 1638 // Count to 3: once at the Trex creation, once at the runner.update() and |
| 1639 // once for the first frame update using requestAnimationFrame |
| 1640 if(this.count < 3) { |
| 1641 this.count++; |
| 1642 this.draw(0, 0); |
| 1643 } |
| 1644 |
| 1636 // Game intro animation, T-rex moves in from the left. | 1645 // Game intro animation, T-rex moves in from the left. |
| 1637 if (this.playingIntro && this.xPos < this.config.START_X_POS) { | 1646 if (this.playingIntro && this.xPos < this.config.START_X_POS) { |
| 1638 this.xPos += Math.round((this.config.START_X_POS / | 1647 this.xPos += Math.round((this.config.START_X_POS / |
| 1639 this.config.INTRO_DURATION) * deltaTime); | 1648 this.config.INTRO_DURATION) * deltaTime); |
| 1640 } | 1649 } |
| 1641 | 1650 |
| 1642 if (this.status == Trex.status.WAITING) { | 1651 if (this.status == Trex.status.WAITING) { |
| 1643 this.blink(getTimeStamp()); | 1652 this.blink(getTimeStamp()); |
| 1644 } else { | 1653 } else { |
| 1645 this.draw(this.currentAnimFrames[this.currentFrame], 0); | 1654 this.draw(this.currentAnimFrames[this.currentFrame], 0); |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2681 | 2690 |
| 2682 /** | 2691 /** |
| 2683 * Add a new cloud to the horizon. | 2692 * Add a new cloud to the horizon. |
| 2684 */ | 2693 */ |
| 2685 addCloud: function() { | 2694 addCloud: function() { |
| 2686 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, | 2695 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, |
| 2687 this.dimensions.WIDTH)); | 2696 this.dimensions.WIDTH)); |
| 2688 } | 2697 } |
| 2689 }; | 2698 }; |
| 2690 })(); | 2699 })(); |
| OLD | NEW |