Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- import time
- def main(stdscr):
- curses.curs_set(0)
- stdscr.nodelay(1)
- stdscr.timeout(100)
- curses.start_color()
- curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
- curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
- curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
- curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
- curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
- curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK)
- height, width = stdscr.getmaxyx()
- paddle_height = 5
- paddle_width = 1
- ball_row = height // 2
- ball_col = width // 2
- ball_velocity_row = 1
- ball_velocity_col = 1
- paddle1_row = (height - paddle_height) // 2
- paddle2_row = (height - paddle_height) // 2
- score1 = 0
- score2 = 0
- while True:
- stdscr.clear()
- # Draw paddles with colors
- for i in range(paddle_height):
- stdscr.addch(paddle1_row + i, 0, '|', curses.color_pair(1))
- stdscr.addch(paddle2_row + i, width - 1, '|', curses.color_pair(2))
- # Draw ball (circle) with color
- stdscr.addstr(ball_row, ball_col, 'o', curses.color_pair(3))
- # Display scores with colors
- stdscr.addstr(0, width // 2 - 10, f"Player 1: {score1} Player 2: {score2}", curses.color_pair(4))
- # Move ball
- ball_row += ball_velocity_row
- ball_col += ball_velocity_col
- # Ball collision with walls
- if ball_row == 0 or ball_row == height - 1:
- ball_velocity_row = -ball_velocity_row
- if ball_col == 0:
- score2 += 1
- ball_row = height // 2
- ball_col = width // 2
- if ball_col == width - 1:
- score1 += 1
- ball_row = height // 2
- ball_col = width // 2
- # Ball collision with paddles
- if ball_col == 1 and paddle1_row <= ball_row < paddle1_row + paddle_height:
- ball_velocity_col = -ball_velocity_col
- if ball_col == width - 2 and paddle2_row <= ball_row < paddle2_row + paddle_height:
- ball_velocity_col = -ball_velocity_col
- # Move paddles with boundary checks
- key = stdscr.getch()
- if key == ord('q') or key == ord('Q'):
- break
- if key == curses.KEY_UP and paddle2_row > 0:
- paddle2_row -= 1
- if key == curses.KEY_DOWN and paddle2_row < height - paddle_height - 1:
- paddle2_row += 1
- if key == ord('w') or key == ord('W'):
- if paddle1_row > 0:
- paddle1_row -= 1
- if key == ord('s') or key == ord('S'):
- if paddle1_row < height - paddle_height:
- paddle1_row += 1
- stdscr.refresh()
- curses.wrapper(main)
- """
- Copyright (c) 2023 Zeromega
- Drop a link or a Sub on one of my videos if this script help you, copy the link below
- https://www.youtube.com/channel/UCfqUJ4rmk6W-ZAjDtkBZ1CA?sub_confirmation=1
- """
Advertisement
Comments
-
- This was a fun thing to make, next is to add AI for player two
Add Comment
Please, Sign In to add comment
Advertisement