Mercurial > qq-kill
changeset 5:22fd63214aed
level map
| author | Radomir Dopieralski <moindev@sheep.art.pl> |
|---|---|
| date | Sat, 23 Aug 2008 21:18:41 +0200 |
| parents | bc3b371cb5c4 |
| children | 3a6e7753aa28 |
| files | qq.py |
| diffstat | 1 files changed, 37 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/qq.py Sat Aug 23 02:35:05 2008 +0200 +++ b/qq.py Sat Aug 23 21:18:41 2008 +0200 @@ -5,7 +5,7 @@ from pygame.locals import * pygame.init() -pygame.display.set_mode((360, 240)) +pygame.display.set_mode((424, 400)) font = pygame.font.Font("MgOpenModataBold.ttf", 11) # Motion offsets for particular directions @@ -57,13 +57,13 @@ return - class SortedUpdates(pygame.sprite.RenderUpdates): def sprites(self): sprites = self.spritedict.keys() sprites.sort(lambda a, b: a.depth - b.depth) return sprites + class Shadow(pygame.sprite.Sprite): image = pygame.image.load("shadow.png").convert() image.set_alpha(64) @@ -76,6 +76,7 @@ def update(self): self.rect.midbottom = self.sprite.rect.midbottom + class Sprite(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) @@ -83,12 +84,12 @@ self.rect = self.image.get_rect() self.animation = self.stand_animation() - def get_pos(self): - return self.rect.midbottom - def set_pos(self, pos): - self.rect.midbottom = pos + def _get_pos(self): + return (self.rect.midbottom[0]-12)/24, (self.rect.midbottom[1]+12)/16 + def _set_pos(self, pos): + self.rect.midbottom = pos[0]*24+12, pos[1]*16+12 self.depth = pos[1] - pos = property(get_pos, set_pos) + pos = property(_get_pos, _set_pos) def move(self, dx, dy): self.rect.move_ip(dx, dy) @@ -107,17 +108,37 @@ class Level: - width = 15 - height = 15 - def __init__(self): + self.map = [ + "xxxxxxxxxxxxxxx", + "x.x.x.x.xxx...x", + "xx.x.x.x.x....x", + "x.x.x.x.xxx...x", + "xx.x.x.x.xxxxxx", + "x.x.x.x.xxx...x", + "xx.x.x.x.xx...x", + "x.x.x.x.x.....x", + "xx.x.x.x.xx...x", + "x.x.x.x.xxx...x", + "xx.x.x.x.xxxxxx", + "x.x.x.x.xxx...x", + "xx.x.x.x.x....x", + "x.x.x.x.xxx...x", + "xxxxxxxxxxxxxxx", + ] tile_image = pygame.image.load("corridor.png").convert() tile_width, tile_height = tile_image.get_size() - self.image = pygame.Surface((self.width*tile_width, - self.height*tile_height)) - for y in range(15): - for x in range(15): - self.image.blit(tile_image, (x*tile_width, y*tile_height)) + width = len(self.map[0]) + height = len(self.map) + self.image = pygame.Surface((width*tile_width, height*tile_height)) + y = 0 + for line in self.map: + x = 0 + for tile in line: + if self.map[y][x] != 'x': + self.image.blit(tile_image, (x*tile_width, y*tile_height)) + x += 1 + y += 1 def draw(self, surface): surface.blit(self.image, (0, 0)) @@ -139,7 +160,7 @@ self.direction = 2 self.animation = None self.image = self.frames[self.direction][0] - self.pos = (16, 32) # XXX Temporary, will be set on creation later + self.pos = (0, 0) # XXX Temporary, will be set on creation later def walk_animation(self): for frame in range(4): @@ -217,4 +238,3 @@ if __name__ == "__main__": Game().main() - Message("Hello\nworld!").show()
