Making the chrome dino game play itself using Javascript
source link: https://dev.to/official_fire/making-the-chrome-dino-game-play-itself-using-javascript-2j8n
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hello, guys in today's blog we are gonna hack chrome dino ( automating it ) using javascript
Chrome dino game is made by Google. this game is available in chromium based browsers like brave, chrome, edge and other browsers out there
you can play this game by turning off your internet/wifi or going to chrome://dino
😊
Anyways lets automate it
Watch this video to get better understanding
https://www.youtube.com/watch?v=r0b4j8JUVUc&t=236s
first we make a function with the name autoPlay()
Note (these are the objects in the chrome dino game) :-
------ DINO ------
tRex - Is the DINO
------ CACTUS ------
CACTUS_SMALL - is the smallest cactus
CACTUS_LARGE - is the largest cactus
------ BIRD ------
The name of the bird is pretty hard 🤣
PTERODACTYL - the bird
In the code i have given comments and tried to explain you each line of code :)
function autoplay() {
setTimeout(function () {
myinstance = this.Runner.instance_;
myobstacles = myinstance.horizon.obstacles;
// if my tRex is ducking then
if (myinstance.tRex.ducking) {
// make my tRex to duck
myinstance.tRex.setDuck(true);
}
if (myinstance.crashed) {
// When the game is over then
console.log("Game Over... Paste the code again to automate the game");
return;
}
if (myobstacles.length > 0) {
action = "JUMP";
obstacle_type = myobstacles[0]["typeConfig"]["type"];
// Defining which action to perform if it match the following cases
if (obstacle_type == "CACTUS_SMALL" || obstacle_type == "CACTUS_LARGE") {
action = "JUMP";
// i know its a hard name ( actually PTERODACTYL its the bird )
} else if (obstacle_type == "PTERODACTYL") {
if (myobstacles[0]["yPost"] == 75 || myobstacles[0]["yPost"] == 50)
action = "DUCK";
}
// Making the action work
if (myobstacles[0].xPos <= 100) {
console.log(myobstacles[0]);
// Perform the action
if (action == "JUMP") {
console.log("Jumping.. Yahoo");
// we get the current speed of our dino
curr_speed = myinstance.currentSpeed;
// then making it jump
myinstance.tRex.startJump(curr_speed);
} else if (action == "DUCK") {
console.log("Ducking.. Oo");
myinstance.tRex.setDuck(true);
}
}
}
autoplay();
// setting the timer for 20 mili seconds
}, 20);
}
console.log('Done.. Automated the game, Now Start')
autoplay();
And Voila! we are done 😀👍 so i hope you guys enjoyed this blog and had fun! Have a nice day and be safe guys 💖
Dont forget to subscribe to my youtube channel for more amazing videos - https://youtube.com/codingfire?sub_confirmation=1
Recommend
-
47
Whack a Dino(Game) | Made of HTML, CSS and JavaScript Whack a Dino Hey guys, in this post i am here with a Simple game that ...
-
9
1. IntroductionI am taking the invitation of Hackernoon to have a writing contest on the topic of decentralization.0 reactionsDecentralization is a dear topic for me as I work on a decentralization proje...
-
8
扫码领取奖励更多详情链小象(CFOR)未来可兑换比特币、以太坊、瑞波、EOS等区块链资产;链向财经合作区块链项目资产;链向财经应用内的增值产品和服务、链向财经主办活动的奖品。
-
5
Snyk Team Welcoming Dino DiMarino: The first Snyk Chief Revenue Officer
-
2
SpandyBoss Posted on Nov 23...
-
3
Dino. Communicating happiness. Dino 0.3 Release Video calls and conferences - encrypted and peer-to-peer Sat Feb 12, 2022 · 4 min read ·...
-
6
Oraichain Launches Rebranded DINO Hub To Transform The Web3 Creator Economy With Data & AI June 1, 2022
-
2
TelevisionPower Rangers is Going Cosmic Again, and It's Bringing Back the Dino Fury TeamGetting shades of Mighty...
-
1
1. 融合效果# 融合效果是指对两个接近的元素进行高斯模糊后再提高对比度,使它们看上去“粘”在一起。在之前的
-
4
How To Add Google Chrome's Dino-Game Widget To Your Android Home Screen ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK