Python: How to make a map editor in pygame (part 1)

In this first part we will see how to make a map for this game or for any other game like this that uses tiles.

the vlog
# editor
import pygame



width = 15
height = 9

class Sprite:
    width = 32
    height = 32

tiles = pygame.image.load("assets\\tiles.png")

_map = (
    "               ", #1
    "               ", #2
    "               ", #3
    "  72  22 2 26 ",
    "    7222226    ",
    "      22       ",
    "      22       ",
    "000000000000000",
    "000000000000000",
    "111111111111111",
    )


screen = pygame.display.set_mode((width*Sprite.width, height*Sprite.height))



while True:
  for event in pygame.event.get():
      if event.type == pygame.QUIT:
          pygame.quit()
  for y, line in enumerate(_map): # y is the number of the line
      for x, str_num in enumerate(line): # x is the number of the column
          if str_num != " ":
              screen.blit(tiles, (x*32, y*32), (int(str_num) * 32, 0, 32, 32))
  pygame.display.flip()



Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.