Chromium Code Reviews| 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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 } | 651 } |
| 652 }, | 652 }, |
| 653 | 653 |
| 654 /** | 654 /** |
| 655 * Process keydown. | 655 * Process keydown. |
| 656 * @param {Event} e | 656 * @param {Event} e |
| 657 */ | 657 */ |
| 658 onKeyDown: function(e) { | 658 onKeyDown: function(e) { |
| 659 // Prevent native page scrolling whilst tapping on mobile. | 659 // Prevent native page scrolling whilst tapping on mobile. |
| 660 if (IS_MOBILE && this.playing) { | 660 if (IS_MOBILE && this.playing) { |
| 661 e.preventDefault(); | 661 e.preventDefault(); |
|
mmenke
2017/03/20 15:11:28
Is this the right thing to do if e.target == this.
edwardjung
2017/03/21 18:51:21
Yes, as during game play you don't want to be acci
| |
| 662 } | 662 } |
| 663 | 663 |
| 664 if (e.target != this.detailsButton) { | 664 if (!this.paused) { |
|
mmenke
2017/03/20 15:11:28
Exactly what line are you trying to skip here? I
edwardjung
2017/03/21 18:51:21
this.update();
As the delta time is calculated wh
| |
| 665 if (!this.crashed && (Runner.keycodes.JUMP[e.keyCode] || | 665 if (e.target != this.detailsButton) { |
| 666 e.type == Runner.events.TOUCHSTART)) { | 666 if (!this.crashed && (Runner.keycodes.JUMP[e.keyCode] || |
| 667 if (!this.playing) { | 667 e.type == Runner.events.TOUCHSTART)) { |
| 668 this.loadSounds(); | 668 if (!this.playing) { |
| 669 this.playing = true; | 669 this.loadSounds(); |
| 670 this.update(); | 670 this.playing = true; |
| 671 if (window.errorPageController) { | 671 this.update(); |
| 672 errorPageController.trackEasterEgg(); | 672 if (window.errorPageController) { |
| 673 errorPageController.trackEasterEgg(); | |
| 674 } | |
| 675 } | |
| 676 // Play sound effect and jump on starting the game for the first time. | |
| 677 if (!this.tRex.jumping && !this.tRex.ducking) { | |
| 678 this.playSound(this.soundFx.BUTTON_PRESS); | |
| 679 this.tRex.startJump(this.currentSpeed); | |
| 673 } | 680 } |
| 674 } | 681 } |
| 675 // Play sound effect and jump on starting the game for the first time. | 682 |
| 676 if (!this.tRex.jumping && !this.tRex.ducking) { | 683 if (this.crashed && e.type == Runner.events.TOUCHSTART && |
| 677 this.playSound(this.soundFx.BUTTON_PRESS); | 684 e.currentTarget == this.containerEl) { |
| 678 this.tRex.startJump(this.currentSpeed); | 685 this.restart(); |
| 679 } | 686 } |
| 680 } | 687 } |
| 681 | 688 |
| 682 if (this.crashed && e.type == Runner.events.TOUCHSTART && | 689 if (this.playing && !this.crashed && Runner.keycodes.DUCK[e.keyCode]) { |
| 683 e.currentTarget == this.containerEl) { | 690 e.preventDefault(); |
| 684 this.restart(); | 691 if (this.tRex.jumping) { |
| 685 } | 692 // Speed drop, activated only when jump key is not pressed. |
| 686 } | 693 this.tRex.setSpeedDrop(); |
| 687 | 694 } else if (!this.tRex.jumping && !this.tRex.ducking) { |
| 688 if (this.playing && !this.crashed && Runner.keycodes.DUCK[e.keyCode]) { | 695 // Duck. |
| 689 e.preventDefault(); | 696 this.tRex.setDuck(true); |
| 690 if (this.tRex.jumping) { | 697 } |
| 691 // Speed drop, activated only when jump key is not pressed. | |
| 692 this.tRex.setSpeedDrop(); | |
| 693 } else if (!this.tRex.jumping && !this.tRex.ducking) { | |
| 694 // Duck. | |
| 695 this.tRex.setDuck(true); | |
| 696 } | 698 } |
| 697 } | 699 } |
| 698 }, | 700 }, |
| 699 | 701 |
| 700 | 702 |
| 701 /** | 703 /** |
| 702 * Process key up. | 704 * Process key up. |
| 703 * @param {Event} e | 705 * @param {Event} e |
| 704 */ | 706 */ |
| 705 onKeyUp: function(e) { | 707 onKeyUp: function(e) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 this.time = getTimeStamp(); | 807 this.time = getTimeStamp(); |
| 806 this.update(); | 808 this.update(); |
| 807 } | 809 } |
| 808 }, | 810 }, |
| 809 | 811 |
| 810 restart: function() { | 812 restart: function() { |
| 811 if (!this.raqId) { | 813 if (!this.raqId) { |
| 812 this.playCount++; | 814 this.playCount++; |
| 813 this.runningTime = 0; | 815 this.runningTime = 0; |
| 814 this.playing = true; | 816 this.playing = true; |
| 817 this.paused = false; | |
| 815 this.crashed = false; | 818 this.crashed = false; |
| 816 this.distanceRan = 0; | 819 this.distanceRan = 0; |
| 817 this.setSpeed(this.config.SPEED); | 820 this.setSpeed(this.config.SPEED); |
| 818 this.time = getTimeStamp(); | 821 this.time = getTimeStamp(); |
| 819 this.containerEl.classList.remove(Runner.classes.CRASHED); | 822 this.containerEl.classList.remove(Runner.classes.CRASHED); |
| 820 this.clearCanvas(); | 823 this.clearCanvas(); |
| 821 this.distanceMeter.reset(this.highestScore); | 824 this.distanceMeter.reset(this.highestScore); |
| 822 this.horizon.reset(); | 825 this.horizon.reset(); |
| 823 this.tRex.reset(); | 826 this.tRex.reset(); |
| 824 this.playSound(this.soundFx.BUTTON_PRESS); | 827 this.playSound(this.soundFx.BUTTON_PRESS); |
| (...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2691 | 2694 |
| 2692 /** | 2695 /** |
| 2693 * Add a new cloud to the horizon. | 2696 * Add a new cloud to the horizon. |
| 2694 */ | 2697 */ |
| 2695 addCloud: function() { | 2698 addCloud: function() { |
| 2696 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, | 2699 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, |
| 2697 this.dimensions.WIDTH)); | 2700 this.dimensions.WIDTH)); |
| 2698 } | 2701 } |
| 2699 }; | 2702 }; |
| 2700 })(); | 2703 })(); |
| OLD | NEW |