
Remember to change the query selector before running the script in your browser.
- Game Character = sleeping emoji
- Obstacle = Notification emoji
Here's what each part of the code does:
Configuration:
- It knows that the sleeping emoji is always 50 pixels from the left side of the screen.
- It is set to make the sleeping emoji jump when the obstacle is 70 pixels away from it — this is like seeing something coming and deciding when to jump to avoid it.
- It checks the position of the obstacle every 100 milliseconds, which is pretty quick (ten times a second).
Starting the Game Automation:
- It starts its watch, constantly checking for obstacles.
- If it sees an obstacle getting too close (less than 70 pixels away), it tells the sleeping emoji to jump.
- It keeps watching and jumping as needed, repeating this check every 100 milliseconds.
Jumping:
- When it's time to jump, the code sends a signal as if the "up arrow" key on your keyboard was pressed, which is the command for the emoji to jump.
Stopping and Starting:
- The code will keep playing the game non-stop, but if you want to take a break and stop it, you press the "Escape" key on your keyboard.
- Pressing the "Escape" key again will make the robot start playing the game again.