Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import time
- from Apple import Apple
- # width and height of the display
- DISPLAY_WIDTH = 800
- DISPLAY_HEIGHT = 608
- # background creation
- background = pygame.Surface((800, 608))
- for i in range(25):
- for j in range(19):
- image = pygame.image.load("images/background.png")
- mask = (random.randrange(0, 20), random.randrange(
- 0, 20), random.randrange(0, 20))
- image.fill(mask, special_flags=pygame.BLEND_ADD)
- background.blit(image, (i*32, j*32))
- # settings
- pygame.init()
- # display object and game clock
- display = pygame.display.set_mode([DISPLAY_WIDTH, DISPLAY_HEIGHT])
- clock = pygame.time.Clock()
- # apples
- apple = Apple()
- apples = pygame.sprite.Group()
- apples.add(apple)
- game_on = True
- while game_on:
- for event in pygame.event.get():
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- game_on = False
- elif event.type == pygame.QUIT:
- game_on = False
- # drawing background
- display.blit(background, (0, 0))
- # drawing apples
- for apple in apples:
- display.blit(apple.image, apple.rect)
- # display wipe
- pygame.display.flip()
- # setting the FPS to 30
- clock.tick(30)
- # 3 second sleep time
- time.sleep(3)
- # closing the game
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement