Merge branch 'master' of hongabar.org:robotgame
This commit is contained in:
commit
4afd08724f
|
@ -191,3 +191,36 @@ class RisingBlock(Block):
|
||||||
def draw(self, window):
|
def draw(self, window):
|
||||||
self.img = self.level.imgs[self.anim][int(self.frame)]
|
self.img = self.level.imgs[self.anim][int(self.frame)]
|
||||||
Block.draw(self, window)
|
Block.draw(self, window)
|
||||||
|
|
||||||
|
|
||||||
|
class ActionBlock(Block):
|
||||||
|
def __init__(self, level, x, y, action=None, movable=True):
|
||||||
|
self.__dict__.update(locals())
|
||||||
|
Block.__init__(
|
||||||
|
self, level, x, y, img=level.imgs['block1'],
|
||||||
|
movable=movable)
|
||||||
|
self._last_pos = None
|
||||||
|
|
||||||
|
def update(self, e, t, dt):
|
||||||
|
if (self.x, self.y) != self._last_pos and not self.is_moving:
|
||||||
|
self.action(self)
|
||||||
|
self._last_pos = self.x, self.y
|
||||||
|
|
||||||
|
worldobject.WorldObject.update(self, e, t, dt)
|
||||||
|
|
||||||
|
class ColorWell(Block):
|
||||||
|
def __init__(self, level, x, y):
|
||||||
|
self.__dict__.update(locals())
|
||||||
|
worldobject.WorldObject.__init__(
|
||||||
|
self, level, x, y, movable=False)
|
||||||
|
self.img = pygame.Surface((64, 64))
|
||||||
|
|
||||||
|
def set_colour(self, r, g, b):
|
||||||
|
self.well_colour = r * 255, g * 255, b * 255
|
||||||
|
self.img.fill(self.well_colour)
|
||||||
|
|
||||||
|
def draw(self, window):
|
||||||
|
if self.visible:
|
||||||
|
window.blit(self.img, (self.x - self.level.camera_x,
|
||||||
|
self.y - self.img.get_size()[1]
|
||||||
|
- self.level.camera_y))
|
||||||
|
|
|
@ -28,6 +28,7 @@ import os
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import itertools
|
||||||
|
|
||||||
import level
|
import level
|
||||||
import player
|
import player
|
||||||
|
@ -38,6 +39,7 @@ import lever
|
||||||
import trigger
|
import trigger
|
||||||
|
|
||||||
import logic.rollingstone
|
import logic.rollingstone
|
||||||
|
import logic.colourboxes
|
||||||
|
|
||||||
class Level1(level.Level):
|
class Level1(level.Level):
|
||||||
def __init__(self, game, graphics_dir, paused=False):
|
def __init__(self, game, graphics_dir, paused=False):
|
||||||
|
@ -191,6 +193,50 @@ class Level1(level.Level):
|
||||||
self.imgs['hole'], [b],
|
self.imgs['hole'], [b],
|
||||||
signal=[0, 2]))
|
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
|
### Task 4: Inverted bits
|
||||||
|
|
||||||
task4_pos = (64 * 13, 48 * 13)
|
task4_pos = (64 * 13, 48 * 13)
|
||||||
|
|
|
@ -44,33 +44,6 @@ import lever
|
||||||
import logic.colourboxes
|
import logic.colourboxes
|
||||||
|
|
||||||
|
|
||||||
class ActionBlock(block.Block):
|
|
||||||
def __init__(self, level, x, y, action, movable=True):
|
|
||||||
self.__dict__.update(locals())
|
|
||||||
block.Block.__init__(
|
|
||||||
self, level, x, y, img=level.imgs['block1'],
|
|
||||||
movable=movable)
|
|
||||||
self._last_pos = None
|
|
||||||
|
|
||||||
def update(self, e, t, dt):
|
|
||||||
if (self.x, self.y) != self._last_pos and not self.is_moving:
|
|
||||||
self.action(self)
|
|
||||||
self._last_pos = self.x, self.y
|
|
||||||
|
|
||||||
worldobject.WorldObject.update(self, e, t, dt)
|
|
||||||
|
|
||||||
class ColorWell(block.Block):
|
|
||||||
def __init__(self, level, x, y):
|
|
||||||
self.__dict__.update(locals())
|
|
||||||
worldobject.WorldObject.__init__(
|
|
||||||
self, level, x, y, movable=False)
|
|
||||||
self.img = pygame.Surface((128, 96))
|
|
||||||
self.set_colour(0, 0, 0)
|
|
||||||
|
|
||||||
def set_colour(self, r, g, b):
|
|
||||||
self.well_colour = r * 255, g * 255, b * 255
|
|
||||||
self.img.fill(self.well_colour)
|
|
||||||
|
|
||||||
class Level3(level.Level):
|
class Level3(level.Level):
|
||||||
def __init__(self, game, graphics_dir, paused=False):
|
def __init__(self, game, graphics_dir, paused=False):
|
||||||
level.Level.__init__(self, game, graphics_dir, size=(64*20, 48*20),
|
level.Level.__init__(self, game, graphics_dir, size=(64*20, 48*20),
|
||||||
|
@ -83,40 +56,6 @@ class Level3(level.Level):
|
||||||
# self.tiles.append(
|
# self.tiles.append(
|
||||||
# tile.Tile(self, i*64, j*48, self.imgs['ground1']))
|
# tile.Tile(self, i*64, j*48, self.imgs['ground1']))
|
||||||
|
|
||||||
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, 6), range(3, 6))):
|
|
||||||
self.tiles.append(tile.Tile(self, x * 64, y * 48, self.imgs['ground1']))
|
|
||||||
pos_colour[(x, y)] = box
|
|
||||||
|
|
||||||
blocks = [ActionBlock(self, 64 * i, 0, action=None, movable=True)
|
|
||||||
for i in range(1, 4)]
|
|
||||||
self.objects.extend(blocks)
|
|
||||||
|
|
||||||
wells = [ColorWell(self, 64 * 5, 0)]
|
|
||||||
self.objects.extend(wells)
|
|
||||||
|
|
||||||
def update_wells(block):
|
|
||||||
cur_boxes = []
|
|
||||||
for block in blocks:
|
|
||||||
box = pos_colour.get((block.x / 64, block.y / 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 blocks:
|
|
||||||
b.action = update_wells
|
|
||||||
|
|
||||||
self.draw_background()
|
self.draw_background()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,13 @@ def generate_simple_playfield(nmirrors):
|
||||||
succs = (lambda s: lambda d: succ(s(d)))(succs)
|
succs = (lambda s: lambda d: succ(s(d)))(succs)
|
||||||
source_direc = succ(source_direc)
|
source_direc = succ(source_direc)
|
||||||
|
|
||||||
|
occup = set(playfield.keys())
|
||||||
emptys = list(
|
emptys = list(
|
||||||
set([(0, y) for y in range(12)]
|
set([(0, y) for y in filter(lambda y: (1, y) not in occup, range(12))]
|
||||||
+ [(11, y) for y in range(12)]
|
+ [(11, y) for y in filter(lambda y: (10, y) not in occup, range(12))]
|
||||||
+ [(x, 0) for x in range(12)]
|
+ [(x, 0) for x in filter(lambda x: (x, 1) not in occup, range(12))]
|
||||||
+ [(x, 11) for x in range(12)])
|
+ [(x, 11) for x in filter(lambda x: (x, 10) not in occup, range(12))])
|
||||||
- set(playfield.keys()))
|
- occup)
|
||||||
if len(emptys) < nlevers:
|
if len(emptys) < nlevers:
|
||||||
raise Exception("Not enough space for all levers!")
|
raise Exception("Not enough space for all levers!")
|
||||||
for pos in misc.pick_random_elements(emptys, nlevers):
|
for pos in misc.pick_random_elements(emptys, nlevers):
|
||||||
|
|
Loading…
Reference in New Issue