| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 */ | 285 */ |
| 286 loadImages: function() { | 286 loadImages: function() { |
| 287 if (IS_HIDPI) { | 287 if (IS_HIDPI) { |
| 288 Runner.imageSprite = document.getElementById('offline-resources-2x'); | 288 Runner.imageSprite = document.getElementById('offline-resources-2x'); |
| 289 this.spriteDef = Runner.spriteDefinition.HDPI; | 289 this.spriteDef = Runner.spriteDefinition.HDPI; |
| 290 } else { | 290 } else { |
| 291 Runner.imageSprite = document.getElementById('offline-resources-1x'); | 291 Runner.imageSprite = document.getElementById('offline-resources-1x'); |
| 292 this.spriteDef = Runner.spriteDefinition.LDPI; | 292 this.spriteDef = Runner.spriteDefinition.LDPI; |
| 293 } | 293 } |
| 294 | 294 |
| 295 this.init(); | 295 if (Runner.imageSprite.complete) { |
| 296 this.init(); |
| 297 } else { |
| 298 // If the images are not yet loaded, add a listener. |
| 299 Runner.imageSprite.addEventListener(Runner.events.LOAD, |
| 300 this.init.bind(this)); |
| 301 } |
| 296 }, | 302 }, |
| 297 | 303 |
| 298 /** | 304 /** |
| 299 * Load and decode base 64 encoded sounds. | 305 * Load and decode base 64 encoded sounds. |
| 300 */ | 306 */ |
| 301 loadSounds: function() { | 307 loadSounds: function() { |
| 302 if (!IS_IOS) { | 308 if (!IS_IOS) { |
| 303 this.audioContext = new AudioContext(); | 309 this.audioContext = new AudioContext(); |
| 304 | 310 |
| 305 var resourceTemplate = | 311 var resourceTemplate = |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 if (IS_MOBILE && this.activated) { | 659 if (IS_MOBILE && this.activated) { |
| 654 e.preventDefault(); | 660 e.preventDefault(); |
| 655 } | 661 } |
| 656 | 662 |
| 657 if (e.target != this.detailsButton) { | 663 if (e.target != this.detailsButton) { |
| 658 if (!this.crashed && (Runner.keycodes.JUMP[e.keyCode] || | 664 if (!this.crashed && (Runner.keycodes.JUMP[e.keyCode] || |
| 659 e.type == Runner.events.TOUCHSTART)) { | 665 e.type == Runner.events.TOUCHSTART)) { |
| 660 if (!this.activated) { | 666 if (!this.activated) { |
| 661 this.loadSounds(); | 667 this.loadSounds(); |
| 662 this.activated = true; | 668 this.activated = true; |
| 663 errorPageController.trackEasterEgg(); | 669 if (window.errorPageController) { |
| 670 errorPageController.trackEasterEgg(); |
| 671 } |
| 664 } | 672 } |
| 665 | 673 |
| 666 if (!this.tRex.jumping && !this.tRex.ducking) { | 674 if (!this.tRex.jumping && !this.tRex.ducking) { |
| 667 this.playSound(this.soundFx.BUTTON_PRESS); | 675 this.playSound(this.soundFx.BUTTON_PRESS); |
| 668 this.tRex.startJump(this.currentSpeed); | 676 this.tRex.startJump(this.currentSpeed); |
| 669 } | 677 } |
| 670 } | 678 } |
| 671 | 679 |
| 672 if (this.crashed && e.type == Runner.events.TOUCHSTART && | 680 if (this.crashed && e.type == Runner.events.TOUCHSTART && |
| 673 e.currentTarget == this.containerEl) { | 681 e.currentTarget == this.containerEl) { |
| (...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2680 | 2688 |
| 2681 /** | 2689 /** |
| 2682 * Add a new cloud to the horizon. | 2690 * Add a new cloud to the horizon. |
| 2683 */ | 2691 */ |
| 2684 addCloud: function() { | 2692 addCloud: function() { |
| 2685 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, | 2693 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, |
| 2686 this.dimensions.WIDTH)); | 2694 this.dimensions.WIDTH)); |
| 2687 } | 2695 } |
| 2688 }; | 2696 }; |
| 2689 })(); | 2697 })(); |
| OLD | NEW |