-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_background_styles.py
More file actions
315 lines (277 loc) · 12.8 KB
/
create_background_styles.py
File metadata and controls
315 lines (277 loc) · 12.8 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import os
import pygame
import sys
import random
import math
# Initialize pygame
pygame.init()
# Constants
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
# Create directories if they don't exist
os.makedirs("assets/images", exist_ok=True)
# Background styles to create
bg_styles = ["default", "forest", "desert", "snow", "night"]
# Function to create a background for a specific style and level
def create_background(style, level_num):
surf = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
# Base color and elements depend on style
if style == "default":
# Blue gradient
base_color = (0, 0, 50)
for y in range(SCREEN_HEIGHT):
intensity = y / SCREEN_HEIGHT
color = [int(c * (1 + intensity * 0.5)) for c in base_color]
color = [min(255, c) for c in color]
pygame.draw.line(surf, color, (0, y), (SCREEN_WIDTH, y))
# Add stars
for _ in range(100):
x = random.randint(0, SCREEN_WIDTH)
y = random.randint(0, SCREEN_HEIGHT // 2)
size = random.randint(1, 3)
brightness = random.randint(150, 255)
pygame.draw.circle(surf, (brightness, brightness, brightness), (x, y), size)
elif style == "forest":
# Green gradient
for y in range(SCREEN_HEIGHT):
green = min(255, int(50 + (y / SCREEN_HEIGHT) * 100))
pygame.draw.line(surf, (0, green, 0), (0, y), (SCREEN_WIDTH, y))
# Add trees
for _ in range(20):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(100, 200)
width = random.randint(20, 40)
# Tree trunk
pygame.draw.rect(surf, (100, 50, 0), (x, SCREEN_HEIGHT - height, width, height))
# Tree top
pygame.draw.circle(surf, (0, 150, 0), (x + width//2, SCREEN_HEIGHT - height - 50), 60)
elif style == "desert":
# Sandy gradient
for y in range(SCREEN_HEIGHT):
intensity = y / SCREEN_HEIGHT
r = min(255, int(200 + intensity * 55))
g = min(255, int(150 + intensity * 50))
b = min(255, int(50 + intensity * 50))
pygame.draw.line(surf, (r, g, b), (0, y), (SCREEN_WIDTH, y))
# Add cacti
for _ in range(10):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(50, 150)
width = random.randint(10, 30)
pygame.draw.rect(surf, (0, 100, 0), (x, SCREEN_HEIGHT - height, width, height))
# Cactus arms
arm_height = height // 3
pygame.draw.rect(surf, (0, 100, 0), (x - width//2, SCREEN_HEIGHT - height + arm_height, width//2, width))
pygame.draw.rect(surf, (0, 100, 0), (x + width, SCREEN_HEIGHT - height + arm_height * 2, width//2, width))
elif style == "snow":
# Snowy gradient
for y in range(SCREEN_HEIGHT):
intensity = 1 - (y / SCREEN_HEIGHT)
color = min(255, int(200 + intensity * 55))
pygame.draw.line(surf, (color, color, 255), (0, y), (SCREEN_WIDTH, y))
# Add snowflakes
for _ in range(200):
x = random.randint(0, SCREEN_WIDTH)
y = random.randint(0, SCREEN_HEIGHT)
size = random.randint(1, 4)
pygame.draw.circle(surf, (255, 255, 255), (x, y), size)
elif style == "night":
# Dark gradient
for y in range(SCREEN_HEIGHT):
intensity = y / SCREEN_HEIGHT
color = min(50, int(10 + intensity * 40))
pygame.draw.line(surf, (color, color, color + 20), (0, y), (SCREEN_WIDTH, y))
# Add stars and moon
for _ in range(300):
x = random.randint(0, SCREEN_WIDTH)
y = random.randint(0, SCREEN_HEIGHT * 2 // 3)
size = random.randint(1, 3)
brightness = random.randint(150, 255)
pygame.draw.circle(surf, (brightness, brightness, brightness), (x, y), size)
# Moon
pygame.draw.circle(surf, (200, 200, 180), (SCREEN_WIDTH - 100, 100), 50)
pygame.draw.circle(surf, (50, 50, 70), (SCREEN_WIDTH - 120, 80), 40)
# Add level-specific elements
level_text = f"Level {level_num + 1}"
font = pygame.font.SysFont(None, 24)
text_surf = font.render(level_text, True, (255, 255, 255))
surf.blit(text_surf, (20, 20))
return surf
# Function to create a parallax layer for a specific style
def create_parallax_layer(style, layer_num):
surf = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
if style == "default":
# Different style for each layer
if layer_num == 1: # Far background
# Draw distant mountains
for i in range(5):
width = random.randint(100, 300)
height = random.randint(50, 150)
x = random.randint(0, SCREEN_WIDTH - width)
color = (20, 20, 40)
pygame.draw.polygon(surf, color, [
(x, SCREEN_HEIGHT),
(x + width//2, SCREEN_HEIGHT - height),
(x + width, SCREEN_HEIGHT)
])
elif layer_num == 2: # Middle layer
# Draw hills
for i in range(8):
width = random.randint(80, 200)
height = random.randint(40, 100)
x = random.randint(0, SCREEN_WIDTH - width)
color = (30, 50, 30)
pygame.draw.circle(surf, color, (x + width//2, SCREEN_HEIGHT + height//2), height)
elif layer_num == 3: # Front layer
# Draw trees or foreground elements
for i in range(10):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(50, 150)
width = random.randint(10, 30)
# Tree trunk
pygame.draw.rect(surf, (60, 30, 10), (x, SCREEN_HEIGHT - height, width, height))
# Tree top
pygame.draw.circle(surf, (0, 80, 0), (x + width//2, SCREEN_HEIGHT - height - 30), 40)
elif style == "forest":
if layer_num == 1: # Far background
# Distant forest
for i in range(15):
width = random.randint(100, 200)
height = random.randint(100, 200)
x = random.randint(0, SCREEN_WIDTH - width)
color = (0, 50, 0)
pygame.draw.circle(surf, color, (x + width//2, SCREEN_HEIGHT - height//2), width//2)
elif layer_num == 2: # Middle layer
# Closer trees
for i in range(10):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(100, 200)
width = random.randint(20, 40)
# Tree trunk
pygame.draw.rect(surf, (80, 40, 0), (x, SCREEN_HEIGHT - height, width, height))
# Tree top
pygame.draw.circle(surf, (0, 100, 0), (x + width//2, SCREEN_HEIGHT - height - 50), 70)
elif layer_num == 3: # Front layer
# Foreground bushes
for i in range(20):
x = random.randint(0, SCREEN_WIDTH)
size = random.randint(30, 60)
pygame.draw.circle(surf, (0, 120, 0), (x, SCREEN_HEIGHT - size//2), size)
elif style == "desert":
if layer_num == 1: # Far background
# Distant mountains
for i in range(5):
width = random.randint(200, 400)
height = random.randint(100, 200)
x = random.randint(0, SCREEN_WIDTH - width)
color = (150, 100, 50)
pygame.draw.polygon(surf, color, [
(x, SCREEN_HEIGHT),
(x + width//2, SCREEN_HEIGHT - height),
(x + width, SCREEN_HEIGHT)
])
elif layer_num == 2: # Middle layer
# Sand dunes
for i in range(8):
width = random.randint(100, 300)
height = random.randint(50, 100)
x = random.randint(0, SCREEN_WIDTH - width)
color = (200, 180, 100)
pygame.draw.circle(surf, color, (x + width//2, SCREEN_HEIGHT + height//2), height)
elif layer_num == 3: # Front layer
# Cacti and rocks
for i in range(8):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(40, 100)
width = random.randint(10, 20)
pygame.draw.rect(surf, (0, 100, 0), (x, SCREEN_HEIGHT - height, width, height))
# Cactus arms
pygame.draw.rect(surf, (0, 100, 0), (x - width//2, SCREEN_HEIGHT - height + height//3, width//2, width))
elif style == "snow":
if layer_num == 1: # Far background
# Distant mountains
for i in range(5):
width = random.randint(200, 400)
height = random.randint(150, 250)
x = random.randint(0, SCREEN_WIDTH - width)
color = (200, 200, 220)
pygame.draw.polygon(surf, color, [
(x, SCREEN_HEIGHT),
(x + width//2, SCREEN_HEIGHT - height),
(x + width, SCREEN_HEIGHT)
])
elif layer_num == 2: # Middle layer
# Snow hills
for i in range(8):
width = random.randint(100, 300)
height = random.randint(50, 100)
x = random.randint(0, SCREEN_WIDTH - width)
color = (220, 220, 240)
pygame.draw.circle(surf, color, (x + width//2, SCREEN_HEIGHT + height//2), height)
elif layer_num == 3: # Front layer
# Snow-covered trees
for i in range(10):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(50, 150)
width = random.randint(10, 30)
# Tree trunk
pygame.draw.rect(surf, (100, 80, 60), (x, SCREEN_HEIGHT - height, width, height))
# Snow-covered top
pygame.draw.circle(surf, (230, 230, 250), (x + width//2, SCREEN_HEIGHT - height - 30), 40)
elif style == "night":
if layer_num == 1: # Far background
# Distant city silhouette
for i in range(20):
width = random.randint(30, 100)
height = random.randint(50, 200)
x = random.randint(0, SCREEN_WIDTH - width)
color = (20, 20, 30)
pygame.draw.rect(surf, color, (x, SCREEN_HEIGHT - height, width, height))
# Windows
for _ in range(random.randint(2, 8)):
wx = x + random.randint(5, width-10)
wy = SCREEN_HEIGHT - height + random.randint(10, height-10)
wsize = random.randint(3, 8)
pygame.draw.rect(surf, (255, 255, 150), (wx, wy, wsize, wsize))
elif layer_num == 2: # Middle layer
# Hills and trees
for i in range(8):
width = random.randint(100, 300)
height = random.randint(50, 100)
x = random.randint(0, SCREEN_WIDTH - width)
color = (10, 10, 30)
pygame.draw.circle(surf, color, (x + width//2, SCREEN_HEIGHT + height//2), height)
elif layer_num == 3: # Front layer
# Foreground trees
for i in range(10):
x = random.randint(0, SCREEN_WIDTH)
height = random.randint(100, 200)
width = random.randint(10, 30)
# Tree silhouette
pygame.draw.rect(surf, (5, 5, 15), (x, SCREEN_HEIGHT - height, width, height))
pygame.draw.circle(surf, (5, 5, 15), (x + width//2, SCREEN_HEIGHT - height - 40), 50)
return surf
# Create level backgrounds for each style
print("Creating level backgrounds...")
for style in bg_styles:
for level in range(10):
bg = create_background(style, level)
if style == "default":
filename = f"assets/images/background_{level+1}.png"
else:
filename = f"assets/images/background_{style}_{level+1}.png"
pygame.image.save(bg, filename)
print(f"Created {filename}")
# Create parallax backgrounds for each style
print("\nCreating parallax backgrounds...")
for style in bg_styles:
for layer in range(1, 4):
bg_layer = create_parallax_layer(style, layer)
if style == "default":
filename = f"assets/images/bg_layer{layer}.png"
else:
filename = f"assets/images/bg_{style}_layer{layer}.png"
pygame.image.save(bg_layer, filename)
print(f"Created {filename}")
print("\nAll background styles have been created!")
print("You can now select these backgrounds in the game.")