Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys
- #constants representing colors
- BLACK = (0,0,0)
- BROWN = (153,76,0)
- GREEN = (0,255,0)
- BLUE = (0,0,255)
- #constants representing resources
- DIRT = 0
- GRASS = 1
- WATER = 2
- COAL = 3
- #a dictionary linking resources to colors
- colors = {
- DIRT : BROWN,
- GRASS : GREEN,
- WATER : BLUE,
- COAL : BLACK
- }
- #a list representing the tilemap
- tilemap = [
- [GRASS,COAL,DIRT],
- [WATER,WATER,GRASS],
- [COAL,GRASS,WATER],
- [DIRT,GRASS,COAL],
- [GRASS,WATER,DIRT],
- ]
- #useful game dimensions
- TILESIZE = 40
- MAPWIDTH = 3
- MAPHEIGHT = 5
- #set up the display
- pygame.init()
- DISPLAYSURF = pygame.display.set_mode((MAPWIDTH*TILESIZE,MAPHEIGHT*TILESIZE))
- while True:
- #get all user events
- for event in pygame.event.get():
- #if user wants to quit
- if event.type == pygame.QUIT:
- #close the game and window
- pygame.quit()
- sys.exit()
- #loop thru each row
- for row in range(MAPHEIGHT):
- #loop thru each column in row
- for column in range(MAPWIDTH):
- #draw the resource at that pos in tilemap, using correct color
- pygame.draw.rect(DISPLAYSURF, colors[tilemap[row][column]], (column*TILESIZE,row*TILESIZE,TILESIZE,TILESIZE))
- #update display
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement