-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflappbat_C.py
69 lines (67 loc) · 1.74 KB
/
flappbat_C.py
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
# Flappy Bat (C) 2024 by Mikael O. Bonnier, Lund, Sweden. License: GPLv3+.
# Run using: python3 flappbat_C.py
from time import *
from random import *
import curses
from curses import wrapper
from atco_s import *
def main(stdscr):
curses.curs_set(False)
stdscr.nodelay(False)
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
# Example: curses.color_pair(1) | curses.A_BOLD | curses.REVERSE
curses.init_pair(2,curses.COLOR_YELLOW,curses.COLOR_BLACK)
curses.init_pair(3,curses.COLOR_BLACK,curses.COLOR_YELLOW)
stdscr.addstr(0,0,"Flappy Bat",curses.color_pair(1))
stdscr.addstr(0,6,"~",curses.color_pair(2))
stdscr.addstr(0,10,"~"*(22),curses.color_pair(2))
# stdscr.addstr(1,0," "*(9*32),curses.color_pair(1))
stdscr.addstr(10,0," "*32,curses.color_pair(3))
stdscr.addstr(0,0,"",curses.color_pair(1))
y=9
x1=31
m=True
p=0
t=monotonic()
seed(t)
h=randrange(8)+1
tot=0
s1="r=%d c=%d h=%d moths=%d/%d "
s2=" Bat hit lava! "
while True:
stdscr.addstr(int(y),6,"Y")
if m:
stdscr.addstr(h,int(x1),"<")
stdscr.refresh()
sleep(.3)
if m:
stdscr.addstr(h,int(x1)," ")
stdscr.addstr(int(y),6," ")
stdscr.addstr(9,0,s1%(int(10*y),int(10*x1),int(10*h),p,tot))
stdscr.refresh()
while stdscr.getch()!=10:
pass
ts=t
t=monotonic()
dt=(t-ts)
y-=1-1.5*dt
x1-=dt
if m and int(x1)==6 and int(y)==h:
m=False
p+=1
if x1<0:
x1=31
m=True
h=randrange(8)+1
tot+=1
if y>10 or y<0:
stdscr.addstr(10,12,s2,curses.color_pair(3))
stdscr.refresh()
break
stdscr.getch()
curses.curs_set(True)
curses.endwin()
print()
print(s1%(int(10*y),int(10*x1),int(10*h),p,tot))
print(co(0,12)+s2+co(9,0))
wrapper(main)