SHOW:
|
|
- or go back to the newest paste.
1 | import pygame | |
2 | import random | |
3 | import time | |
4 | from Apple import Apple | |
5 | ||
6 | # width and height of the display | |
7 | DISPLAY_WIDTH = 800 | |
8 | DISPLAY_HEIGHT = 608 | |
9 | ||
10 | # background creation | |
11 | - | background = pygame.Surface((800, 608)) |
11 | + | background = pygame.Surface((DISPLAY_WIDTH, DISPLAY_HEIGHT)) |
12 | for i in range(25): | |
13 | for j in range(19): | |
14 | image = pygame.image.load("images/background.png") | |
15 | mask = (random.randrange(0, 20), random.randrange( | |
16 | 0, 20), random.randrange(0, 20)) | |
17 | ||
18 | image.fill(mask, special_flags=pygame.BLEND_ADD) | |
19 | background.blit(image, (i*32, j*32)) | |
20 | ||
21 | # settings | |
22 | pygame.init() | |
23 | # display object and game clock | |
24 | display = pygame.display.set_mode([DISPLAY_WIDTH, DISPLAY_HEIGHT]) | |
25 | clock = pygame.time.Clock() | |
26 | ||
27 | # apples | |
28 | apple = Apple() | |
29 | apples = pygame.sprite.Group() | |
30 | apples.add(apple) | |
31 | ||
32 | game_on = True | |
33 | while game_on: | |
34 | for event in pygame.event.get(): | |
35 | if event.type == pygame.KEYDOWN: | |
36 | if event.key == pygame.K_ESCAPE: | |
37 | game_on = False | |
38 | ||
39 | elif event.type == pygame.QUIT: | |
40 | game_on = False | |
41 | ||
42 | # drawing background | |
43 | display.blit(background, (0, 0)) | |
44 | # drawing apples | |
45 | for apple in apples: | |
46 | display.blit(apple.image, apple.rect) | |
47 | ||
48 | # display wipe | |
49 | pygame.display.flip() | |
50 | # setting the FPS to 30 | |
51 | clock.tick(30) | |
52 | ||
53 | # 3 second sleep time | |
54 | time.sleep(3) | |
55 | # closing the game | |
56 | pygame.quit() | |
57 |