Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pygame import *
- import random
- init()
- width = 1000
- height = 1000
- screen = display.set_mode((width, height))
- clock = time.Clock()
- # ------------------------------------------------------------------------------------------
- class map():
- def __init__(self):
- self.map = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
- self.dirtImg = image.load("dirt.jpg")
- self.dirtImg = transform.scale(self.dirtImg, (100, 100))
- self.goldImg = image.load("gold.png")
- self.goldImg = transform.scale(self.goldImg, (100, 100))
- self.gold = random.randint(1,10)
- def createterrain(self):
- posx = 0
- posy = 0
- while posx < 10 and posy < 10:
- self.map[posx][posy] = "D"
- posx = posx + 1
- while posx == 10:
- posx = 0
- posy = posy + 1
- posx = 0
- posy = 0
- while posx < 10 and posy < 10:
- if self.gold == 1:
- self.map[posx][posy] = "G"
- self.gold = random.randint(1, 5)
- posx = posx + 1
- while posx == 10:
- posx = 0
- posy = posy + 1
- return self.map
- def display(self,screen):
- posx = 0
- posy = 0
- self.x = 0
- self.y = 100
- while posx < 10 and posy < 10:
- if self.map[posy][posx] == "D":
- screen.blit(self.dirtImg,(self.x,self.y))
- if self.map[posy][posx] == "G":
- screen.blit(self.goldImg,(self.x,self.y))
- posx = posx + 1
- self.x = self.x + 100
- while posx == 10:
- posx = 0
- self.x = 0
- self.y = self.y + 100
- posy = posy + 1
- screen.fill((0, 0, 0))
- world = map()
- world.createterrain()
- world.display(screen)
- game = True
- while game == True:
- for e in event.get():
- if e.type == constants.QUIT: # to quit game (close tab)
- game = False
- if e.type == KEYDOWN:
- if e.key == K_RIGHT:
- world.createterrain()
- world.display(screen)
- display.flip()
- clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement