-#!/usr/bin/env python3
+#!/usr/bin/env python
# level designer gui - this is used to design level graphics
# very rough and ready - main purpose is to allow quick game
-# design. inputting levels by hand array is very tough
+# design. inputting levels by hand array is very tedious
import pygame
import os.path
# get the actual data in that place
leveldata[row][col][2] = not leveldata[row][col][2]
+# 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
+
+
# the actual level editor
def level_editor (fname):
# load level data
screen = pygame.display.set_mode ((720, 512))
pygame.display.set_caption ("Level editor")
currow, curcol = 0, 0
+ tilerow, tilecol = 0, 0
while 1:
screen.fill (pygame.Color (0, 0, 0))
if event.key == ord ("q"):
pygame.quit ()
return
+ elif event.key == ord ("s"):
+ cPickle.dump (leveldata, file (fname, "w"))
+ print ("Level saved")
elif event.key == pygame.K_DOWN:
currow += 1
if currow > 9:
curcol += 1
if curcol > 9:
curcol = 0
+ elif event.key == pygame.K_SPACE or event.key == pygame.K_RETURN:
+ put_tile (leveldata, currow, curcol, tilerow, tilecol)
+ elif event.key == ord ("p"):
+ tile = pick_tile (screen, tileset)
+ if tile is not None:
+ tilerow = tile[0]
+ tilecol = tile[1]
elif event.key == ord ("w"):
make_wall (leveldata, currow, curcol)
level_editor (fname)
def load_level ():
- pass
+ fname = raw_input ("Level file to load: ")
+ level_editor (fname)
def main ():
while 1:
if __name__=="__main__":
- main ()
\ No newline at end of file
+ main ()