Guest User

pajton problem

a guest
Mar 2nd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. import pygame, sys
  2.  
  3. pygame.init()
  4.  
  5. gamename = pygame.display.set_caption('Pong')
  6.  
  7. clock = pygame.time.Clock()
  8. FPS = 30
  9.  
  10. black = (0, 0, 0)
  11. white = (255, 255, 255)
  12.  
  13. screen = pygame.display.set_mode((800, 800))
  14. screen.fill(black)
  15.  
  16. def drawline():
  17.     pygame.draw.line(screen, white, (400, 800), (400, 0), 5)
  18.  
  19. class Ball(object):
  20.     def __init__(self, screen):
  21.         ballw = 26
  22.         ballh = 26
  23.         ballx = 387
  24.         bally = 400
  25.         xdist = 5
  26.         ydist = 5
  27.         self.ballw = ballw
  28.         self.ballh = ballh
  29.         self.ballx = ballx
  30.         self.bally = bally
  31.         self.xdist = xdist
  32.         self.ydist = ydist
  33.         self.screen = screen
  34.  
  35.     def draw(self):
  36.         ball = pygame.rect.Rect((self.ballx, self.bally, self.ballw, self.ballh))
  37.         pygame.draw.rect(screen, white, ball)
  38.  
  39.     def move(self):
  40.        
  41.  
  42.     def bounce(self):
  43.        
  44.  
  45. class PlayerOne(object):
  46.     def __init__(self, screen):
  47.         padx = 20
  48.         pady = 350
  49.         padh = 120
  50.         padw = 25
  51.         dist = 10
  52.         self.padx = padx
  53.         self.pady = pady
  54.         self.padh = padh
  55.         self.padw = padw
  56.         self.dist = dist
  57.         self.screen = screen
  58.  
  59.     def draw(self):
  60.         playeronepaddle = pygame.rect.Rect((self.padx, self.pady, self.padw, self.padh))
  61.         pygame.draw.rect(self.screen, white, playeronepaddle)
  62.  
  63.     def controlsandcollision(self):
  64.         key = pygame.key.get_pressed()
  65.         if key[pygame.K_w]:
  66.             if self.pady <= 0: self.pady + 0
  67.             else: self.pady -= self.dist
  68.         elif key[pygame.K_s]:
  69.             if self.pady >= 680: self.pady + 0
  70.             else: self.pady += self.dist
  71.  
  72. class PlayerTwo(object):
  73.     def __init__(self, screen):
  74.         pady = 350
  75.         padx = 760
  76.         padh = 120
  77.         padw = 25
  78.         dist = 10
  79.         self.pady = pady
  80.         self.padx = padx
  81.         self.padh = padh
  82.         self.padw = padw
  83.         self.dist = dist
  84.         self.screen = screen
  85.  
  86.     def draw(self):
  87.         playertwopaddle = pygame.rect.Rect((self.padx, self.pady, self.padw, self.padh))
  88.         pygame.draw.rect(self.screen, white, playertwopaddle)
  89.  
  90.     def controlsandcollision(self):
  91.         key = pygame.key.get_pressed()
  92.         if key[pygame.K_UP]:
  93.             if self.pady <= 0: self.pady + 0
  94.             else: self.pady -= self.dist
  95.         elif key[pygame.K_DOWN]:
  96.             if self.pady >= 680: self.pady + 0
  97.             else: self.pady += self.dist
  98.  
  99.  
  100.  
  101. pygame.display.update()
  102.  
  103. ball = Ball(screen)
  104. playerone = PlayerOne(screen)
  105. playertwo = PlayerTwo(screen)
  106. ball.move()
  107.  
  108. while True:
  109.     for event in pygame.event.get():
  110.         if event.type == pygame.QUIT:
  111.             sys.exit()
  112.  
  113.     screen.fill(black)
  114.     drawline()
  115.     ball.draw()
  116.     ball.move()
  117.     playerone.controlsandcollision()
  118.     playerone.draw()
  119.     playertwo.controlsandcollision()
  120.     playertwo.draw()
  121.     pygame.display.update()
  122.     clock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment