Created
August 23, 2025 06:16
-
-
Save mathgeniuszach/be9ffb16382fdd53d01deac0f9a54ed7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Some code using python's curses library to obtain banana | |
| # Released into the Public Domain and CC0 | |
| import curses | |
| import time | |
| FPS = 60 | |
| bananas = 0 | |
| banana_cooldown = 0 | |
| def init(window): | |
| window.addstr(0, 0, "Press space to obtain banana") | |
| window.refresh() | |
| def update(window, dt): | |
| global banana_cooldown | |
| window.addstr(1, 0, f"{bananas} banana") | |
| window.refresh() | |
| if banana_cooldown > 0: | |
| banana_cooldown -= dt | |
| def event(window, ch): | |
| global bananas, banana_cooldown | |
| if ch == ord(" "): | |
| if banana_cooldown <= 0: | |
| bananas += 1 | |
| banana_cooldown = 0.1 | |
| def main(window): | |
| try: | |
| window.timeout(0) | |
| frame_time = 1 / FPS | |
| start_time = time.monotonic() | |
| init(window) | |
| old_time = time.monotonic() | |
| while True: | |
| time.sleep(frame_time - (time.monotonic() - start_time) % frame_time) | |
| new_time = time.monotonic() | |
| while (ch := window.getch()) > -1: | |
| event(window, ch) | |
| update(window, new_time - old_time) | |
| old_time = new_time | |
| except KeyboardInterrupt: | |
| pass | |
| if __name__ == "__main__": | |
| curses.wrapper(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment