Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Untitled

Unknown
dotepub.com
import pygameimport sys

Initialize Pygame
pygame.init()

Set up the game window


screen = pygame.display.setmode((800,
600))pygame.display.setcaption(“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)

Define the paddle


paddle = pygame.Rect(350, 550, 100, 10)

Main game loop


while True: for event in pygame.event.get(): if event.type ==
pygame.QUIT: pygame.quit() sys.exit() # Get keys pressedkeys =
pygame.key.get_pressed()# Move paddleif keys[pygame.K_LEFT] and paddle.left > 0:
paddle.left -= 5if keys[pygame.K_RIGHT] and paddle.right < 800: paddle.right += 5#
Fill the screen with whitescreen.fill(WHITE)# Draw the blockpygame.draw.rect(screen,
BLUE, block)# Draw the paddlepygame.draw.rect(screen, RED, paddle)# Update the
displaypygame.display.flip()

If you use dotepub often, consider making a donation.


Your contribution allows us to continue its development.
Disclaimer

This information was automatically retrieved on 2024-07-


17T14:33:24+00:00 from:
http://dotepub.com/creator/
It is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. This e-book is
not an authoritative source: please, visit the original webpage.
(API v.1)

You might also like