a-robots-conundrum/robotgame/level1.py

601 lines
24 KiB
Python
Raw Normal View History

# 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/>.
#
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
#
# level1.py
# --------------------
# date created : Tue Aug 7 2012
# copyright : (C) 2012 Sakse Dalum
# maintained by : Sakse Dalum <don_s@hongabar.org>
"""
The first level.
"""
2012-08-07 21:23:10 +02:00
import os
import pygame
import random
2012-08-08 16:46:26 +02:00
import re
2012-08-10 12:09:07 +02:00
import itertools
2012-08-07 21:23:10 +02:00
import level
import player
2012-08-07 21:23:10 +02:00
import tile
import block
2012-08-08 16:46:26 +02:00
import boulder
2012-08-08 17:06:10 +02:00
import lever
import trigger
2012-08-10 22:31:15 +02:00
import worldobject
import logic.teleportermap
import logic.rollingstone
2012-08-10 12:09:07 +02:00
import logic.colourboxes
class Level1(level.Level):
2012-08-08 13:50:48 +02:00
def __init__(self, game, graphics_dir, paused=False):
2012-08-12 20:28:20 +02:00
level.Level.__init__(self, game, graphics_dir, size=(64 * 40,
48 * 40),
2012-08-08 19:53:48 +02:00
paused=paused)
2012-08-12 19:05:54 +02:00
self.solution = range(1, 6)
random.shuffle(self.solution)
self.solution = self.solution[:3]
self.task_completions = [0, 0, 0]
2012-08-09 22:48:30 +02:00
self.set_darkness(0)
2012-08-09 17:18:44 +02:00
2012-08-12 20:28:20 +02:00
for i in range(self.size[0] / 64):
for j in range(self.size[1] / 48):
2012-08-07 21:23:10 +02:00
self.tiles.append(
tile.Tile(self, i*64, j*48, self.imgs['ground1']))
2012-08-12 17:56:09 +02:00
self.player.set_pos(64 * 15, 48 * 30)
2012-08-08 22:40:27 +02:00
self.player.set_init_pos()
2012-08-12 20:28:20 +02:00
for i in range(self.size[0] / 64):
2012-08-12 18:28:09 +02:00
if not i % 3:
self.objects.append(block.Block(self, i * 64,
48 * 3,
self.imgs['wall_outside'],
width=3))
2012-08-09 14:26:53 +02:00
self.objects.append(block.InvisBlock(self, i * 64,
2012-08-12 21:24:01 +02:00
self.size[1]))
2012-08-12 20:28:20 +02:00
for i in range(self.size[1] / 48):
2012-08-12 18:28:09 +02:00
self.objects.append(block.InvisBlock(self, - 64,
2012-08-09 14:26:53 +02:00
i * 48))
2012-08-12 20:28:20 +02:00
self.objects.append(block.InvisBlock(self, self.size[0],
2012-08-09 14:26:53 +02:00
i * 48))
2012-08-10 22:31:15 +02:00
2012-08-12 20:01:58 +02:00
### Task 1: Teleporters
2012-08-10 22:31:15 +02:00
task5_size = 8, 5
2012-08-12 20:01:58 +02:00
task5_pos = (64 * 12, 48 * 19)
2012-08-10 22:31:15 +02:00
tmap = logic.teleportermap.generate_teleporter_map3(*task5_size)
2012-08-12 20:01:58 +02:00
for x in range(task5_size[0]):
for y in range(task5_size[1]):
# if not (x, y) in tmap:
# continue
2012-08-12 20:01:58 +02:00
self.add_tile(task5_pos[0] - 64 * (x - 1),
task5_pos[1] - 48 * y,
'indoor%d' % random.randint(1, 6), blocking=False)
for x, y in tmap:
2012-08-12 20:01:58 +02:00
self.objects.append(
trigger.Trigger(self,
task5_pos[0] - 64 * (x - 1),
task5_pos[1] - 48 * y,
2012-08-12 20:01:58 +02:00
[lambda x: self.player.set_pos(
task5_pos[0] + 2 * 64,
(task5_pos[1]
- random.randint(0, task5_size[1] - 1) * 48))],
2012-08-12 20:01:58 +02:00
self.imgs['hole'],
[self.player],
visible=False,
no_stop=True))
2012-08-12 20:01:58 +02:00
for i in range(task5_size[0] + 1):
2012-08-12 20:01:58 +02:00
self.add_tile(task5_pos[0] - 64 * i,
task5_pos[1] + 48,
'moat_horizontal')
self.add_tile(task5_pos[0] - 64 * i,
task5_pos[1] - task5_size[1] * 48,
2012-08-12 20:01:58 +02:00
'moat_horizontal')
self.add_tile(task5_pos[0] + 64,
task5_pos[1] + 48,
'moat_end_horizontal_flip')
# self.add_tile(task5_pos[0] + 64,
# task5_pos[1] - task5_size[1] * 48,
2012-08-12 20:01:58 +02:00
# 'moat_end_horizontal_flip')
self.add_tile(task5_pos[0] - 64 * (task5_size[0] + 1),
2012-08-12 20:01:58 +02:00
task5_pos[1] + 48,
'moat_corner_south')
self.add_tile(task5_pos[0] - 64 * (task5_size[0] + 1),
task5_pos[1] - task5_size[1] * 48,
2012-08-10 22:31:15 +02:00
'moat_corner_north')
2012-08-12 20:01:58 +02:00
for i in range(task5_size[0]):
self.add_tile(task5_pos[0] - 64 * (task5_size[0] + 1),
2012-08-12 20:01:58 +02:00
task5_pos[1] - 48 * i,
2012-08-10 22:46:22 +02:00
'moat_vertical')
2012-08-12 20:01:58 +02:00
self.objects.append(
lever.Lever(self,
task5_pos[0] - 64 * (task5_size[0]),
task5_pos[1] - (task5_size[1] / 2) * 48,
2012-08-12 20:01:58 +02:00
[lambda *x: self.complete_task(1)]))
2012-08-10 22:31:15 +02:00
2012-08-08 22:40:27 +02:00
### Task 2: Rolling stone
2012-08-08 18:13:53 +02:00
2012-08-09 13:54:27 +02:00
task2_size = 15, 10
2012-08-08 22:40:27 +02:00
task2_pos = (64 * 20, 48 * 20)
playfield, nsteps, directions = (
2012-08-08 22:40:27 +02:00
logic.rollingstone.generate_simple_unsolved_solvable_extra(
task2_size[0], task2_size[1], 5, 50))
2012-08-08 22:40:27 +02:00
2012-08-08 19:53:48 +02:00
n = 0
c = len(playfield) / len(directions)
ns = [k * c for k in range(len(directions))]
arrow_blocks = []
for i, j in playfield:
if n in ns:
arrow_blocks.append(
block.ArrowBlock(self,
task2_pos[0] + 64 * i,
task2_pos[1] + 48 * j,
directions[n / c].next_pos((0, 0))))
else:
self.objects.append(
block.Block(self,
task2_pos[0] + 64 * i,
task2_pos[1] + 48 * j,
self.imgs['block1'],
movable=True)
if (random.randint(0, 2) or (i, j) == (4, 0)) else
block.Block(self,
task2_pos[0] + 64 * i,
task2_pos[1] + 48 * j,
self.imgs['block3'],
movable=False))
2012-08-08 19:53:48 +02:00
n += 1
# arrow_blocks = []
# n = 0
# for i in directions:
# arrow_blocks.append(
# block.ArrowBlock(self,
# task2_pos[0] + 64 * (task2_size[0] - n),
# task2_pos[1] + 48 * (task2_size[1] + 2),
# i.next_pos((0, 0))))
# n += 1
2012-08-08 19:53:48 +02:00
self.objects.extend(arrow_blocks)
2012-08-08 22:40:27 +02:00
self.objects.append(lever.Lever(self,
task2_pos[0] + 64 * 3,
task2_pos[1] - 48 * 2,
2012-08-08 19:53:48 +02:00
[arrow_block.activate
for arrow_block in arrow_blocks],
2012-08-08 22:40:27 +02:00
toggling=True,
anim='lever_updown'))
2012-08-09 13:54:27 +02:00
b = boulder.Boulder(self, task2_pos[0], task2_pos[1] - 48,
2012-08-08 22:40:27 +02:00
direction=(0, 1))
self.objects.append(b)
self.objects.append(lever.Lever(self,
task2_pos[0] + 64 * 2,
task2_pos[1] - 48 * 2,
[b.activate],
anim='lever_updown'))
2012-08-09 13:54:27 +02:00
# Moat sides
for i in range(-1, task2_size[1]):
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] - 64,
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * i,
'moat_vertical')
for i in range(task2_size[1] - 2):
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * task2_size[0],
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * i,
'moat_vertical')
for i in range(6, task2_size[0]):
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * i,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48,
'moat_horizontal')
for i in range(task2_size[0] - 2):
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * i,
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * task2_size[1],
'moat_horizontal')
# Corners
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * task2_size[0],
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48,
'moat_corner_north_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] - 64,
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * task2_size[1],
'moat_corner_south')
# Start
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * 2,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48,
'moat_horizontal')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * 3,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48,
'moat_end_horizontal_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * 5,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48,
'moat_end_horizontal')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] - 64,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48 * 2,
'moat_corner_north')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0],
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48 * 2,
'moat_horizontal')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48 * 2,
'moat_corner_north_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64,
2012-08-09 13:54:27 +02:00
task2_pos[1] - 48,
'moat_corner_south')
# End
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * task2_size[0],
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * (task2_size[1] - 2),
'moat_corner_south')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * (task2_size[0] + 1),
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * (task2_size[1] - 2),
'moat_corner_north_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * (task2_size[0] + 1),
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * (task2_size[1] - 1),
'moat_vertical')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * (task2_size[0] + 1),
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * (task2_size[1]),
'moat_corner_south_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * (task2_size[0]),
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * (task2_size[1]),
'moat_end_horizontal')
2012-08-10 18:37:17 +02:00
self.add_tile(task2_pos[0] + 64 * (task2_size[0] - 2),
2012-08-09 13:54:27 +02:00
task2_pos[1] + 48 * (task2_size[1]),
'moat_end_horizontal_flip')
2012-08-08 22:40:27 +02:00
self.objects.append(
trigger.Trigger(self, task2_pos[0] + 64 * (task2_size[0]),
task2_pos[1] + 48 * (task2_size[1] - 1),
2012-08-09 17:00:14 +02:00
[self.complete_task, b.fall],
self.imgs['hole'], [b],
2012-08-12 20:01:58 +02:00
signal=[0, 2],
toggling=True))
2012-08-10 12:09:07 +02:00
2012-08-10 15:30:30 +02:00
2012-08-12 20:01:58 +02:00
### Task 3: Inverted bits
2012-08-08 22:40:27 +02:00
2012-08-10 18:37:17 +02:00
task4_pos = (64 * 26, 48 * 18)
2012-08-08 22:40:27 +02:00
b = boulder.Boulder(self, task4_pos[0] - 64, task4_pos[1] - 48 * 3,
direction=(1, 0))
self.objects.append(b)
2012-08-08 19:53:48 +02:00
2012-08-08 22:40:27 +02:00
self.objects.append(lever.Lever(self,
2012-08-09 13:54:27 +02:00
task4_pos[0] - 64 * 3,
2012-08-08 22:40:27 +02:00
task4_pos[1] - 48 * 3,
[b.activate]))
risingblocks = [block.RisingBlock(self, task4_pos[0] + 64 * i,
task4_pos[1] - 48 * 3,
is_up = False)
for i in range(8)]
for i in range(8):
r = range(8)
r.remove(i)
2012-08-08 22:40:27 +02:00
self.objects.append(risingblocks[i])
n = random.choice(r)
2012-08-08 22:40:27 +02:00
self.objects.append(lever.Lever(self,
task4_pos[0] + 64 * i,
task4_pos[1] - 48 * 2,
[risingblocks[i].activate,
risingblocks[n].activate],
anim='lever_updown',
toggling=True,
signal=[0, 1]))
for k in range(random.randint(0, 1)):
self.objects[-1].use(self)
self.objects[-1].set_init_pos()
risingblocks[i].set_init_pos()
risingblocks[n].set_init_pos()
n = random.choice(r)
2012-08-08 22:40:27 +02:00
self.objects.append(lever.Lever(self,
task4_pos[0] + 64 * i,
task4_pos[1],
[risingblocks[i].activate,
risingblocks[n].activate],
anim='lever_updown',
toggling=True,
signal=[2, 3]))
2012-08-08 23:08:53 +02:00
for k in range(random.randint(0, 1)):
2012-08-08 22:40:27 +02:00
self.objects[-1].use(self)
self.objects[-1].set_init_pos()
risingblocks[i].set_init_pos()
risingblocks[n].set_init_pos()
self.objects.append(trigger.Trigger(self, task4_pos[0] + 64 * 8,
task4_pos[1] - 48 * 3,
2012-08-09 17:00:14 +02:00
[self.complete_task, b.fall],
self.imgs['hole'], [b],
signal=[0, 3],
toggling=True))
2012-08-09 13:54:27 +02:00
# Moat
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 4,
2012-08-09 13:54:27 +02:00
'moat_corner_north')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 3,
2012-08-09 13:54:27 +02:00
'moat_vertical')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 2,
2012-08-09 13:54:27 +02:00
'moat_corner_south')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] - 64, task4_pos[1] - 48 * 2,
2012-08-09 13:54:27 +02:00
'moat_end_horizontal_flip')
for i in range(10):
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] + 64 * (i - 1), task4_pos[1] - 48 * 4,
2012-08-09 13:54:27 +02:00
'moat_horizontal')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 4,
2012-08-09 13:54:27 +02:00
'moat_corner_north_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 3,
2012-08-09 13:54:27 +02:00
'moat_vertical')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 2,
2012-08-09 13:54:27 +02:00
'moat_corner_south_flip')
2012-08-10 18:37:17 +02:00
self.add_tile(task4_pos[0] + 64 * 8, task4_pos[1] - 48 * 2,
2012-08-09 13:54:27 +02:00
'moat_end_horizontal')
2012-08-12 14:22:41 +02:00
2012-08-12 20:01:58 +02:00
### Task 4: Colour blocks
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
task3_pos = (64 * 15, 48 * 20)
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
# Abstract "boxes", actually colour fields
boxes = logic.colourboxes.generate_colour_boxes(1, 3)
boxes += boxes
boxes += [logic.colourboxes.generate_random_box(1) for _ in range(3)]
random.shuffle(boxes)
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
pos_colour = {}
for box, (x, y) in zip(boxes, itertools.product(range(3), range(3))):
# self.tiles.append(tile.Tile(self, x * 64 + task3_pos[0],
# y * 48 + task3_pos[1],
# self.imgs['ground1']))
pos_colour[(x, y)] = box
self.add_tile(task3_pos[0] + 64 * x, task3_pos[1] + 48 * (y + 1),
'indoor%d' % random.randint(1, 6), blocking=False)
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
action_blocks = [block.ActionBlock(self, 64 * i + task3_pos[0],
task3_pos[1], movable=True)
for i in range(3)]
self.objects.extend(action_blocks)
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
wells = [block.ColorWell(self, task3_pos[0] + 64,
task3_pos[1] + 48 * 5)]
self.objects.extend(wells)
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
def update_wells(block):
cur_boxes = []
for block in action_blocks:
box = pos_colour.get(((block.x - task3_pos[0]) / 64,
(block.y - task3_pos[1] - 48) / 48))
if box:
cur_boxes.append(box)
2012-08-12 17:36:59 +02:00
2012-08-12 20:01:58 +02:00
if not cur_boxes:
well_colours = [(0, 0, 0)] * len(wells)
else:
well_colours = logic.colourboxes.get_colours(cur_boxes)
for i in range(len(wells)):
wells[i].set_colour(*well_colours[i])
for b in action_blocks:
b.action = update_wells
self.objects.append(
lever.Lever(self,
task3_pos[0] + 64,
task3_pos[1] + 48 * 4,
[lambda *x: (self.complete_task(4)
if (len([w for w in wells
if (w.well_colour
== (255, 255, 255))
])
== len(wells))
else lambda: None)]))
### Task 5: Rising columns
task1_pos = (64 * 15, 48 * 13)
ws = []
for i in range(5):
w1 = Wheel(self, task1_pos[0] + 64 * i, task1_pos[1] - 48 * 2)
w2 = Wheel(self, task1_pos[0] + 64 * i, task1_pos[1],
immitate=w1)
self.objects.extend([w1, w2])
self.objects.append(lever.Lever(self,
task1_pos[0] + 64 * i,
task1_pos[1] + 48 * 1,
[w2.activate],
anim='lever_updown'))
ws.append(w2)
self.add_tile(task1_pos[0] + 64 * i,
task1_pos[1] - 48 * 3,
2012-08-12 17:36:59 +02:00
'moat_horizontal')
self.objects.append(
lever.Lever(self,
2012-08-12 20:01:58 +02:00
task1_pos[0] + 64 * 5,
task1_pos[1] + 48 * 2,
[lambda *xs: self.complete_task(5)
if len(ws) == len([w for w in ws if w.on])
else lambda: None]))
self.add_tile(task1_pos[0] - 64,
task1_pos[1] - 48 * 3,
'moat_corner_north')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] - 48 * 3,
'moat_corner_north_flip')
for i in range(3):
self.add_tile(task1_pos[0] - 64,
task1_pos[1] + 48 * (i - 2),
'moat_vertical')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] + 48 * (i - 2),
'moat_vertical')
self.add_tile(task1_pos[0] - 64,
task1_pos[1] + 48,
'moat_corner_south_flip')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] + 48,
'moat_corner_south')
self.add_tile(task1_pos[0] - 64 * 2,
task1_pos[1] + 48,
'moat_horizontal')
self.add_tile(task1_pos[0] + 64 * 6,
task1_pos[1] + 48,
'moat_end_horizontal_flip')
2012-08-12 19:05:54 +02:00
### Final: The door
door_x = 22
for i in range(12):
self.add_tile(door_x * 64,
48 * (5 + i),
'indoor%d' % random.randint(1, 6), blocking=False)
for i in range(7):
self.add_tile((door_x - i - 1) * 64,
48 * (5 + 11),
'indoor%d' % random.randint(1, 6), blocking=False)
door = block.Door(self, 64 * door_x, 48 * 4)
self.objects.append(door)
self.objects.append(
lever.Lever(self, 64 * (door_x + 3), 48 * 4,
[lambda x: door.activate(x)
if self.task_completions == self.solution
else lambda *v: None],
anim='lever_updown', toggling=False))
self.objects.append(
trigger.Trigger(self, 64 * door_x, 48 * 4,
[self.game.goto_level],
self.imgs['indoor1'],
[self.player]))
if random.randint(0, 1):
for i in range(3):
self.objects.append(
CompletionBlock(self, 64 * (door_x - 5 + i), 48 * 4,
self.solution[i], i + 1))
else:
for i in range(3):
self.objects.append(
CompletionBlock(self, 64 * (door_x - 3 - i), 48 * 4,
self.solution[i], i + 1))
2012-08-12 17:36:59 +02:00
# DRAW THE BACKGROUND
2012-08-12 14:22:41 +02:00
2012-08-09 13:54:27 +02:00
self.draw_background()
2012-08-10 18:37:17 +02:00
def add_tile(self, x, y, img, blocking=True):
2012-08-09 13:54:27 +02:00
self.tiles.append(tile.Tile(self, x, y, self.imgs[img]))
2012-08-10 18:37:17 +02:00
if blocking:
self.objects.append(block.InvisBlock(self, x, y))
2012-08-08 23:08:53 +02:00
def complete_task(self, task):
if task == 0:
return
self.task_completions.append(task)
if len(self.task_completions) > 3:
self.task_completions = self.task_completions[-3:]
def restart(self):
2012-08-08 18:13:53 +02:00
for obj in self.objects:
obj.reset_pos()
2012-08-10 22:31:15 +02:00
class CompletionBlock(block.Block):
def __init__(self, level, x, y, task, number):
self.__dict__.update(locals())
block.Block.__init__(self, level, x, y)
def update(self, e, t, dt):
self.img = self.level.imgs['symbol%02d-0016' % (self.task + 12)]
for t in range(1, 4):
if (self.level.task_completions[-t:] == self.level.solution[:t]
and t >= self.number):
self.img = self.level.imgs['symbol%02d-0018' % (self.task + 12)]
break
2012-08-10 22:31:15 +02:00
class Wheel(block.Block):
def __init__(self, level, x, y, immitate=None):
self.__dict__.update(locals())
worldobject.WorldObject.__init__(self, level, x, y)
self.frame = 0
self.anim_speed = 15
2012-08-11 15:00:50 +02:00
self.nsettings = 5
2012-08-10 22:31:15 +02:00
self.setting = random.randint(0, self.nsettings - 1)
if self.immitate:
self.on = self.setting == self.immitate.setting
self.init_setting = self.setting
2012-08-11 14:47:06 +02:00
self.anim = 'elevating_column'
2012-08-10 22:31:15 +02:00
self.anim_direction = 1
def set_init_pos(self):
worldobject.WorldObject.set_init_pos(self)
self.init_setting = self.setting
def reset_pos(self):
worldobject.WorldObject.reset_pos(self)
self.setting = self.init_setting
def set_direction(self, setting):
self.anim_direction = -1 if setting else 1
def activate(self, setting):
self.setting = (self.setting + 1 * self.anim_direction) % self.nsettings
self.on = self.setting == self.immitate.setting
def update(self, e, t, dt):
# Update the animation
l = len(self.level.imgs[self.anim])
2012-08-11 15:00:50 +02:00
if not (int(self.frame) == self.setting * (l - 1)
/ (self.nsettings - 1)):
2012-08-10 22:31:15 +02:00
self.frame = ((self.frame + self.anim_speed * dt) % l
if (self.setting > 0 and self.anim_direction > 0)
or (self.setting == self.nsettings - 1
and self.anim_direction < 0) else
(self.frame - self.anim_speed * dt) % l)
worldobject.WorldObject.update(self, e, t, dt)
def draw(self, window):
self.img = self.level.imgs[self.anim][int(self.frame)]
if self.visible:
window.blit(self.img, (self.x - 32 - self.level.camera_x,
self.y - self.img.get_size()[1] + 24
- self.level.camera_y))