+# place a tile at current spot
+def put_tile (leveldata, row, col, tilerow, tilecol):
+ leveldata[row][col][0] = tilerow
+ leveldata[row][col][1] = tilecol
+
+# picking a tile from the tileset
+def pick_tile (screen, tileset):
+ selrow, selcol = 0, 0
+
+ totalrows = tileset.get_height () / 48
+ totalcols = tileset.get_width () / 48
+
+ while 1:
+ screen.fill (pygame.Color (0, 0, 0))
+ screen.blit (tileset, (0, 0))
+ draw_cursor (screen, selrow, selcol)
+ pygame.display.update ()
+ for event in pygame.event.get ():
+ if event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_ESCAPE:
+ return None
+ elif event.key == pygame.K_SPACE or event.key == pygame.K_RETURN:
+ return selrow, selcol
+ elif event.key == pygame.K_UP:
+ selrow -= 1
+ if selrow < 0:
+ selrow = totalrows - 1
+ elif event.key == pygame.K_DOWN:
+ selrow += 1
+ if selrow >= totalrows:
+ selrow = 0
+ elif event.key == pygame.K_LEFT:
+ selcol -= 1
+ if selcol < 0:
+ selcol = totalcols - 1
+ elif event.key == pygame.K_RIGHT:
+ selcol += 1
+ if selcol >= totalcols:
+ selcol = 0
+
+