Mercurial > scrounge
changeset 12:7179a8e8134f
add entrances
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 21 Aug 2011 20:09:21 +0200 |
| parents | 69b00c82b380 |
| children | 028bb963b92b |
| files | display.py generator.py hero.py level.py main.py thing.py |
| diffstat | 6 files changed, 48 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/display.py Sun Aug 21 19:47:11 2011 +0200 +++ b/display.py Sun Aug 21 20:09:21 2011 +0200 @@ -155,6 +155,11 @@ self.key = None return keys + def scroll_to(self, rect): + self.scroll_offset = (self.screen.get_width() / 2 - rect.center[0], + self.screen.get_height() / 2 - rect.center[1]) + self.redraw() + def scroll_after(self, rect): x, y = self.scroll_offset hscroll, vscroll = 0, 0
--- a/generator.py Sun Aug 21 19:47:11 2011 +0200 +++ b/generator.py Sun Aug 21 20:09:21 2011 +0200 @@ -51,8 +51,17 @@ line[i] = 'x' self.make_stairs() + def _random_place(self): + r1 = random.choice(random.choice(self.rooms)) + x1 = random.randint(r1[0] + 1, r1[2] - 1) + y1 = random.randint(r1[1] + 1, r1[3] - 1) + return x1, y1 + def make_stairs(self): - pass + x1, y1 = self._random_place() + self.things.append(thing.Entrance(x1, y1)) + x1, y1 = self._random_place() + self.map[y1][x1] = '>' def make_connections(self): connected = [(random.randint(0, 2), random.randint(0, 2))]
--- a/hero.py Sun Aug 21 19:47:11 2011 +0200 +++ b/hero.py Sun Aug 21 20:09:21 2011 +0200 @@ -42,8 +42,8 @@ yield def anim_drop(self): + self.depth = self.rect.midbottom[1] + 1 self.rect.move_ip(0, -15) - self.depth = self.rect.midbottom[1] + 1 for step in range(6): yield self.rect.move_ip(0, step)
--- a/level.py Sun Aug 21 19:47:11 2011 +0200 +++ b/level.py Sun Aug 21 20:09:21 2011 +0200 @@ -3,6 +3,7 @@ import display import hero +import thing import generator import pygame @@ -30,6 +31,10 @@ tx, ty = 3, 3 +class StairsTile(Tile): + tx, ty = 1, 3 + + class WallTile(Tile): filename = 'wall.png' blocks = True @@ -67,17 +72,20 @@ '.': Tile, '+': DoorTile, ',': CorridorTile, + '>': StairsTile, 'x': WallTile, } BLOCKED = 1 def __init__(self): + self.hero = None gen = generator.LevelGenerator() self.map = gen.map self.things = {} for t in gen.things: self.things[(t.x, t.y)] = t - self.hero = None + if isinstance(t, thing.Entrance) and self.hero is None: + self.hero = hero.Hero(t.x, t.y) def is_blocked(self, x, y): if x<0 or y<0: @@ -95,8 +103,6 @@ for y, line in enumerate(self.map): self.flags.append([]) for x, c in enumerate(line): - if not self.hero and c == '.': - self.hero = hero.Hero(x, y) tile_class = self.key.get(c) if tile_class: tile = tile_class(x, y, self.map)
--- a/main.py Sun Aug 21 19:47:11 2011 +0200 +++ b/main.py Sun Aug 21 20:09:21 2011 +0200 @@ -12,7 +12,7 @@ self.display = display.Display((320, 256)) self.level = level.Level() self.level.render(self.display) - self.display.redraw() + self.display.scroll_to(self.level.hero.sprite.rect) def control(self): if self.display.key == pygame.locals.K_ESCAPE:
--- a/thing.py Sun Aug 21 19:47:11 2011 +0200 +++ b/thing.py Sun Aug 21 20:09:21 2011 +0200 @@ -3,16 +3,30 @@ import display -class Door(object): +class Thing(object): + tx, ty = 0, 1 + + def __init__(self, x, y): + self.x = x + self.y = y + + def render(self, to_display): + self.sprite = display.Sprite(self.x, self.y, 'objects.png', + self.tx, self.ty) + to_display.sprites.add(self.sprite) + + +class Door(Thing): + tx, ty = 0, 0 + def __init__(self, x, y, vertical): self.x = x self.y = y self.vertical = vertical + if self.vertical: + self.tx = 1 - def render(self, to_display): - if self.vertical: - tx = 1 - else: - tx = 0 - self.sprite = display.Sprite(self.x, self.y, 'objects.png', tx, 0) - to_display.sprites.add(self.sprite) + +class Entrance(Thing): + tx, ty = 3, 0 +
