import pygame
import sys
# Initialize Pygame
pygame.init()
# Constants
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BALL_RADIUS = 15
# Set up the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Simple Pool Game")
# Ball class
class Ball:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color
def draw(self):
pygame.draw.circle(screen, self.color, (self.x, self.y), BALL_RADIUS)
# Main function
def main():
ball = Ball(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, WHITE)
# Game loop
while True:
screen.fill(BLACK)
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Draw the ball
ball.draw()
# Update the display
pygame.display.flip()
# Run the game
if __name__ == "__main__":
main()
No comments:
Post a Comment