Merge branch 'master' of hongabar.org:robotgame

This commit is contained in:
Sakse Dalum
2012-08-10 12:50:40 +02:00
4 changed files with 85 additions and 66 deletions

View File

@@ -28,6 +28,7 @@ import os
import pygame
import random
import re
import itertools
import level
import player
@@ -38,6 +39,7 @@ import lever
import trigger
import logic.rollingstone
import logic.colourboxes
class Level1(level.Level):
def __init__(self, game, graphics_dir, paused=False):
@@ -191,6 +193,50 @@ class Level1(level.Level):
self.imgs['hole'], [b],
signal=[0, 2]))
### Task 3: Colour blocks
task3_pos = (64 * 3, 48 * 16)
# 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)
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
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)
wells = [block.ColorWell(self, task3_pos[0] + 64, task3_pos[1] + 48 * 5)]
self.objects.extend(wells)
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)
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
### Task 4: Inverted bits
task4_pos = (64 * 13, 48 * 13)