Mercurial > skaapsteker
comparison scripts/level-editor @ 45:7f7b4bfbaf0e
Trivial text rendering widget
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 03 Apr 2011 20:48:26 +0200 |
parents | 4a9e26f1f35a |
children | 416e40b77924 |
comparison
equal
deleted
inserted
replaced
44:ccc7ed272e84 | 45:7f7b4bfbaf0e |
---|---|
8 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | 8 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) |
9 | 9 |
10 import pygame | 10 import pygame |
11 import pygame.key | 11 import pygame.key |
12 from pygame.locals import (SWSURFACE, QUIT, KEYDOWN, K_UP, K_DOWN, K_LEFT, | 12 from pygame.locals import (SWSURFACE, QUIT, KEYDOWN, K_UP, K_DOWN, K_LEFT, |
13 K_RIGHT, KMOD_SHIFT, K_q) | 13 K_RIGHT, KMOD_SHIFT, K_q, K_ESCAPE) |
14 | 14 |
15 from skaapsteker.constants import SCREEN | 15 from skaapsteker.constants import SCREEN |
16 from skaapsteker.level import Level | 16 from skaapsteker.level import Level |
17 import skaapsteker.widgets.text | |
17 | 18 |
18 FRAMERATE = 60 | 19 FRAMERATE = 60 |
19 | 20 |
20 def run(levelname): | 21 def run(levelname): |
21 clock = pygame.time.Clock() | 22 clock = pygame.time.Clock() |
38 position[1] += distance | 39 position[1] += distance |
39 elif ev.key == K_LEFT: | 40 elif ev.key == K_LEFT: |
40 position[0] -= distance | 41 position[0] -= distance |
41 elif ev.key == K_RIGHT: | 42 elif ev.key == K_RIGHT: |
42 position[0] += distance | 43 position[0] += distance |
43 elif ev.key == K_q: | 44 elif ev.key in (K_q, K_ESCAPE): |
44 return | 45 return |
45 | 46 |
46 position[0] = max(position[0], 0) | 47 position[0] = max(position[0], 0) |
47 position[0] = min(position[0], level.pixel_size[0] - SCREEN[0]) | 48 position[0] = min(position[0], level.pixel_size[0] - SCREEN[0]) |
48 position[1] = max(position[1], 0) | 49 position[1] = max(position[1], 0) |
50 | 51 |
51 clip_rect = pygame.Rect(position, screen_surface.get_size()) | 52 clip_rect = pygame.Rect(position, screen_surface.get_size()) |
52 level_surface.set_clip(clip_rect) | 53 level_surface.set_clip(clip_rect) |
53 level.draw(level_surface) | 54 level.draw(level_surface) |
54 screen_surface.blit(level_surface, (0, 0), clip_rect) | 55 screen_surface.blit(level_surface, (0, 0), clip_rect) |
56 | |
57 text = skaapsteker.widgets.text.Text("Level: %s. Offset: %r" | |
58 % (levelname, position), | |
59 colour='white') | |
60 text.draw(screen_surface, (10, 10)) | |
55 | 61 |
56 pygame.display.flip() | 62 pygame.display.flip() |
57 clock.tick(FRAMERATE) | 63 clock.tick(FRAMERATE) |
58 | 64 |
59 def main(): | 65 def main(): |