0% found this document useful (0 votes)
12 views3 pages

Creating The Game Window and Basic Elements

This document discusses creating the basic elements of a game window in Python using Pygame. It describes initializing Pygame, setting up the game window and screen, defining colors, and adding a basic block and paddle rectangle objects to the screen.

Uploaded by

bandband.piyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Creating The Game Window and Basic Elements

This document discusses creating the basic elements of a game window in Python using Pygame. It describes initializing Pygame, setting up the game window and screen, defining colors, and adding a basic block and paddle rectangle objects to the screen.

Uploaded by

bandband.piyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Creating the Game Window and Basic Elements

1. Coding the Game Window

We have already created a basic game window in the first step. Now, let's refine it by adding more

elements.

import pygame

import sys

# Initialize Pygame

pygame.init()

# Set up the game window

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption("Simple Block Game")

# Define colors

WHITE = (255, 255, 255)

BLUE = (0, 0, 255)

# Main game loop

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

pygame.quit()

sys.exit()
# Fill the screen with white

screen.fill(WHITE)

# Update the display

pygame.display.flip()

2. Adding Basic Elements: Block and Paddle

Next, we add a block and a paddle to the game. The block will be a simple rectangle.

import pygame

import sys

# Initialize Pygame

pygame.init()

# Set up the game window

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption("Simple Block Game")

# Define colors

WHITE = (255, 255, 255)

BLUE = (0, 0, 255)

RED = (255, 0, 0)

# Define the block


block = pygame.Rect(375, 275, 50, 50)

# Main game loop

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

pygame.quit()

sys.exit()

# Fill the screen with white

screen.fill(WHITE)

# Draw the block

pygame.draw.rect(screen, BLUE, block)

# Update the display

pygame.display.flip()

You might also like