Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys
- pygame.init()
- gamename = pygame.display.set_caption('Pong')
- clock = pygame.time.Clock()
- FPS = 30
- black = (0, 0, 0)
- white = (255, 255, 255)
- screen = pygame.display.set_mode((800, 800))
- screen.fill(black)
- def drawline():
- pygame.draw.line(screen, white, (400, 800), (400, 0), 5)
- class Ball(object):
- def __init__(self, screen):
- ballw = 26
- ballh = 26
- ballx = 387
- bally = 400
- xdist = 5
- ydist = 5
- self.ballw = ballw
- self.ballh = ballh
- self.ballx = ballx
- self.bally = bally
- self.xdist = xdist
- self.ydist = ydist
- self.screen = screen
- def draw(self):
- ball = pygame.rect.Rect((self.ballx, self.bally, self.ballw, self.ballh))
- pygame.draw.rect(screen, white, ball)
- def move(self):
- def bounce(self):
- class PlayerOne(object):
- def __init__(self, screen):
- padx = 20
- pady = 350
- padh = 120
- padw = 25
- dist = 10
- self.padx = padx
- self.pady = pady
- self.padh = padh
- self.padw = padw
- self.dist = dist
- self.screen = screen
- def draw(self):
- playeronepaddle = pygame.rect.Rect((self.padx, self.pady, self.padw, self.padh))
- pygame.draw.rect(self.screen, white, playeronepaddle)
- def controlsandcollision(self):
- key = pygame.key.get_pressed()
- if key[pygame.K_w]:
- if self.pady <= 0: self.pady + 0
- else: self.pady -= self.dist
- elif key[pygame.K_s]:
- if self.pady >= 680: self.pady + 0
- else: self.pady += self.dist
- class PlayerTwo(object):
- def __init__(self, screen):
- pady = 350
- padx = 760
- padh = 120
- padw = 25
- dist = 10
- self.pady = pady
- self.padx = padx
- self.padh = padh
- self.padw = padw
- self.dist = dist
- self.screen = screen
- def draw(self):
- playertwopaddle = pygame.rect.Rect((self.padx, self.pady, self.padw, self.padh))
- pygame.draw.rect(self.screen, white, playertwopaddle)
- def controlsandcollision(self):
- key = pygame.key.get_pressed()
- if key[pygame.K_UP]:
- if self.pady <= 0: self.pady + 0
- else: self.pady -= self.dist
- elif key[pygame.K_DOWN]:
- if self.pady >= 680: self.pady + 0
- else: self.pady += self.dist
- pygame.display.update()
- ball = Ball(screen)
- playerone = PlayerOne(screen)
- playertwo = PlayerTwo(screen)
- ball.move()
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit()
- screen.fill(black)
- drawline()
- ball.draw()
- ball.move()
- playerone.controlsandcollision()
- playerone.draw()
- playertwo.controlsandcollision()
- playertwo.draw()
- pygame.display.update()
- clock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment