Mercurial > undermine
changeset 9:8fd6bbf0901a
use constants for map
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 26 Apr 2014 21:15:52 +0200 |
| parents | 1890b3dcf669 |
| children | 8c716634eb31 |
| files | undermine/game.py undermine/undermine.png |
| diffstat | 2 files changed, 23 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/undermine/game.py Sat Apr 26 20:55:18 2014 +0200 +++ b/undermine/game.py Sat Apr 26 21:15:52 2014 +0200 @@ -10,6 +10,16 @@ import undermine.sprites +MAP_DIRT, MAP_TUNNEL, MAP_BOULDER, MAP_GEM, MAP_PLAYER = range(5) +TILES = { + MAP_DIRT: 8, + MAP_TUNNEL: 11, + MAP_BOULDER: 11, + MAP_GEM: 11, + MAP_PLAYER: 11, +} + + class Game(object): def __init__(self, fps=24, map_size=(12, 12)): self.fps = fps @@ -24,23 +34,22 @@ if not (0 <= x + dx <= len(self.map[0]) and 0 <= y +dy < len(self.map)): return - if self.map[y + dy][x + dx] == 2: + if self.map[y + dy][x + dx] == MAP_BOULDER: return self.hero.animations.append(self.hero.move_anim(dx, dy)) self.hero.place((x + dx, y + dy), False) - self.dig((x + dx, y + dy)) - self.map[y][x] = 1 + if self.map[y + dy][x + dx] in (MAP_DIRT, MAP_GEM): + self.dig((x + dx, y + dy)) + self.map[y + dy][x + dx] = MAP_PLAYER + self.map[y][x] = MAP_TUNNEL def dig(self, (x, y)): - if self.map[y][x]: - return - self.map[y][x] = 4 - self.display.background.blit(self.images[11], (x * 64, y * 64)) + self.display.background.blit(self.images[TILES[MAP_TUNNEL]], + (x * 64, y * 64)) dirt = undermine.sprites.Dirt(self.images) dirt.place((x, y)) self.display.back_sprites.add(dirt) - def make_map(self, map_size): self.boulders = [] squares = [] @@ -54,26 +63,26 @@ self.hero = undermine.sprites.Hero(self.images) self.hero.place(squares.pop()) self.display.sprites.add(self.hero) - self.map[self.hero.pos[1]][self.hero.pos[0]] = 1 + self.map[self.hero.pos[1]][self.hero.pos[0]] = MAP_PLAYER for i in range(8): boulder = undermine.sprites.Boulder(self.images[4]) x, y = squares.pop() boulder.place((x, y)) self.display.sprites.add(boulder) self.boulders.append(boulder) - self.map[y][x] = 2 + self.map[y][x] = MAP_BOULDER for i in range(4): gem = undermine.sprites.Gem(self.images[5]) x, y = squares.pop() gem.place((x, y)) self.display.sprites.add(gem) self.boulders.append(gem) - self.map[y][x] = 3 + self.map[y][x] = MAP_GEM def draw_map(self): for y, row in enumerate(self.map): for x, tile in enumerate(row): - self.display.background.blit(self.images[tile + 8], + self.display.background.blit(self.images[TILES[tile]], (x * 64, y * 64)) def update_boulders(self): @@ -82,10 +91,10 @@ if boulder.animations: continue x, y = boulder.pos - if y + 1 < len(self.map) and self.map[y + 1][x] == 1: + if y + 1 < len(self.map) and self.map[y + 1][x] == MAP_TUNNEL: boulder.animations.append(boulder.fall_anim()) self.map[y + 1][x] = self.map[y][x] - self.map[y][x] = 1 + self.map[y][x] = MAP_TUNNEL boulder.place((x, y +1), False) def run(self):
