Mercurial > fhrl
changeset 4:56b6fab47935
Nicer walls
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Mon, 11 Mar 2013 21:47:43 +0100 |
| parents | b58123926938 |
| children | 87e2727bb411 |
| files | fhrl/__init__.pyc fhrl/__main__.py fhrl/mobs2.png fhrl/rocks.png fhrl/walls.png |
| diffstat | 5 files changed, 26 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/fhrl/__main__.py Mon Mar 11 09:44:59 2013 +0100 +++ b/fhrl/__main__.py Mon Mar 11 21:47:43 2013 +0100 @@ -37,12 +37,12 @@ self.width = width self.height = height self.grid = [ - [0] * width for y in xrange(height) + [1] * width for y in xrange(height) ] for i in xrange(200): x = random.randrange(1, self.width) y = random.randrange(1, self.height) - self.grid[y][x] = 1 + self.grid[y][x] = 0 for i in xrange(50, 200): x = random.randrange(2, self.width - 3) y = random.randrange(2, self.height - 3) @@ -50,23 +50,23 @@ h = random.randrange(3, 10) w = max(1, min(self.width - x - 2, w)) h = max(1, min(self.height - y - 2, h)) - self.rect(x, y, w, h, 1) - self.rect(x-1, y-1, w+2, h+2, 0) - self.rect(x+1, y+1, w-2, h-2, 0) + self.rect(x, y, w, h, 0) + self.rect(x-1, y-1, w+2, h+2, 1) + self.rect(x+1, y+1, w-2, h-2, 1) if w > 2 and h > 2: if random.choice((0, 1)): dx = x + random.randrange(w - 2) + 1 if random.choice((0, 1)): - self.grid[y][dx] = 0 + self.grid[y][dx] = 1 else: - self.grid[y + h - 1][dx] = 0 + self.grid[y + h - 1][dx] = 1 else: dy = y + random.randrange(h - 2) + 1 if random.choice((0, 1)): - self.grid[dy][x] = 0 + self.grid[dy][x] = 1 else: - self.grid[dy][x + w - 1] = 0 - self.rect(0, 0, self.width, self.height, 1) + self.grid[dy][x + w - 1] = 1 + self.rect(0, 0, self.width, self.height, 0) def __iter__(self): return iter(self.grid) @@ -90,7 +90,7 @@ for y, (row, nrow) in enumerate(zip(self.grid, nrows)): for x, ts in enumerate(zip(row, row[1:], nrow, nrow[1:])): surf.blit( - tiles[sum(bool(t) * 2**i for i, t in enumerate(ts))], + tiles[sum((not t) * 2**i for i, t in enumerate(ts))], (x * 48, y * 32) ) @@ -106,7 +106,7 @@ def walk(self, d, level): x = self.x + DX[d] y = self.y + DY[d] - if level.grid[y][x]: + if not level.grid[y][x]: return False self.rect.move_ip(DX[d] * 48, DY[d] * 32) self.x, self.y = x, y @@ -145,15 +145,19 @@ self.y = 0 self.screen = pygame.display.set_mode((self.width, self.height)) self.clock = pygame.time.Clock() - self.grass = load_atlas('grass.png', 48, 32) - self.mobs = load_atlas('mobs.png', 48, 48) + self.walls = load_atlas('walls.png', 48, 32) + self.floor = load_atlas('rocks.png', 48, 32) + self.mobs = load_atlas('mobs2.png', 48, 48) self.level = Level((32, 32)) self.sprites = SortedUpdates() self.background = pygame.Surface( - (self.level.width * 48, self.level.height * 32) + (self.level.width * 48 - 48, self.level.height * 32 - 32) ) - - self.level.render(self.background, self.grass) + w, h = self.background.get_size() + for y in xrange(0, h, 32): + for x in xrange(0, w, 48): + self.background.blit(self.floor[0], (x, y)) + self.level.render(self.background, self.walls) self.level.hero = Hero(self.mobs[0], (1, 1)) self.level.monsters = [ Mob(self.mobs[1], (2, 2)) @@ -163,15 +167,14 @@ self.sprites.add(m) def scroll_by(self, dx, dy): - if self.x - dx > 0: - dx = self.x - if self.y - dy > 0: - dy = self.y + w, h = self.background.get_size() + dx = min(max(self.x, dx), self.x+w-self.width) + dy = min(max(self.y, dy), self.y+h-self.height) for s in self.sprites: s.rect.move_ip(-dx, -dy) self.x -= dx self.y -= dy - self.screen.fill((0, 0, 0)) + self.screen.fill((0x66, 0x66, 0x66)) self.screen.blit(self.background, (self.x, self.y)) self.sprites.draw(self.screen) pygame.display.flip() @@ -179,7 +182,7 @@ def _sprite_clear(self, screen, rect): source = rect.move(-self.x, -self.y) if not self.background.get_rect().contains(source): - screen.fill((0, 0, 0), rect) + screen.fill((0x66, 0x66, 0x66), rect) screen.blit(self.background, rect, source)
