-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.py
47 lines (35 loc) · 1.7 KB
/
background.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from color import *
from config import *
import pygame
class Background() :
def __init__(self) :
## Load config file
conf = Config()
## Import background pictures (don't convert picture to pygame format to keep transarence)
self.bg1_base = pygame.image.load("PNG/Background/bg_layer1.png")
self.bg2_base = pygame.image.load("PNG/Background/bg_layer2.png")
self.bg3_base = pygame.image.load("PNG/Background/bg_layer3.png")
self.bg4_base = pygame.image.load("PNG/Background/bg_layer4.png")
self.bg_game_over = pygame.image.load("PNG/Background/red.png")
## Creat background surface
self.bg = pygame.Surface([conf.width, conf.height])
## Resize background picturesd
self.bg1 = pygame.transform.scale(self.bg1_base, (conf.width, conf.height))
self.bg2 = pygame.transform.scale(self.bg2_base, (conf.width, conf.height))
self.bg3 = pygame.transform.scale(self.bg3_base, (conf.width, conf.height))
self.bg4 = pygame.transform.scale(self.bg4_base, (conf.width, conf.height))
self.bg_game_over = pygame.transform.scale(self.bg_game_over, (conf.width, conf.height))
## Fuse background onto background surface
self.reset()
def update(self, screen) :
## Print background on screen
screen.blit(self.bg, [0, 0])
def game_over(self) :
## Add red filter to background
self.bg.blit(self.bg_game_over, [0, 0])
def reset(self) :
## Fuse background onto background surface
self.bg.blit(self.bg1, [0, 0])
self.bg.blit(self.bg2, [0, 0])
self.bg.blit(self.bg3, [0, 0])
self.bg.blit(self.bg4, [0, 0])