Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter.constants import Y
- from PyGame.ponggame4p import Yvelo
- import pygame # importing the module
- WIDTH = 800
- HEIGHT = 600
- pygame.init() # initializing the module
- screen = pygame.display.set_mode((WIDTH, HEIGHT)) # making the window of size WIDTH and HEIGHT
- pygame.display.set_caption('Pong Game') # setting the title of the window
- clock = pygame.time.Clock()
- run = True
- speed = 2
- y = 200
- dy = speed
- while run: #-> while the game is running >>> 1 frame every time the loop runs
- screen.fill((0,0,0)) # r g b color inside
- clock.tick(60) # controlling the frame rate
- for event in pygame.event.get(): # for each event occuring in the window
- if event.type == pygame.QUIT: # checking if the close button was pressed
- run = False # update game status to stop (not running)
- y += dy # delta y -> change in y
- ball = pygame.draw.circle(screen, (255, 0, 0 ), (100, y), 25)
- if ball.bottom >= HEIGHT:
- dy = -speed
- elif ball.top <= 0:
- dy = speed
- pygame.display.flip() # update our window with all the changes that we have done
- pygame.quit() # close the window
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement