# Untitled

Jan 13th, 2021
41
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from pygame import *
2. from random import *
3. init()
4. # set up code
5.
6.
7. # Set up screen
8.
9.
10. width = 1200
11.
12. height = 700
13.
14. screen = display.set_mode((width, height))
15.
16. clock = time.Clock()
17.
18. # ------------------------------------------------------------------------------------------
19.
20. # load pictures and scale it!
22.
23. dirtImg = transform.scale(dirtImg, (60, 60))
24.
26.
27. goldImg = transform.scale(goldImg, (60, 60))
28.
29.
30.
31. x = 350  # position of first alien
32.
33. y = 20
34.
35. Terrain = []
36.
37. count = 0
38.
39. row = 0
40.
41.
42.
43. def createterrain(count, row):
44.     x = 0
45.
46.     y = 400
47.
48.     while count < 20 and row < 5:  # count = number of aliens, row = number of rows
49.
50.         dirt = Rect(x, y, 60, 60)
51.         gold = Rect(x, y, 60, 60)
52.         dirtnum = randint(1, 2)
53.         goldnum = randint(1, 100)
54.
55.         print("d: " +str(dirtnum))
56.         print("g: " +str(goldnum))
57.         if dirtnum == 1:
58.             Terrain.append(dirt)
59.         if goldnum == 1:
60.             Terrain.append(gold)
61.
62.         x = x + 60  # distance of aliens on x-axis
63.
64.         count = count + 1
65.
66.         if count == 20:
67.             count = 0
68.
69.             y = y + 60  # distance of aliens on y-axis
70.
71.             row = row + 1
72.
73.             x = 0
74.
75.     return Terrain
76.
77.
78. terrain = createterrain(count, row)  # calls function
79.
80.
81.
82. run = True
83. while run:
84.     for e in event.get():
85.
86.         if e.type == constants.QUIT:
87.             run = False
88.
89.     for t in Terrain:
90.         screen.blit(dirtImg, t)
91.     for t in Terrain:
92.         screen.blit(goldImg, t)
93.
94.     display.flip()
95.     screen.fill((0, 0, 0))
96.
97.     clock.tick(60)
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.