in scripts/breakout.py [0:0]
def main(stdscr):
global height, width, ship
for i in range(1, 8):
curses.init_pair(i, i, 0)
curses.curs_set(0)
curses.raw()
height, width = stdscr.getmaxyx()
if height < 15 or width < 30:
raise PowerOverwhelmingException(
"Your computer is not powerful enough to run 'arc anoid'. "
"It must support at least 30 columns and 15 rows of next-gen "
"full-color 3D graphics.")
status = curses.newwin(1, width, 0, 0)
height -= 1
game = curses.newwin(height, width, 1, 0)
game.nodelay(1)
game.keypad(1)
grid[:] = [ [ None for x in range(width + 2) ] for y in range(height + 2) ]
wall = Wall()
for x in range(width + 2):
grid[0][x] = wall
for y in range(height + 2):
grid[y][0] = grid[y][-1] = wall
ship = Ship(width / 2, height - 5)
entities.append(ship)
colors = [ 1, 3, 2, 6, 4, 5 ]
h = height / 10
for x in range(1, width / 7 - 1):
for y in range(1, 7):
entities.append(Block(x * 7,
y * h + x / 2 % 2,
7,
h,
colors[y - 1]))
while True:
while select.select([ sys.stdin ], [], [], 0)[0]:
key = game.getch()
if key == curses.KEY_LEFT or key == ord('a') or key == ord('A'):
ship.shift(-1)
elif key == curses.KEY_RIGHT or key == ord('d') or key == ord('D'):
ship.shift(1)
elif key == ord(' '):
ship.spawn()
elif key == 0x1b or key == 3 or key == ord('q') or key == ord('Q'):
return
game.resize(height, width)
game.erase()
entities[:] = [ ent for ent in entities if ent.tick(game) ]
status.hline(0, 0, curses.ACS_HLINE, width)
status.addch(0, 2, curses.ACS_RTEE)
status.addstr(' SCORE: ', curses.A_BOLD | curses.color_pair(4))
status.addstr('%s/%s ' % (Block.killed, Block.total), curses.A_BOLD)
status.addch(curses.ACS_VLINE)
status.addstr(' DEATHS: ', curses.A_BOLD | curses.color_pair(4))
status.addstr('%s ' % Ball.killed, curses.A_BOLD)
status.addch(curses.ACS_LTEE)
if Block.killed == Block.total:
message = ' A WINNER IS YOU!! '
i = int(time.time() / 0.8)
for x in range(width):
for y in range(6):
game.addch(height / 2 + y - 3 + (x / 8 + i) % 2, x,
curses.ACS_BLOCK,
curses.A_BOLD | curses.color_pair(colors[y]))
game.addstr(height / 2, (width - len(message)) / 2, message,
curses.A_BOLD | curses.color_pair(7))
game.refresh()
status.refresh()
time.sleep(0.05)