40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
|
import pygame
|
||
|
import sys
|
||
|
|
||
|
# Some constants that we use in the program
|
||
|
|
||
|
BACKGROUND_COLOR = (0, 0, 0) # Black background
|
||
|
SCREEN_SIZE = (500, 500) # Screen size is 500 x 500
|
||
|
PADDLE_COLOR = (255, 255, 255) # Paddle color is white
|
||
|
|
||
|
# This class will represent our game
|
||
|
class Game:
|
||
|
# This function will be called when the class is first created
|
||
|
def __init__(self):
|
||
|
pygame.init()
|
||
|
self.window = pygame.display.set_mode(SCREEN_SIZE)
|
||
|
pygame.display.set_caption("Hello world")
|
||
|
|
||
|
# This function will render the contents of the screen
|
||
|
def render(self):
|
||
|
self.window.fill(BACKGROUND_COLOR)
|
||
|
|
||
|
# Draw a single paddle
|
||
|
pygame.draw.rect(self.window, PADDLE_COLOR, (50, 50, 10, 100))
|
||
|
|
||
|
pygame.display.flip()
|
||
|
|
||
|
def start(self):
|
||
|
# The main loop will run until the QUIT event is triggered
|
||
|
# this event will be triggered by closing the window
|
||
|
while True:
|
||
|
for event in pygame.event.get():
|
||
|
if event.type == pygame.QUIT:
|
||
|
pygame.quit()
|
||
|
sys.exit()
|
||
|
|
||
|
self.render()
|
||
|
|
||
|
# Create the game object and start the game
|
||
|
game = Game()
|
||
|
game.start()
|