Mercurial > scrounge
changeset 15:ba21d882480c
random trash for dungeon decoration
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 21 Aug 2011 21:10:19 +0200 |
| parents | 2fee7a784843 |
| children | 18954a799e9e |
| files | generator.py hero.py level.py |
| diffstat | 3 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/generator.py Sun Aug 21 20:53:33 2011 +0200 +++ b/generator.py Sun Aug 21 21:10:19 2011 +0200 @@ -8,7 +8,7 @@ class LevelGenerator(object): def __init__(self): self.map = [['x'] * 30 for i in range(30)] - self.things = [] + self.things = {} self.rooms = [[self.make_room(x, y) for x in range(3)] for y in range(3)] for line in self.rooms: @@ -30,11 +30,15 @@ def make_trash(self): for i in range(25): - self.things.append(thing.Plant(*self._random_place())) + p = self._random_place() + if p not in self.things: + self.things[p] = thing.Plant(*p) def make_stairs(self): - x1, y1 = self._random_place() - self.things.append(thing.Entrance(x1, y1)) + p = self._random_place() + while p in self.things: + p = self._random_place() + self.things[p] = thing.Entrance(*p) x1, y1 = self._random_place() self.map[y1][x1] = '>' @@ -107,9 +111,9 @@ self.map[y1][x1] = '+' self.map[y2][x2] = '+' if random.randint(0, 10) > 7: - self.things.append(thing.Door(x1, y1, not v)) + self.things[(x1, y1)] = thing.Door(x1, y1, not v) if random.randint(0, 10) > 7: - self.things.append(thing.Door(x2, y2, not v)) + self.things[(x2, y2)] = thing.Door(x2, y2, not v) def rect(self, x1, y1, x2, y2, c, fill=None): if fill:
--- a/hero.py Sun Aug 21 20:53:33 2011 +0200 +++ b/hero.py Sun Aug 21 21:10:19 2011 +0200 @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import display +import thing class HeroSprite(display.Sprite): @@ -49,7 +50,7 @@ self.rect.move_ip(0, step) -class Hero(object): +class Hero(thing.Thing): def __init__(self, x=1, y=1): self.x, self.y = x, y self.sprite = HeroSprite(self.x, self.y)
--- a/level.py Sun Aug 21 20:53:33 2011 +0200 +++ b/level.py Sun Aug 21 21:10:19 2011 +0200 @@ -102,7 +102,7 @@ gen = generator.LevelGenerator() self.map = gen.map self.things = {} - for t in gen.things: + for t in gen.things.itervalues(): self.things[(t.x, t.y)] = t if isinstance(t, thing.Entrance) and self.hero is None: self.hero = hero.Hero(t.x, t.y)
