Mercurial > fhrl
changeset 13:768d7bd98d15
doors
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 13 Mar 2013 22:30:50 +0100 |
| parents | 584503aa3366 |
| children | 7a3935873931 |
| files | fhrl/display.py fhrl/level.py fhrl/mobs.py fhrl/mobs2.png fhrl/stuff.png |
| diffstat | 5 files changed, 39 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/fhrl/display.py Wed Mar 13 17:20:28 2013 +0100 +++ b/fhrl/display.py Wed Mar 13 22:30:50 2013 +0100 @@ -6,7 +6,7 @@ class SortedUpdates(pygame.sprite.RenderUpdates): def sprites(self): - return sorted(self.spritedict.keys(), key=lambda s: s.rect.bottom) + return sorted(self.spritedict.keys(), key=lambda s: s.rect.bottom + getattr(s, 'depth', 0))
--- a/fhrl/level.py Wed Mar 13 17:20:28 2013 +0100 +++ b/fhrl/level.py Wed Mar 13 22:30:50 2013 +0100 @@ -23,10 +23,6 @@ x = max(1, min(self.width - 1, x + random.randrange(-1, 2))) y = max(1, min(self.height - 1, y + random.randrange(-1, 2))) self.grid[y][x] = 0 - for i in xrange(200): - x = random.randrange(1, self.width) - y = random.randrange(1, self.height) - self.grid[y][x] = 1 for i in xrange(50, 200): x = random.randrange(2, self.width - 3) y = random.randrange(2, self.height - 3) @@ -51,11 +47,6 @@ self.grid[dy][x] = 3 else: self.grid[dy][x + w - 1] = 3 - for i in xrange(200): - x = random.randrange(1, self.width) - y = random.randrange(1, self.height) - if self.grid[y][x] == 1: - self.grid[y][x] = 4 self.rect(0, 0, self.width, self.height, 0) @@ -64,7 +55,7 @@ (x, y) for y, row in enumerate(self.grid) for x, f in enumerate(row) - if f + if f == 1 ] random.shuffle(self.free) self.hero = Hero(0, self.free.pop()) @@ -76,10 +67,24 @@ Item(random.randrange(6), self.free.pop()) for i in xrange(20) ] - self.stuff = [ - Stuff(random.randrange(4), self.free.pop()) - for i in xrange(20) - ] + self.stuff = [] + for y, row in enumerate(self.grid): + for x, f in enumerate(row): + if f <= 1: + continue + if (f == 2 and + self.is_wall((x - 1, y)) and + self.is_wall((x + 1, y))): + kind = random.randrange(4, 6) + self.stuff.append(Stuff(kind, (x, y))) + elif (f == 3 and + self.is_wall((x, y - 1)) and + self.is_wall((x, y + 1))): + kind = random.randrange(6, 8) + self.stuff.append(Stuff(kind, (x, y))) + else: + kind = random.randrange(4) + self.stuff.append(Stuff(kind, (x, y))) x, y = self.free.pop() self.grid[y][x] = 5 @@ -90,11 +95,22 @@ if (x, y) == (self.hero.x, self.hero.y): return self.hero + def is_wall(self, (x, y)): + if x < 0 or x > self.width: + return True + if y < 0 or y > self.height: + return True + if self.grid[y][x] == 0: + return True + return False + def is_blocked(self, (x, y)): - if self.grid[y][x] == 0: + if self.is_wall((x, y)): return True for s in self.stuff: if (x, y) == (s.x, s.y): + if s.kind in (5, 7): + return False return True return False @@ -102,15 +118,17 @@ return iter(self.grid) def rect(self, sx, sy, w, h, v): + def s(x, y, v): + self.grid[y][x] = max(self.grid[y][x], v) if v>0 else 0 sx = max(0, min(self.width, sx)) sy = max(0, min(self.height, sy)) w = max(1, min(self.width - sx, w)) h = max(1, min(self.height - sy, h)) for y in xrange(sy, sy + h): - self.grid[y][sx] = v - self.grid[y][sx + w - 1] = v + s(sx, y, v) + s(sx + w - 1, y, v) for x in xrange(sx, sx + w): - self.grid[sy][x] = v - self.grid[sy + h - 1][x] = v + s(x, sy, v) + s(x, sy + h - 1, v) return sx, sy, w, h
