Advertisement
Ward_Programm3r

Game1

Oct 6th, 2013
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import pygame
  2. import sys
  3.  
  4. pygame.init()
  5.  
  6. width = 673
  7. height = 449
  8. size = width, height
  9. midx = width/2
  10. midy = height/2
  11. middle = midx, midy
  12. speed = [2, 2]
  13. black = 0, 0, 0
  14.  
  15. Running = True
  16.  
  17. screen = pygame.display.set_mode(size)
  18.  
  19. ball = pygame.image.load("small_ball.png")
  20. ballRect = ball.get_rect()
  21.  
  22. player = pygame.image.load("playerImg.gif")
  23. playerRect = player.get_rect()
  24.  
  25. bkg = pygame.image.load("soccer_field.png")
  26. bkgRect = bkg.get_rect()
  27.  
  28. Clock = pygame.time.Clock()
  29. time = 1
  30. newgame = True
  31.  
  32. def ballSnapLeft():
  33. ballRect.right = playerRect.left - (0, 1)
  34.  
  35. while Running == True:
  36. Clock.tick(120)
  37. for event in pygame.event.get():
  38. if event.type == pygame.QUIT:
  39. Running = False
  40. elif event.type == pygame.KEYDOWN:
  41. if event.key == pygame.K_ESCAPE:
  42. Running = False
  43. elif event.key == pygame.K_UP:
  44. playerRect = playerRect.move(1, 1)
  45. if newgame is True:
  46. time = 1
  47. if time == 1:
  48. ballRect.center = middle
  49. newgame = False
  50. time = time + 1
  51.  
  52. if newgame is True:
  53. time = 1
  54. ballRect = ballRect.move(speed)
  55. if ballRect.left < 0 or ballRect.right > width:
  56. speed[0] = -speed[0]
  57. if ballRect.top < 0 or ballRect.bottom > height:
  58. speed[1] = -speed[1]
  59. if ballRect.right == playerRect.left:
  60. ballSnapLeft()
  61. if ballRect.left == playerRect.right:
  62. ballSnapRight()
  63. if ballRect.top == playerRect.bottom:
  64. ballSnapBottom()
  65. if ballRect.bottom == playerRect.top:
  66. ballSnapTop()
  67. screen.fill(black)
  68. screen.blit(bkg, bkgRect)
  69. screen.blit(ball, ballRect)
  70. pygame.display.flip()
  71.  
  72. pygame.quit()
  73. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement