Skip to content

Instantly share code, notes, and snippets.

@BillyDoesDev
Last active February 27, 2022 04:22
Show Gist options
  • Save BillyDoesDev/657be0827bb3a3c522814ab07c8ba40c to your computer and use it in GitHub Desktop.
Save BillyDoesDev/657be0827bb3a3c522814ab07c8ba40c to your computer and use it in GitHub Desktop.
Chrome dino game clone.. in python3!
# Controls: `space` to jump
import curses
import random
from curses import wrapper
def gen_path() -> str:
path = "_" * 50 + "".join(
[
"______∆____"
if random.randint(0, 100) % 3 == 0
else "_______∆∆____"
if random.randint(0, 100) % 5 == 0
else "______∆∆∆____"
if random.randint(0, 100) % 6 == 0
else "_______"
for i in range(100)
]
)
return path
def main(stdscr):
curses.use_default_colors()
game_win = curses.newwin(7, 71, 2, 1)
stdscr.refresh()
path = gen_path()
height = 6
jump_started = False
jumps = 0
status_win = curses.newwin(1, 70, 1, 1)
ded = False
score = 0
while not ded:
curses.noecho()
curses.curs_set(0)
game_win.nodelay(True)
for i in range(len(path)):
game_win.erase()
status_win.erase()
game_win.addstr(6, 0, (path[i:] + path[:i])[:70])
curr_path = path[i:] + path[:i]
if not jump_started:
if game_win.getch() == 32:
jump_started = True
if jump_started:
if jumps == 0:
height = 5
jumps += 1
elif jumps == 1:
height = 4
jumps += 1
elif jumps == 2:
height = 3
jumps += 1
elif jumps == 3:
height = 4
jumps += 1
elif jumps == 4:
height = 5
jumps += 1
else:
height = 6
jumps = 0
jump_started = False
game_win.addch(height, 6, "▅")
status_win.addstr(f"Score: {score}", curses.A_BOLD)
status_win.refresh()
game_win.refresh()
score += 1
curses.napms(40)
if height == 6 and curr_path[6] == "∆":
ded = True
status_win.erase()
status_win.addstr(f"Score: {score}", curses.A_BOLD)
status_win.refresh()
game_over_win = curses.newwin(2, 20, 3, 25)
game_over_win.addstr(0, 6, "u is ded", curses.A_BOLD)
game_over_win.addstr(1, 8, "lmao")
game_over_win.refresh()
game_win.nodelay(False)
curses.curs_set(1)
curses.echo()
menu_win = curses.newwin(2, 50, 10, 1)
menu_win.addstr("Enter R to play again or X to exit: ")
menu_win.refresh()
choice = menu_win.getstr().decode("utf-8").strip().lower()
if choice == "r":
ded = False
score = 0
path = gen_path()
menu_win.erase()
menu_win.refresh()
break
wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment