Mercurial > mhrok
changeset 20:8e16e129d2b5
Illuminate whole rooms
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Thu, 01 Mar 2012 23:29:17 +0100 |
| parents | 9dfb03427133 |
| children | 2ee01ad22b36 |
| files | mhrok.py |
| diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mhrok.py Thu Mar 01 23:07:25 2012 +0100 +++ b/mhrok.py Thu Mar 01 23:29:17 2012 +0100 @@ -134,6 +134,7 @@ self.width = 31 self.height = 38 + self.lit_rooms = [] self.map = [[0] * self.width for y in xrange(self.height)] areas = [ @@ -176,6 +177,7 @@ (x, y), (w, h) = random.choice(rooms) self.pc.place((r(x, x+w), r(y, y+h))) + self.rooms = rooms def __getitem__(self, (x, y)): @@ -201,6 +203,11 @@ return self[ex, y] = fill + def find_room(self, x, y): + for room in self.rooms: + (rx, ry), (rw, rh) = room + if rx <= x <= rx + rw and ry <= y <= ry + rh: + return room def render_background(self, tiles): background = pygame.Surface((self.width * 20 + 20, self.height * 12 + 20)) @@ -284,6 +291,12 @@ self.screen.blit(self.background, dirty.topleft, area=dirty) self.dirty.append(dirty) + def light_room(self, room): + (rx, ry), (rw, rh) = room + for y in xrange(ry * 12, (ry + rh)* 12, 3): + for x in xrange(4 + rx * 20, 4 + (rx + rw)* 20, 5): + self.light((16+x, 20+y)) + def draw(self): if self.first_draw: self.screen.blit(self.background, (0, 0)) @@ -318,7 +331,13 @@ def main(self): while not self.game_over: self.pc.control(self.level) - self.display.light(self.pc.mob.rect.center) + mx, my = self.pc.mob.rect.topleft + room = self.level.find_room((mx+1)/20, (my+6)/12) + if room and room not in self.level.lit_rooms: + self.level.lit_rooms.append(room) + self.display.light_room(room) + else: + self.display.light(self.pc.mob.rect.center) self.display.draw() self.clock.tick(15) self.display.update()
