2012-10-12 13:50:02 +02:00
|
|
|
#!/usr/bin/env python.
|
2012-08-08 20:22:13 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2012-10-12 13:50:02 +02:00
|
|
|
# This file is part of A Robot's Conundrum
|
2012-08-08 20:22:13 +02:00
|
|
|
#
|
2012-10-12 13:50:02 +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-08 20:22:13 +02:00
|
|
|
#
|
2012-10-12 13:50:02 +02:00
|
|
|
# A Robot's Conundrum is distributed in the hope that it will be useful, but WITHOUT ANY
|
2012-08-08 20:22:13 +02:00
|
|
|
# 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
|
2012-10-12 13:50:02 +02:00
|
|
|
# A Robot's Conundrum. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-08 20:22:13 +02:00
|
|
|
#
|
|
|
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
|
|
|
#
|
|
|
|
# level3.py
|
|
|
|
# --------------------
|
|
|
|
# date created : Wed Aug 8 2012
|
|
|
|
# copyright : (C) 2012 Niels G. W. Serup
|
2012-10-12 13:50:02 +02:00
|
|
|
# maintained by : Niels G. W. Serup <ngws@metanohi.name>
|
2012-08-08 20:22:13 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
The third level.
|
|
|
|
"""
|
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2012-08-08 20:22:13 +02:00
|
|
|
import os
|
|
|
|
import pygame
|
|
|
|
import random
|
|
|
|
import re
|
2012-08-08 21:45:05 +02:00
|
|
|
import itertools
|
2012-08-08 20:22:13 +02:00
|
|
|
|
2012-08-08 21:45:05 +02:00
|
|
|
import worldobject
|
2012-08-08 20:22:13 +02:00
|
|
|
import level
|
|
|
|
import player
|
2012-08-21 18:36:51 +02:00
|
|
|
import trigger
|
2012-08-08 20:22:13 +02:00
|
|
|
import tile
|
|
|
|
import block
|
|
|
|
import lever
|
2012-08-21 18:36:51 +02:00
|
|
|
import fadeout
|
2012-08-08 20:22:13 +02:00
|
|
|
|
|
|
|
import logic.colourboxes
|
|
|
|
|
2012-08-08 21:45:05 +02:00
|
|
|
|
2012-08-08 20:22:13 +02:00
|
|
|
class Level3(level.Level):
|
|
|
|
def __init__(self, game, graphics_dir, paused=False):
|
2012-08-21 18:36:51 +02:00
|
|
|
level.Level.__init__(self, game, graphics_dir, size=(64*11, 48*20),
|
2012-08-08 20:22:13 +02:00
|
|
|
paused=paused)
|
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
self.dimensions = 11, 20
|
2012-08-08 20:22:13 +02:00
|
|
|
|
2012-08-08 21:45:05 +02:00
|
|
|
# for i in range(self.dimensions[0]):
|
|
|
|
# for j in range(self.dimensions[1]):
|
|
|
|
# self.tiles.append(
|
|
|
|
# tile.Tile(self, i*64, j*48, self.imgs['ground1']))
|
2012-08-08 20:22:13 +02:00
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
self.task_start = (1, 6)
|
2012-08-10 13:47:26 +02:00
|
|
|
|
|
|
|
# Abstract "boxes", actually colour fields
|
2012-08-10 21:54:21 +02:00
|
|
|
boxes = []
|
|
|
|
for i in range(4):
|
|
|
|
boxes.extend([(0, 0, 0)] * i + box + [(0, 0, 0)] * (3 - i)
|
|
|
|
for box in logic.colourboxes.generate_colour_boxes(1, 3))
|
|
|
|
boxes.extend(logic.colourboxes.generate_random_box(4, 2) for _ in range(20))
|
|
|
|
boxes.extend([(0, 0, 0)] * 4 for _ in range(10))
|
2012-08-10 13:47:26 +02:00
|
|
|
random.shuffle(boxes)
|
|
|
|
pos_colour = {}
|
2012-08-21 18:36:51 +02:00
|
|
|
for i, j in self._positions():
|
|
|
|
self.tiles.append(
|
|
|
|
tile.Tile(self, i * 64, (j + 4) * 48, self.imgs['indoor%d' % random.randint(1, 6)]))
|
|
|
|
|
2012-08-10 21:54:21 +02:00
|
|
|
for box, (x, y) in zip(boxes, itertools.product(range(7), range(6))):
|
2012-08-21 18:36:51 +02:00
|
|
|
# self.tiles.append(tile.Tile(self, 64 * (x + self.task_start[0] + 1),
|
|
|
|
# 48 * (y + self.task_start[1] + 1),
|
|
|
|
# self.imgs['indoor%d' % random.randint(1, 6)]))
|
2012-08-10 13:47:26 +02:00
|
|
|
pos_colour[(x, y)] = box
|
|
|
|
|
2012-08-08 20:22:13 +02:00
|
|
|
self.draw_background()
|
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
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-10 21:54:21 +02:00
|
|
|
action_blocks = list(itertools.chain(*
|
2012-08-21 18:36:51 +02:00
|
|
|
[(block.ActionBlock(self, 64 * self.task_start[0],
|
|
|
|
48 * (i + 1 + self.task_start[1]),
|
2012-08-10 21:54:21 +02:00
|
|
|
movable=True),
|
2012-08-21 18:36:51 +02:00
|
|
|
block.ActionBlock(self, 64 * (self.task_start[0] + 8),
|
|
|
|
48 * (i + 1 + self.task_start[1]),
|
2012-08-10 21:54:21 +02:00
|
|
|
movable=True))
|
|
|
|
for i in range(6)]))
|
2012-08-10 13:47:26 +02:00
|
|
|
self.objects.extend(action_blocks)
|
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
wells = [block.ColorWell(self, self.task_start[0] * 64, self.task_start[1] * 48),
|
|
|
|
block.ColorWell(self, (self.task_start[0] + 8) * 64, self.task_start[1] * 48),
|
|
|
|
block.ColorWell(self, self.task_start[0] * 64, (self.task_start[1] + 7) * 48),
|
|
|
|
block.ColorWell(self, (self.task_start[0] + 8) * 64, (self.task_start[1] + 7) * 48),
|
2012-08-10 13:47:26 +02:00
|
|
|
]
|
|
|
|
self.objects.extend(wells)
|
2012-08-21 18:36:51 +02:00
|
|
|
self.wells = wells
|
|
|
|
|
|
|
|
self.bottom_objects.append(worldobject.WithBackground(
|
|
|
|
self, self.imgs['elevator_top'], 64 * (self.task_start[0] + 3), 48 * (self.task_start[1] + 10)))
|
|
|
|
self.elevator = worldobject.WithBackground(
|
|
|
|
self, self.imgs['elevator'], 64 * (self.task_start[0] + 3), 48 * (self.task_start[1] + 11), 48)
|
|
|
|
self.bottom_objects.append(self.elevator)
|
|
|
|
self._next_level_trigger = trigger.Trigger(
|
|
|
|
self, 64 * (self.task_start[0] + 4), 48 * (self.task_start[1] + 10), [lambda _: self.try_goto_next_level()],
|
|
|
|
self.imgs['hole'],
|
|
|
|
[self.player], visible=False, no_stop=True)
|
|
|
|
self.objects.append(self._next_level_trigger)
|
|
|
|
self.bottom_objects.append(worldobject.WithBackground(
|
|
|
|
self, self.imgs['elevator_bottom'], 64 * (self.task_start[0] + 3), 48 * (self.task_start[1] + 12)))
|
2012-08-10 13:47:26 +02:00
|
|
|
|
|
|
|
def update_wells(block):
|
|
|
|
cur_boxes = []
|
|
|
|
for block in action_blocks:
|
2012-08-21 18:36:51 +02:00
|
|
|
box = pos_colour.get((block.x / 64 - self.task_start[0] - 1,
|
|
|
|
block.y / 48 - self.task_start[1] - 1))
|
2012-08-10 13:47:26 +02:00
|
|
|
if box:
|
|
|
|
cur_boxes.append(box)
|
|
|
|
|
|
|
|
if not cur_boxes:
|
|
|
|
well_colours = [(0, 0, 0)] * len(wells)
|
|
|
|
else:
|
|
|
|
well_colours = logic.colourboxes.get_colours(cur_boxes)
|
|
|
|
for well, color in zip(wells, well_colours):
|
|
|
|
well.set_colour(*color)
|
|
|
|
|
|
|
|
for b in action_blocks:
|
|
|
|
b.action = update_wells
|
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
self.player.set_pos(64 * 5, 48 * 4)
|
2012-08-14 00:59:06 +02:00
|
|
|
self.player.set_init_pos()
|
2012-08-08 20:22:13 +02:00
|
|
|
|
2012-08-21 18:36:51 +02:00
|
|
|
def try_goto_next_level(self):
|
|
|
|
# if not all(well.well_colour == (255, 255, 255)
|
|
|
|
# for well in self.wells):
|
|
|
|
# return
|
|
|
|
self.objects.remove(self._next_level_trigger)
|
|
|
|
self._old_player_update = self.player.update
|
|
|
|
self.player.update = lambda e, t, dt: self._old_player_update([], t, dt)
|
|
|
|
self.update = self.update2
|
|
|
|
self._start_time = pygame.time.get_ticks()
|
|
|
|
fadeout.Fadeout(self.game, self.goto_next_level, duration=1500)
|
|
|
|
|
|
|
|
def update2(self, e, t, dt):
|
|
|
|
level.Level.update(self, e, t, dt)
|
|
|
|
start_offset = (t - self._start_time) / 25
|
|
|
|
self.elevator.z_px = 48 - start_offset
|
|
|
|
self.player.y = 48 * (self.task_start[1] + 10) - start_offset
|
|
|
|
|
|
|
|
def goto_next_level(self):
|
|
|
|
self.game.goto_level(4)
|
|
|
|
|
2012-08-08 20:22:13 +02:00
|
|
|
def restart(self):
|
|
|
|
for obj in self.objects:
|
|
|
|
obj.reset_pos()
|