a-robots-conundrum/arobotsconundrum/level_bonus.py

107 lines
3.4 KiB
Python
Raw Normal View History

# This file is part of A Robot's Conundrum.
2012-08-09 15:51:59 +02:00
#
# A Robot's Conundrum 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.
2012-08-09 15:51:59 +02:00
#
# A Robot's Conundrum 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.
2012-08-09 15:51:59 +02:00
#
# You should have received a copy of the GNU General Public License along with
# A Robot's Conundrum. If not, see <http://www.gnu.org/licenses/>.
2012-08-09 15:51:59 +02:00
#
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
#
# level_bonus.py
# --------------------
# date created : Thu Aug 9 2012
# copyright : (C) 2012 Niels G. W. Serup
# maintained by : Niels G. W. Serup <ngws@metanohi.name>
2012-08-09 15:51:59 +02:00
"""
Fun bonus level.
"""
import os
import pygame
import random
import re
import itertools
import misc
2012-08-09 15:51:59 +02:00
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*21, 48*20),
2012-08-09 15:51:59 +02:00
paused=paused)
self.dimensions = 21, 20
2012-08-09 15:51:59 +02:00
for i, j in self._positions():
self.tiles.append(
tile.Tile(self, i * 64, (j + 4) * 48, self.imgs['ground1']))
2012-08-09 15:51:59 +02:00
self.draw_background()
top = self.dimensions[0]
for i in range(top):
if i % 3 == 0:
self.objects.append(block.Block(
self, i * 64, 48 * 3,
self.imgs['wall'],
width=2 if i == top - 2 else 3,
blit_area=(0, 0, 160, 192) if i == top - 2 else None))
self.objects.append(block.InvisBlock(self, i * 64,
self.size[1]))
for i in range(self.dimensions[1]):
self.objects.append(block.InvisBlock(self, - 64, i * 48))
self.objects.append(block.InvisBlock(self, self.size[0], i * 48))
2012-08-09 15:51:59 +02:00
def go_back():
self._update = self.update
self.update = lambda *args: None
def g():
self.update = self._update
self.exit()
fadeout.Fadeout(self.game, g)
2012-08-09 15:51:59 +02:00
self.objects.append(
lever.Lever(
self, 0, 48 * 4,
[lambda setting: go_back()],
2012-08-09 15:51:59 +02:00
toggling=False,
anim='lever_updown'))
for x, y in misc.pick_random_elements(
list(itertools.product(range(2, 19), range(2, 14))), 150):
self.objects.append(block.Block(self, 64 * x, 48 * (4 + y),
self.imgs['block1'], movable=True))
self.player.set_pos(0, 48 * 5)
2012-08-14 00:59:06 +02:00
self.player.set_init_pos()
2012-08-09 15:51:59 +02:00
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()