-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoration.py
92 lines (75 loc) · 3.43 KB
/
decoration.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from random import choice, randint
import pygame
from settings import vertical_tile_number, tile_size, screen_width
from tiles import AnimatedTile, StaticTile
from utilities import import_folder
class Sky:
def __init__(self, horizon, style='level'):
self.top = pygame.image.load('graphics/decoration/sky/sky_top.png').convert()
self.bottom = pygame.image.load('graphics/decoration/sky/sky_bottom.png').convert()
self.middle = pygame.image.load('graphics/decoration/sky/sky_middle.png').convert()
self.horizon = horizon
self.top = pygame.transform.scale(self.top, (screen_width, tile_size))
self.bottom = pygame.transform.scale(self.bottom, (screen_width, tile_size))
self.middle = pygame.transform.scale(self.middle, (screen_width, tile_size))
self.style = style
if self.style == 'overworld':
palm_surfaces = import_folder('graphics/overworld/palms')
self.palms = []
for surface in [choice(palm_surfaces) for image in range(10)]:
x = randint(0, screen_width)
y = (self.horizon * tile_size) + randint(50, 100)
rect = surface.get_rect(midbottom=(x, y))
self.palms.append((surface, rect))
clouds_surfaces = import_folder('graphics/overworld/clouds')
self.clouds = []
for surface in [choice(clouds_surfaces) for image in range(10)]:
x = randint(0, screen_width)
y = randint(0, (self.horizon * tile_size) - 100)
rect = surface.get_rect(midbottom=(x, y))
self.clouds.append((surface, rect))
def draw(self, surface):
for row in range(vertical_tile_number):
y = row * tile_size
if row < self.horizon:
surface.blit(self.top, (0, y))
elif row == self.horizon:
surface.blit(self.middle, (0, y))
else:
surface.blit(self.bottom, (0, y))
if self.style == 'overworld':
for palm in self.palms:
surface.blit(palm[0], palm[1])
for cloud in self.clouds:
surface.blit(cloud[0], cloud[1])
class Water:
def __init__(self, top, level_width):
water_start = -screen_width
water_tile_width = 192
tile_x_amount = (level_width + screen_width * 2) // water_tile_width
self.water_sprites = pygame.sprite.Group()
for tile in range(tile_x_amount):
x = tile * water_tile_width + water_start
y = top
sprite = AnimatedTile(192, x, y, 'graphics/decoration/water')
self.water_sprites.add(sprite)
def draw(self, surface, shift):
self.water_sprites.update(shift)
self.water_sprites.draw(surface)
class Clouds:
def __init__(self, horizon, level_width, cloud_number):
cloud_surf_list = import_folder('graphics/decoration/clouds')
min_x = -screen_width
max_x = level_width + screen_width
min_y = 0
max_y = horizon
self.cloud_sprites = pygame.sprite.Group()
for cloud in range(cloud_number):
cloud = choice(cloud_surf_list)
x = randint(min_x, max_x)
y = randint(min_y, max_y)
sprite = StaticTile(0, x, y, cloud)
self.cloud_sprites.add(sprite)
def draw(self, surface, shift):
self.cloud_sprites.update(shift)
self.cloud_sprites.draw(surface)