Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- # Constants
- WIDTH = 700
- HEIGHT = 500
- SCREEN_AREA = pygame.Rect(0, 0, WIDTH, HEIGHT)
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- startx=50
- starty=25
- rowcount = 5
- columncount = 10
- # Initialization
- pygame.init()
- pygame.font.init()
- screen = pygame.display.set_mode([WIDTH, HEIGHT])
- pygame.mouse.set_visible(0)
- pygame.display.set_caption("Breakout Recreation WIP")
- clock = pygame.time.Clock()
- # Variables
- paddle = pygame.Rect(350, 480, 50, 10)
- ball = pygame.Rect(10, 250, 15, 15)
- #block1 = pygame.Rect(startx + 50*(j-1), starty+25*(i-1))
- paddle_movement_x = 0
- ball_direction = (1, 1)
- balls = 3
- level = 1
- done = False
- #Array
- blockArr = []
- blockArr.append([])
- blockArr.append([])
- blockArr.append([])
- blockArr.append([])
- blockArr.append([])
- for i in range(0, 9):
- blockArr[0].append(i)
- for i in range(0, 9):
- blockArr[1].append(i)
- for i in range(0, 9):
- blockArr[2].append(i)
- for i in range(0, 9):
- blockArr[3].append(i)
- for i in range(0, 9):
- blockArr[4].append(i)
- while not done and balls > 0:
- # Process events
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT]:
- paddle_movement_x = -2
- elif keys[pygame.K_RIGHT]:
- paddle_movement_x = 2
- else:
- paddle_movement_x = 0
- # Move paddle
- paddle.move_ip(paddle_movement_x, 0)
- paddle.clamp_ip(SCREEN_AREA)
- # Move ball
- ball.move_ip(*ball_direction)
- if ball.right > WIDTH or ball.left < 0:
- ball_direction = -ball_direction[0], ball_direction[1]
- elif ball.top < 0 or paddle.colliderect(ball):
- ball_direction = ball_direction[0], -ball_direction[1]
- elif ball.bottom > HEIGHT:
- balls = balls - 1
- ball_direction = (1, 1)
- ball = pygame.Rect(10, 250, 15, 15)
- ball.clamp_ip(SCREEN_AREA)
- # Redraw screen
- screen.fill(BLACK)
- #Array that will not Work (commented out)
- for i in range(1, rowcount):
- for j in range(1, columncount):
- if (blockArr[i][j] == True):
- block1 = pygame.Rect(startx + (50*(j-1)), starty+(25*(i-1)))
- #Counter that will not work (commented out):
- #text=font.render("Balls Left: "+str(balls), True, black)
- #screen.blit(text, [10, 10])
- pygame.draw.rect(screen, WHITE, paddle)
- pygame.draw.rect(screen, WHITE, ball)
- pygame.display.flip()
- clock.tick(100)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement