![CleanShot 2024-04-26 at 21 05 31@2x](https://private-user-images.githubusercontent.com/3931017/326038587-72430e14-a34f-4c63-9fec-16266799a352.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3NzcwNzQsIm5iZiI6MTcyMTc3Njc3NCwicGF0aCI6Ii8zOTMxMDE3LzMyNjAzODU4Ny03MjQzMGUxNC1hMzRmLTRjNjMtOWZlYy0xNjI2Njc5OWEzNTIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjNUMjMxOTM0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NWZjZTU0YWM2MDE1MmVhZWMzODY3OTI1YzA0OGJhYzQ2ZmI3ZTJjYjEzOGFhMTA1YzJkMGYyYzFlNzZkZGQ2MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.EttzHtAVRbvTXEsa6aUP5BbJ1ZF3iZw1RO_T0PSrkrU)
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.