-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoration.py
97 lines (83 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
93
94
95
96
97
#from settings import self.cfg.vertical_tile_number, self.cfg.tile_size, self.cfg.screen_width
import pygame
import math
from tiles import AnimatedTile, StaticTile
from support import import_folder
from random import choice, randint
class Sky:
def __init__(self, cfg, style = 'level'):
self.cfg = cfg
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()
#vertical_tiles = math.floor(self.cfg.screen_height / self.cfg.tile_size)
self.horizon = math.floor(self.cfg.vertical_tile_number * self.cfg.horizon_level)
# stretch
self.top = pygame.transform.scale(self.top,(self.cfg.screen_width,self.cfg.tile_size))
self.bottom = pygame.transform.scale(self.bottom,(self.cfg.screen_width,self.cfg.tile_size))
self.middle = pygame.transform.scale(self.middle,(self.cfg.screen_width,self.cfg.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,self.cfg.screen_width)
y = (self.horizon * self.cfg.tile_size) + randint(50, 100)
rect = surface.get_rect(midbottom = (x,y))
self.palms.append((surface,rect))
cloud_surfaces = import_folder('graphics/overworld/clouds')
self.clouds = []
for surface in [choice(cloud_surfaces) for image in range(10)]:
x = randint(0,self.cfg.screen_width)
y = randint(0,(self.horizon * self.cfg.tile_size) - 100)
rect = surface.get_rect(midbottom = (x,y))
self.clouds.append((surface,rect))
def draw(self, surface):
for row in range(self.cfg.vertical_tile_number):
y = row * self.cfg.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, cfg, level_width):
self.cfg = cfg
top = self.cfg.screen_height - 20
water_start = -self.cfg.screen_width
water_tile_width = 192
tile_x_amount = int((level_width + self.cfg.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(water_tile_width, 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, cfg, level_width, cloud_number):
self.cfg = cfg
cloud_surf_list = import_folder('graphics/decoration/clouds')
self.horizon = math.floor(self.cfg.vertical_tile_number * self.cfg.horizon_level)
min_x = -self.cfg.screen_width
max_x = level_width + self.cfg.screen_width
min_y = 0
max_y = (self.horizon * self.cfg.tile_size) - 100
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)