Mercurial > skaapsteker
comparison scripts/level-editor @ 19:0831989ce8e1
Add simple level browser
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 03 Apr 2011 17:23:43 +0200 |
parents | |
children | 3d70de522b11 |
comparison
equal
deleted
inserted
replaced
18:81974842b38e | 19:0831989ce8e1 |
---|---|
1 #!/usr/bin/env python | |
2 "Skaapsteker level editor" | |
3 | |
4 import optparse | |
5 | |
6 import pygame | |
7 import pygame.key | |
8 from pygame.locals import (SWSURFACE, QUIT, KEYDOWN, K_UP, K_DOWN, K_LEFT, | |
9 K_RIGHT, KMOD_SHIFT) | |
10 | |
11 from skaapsteker.constants import SCREEN | |
12 from skaapsteker.level import Level | |
13 | |
14 FRAMERATE = 60 | |
15 | |
16 def run(levelname): | |
17 clock = pygame.time.Clock() | |
18 surface = pygame.display.get_surface() | |
19 level = Level(levelname) | |
20 position = [0, 0] | |
21 while True: | |
22 events = pygame.event.get() | |
23 for ev in events: | |
24 if ev.type is QUIT: | |
25 return | |
26 elif ev.type is KEYDOWN: | |
27 distance = 10 | |
28 if ev.mod & KMOD_SHIFT != 0: | |
29 distance = 100 | |
30 if ev.key == K_UP: | |
31 position[1] -= distance | |
32 elif ev.key == K_DOWN: | |
33 position[1] += distance | |
34 elif ev.key == K_LEFT: | |
35 position[0] -= distance | |
36 elif ev.key == K_RIGHT: | |
37 position[0] += distance | |
38 | |
39 position[0] = max(position[0], 0) | |
40 position[0] = min(position[0], level.level_size[0] - SCREEN[0]) | |
41 position[1] = max(position[1], 0) | |
42 position[1] = min(position[1], level.level_size[1] - SCREEN[1]) | |
43 | |
44 level.draw(surface, position) | |
45 pygame.display.flip() | |
46 clock.tick(FRAMERATE) | |
47 | |
48 def main(): | |
49 p = optparse.OptionParser(usage="%prog [options] levelname") | |
50 opts, args = p.parse_args() | |
51 if len(args) != 1: | |
52 p.error("Must provide level name") | |
53 pygame.display.init() | |
54 pygame.font.init() | |
55 pygame.display.set_mode(SCREEN, SWSURFACE) | |
56 pygame.display.set_caption("Skapsteker Level Editor") | |
57 pygame.key.set_repeat(100, 20) | |
58 run(args[0]) | |
59 | |
60 if __name__ == '__main__': | |
61 main() |