Advertisement
PythonInProgress

Breakout WIP ARRAY

Apr 28th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import pygame
  2.  
  3. # Constants
  4. WIDTH = 700
  5. HEIGHT = 500
  6. SCREEN_AREA = pygame.Rect(0, 0, WIDTH, HEIGHT)
  7. BLACK = (0, 0, 0)
  8. WHITE = (255, 255, 255)
  9. startx=50
  10. starty=25
  11. rowcount = 5
  12. columncount = 10
  13.  
  14.  
  15. # Initialization
  16. pygame.init()
  17. pygame.font.init()
  18. screen = pygame.display.set_mode([WIDTH, HEIGHT])
  19. pygame.mouse.set_visible(0)
  20. pygame.display.set_caption("Breakout Recreation WIP")
  21. clock = pygame.time.Clock()
  22.  
  23. # Variables
  24.  
  25. paddle = pygame.Rect(350, 480, 50, 10)
  26. ball = pygame.Rect(10, 250, 15, 15)
  27. #block1 = pygame.Rect(startx + 50*(j-1), starty+25*(i-1))
  28. paddle_movement_x = 0
  29. ball_direction = (1, 1)
  30. balls = 3
  31. level = 1
  32. done = False
  33.  
  34. #Array
  35. blockArr = []
  36. blockArr.append([])
  37. blockArr.append([])
  38. blockArr.append([])
  39. blockArr.append([])
  40. blockArr.append([])
  41. for i in range(0, 9):
  42. blockArr[0].append(i)
  43. for i in range(0, 9):
  44. blockArr[1].append(i)
  45. for i in range(0, 9):
  46. blockArr[2].append(i)
  47. for i in range(0, 9):
  48. blockArr[3].append(i)
  49. for i in range(0, 9):
  50. blockArr[4].append(i)
  51.  
  52.  
  53.  
  54. while not done and balls > 0:
  55.  
  56. # Process events
  57. for event in pygame.event.get():
  58. if event.type == pygame.QUIT:
  59. done = True
  60. keys = pygame.key.get_pressed()
  61. if keys[pygame.K_LEFT]:
  62. paddle_movement_x = -2
  63. elif keys[pygame.K_RIGHT]:
  64. paddle_movement_x = 2
  65. else:
  66. paddle_movement_x = 0
  67.  
  68. # Move paddle
  69. paddle.move_ip(paddle_movement_x, 0)
  70. paddle.clamp_ip(SCREEN_AREA)
  71.  
  72. # Move ball
  73. ball.move_ip(*ball_direction)
  74. if ball.right > WIDTH or ball.left < 0:
  75. ball_direction = -ball_direction[0], ball_direction[1]
  76. elif ball.top < 0 or paddle.colliderect(ball):
  77. ball_direction = ball_direction[0], -ball_direction[1]
  78. elif ball.bottom > HEIGHT:
  79. balls = balls - 1
  80. ball_direction = (1, 1)
  81. ball = pygame.Rect(10, 250, 15, 15)
  82.  
  83. ball.clamp_ip(SCREEN_AREA)
  84.  
  85. # Redraw screen
  86. screen.fill(BLACK)
  87. #Array that will not Work (commented out)
  88. for i in range(1, rowcount):
  89. for j in range(1, columncount):
  90. if (blockArr[i][j] == True):
  91. block1 = pygame.Rect(startx + (50*(j-1)), starty+(25*(i-1)))
  92.  
  93. #Counter that will not work (commented out):
  94. #text=font.render("Balls Left: "+str(balls), True, black)
  95. #screen.blit(text, [10, 10])
  96.  
  97. pygame.draw.rect(screen, WHITE, paddle)
  98. pygame.draw.rect(screen, WHITE, ball)
  99. pygame.display.flip()
  100. clock.tick(100)
  101.  
  102. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement