-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackingChromeDino.js
More file actions
62 lines (55 loc) · 1.37 KB
/
HackingChromeDino.js
File metadata and controls
62 lines (55 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Javascript AUTOMATED CHROME DINOUSAUR
function autoPlay()
{
// this.Obstacle.types[0]["minGap"] = 150;
// this.Obstacle.types[1]["minGap"] = 150;
setTimeout(function(){
myinstance = this.Runner.instance_;
myobstacles = myinstance.horizon.obstacles;
// myinstance.setSpeed(1999999990);
if(myinstance.tRex.ducking)
{
myinstance.tRex.setDuck(true);
}
if(myinstance.crashed)
{
console.log("Game over.")
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";
}
else if(obstacle_type=="PTERODACTYL")
{
if(myobstacles[0]["yPos"]==75 || myobstacles[0]["yPos"]==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");
curr_speed = myinstance.currentSpeed;
myinstance.tRex.startJump(curr_speed);
}
else if(action=="DUCK")
{
console.log("DUCKING");
myinstance.tRex.setDuck(true);
}
}
}
autoPlay();
},20)
}
console.log("Done, now start the game");
autoPlay();