a-robots-conundrum/robotgame/level_bonus.py

89 lines
2.7 KiB
Python

# This file is part of ROBOTGAME
#
# ROBOTGAME is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# ROBOTGAME is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# ROBOTGAME. If not, see <http://www.gnu.org/licenses/>.
#
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
#
# level_bonus.py
# --------------------
# date created : Thu Aug 9 2012
# copyright : (C) 2012 Niels G. W. Serup
# maintained by : Niels G. W. Serup <ns@metanohi.name>
"""
Fun bonus level.
"""
import os
import pygame
import random
import re
import itertools
import misc
import level
import player
import tile
import block
import boulder
import lever
import fadeout
class Level(level.Level):
def __init__(self, game, graphics_dir, paused=False):
level.Level.__init__(self, game, graphics_dir, size=(64*20, 48*20),
paused=paused)
self.dimensions = 20, 20
for i in range(self.dimensions[0]):
for j in range(self.dimensions[1]):
self.tiles.append(
tile.Tile(self, (i+1)*64, j*48, self.imgs['indoor%d' % random.randint(1, 6)]))
self.draw_background()
for x, y in misc.pick_random_elements(
list(itertools.product(range(2, 20), range(2, 20))), 150):
self.objects.append(block.Block(self, 64 * x, 48 * y,
self.imgs['block1'], movable=True))
def f():
self._update = self.update
self.update = lambda *args: None
def g():
self.update = self._update
self.exit()
fadeout.Fadeout(self.game, g)
self.objects.append(
lever.Lever(
self, 64, 48,
[lambda setting: f()],
toggling=False,
anim='lever_updown'))
def enter(self, root_level):
self.__dict__.update(locals())
self.game.objs.remove(root_level)
self.game.objs.insert(0, self)
self.game.level = self
def exit(self):
self.game.objs.remove(self)
self.game.objs.insert(0, self.root_level)
def restart(self):
for obj in self.objects:
obj.reset_pos()