-
Notifications
You must be signed in to change notification settings - Fork 0
/
dino-bot.js
175 lines (151 loc) · 6.49 KB
/
dino-bot.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
(function() {
let previousSpeed = 0;
let duckTimeoutId;
let jumpsCount = 0;
let ducksCount = 0;
function getNearestObstacle() {
let obstacles = Runner.instance_.horizon.obstacles;
return obstacles.length > 0 ? obstacles[0] : null;
}
function checkForObstacles() {
let obstacle = getNearestObstacle();
let tRex = Runner.instance_.tRex;
if (obstacle) {
let tRexBottomPos = tRex.yPos + tRex.config.HEIGHT;
let speed = 13; // Set the speed to 13
if (speed !== previousSpeed) {
previousSpeed = speed;
}
if (isObstacleClose(obstacle, tRex, speed)) {
if (shouldJump(obstacle, tRex, tRexBottomPos)) {
simulateJump(speed);
} else if (shouldDuck(obstacle, tRex, tRexBottomPos)) {
simulateDuck(speed);
} else {
stopDuck();
}
}
}
}
function shouldJump(obstacle, tRex, tRexBottomPos) {
let type = obstacle.typeConfig.type;
return (type === 'CACTUS_SMALL' || type === 'CACTUS_LARGE' || (type === 'PTERODACTYL' && obstacle.yPos > tRexBottomPos - 60)) && !tRex.jumping;
}
function shouldDuck(obstacle, tRex, tRexBottomPos) {
let type = obstacle.typeConfig.type;
return type === 'PTERODACTYL' && obstacle.yPos < tRexBottomPos - 60;
}
function isObstacleClose(obstacle, tRex, speed) {
let distance = obstacle.xPos - tRex.xPos;
let earlyJumpOffset = speed > 8 ? -30 : 0;
if (speed > 10) earlyJumpOffset = -40;
if (speed > 12) earlyJumpOffset = -50;
return distance < (100 + speed * 2 - earlyJumpOffset);
}
function simulateJump(speed) {
let tRex = Runner.instance_.tRex;
if (!tRex.jumping && !tRex.ducking) {
let jumpDelay = Math.max(0, 250 - speed * 20);
setTimeout(() => {
triggerKeyEvent(38);
jumpsCount++;
updateCountText();
}, jumpDelay);
}
}
function simulateDuck(speed) {
let tRex = Runner.instance_.tRex;
if (!tRex.jumping && !tRex.ducking) {
let duckDelay = Math.max(0, 250 - speed * 20);
setTimeout(() => {
triggerKeyEvent(40);
ducksCount++;
updateCountText();
let duckDuration = 500;
clearTimeout(duckTimeoutId);
duckTimeoutId = setTimeout(stopDuck, duckDuration);
}, duckDelay);
}
}
function stopDuck() {
triggerKeyEvent(40, 'keyup');
}
function triggerKeyEvent(keyCode, eventType = 'keydown') {
let event = new KeyboardEvent(eventType, {
bubbles: true,
cancelable: true,
keyCode: keyCode,
});
document.dispatchEvent(event);
}
function checkForGameOver() {
if (Runner.instance_.crashed) {
Runner.instance_.restart();
}
}
// Add the text overlays
function addTextOverlay() {
let overlayContainer = document.createElement('div');
overlayContainer.id = 'overlay-container';
overlayContainer.style.position = 'absolute';
overlayContainer.style.top = '10px';
overlayContainer.style.left = '50%';
overlayContainer.style.transform = 'translateX(-50%)';
overlayContainer.style.zIndex = '9999';
overlayContainer.style.textAlign = 'center';
let textDiv = document.createElement('div');
textDiv.id = 'like-comment-subscribe';
textDiv.style.fontSize = '24px';
textDiv.style.fontWeight = 'bold';
textDiv.style.color = 'white';
textDiv.style.textShadow = '0 0 10px #ff0000, 0 0 20px #ff0000, 0 0 30px #ff0000';
textDiv.style.animation = 'neon-glow 2s infinite alternate, text-fade 2s infinite';
let countDiv = document.createElement('div');
countDiv.id = 'jump-duck-count';
countDiv.style.fontSize = '18px';
countDiv.style.fontWeight = 'bold';
countDiv.style.color = 'white';
countDiv.style.textShadow = '0 0 10px #ff0000, 0 0 20px #ff0000, 0 0 30px #ff0000';
countDiv.style.animation = 'neon-glow 2s infinite alternate, text-fade 2s infinite';
let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
@keyframes neon-glow {
0% { text-shadow: 0 0 10px #ff0000, 0 0 20px #ff0000, 0 0 30px #ff0000; }
10% { text-shadow: 0 0 10px #ff8000, 0 0 20px #ff8000, 0 0 30px #ff8000; }
20% { text-shadow: 0 0 10px #ffff00, 0 0 20px #ffff00, 0 0 30px #ffff00; }
30% { text-shadow: 0 0 10px #80ff00, 0 0 20px #80ff00, 0 0 30px #80ff00; }
40% { text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00, 0 0 30px #00ff00; }
50% { text-shadow: 0 0 10px #00ff80, 0 0 20px #00ff80, 0 0 30px #00ff80; }
60% { text-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff, 0 0 30px #00ffff; }
70% { text-shadow: 0 0 10px #0080ff, 0 0 20px #0080ff, 0 0 30px #0080ff; }
80% { text-shadow: 0 0 10px #0000ff, 0 0 20px #0000ff, 0 0 30px #0000ff; }
90% { text-shadow: 0 0 10px #8000ff, 0 0 20px #8000ff, 0 0 30px #8000ff; }
100% { text-shadow: 0 0 10px #ff00ff, 0 0 20px #ff00ff, 0 0 30px #ff00ff; }
}
`;
document.head.appendChild(style);
overlayContainer.appendChild(textDiv);
overlayContainer.appendChild(countDiv);
document.body.appendChild(overlayContainer);
let texts = ["LIKE", "COMMENT", "SUBSCRIBE","https://github.com/zufarrizal/Chrome-Dino/"];
let textIndex = 0;
function changeText() {
textDiv.textContent = texts[textIndex];
textIndex = (textIndex + 1) % texts.length;
}
setInterval(changeText, 1000);
}
function updateCountText() {
let countDiv = document.getElementById('jump-duck-count');
countDiv.textContent = `Jumps: ${jumpsCount}, Ducks: ${ducksCount}`;
}
addTextOverlay();
let obstacleIntervalId = setInterval(checkForObstacles, 25);
let gameOverIntervalId = setInterval(checkForGameOver, 100);
// Override the game's speed to make it static at 13
Object.defineProperty(Runner.instance_, 'currentSpeed', {
get: function() { return 13; },
set: function() {}
});
})();