Changeset View
Changeset View
Standalone View
Standalone View
scripts/breakout.py
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | def main(stdscr): | ||||
for i in range(1, 8): | for i in range(1, 8): | ||||
curses.init_pair(i, i, 0) | curses.init_pair(i, i, 0) | ||||
curses.curs_set(0) | curses.curs_set(0) | ||||
curses.raw() | curses.raw() | ||||
height, width = stdscr.getmaxyx() | height, width = stdscr.getmaxyx() | ||||
if height < 15 or width < 30: | if height < 15 or width < 32: | ||||
raise PowerOverwhelmingException( | raise PowerOverwhelmingException( | ||||
"Your computer is not powerful enough to run 'arc anoid'. " | 'Your computer is not powerful enough to run "arc anoid". ' | ||||
"It must support at least 30 columns and 15 rows of next-gen " | 'It must support at least 32 columns and 15 rows of next-gen ' | ||||
"full-color 3D graphics.") | 'full-color 3D graphics.') | ||||
status = curses.newwin(1, width, 0, 0) | status = curses.newwin(1, width, 0, 0) | ||||
height -= 1 | height -= 1 | ||||
game = curses.newwin(height, width, 1, 0) | game = curses.newwin(height, width, 1, 0) | ||||
game.nodelay(1) | game.nodelay(1) | ||||
game.keypad(1) | game.keypad(1) | ||||
grid[:] = [ [ None for x in range(width + 2) ] for y in range(height + 2) ] | grid[:] = [ [ None for x in range(width + 2) ] for y in range(height + 2) ] | ||||
Show All 32 Lines | while True: | ||||
entities[:] = [ ent for ent in entities if ent.tick(game) ] | entities[:] = [ ent for ent in entities if ent.tick(game) ] | ||||
status.hline(0, 0, curses.ACS_HLINE, width) | status.hline(0, 0, curses.ACS_HLINE, width) | ||||
status.addch(0, 2, curses.ACS_RTEE) | status.addch(0, 2, curses.ACS_RTEE) | ||||
status.addstr(' SCORE: ', curses.A_BOLD | curses.color_pair(4)) | status.addstr(' SCORE: ', curses.A_BOLD | curses.color_pair(4)) | ||||
status.addstr('%s/%s ' % (Block.killed, Block.total), curses.A_BOLD) | status.addstr('%s/%s ' % (Block.killed, Block.total), curses.A_BOLD) | ||||
status.addch(curses.ACS_VLINE) | status.addch(curses.ACS_VLINE) | ||||
status.addstr(' DEATHS: ', curses.A_BOLD | curses.color_pair(4)) | status.addstr(' DEATHS: ', curses.A_BOLD | curses.color_pair(4)) | ||||
status.addstr('%s ' % Ball.killed, curses.A_BOLD) | |||||
# See T8693. At the minimum display size, we only have room to render | |||||
# two characters for the death count, so just display "99" if the | |||||
# player has more than 99 deaths. | |||||
display_deaths = Ball.killed | |||||
if (display_deaths > 99): | |||||
display_deaths = 99 | |||||
status.addstr('%s ' % display_deaths, curses.A_BOLD) | |||||
status.addch(curses.ACS_LTEE) | status.addch(curses.ACS_LTEE) | ||||
if Block.killed == Block.total: | if Block.killed == Block.total: | ||||
message = ' A WINNER IS YOU!! ' | message = ' A WINNER IS YOU!! ' | ||||
i = int(time.time() / 0.8) | i = int(time.time() / 0.8) | ||||
for x in range(width): | for x in range(width): | ||||
for y in range(6): | for y in range(6): | ||||
game.addch(height / 2 + y - 3 + (x / 8 + i) % 2, x, | game.addch(height / 2 + y - 3 + (x / 8 + i) % 2, x, | ||||
Show All 15 Lines |