Mercurial > nagslang
annotate tools/area_editor.py @ 109:817d4a62135c
Partially albowify the level editor
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 02 Sep 2013 14:09:39 +0200 |
parents | dde91f8c4335 |
children | 6415db718b36 |
rev | line source |
---|---|
71
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
1 #!/usr/bin/env python |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
2 |
51 | 3 # The basic area editor |
4 # | |
5 # To edit an existing level, use | |
6 # editor levelname | |
7 # | |
8 # To create a new level: | |
9 # | |
10 # editor levelname <xsize> <ysiz> | |
11 # (size specified in pixels | |
12 # | |
13 | |
71
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
14 import os |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
15 import sys |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
16 |
51 | 17 import pygame |
18 import pygame.locals as pgl | |
19 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
20 from albow.root import RootWidget |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
21 from albow.widget import Widget |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
22 from albow.controls import Button |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
23 |
71
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
24 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
c449a3507a6b
Shebang and path hacking, so that the area_editor runs
Stefano Rivera <stefano@rivera.za.net>
parents:
57
diff
changeset
|
25 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
26 from nagslang.constants import SCREEN |
51 | 27 from nagslang.level import Level, POLY_COLORS |
28 | |
29 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
30 # layout constants |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
31 MENU_WIDTH = 200 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
32 MENU_BUTTON_HEIGHT = 35 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
33 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
34 |
51 | 35 class EditorLevel(Level): |
36 | |
37 def __init__(self, name, x=800, y=600): | |
38 super(EditorLevel, self).__init__(name) | |
39 self.x = x | |
40 self.y = y | |
41 | |
42 def round_point(self, pos): | |
43 return (10 * (pos[0] // 10), 10 * (pos[1] // 10)) | |
44 | |
45 def point_to_pymunk(self, pos): | |
46 # inverse of point_to_pygame | |
47 # (this is also the same as point_to_pygame, but a additional | |
48 # function for sanity later in pyweek). | |
49 return (pos[0], self.y - pos[1]) | |
50 | |
51 def add_point(self, poly_index, pos): | |
52 self.polygons.setdefault(poly_index, []) | |
53 if not self.polygons[poly_index]: | |
99 | 54 point = self.point_to_pymunk(self.round_point(pos)) |
55 self.polygons[poly_index].append(point) | |
51 | 56 else: |
57 add_pos = self.fix_angle(poly_index, pos) | |
58 self.polygons[poly_index].append(add_pos) | |
59 | |
60 def fix_angle(self, index, pos): | |
61 # Last point | |
62 point1 = self.point_to_pygame(self.polygons[index][-1]) | |
63 pos = self.round_point(pos) | |
64 # We want the line (point1 to pos) to be an angle of | |
65 # 0, 45, 90, 135, 180, 225, 270, 305 | |
66 # However, we only need to consider half the circle | |
67 # This is a hack to approximate the right thing | |
68 pos0 = (pos[0], point1[1]) | |
69 pos90 = (point1[0], pos[1]) | |
70 dist = max(abs(point1[0] - pos[0]), abs(point1[1] - pos[1])) | |
71 pos45 = (point1[0] + dist, point1[1] + dist) | |
72 pos135 = (point1[0] + dist, point1[1] - dist) | |
73 pos225 = (point1[0] - dist, point1[1] - dist) | |
74 pos305 = (point1[0] - dist, point1[1] + dist) | |
75 min_dist = 9999999 | |
76 new_pos = point1 | |
77 for cand in [pos0, pos90, pos45, pos135, pos225, pos305]: | |
78 dist = (pos[0] - cand[0]) ** 2 + (pos[1] - cand[1]) ** 2 | |
79 if dist < min_dist: | |
80 new_pos = cand | |
81 min_dist = dist | |
82 return self.point_to_pymunk(new_pos) | |
83 | |
84 def delete_point(self, index): | |
85 if index in self.polygons and len(self.polygons[index]) > 0: | |
86 self.polygons[index].pop() | |
87 | |
96
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
88 def draw(self, surface, topleft, mouse_pos, mouse_poly, filled): |
51 | 89 self._draw_background(True) |
90 # Draw polygons as needed for the editor | |
96
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
91 if filled: |
a9b564c38bef
Support showing exterior filled view in the editor
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
92 self._draw_exterior(True) |
51 | 93 for index, polygon in self.polygons.items(): |
94 color = POLY_COLORS[index] | |
95 if len(polygon) > 1: | |
96 pointlist = [self.point_to_pygame(p) for p in polygon] | |
97 pygame.draw.lines(self._surface, color, False, pointlist, 2) | |
98 if index == mouse_poly and mouse_pos: | |
99 endpoint = self.fix_angle(index, mouse_pos) | |
100 pygame.draw.line(self._surface, color, | |
99 | 101 self.point_to_pygame(polygon[-1]), |
102 self.point_to_pygame(endpoint)) | |
51 | 103 surface_area = pygame.rect.Rect(topleft, SCREEN) |
104 surface.blit(self._surface, (0, 0), surface_area) | |
105 | |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
106 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
107 class LevelWidget(Widget): |
51 | 108 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
109 def __init__(self, level): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
110 super(LevelWidget, self).__init__(pygame.rect.Rect(0, 0, |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
111 SCREEN[0], SCREEN[1])) |
51 | 112 self.level = level |
113 self.pos = (0, 0) | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
114 self.filled_mode = False |
51 | 115 self.mouse_pos = None |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
116 self.cur_poly = None |
51 | 117 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
118 def _level_coordinates(self, pos): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
119 # Move positions to level values |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
120 if not pos: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
121 return (0, 0) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
122 return pos[0] + self.pos[0], pos[1] + self.pos[1] |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
123 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
124 def _move_view(self, offset): |
51 | 125 new_pos = [self.pos[0] + offset[0], self.pos[1] + offset[1]] |
126 if new_pos[0] < 0: | |
127 new_pos[0] = self.pos[0] | |
128 elif new_pos[0] > self.level.x - SCREEN[0]: | |
129 new_pos[0] = self.pos[0] | |
130 if new_pos[1] < 0: | |
131 new_pos[1] = self.pos[1] | |
132 elif new_pos[1] > self.level.y - SCREEN[1]: | |
133 new_pos[1] = self.pos[1] | |
134 self.pos = tuple(new_pos) | |
135 | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
136 def draw(self, surface): |
51 | 137 if (self.cur_poly is not None and self.cur_poly in self.level.polygons |
138 and len(self.level.polygons[self.cur_poly])): | |
139 # We have an active polygon | |
140 mouse_pos = self._level_coordinates(self.mouse_pos) | |
141 else: | |
142 mouse_pos = None | |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
143 level.draw(surface, self.pos, mouse_pos, self.cur_poly, |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
144 self.filled_mode) |
51 | 145 |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
146 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
147 if ev.key == pgl.K_LEFT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
148 self._move_view((-10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
149 elif ev.key == pgl.K_RIGHT: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
150 self._move_view((10, 0)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
151 elif ev.key == pgl.K_UP: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
152 self._move_view((0, -10)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
153 elif ev.key == pgl.K_DOWN: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
154 self._move_view((0, 10)) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
155 elif ev.key == pgl.K_1: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
156 self.cur_poly = 1 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
157 self.filled_mode = False |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
158 elif ev.key == pgl.K_2: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
159 self.cur_poly = 2 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
160 self.filled_mode = False |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
161 elif ev.key == pgl.K_3: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
162 self.cur_poly = 3 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
163 self.filled_mode = False |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
164 elif ev.key == pgl.K_4: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
165 self.cur_poly = 4 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
166 self.filled_mode = False |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
167 elif ev.key == pgl.K_5: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
168 self.cur_poly = 5 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
169 self.filled_mode = False |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
170 elif ev.key == pgl.K_6: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
171 self.cur_poly = 6 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
172 self.filled_mode = False |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
173 elif ev.key == pgl.K_0: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
174 self.cur_poly = None |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
175 elif ev.key == pgl.K_d and self.cur_poly: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
176 self.level.delete_point(self.cur_poly) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
177 elif ev.key == pgl.K_s: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
178 level.save() |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
179 elif ev.key == pgl.K_f: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
180 if level.all_closed(): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
181 self.cur_poly = None |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
182 self.filled_mode = True |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
183 else: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
184 print 'Not all polygons closed, so not filling' |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
185 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
186 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
187 old_pos = self.mouse_pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
188 self.mouse_pos = ev.pos |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
189 if self.cur_poly and old_pos != self.mouse_pos: |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
190 self.invalidate() |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
191 |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
192 def mouse_down(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
193 if self.cur_poly: |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
194 # Add a point |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
195 self.level.add_point(self.cur_poly, |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
196 self._level_coordinates(ev.pos)) |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
197 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
198 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
199 class EditorApp(RootWidget): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
200 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
201 def __init__(self, level, surface): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
202 super(EditorApp, self).__init__(surface) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
203 self.level = level |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
204 self.level_widget = LevelWidget(self.level) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
205 self.add(self.level_widget) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
206 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
207 quit_but = Button('Quit', action=self.quit) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
208 quit_but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
209 quit_but.rect.move_ip(SCREEN[0], 25) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
210 self.add(quit_but) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
211 |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
212 def key_down(self, ev): |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
213 if ev.key == pgl.K_ESCAPE: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
214 self.quit() |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
215 else: |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
216 self.level_widget.key_down(ev) |
51 | 217 |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
218 def mouse_move(self, ev): |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
219 self.level_widget.mouse_move(ev) |
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
220 |
51 | 221 |
222 if __name__ == "__main__": | |
223 if len(sys.argv) == 2: | |
224 level = EditorLevel(sys.argv[1]) | |
225 level.load() | |
226 elif len(sys.argv) == 4: | |
227 level = EditorLevel(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) | |
228 else: | |
229 print 'Please supply a levelname or levelname and level size' | |
230 sys.exit() | |
231 pygame.display.init() | |
232 pygame.font.init() | |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
233 pygame.display.set_mode((SCREEN[0] + MENU_WIDTH, SCREEN[1]), |
109
817d4a62135c
Partially albowify the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
108
diff
changeset
|
234 pgl.SWSURFACE) |
51 | 235 pygame.display.set_caption('Nagslang Area Editor') |
108
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
236 pygame.key.set_repeat(200, 100) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
237 app = EditorApp(level, pygame.display.get_surface()) |
dde91f8c4335
Add fonts needed for Albowifying the editor
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
238 app.run() |