Skip to content

Instantly share code, notes, and snippets.

@opentechnologist
Created October 15, 2020 05:50
Show Gist options
  • Save opentechnologist/0a4403c31c7e557cea6bf1a45d4cc031 to your computer and use it in GitHub Desktop.
Save opentechnologist/0a4403c31c7e557cea6bf1a45d4cc031 to your computer and use it in GitHub Desktop.
a snippet to override the game over method of the offline built-in t-rex game.
/*
source code: https://source.chromium.org/chromium/chromium/src/+/master:components/neterror/resources/offline.js
paste into address bar: chrome://dino/
then before starting game, press F12 to open the Chrome developer console
and then paste this code snippet to override the game's gameOver() method.
enjoy!
~Bu
*/
Runner.instance_.gameOver = () => {
context = Runner.instance_;
// do not stop the game, just penalize the player.
const penalize = () => {
// hitting obstacle should slow down dinosaur.
const baseSpeed = context.config.SPEED / 2;
if (context.currentSpeed > baseSpeed) {
context.currentSpeed -= baseSpeed;
context.currentSpeed *= ((100 - 5) / 100); // 5% reduction.
context.currentSpeed += baseSpeed;
}
// penalty is set at 10 distance run per 100 whole distance run laps.
const cost = 10;
const lap = 100;
penalty = Math.floor(context.distanceRan / lap) * cost;
context.distanceRan -= penalty;
};
// hit immunity for a certain period of time.
const currentTime = (new Date).getTime();
if ((context.immunityTimeout ?? 0) < currentTime) {
context.playSound(context.soundFx.HIT);
vibrate(200);
penalize(); // penalize first, then let the immunity take effect.
const immunityTimeout = currentTime + (1 * 1000); // 1 second immunity
context.immunityTimeout = immunityTimeout;
// TODO: set a timer instead to periodically save the highscore.
if (context.distanceRan > context.highestScore) {
context.saveHighScore(context.distanceRan);
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment