Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pygame import *
- from random import *
- init()
- # set up code
- # Set up screen
- width = 1200
- height = 700
- screen = display.set_mode((width, height))
- clock = time.Clock()
- # ------------------------------------------------------------------------------------------
- # load pictures and scale it!
- dirtImg = image.load("dirt.jpg")
- dirtImg = transform.scale(dirtImg, (60, 60))
- goldImg = image.load("gold.png")
- goldImg = transform.scale(goldImg, (60, 60))
- x = 350 # position of first alien
- y = 20
- Terrain = []
- count = 0
- row = 0
- def createterrain(count, row):
- x = 0
- y = 400
- while count < 20 and row < 5: # count = number of aliens, row = number of rows
- dirt = Rect(x, y, 60, 60)
- gold = Rect(x, y, 60, 60)
- dirtnum = randint(1, 2)
- goldnum = randint(1, 100)
- print("d: " +str(dirtnum))
- print("g: " +str(goldnum))
- if dirtnum == 1:
- Terrain.append(dirt)
- if goldnum == 1:
- Terrain.append(gold)
- x = x + 60 # distance of aliens on x-axis
- count = count + 1
- if count == 20:
- count = 0
- y = y + 60 # distance of aliens on y-axis
- row = row + 1
- x = 0
- return Terrain
- terrain = createterrain(count, row) # calls function
- run = True
- while run:
- for e in event.get():
- if e.type == constants.QUIT:
- run = False
- for t in Terrain:
- screen.blit(dirtImg, t)
- for t in Terrain:
- screen.blit(goldImg, g)
- display.flip()
- screen.fill((0, 0, 0))
- clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement