3 # level designer gui - this is used to design level graphics
4 # very rough and ready - main purpose is to allow quick game
5 # design. inputting levels by hand array is very tough
14 # draw the level actually
15 def draw_level (screen
, leveldata
, tileset
):
19 for tilerow
, tilecol
, is_solid
in row
:
22 screen
.blit (tileset
, (j
*48, i
*48), pygame
.Rect (tilex
, tiley
, 48, 48))
24 utility
.put_text (screen
, j
*48+2, i
*48+2, 10, (255,255,0), "w")
28 def display_menu (screen
):
29 utility
.put_text (screen
, 490, 10, 10, (255,255,0), "p to pick tile")
30 utility
.put_text (screen
, 490, 50, 10, (255,255,0), "w to wall (solid)")
31 utility
.put_text (screen
, 490, 90, 10, (255,255,0), "<space> to place")
32 utility
.put_text (screen
, 490, 130, 10,(255,255,0), "Arrows to move around")
33 utility
.put_text (screen
, 490, 170, 10, (255,255,0), "s to Save level")
34 utility
.put_text (screen
, 490, 210, 10, (255,255,0), "q to Quit editor")
36 # draw the tile cursor
37 def draw_cursor (screen
, currow
, curcol
):
38 pygame
.draw
.rect (screen
, (255,255,255), (curcol
*48, currow
*48, 48, 48), 1)
41 def make_wall (leveldata
, row
, col
):
42 # get the actual data in that place
43 leveldata
[row
][col
][2] = not leveldata
[row
][col
][2]
45 # the actual level editor
46 def level_editor (fname
):
48 leveldata
= cPickle
.load (file (fname
))
52 tileset
= pygame
.image
.load (os
.path
.join ("background", "tileset.png"))
53 screen
= pygame
.display
.set_mode ((720, 512))
54 pygame
.display
.set_caption ("Level editor")
58 screen
.fill (pygame
.Color (0, 0, 0))
60 draw_level (screen
, leveldata
, tileset
)
61 draw_cursor (screen
, currow
, curcol
)
62 pygame
.display
.update ()
63 for event
in pygame
.event
.get ():
64 if event
.type == pygame
.KEYDOWN
:
65 if event
.key
== ord ("q"):
68 elif event
.key
== pygame
.K_DOWN
:
72 elif event
.key
== pygame
.K_UP
:
76 elif event
.key
== pygame
.K_LEFT
:
80 elif event
.key
== pygame
.K_RIGHT
:
84 elif event
.key
== ord ("w"):
85 make_wall (leveldata
, currow
, curcol
)
89 fname
= raw_input ("New level file path: ")
90 # prepare level with blank tiles
92 [[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]],
93 [[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]],
94 [[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]],
95 [[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]],
96 [[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]],
97 [[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]],
98 [[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]],
99 [[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]],
100 [[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]],
101 [[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]]
103 # save the level first
104 cPickle
.dump (leveldata
, file (fname
, "w"))
115 print ("Level Editor for the Adventures of Butaba")
117 print ("1. Start a new level")
118 print ("2. Load existing level")
121 ch
= raw_input ("Your choice: ")
129 print ("Wrong choice. Must be 1, 2, or 3")
132 if __name__
=="__main__":