level 4 walls, good laser still under development (algorithm discovered,
implementation next up)
This commit is contained in:
parent
4a8a5b5d70
commit
9d7bb2e946
|
@ -46,14 +46,14 @@ from logic.direction import *
|
||||||
class Level4(level.Level):
|
class Level4(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,
|
level.Level.__init__(self, game, graphics_dir,
|
||||||
size=(64 * 16, 48 * 16), paused=paused)
|
size=(64 * 16, 48 * 20), paused=paused)
|
||||||
|
|
||||||
self.dimensions = 16, 16
|
self.dimensions = 16, 16
|
||||||
|
|
||||||
for i in range(self.dimensions[0]):
|
for i in range(self.dimensions[0]):
|
||||||
for j in range(self.dimensions[1]):
|
for j in range(self.dimensions[1]):
|
||||||
self.tiles.append(
|
self.tiles.append(
|
||||||
tile.Tile(self, i*64, (j+1)*48,
|
tile.Tile(self, i*64, (j+4)*48,
|
||||||
self.imgs['indoor%d' % random.randint(1, 6)]))
|
self.imgs['indoor%d' % random.randint(1, 6)]))
|
||||||
|
|
||||||
self.draw_background()
|
self.draw_background()
|
||||||
|
@ -61,10 +61,11 @@ class Level4(level.Level):
|
||||||
self.playfield = lm.generate_simple_playfield(16)
|
self.playfield = lm.generate_simple_playfield(16)
|
||||||
|
|
||||||
for (x, y), t in self.playfield.items():
|
for (x, y), t in self.playfield.items():
|
||||||
x1, y1 = 64 * x, 48 * (y + 1)
|
x1, y1 = 64 * x, 48 * (y + 4)
|
||||||
if isinstance(t, lm.Source):
|
if isinstance(t, lm.Source):
|
||||||
self.objects.append(block.Block(self, x1, y1,
|
self.objects.append(block.Block(
|
||||||
self.imgs['block3'],
|
self, x1, y1,
|
||||||
|
self.imgs['lasersource_' + t.direction.to_str().lower()],
|
||||||
movable=False))
|
movable=False))
|
||||||
continue
|
continue
|
||||||
def mir(b, x1, y1):
|
def mir(b, x1, y1):
|
||||||
|
@ -84,7 +85,7 @@ class Level4(level.Level):
|
||||||
toggling=True,
|
toggling=True,
|
||||||
anim='lever_leftright' if x in (0, 15)
|
anim='lever_leftright' if x in (0, 15)
|
||||||
else 'lever_updown'),
|
else 'lever_updown'),
|
||||||
lm.Target: block.Block(self, x1, y1, self.imgs['block3'],
|
lm.Target: block.Block(self, x1, y1, self.imgs['lasertarget'],
|
||||||
movable=False),
|
movable=False),
|
||||||
lm.Blocker: block.Block(self, x1, y1, self.imgs['block1'],
|
lm.Blocker: block.Block(self, x1, y1, self.imgs['block1'],
|
||||||
movable=False)
|
movable=False)
|
||||||
|
@ -100,9 +101,23 @@ class Level4(level.Level):
|
||||||
mirrors.remove(m)
|
mirrors.remove(m)
|
||||||
l.links.insert(0, (lambda m: lambda setting: m.rotate())(m))
|
l.links.insert(0, (lambda m: lambda setting: m.rotate())(m))
|
||||||
|
|
||||||
|
for i in range(self.size[0] / 64):
|
||||||
|
if not i % 3:
|
||||||
|
self.objects.append(block.Block(self, i * 64,
|
||||||
|
48 * 3,
|
||||||
|
self.imgs['wall'],
|
||||||
|
width=3))
|
||||||
|
self.objects.append(block.InvisBlock(self, i * 64,
|
||||||
|
self.size[1]))
|
||||||
|
for i in range(self.size[1] / 48):
|
||||||
|
self.objects.append(block.InvisBlock(self, - 64,
|
||||||
|
i * 48))
|
||||||
|
self.objects.append(block.InvisBlock(self, self.size[0],
|
||||||
|
i * 48))
|
||||||
|
|
||||||
self.generate_lasers()
|
self.generate_lasers()
|
||||||
|
|
||||||
self.player.set_pos(64 * 7, 48 * 2)
|
self.player.set_pos(64 * 7, 48 * 5)
|
||||||
self.player.set_init_pos()
|
self.player.set_init_pos()
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
|
@ -121,15 +136,17 @@ class Level4(level.Level):
|
||||||
self._blit_background(window)
|
self._blit_background(window)
|
||||||
|
|
||||||
objs = self._sorted_objs(self.objects + self.lasers)
|
objs = self._sorted_objs(self.objects + self.lasers)
|
||||||
self._after_sort(itertools.groupby(objs, lambda obj: obj.y + obj.z))
|
objs = self._after_sort(itertools.groupby(objs, lambda obj: obj.y + obj.z))
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
obj.draw(window)
|
obj.draw(window)
|
||||||
|
|
||||||
self.darkness.draw(window)
|
self.darkness.draw(window)
|
||||||
|
|
||||||
def _after_sort(self, objss):
|
def _after_sort(self, objss):
|
||||||
for objs in objss:
|
n_objs = []
|
||||||
self._after_sort_line(objs)
|
for c, objs in objss:
|
||||||
|
n_objs.extend(self._after_sort_line(list(objs)))
|
||||||
|
return n_objs
|
||||||
|
|
||||||
def _after_sort_line(self, objs):
|
def _after_sort_line(self, objs):
|
||||||
is_special = lambda obj: isinstance(obj, mirror.Mirror) or isinstance(obj, laser.Laser)
|
is_special = lambda obj: isinstance(obj, mirror.Mirror) or isinstance(obj, laser.Laser)
|
||||||
|
@ -137,39 +154,9 @@ class Level4(level.Level):
|
||||||
return nonspecials + self._sort_line_specials(specials)
|
return nonspecials + self._sort_line_specials(specials)
|
||||||
|
|
||||||
def _sort_line_specials(self, objs):
|
def _sort_line_specials(self, objs):
|
||||||
print(objs)
|
mirrors = filter(lambda obj: isinstance(obj, mirror.Mirror), objs)
|
||||||
return objs
|
lasers = filter(lambda obj: isinstance(obj, laser.Laser), objs)
|
||||||
|
return mirrors + lasers
|
||||||
# def _compare(a, b):
|
|
||||||
# types = map(type, (a, b))
|
|
||||||
# if a.y + a.z == b.y + b.z:
|
|
||||||
# if isinstance(a, mirror.Mirror) and isinstance(b, laser.Laser):
|
|
||||||
# return 1
|
|
||||||
# if isinstance(b, mirror.Mirror) and isinstance(a, laser.Laser):
|
|
||||||
# return -1
|
|
||||||
# # if mirror.Mirror in types and laser.Laser in types:
|
|
||||||
# # if not isinstance(a, laser.Laser):
|
|
||||||
# # a, b, swapped = b, a, True
|
|
||||||
# # else:
|
|
||||||
# # swapped = False
|
|
||||||
# # laser_direc = a.laser_direction
|
|
||||||
# # if a.p0[1] < a.p1[1]:
|
|
||||||
# # laser_direc = Down # instead of Down
|
|
||||||
# # if a.p0[1] > a.p1[1]:
|
|
||||||
# # laser_direc = Up # instead of Up
|
|
||||||
# # mirror_direc = Left if b.left_up else Right
|
|
||||||
# # result = 1 if _is_laser_behind_mirror(mirror_direc, laser_direc) \
|
|
||||||
# # else -1
|
|
||||||
# # result = -1
|
|
||||||
# # return result if not swapped else -1 * result
|
|
||||||
# if a is laser.Laser and b is not laser.Laser:
|
|
||||||
# return 1
|
|
||||||
# if b is laser.Laser and a is not laser.Laser:
|
|
||||||
# return -1
|
|
||||||
# return 0
|
|
||||||
|
|
||||||
# return -1 if a.y + a.z < b.y + b.z \
|
|
||||||
# else 1 if a.y + a.z > b.y + b.z else 0
|
|
||||||
|
|
||||||
def _is_laser_behind_mirror(mirror_direc, laser_direc):
|
def _is_laser_behind_mirror(mirror_direc, laser_direc):
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -51,10 +51,13 @@ class Loader(object):
|
||||||
self.imgs['indoor%d' % o] = pygame.image.load(os.path.join(
|
self.imgs['indoor%d' % o] = pygame.image.load(os.path.join(
|
||||||
self.directory, 'tiles', 'indoor', 'ground%02d.png' % o))
|
self.directory, 'tiles', 'indoor', 'ground%02d.png' % o))
|
||||||
|
|
||||||
l = ['block1', 'block1_lifted', 'block3']
|
l = ['block1', 'block1_lifted', 'block3', '../lasertarget',
|
||||||
|
'../lasersource_up', '../lasersource_down', '../lasersource_right']
|
||||||
for o in l:
|
for o in l:
|
||||||
self.imgs[o] = pygame.image.load(os.path.join(
|
self.imgs[os.path.basename(o)] = pygame.image.load(os.path.join(
|
||||||
self.directory, 'blocks', '%s.png' % o))
|
self.directory, 'blocks', '%s.png' % o))
|
||||||
|
self.imgs['lasersource_left'] = pygame.transform.flip(
|
||||||
|
self.imgs['lasersource_right'], 1, 0)
|
||||||
|
|
||||||
l = ['hole', 'well', 'wall', 'wall_outside', 'intro-screen']
|
l = ['hole', 'well', 'wall', 'wall_outside', 'intro-screen']
|
||||||
for o in l:
|
for o in l:
|
||||||
|
@ -129,7 +132,7 @@ class Loader(object):
|
||||||
img = pygame.image.load(f)
|
img = pygame.image.load(f)
|
||||||
|
|
||||||
# Special treatment:
|
# Special treatment:
|
||||||
if anim == 'arrow_left':
|
if anim in ('arrow_left',):
|
||||||
img = pygame.transform.flip(img, 1, 0)
|
img = pygame.transform.flip(img, 1, 0)
|
||||||
|
|
||||||
self.imgs[anim].append(img)
|
self.imgs[anim].append(img)
|
||||||
|
|
|
@ -29,6 +29,10 @@ class Direction(object):
|
||||||
def next_pos(pos):
|
def next_pos(pos):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_str():
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_sakse(p):
|
def from_sakse(p):
|
||||||
return {(0, -1): Up,
|
return {(0, -1): Up,
|
||||||
|
@ -42,24 +46,40 @@ class Up(Direction):
|
||||||
x, y = pos
|
x, y = pos
|
||||||
return x, y - 1
|
return x, y - 1
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_str():
|
||||||
|
return 'up'
|
||||||
|
|
||||||
class Right(Direction):
|
class Right(Direction):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def next_pos(pos):
|
def next_pos(pos):
|
||||||
x, y = pos
|
x, y = pos
|
||||||
return x + 1, y
|
return x + 1, y
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_str():
|
||||||
|
return 'right'
|
||||||
|
|
||||||
class Down(Direction):
|
class Down(Direction):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def next_pos(pos):
|
def next_pos(pos):
|
||||||
x, y = pos
|
x, y = pos
|
||||||
return x, y + 1
|
return x, y + 1
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_str():
|
||||||
|
return 'down'
|
||||||
|
|
||||||
class Left(Direction):
|
class Left(Direction):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def next_pos(pos):
|
def next_pos(pos):
|
||||||
x, y = pos
|
x, y = pos
|
||||||
return x - 1, y
|
return x - 1, y
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_str():
|
||||||
|
return 'left'
|
||||||
|
|
||||||
all_directions = (Up, Right, Down, Left)
|
all_directions = (Up, Right, Down, Left)
|
||||||
_sp = lambda n: lambda d: all_directions[(all_directions.index(d) + n) % 4]
|
_sp = lambda n: lambda d: all_directions[(all_directions.index(d) + n) % 4]
|
||||||
succ, pred = _sp(1), _sp(-1)
|
succ, pred = _sp(1), _sp(-1)
|
||||||
|
|
Loading…
Reference in New Issue