Merge branch 'master' of hongabar.org:robotgame
This commit is contained in:
commit
f9568e11ce
|
@ -29,9 +29,9 @@ import pygame
|
|||
import worldobject
|
||||
|
||||
class Laser(worldobject.WorldObject):
|
||||
def __init__(self, level, p0, p1):
|
||||
def __init__(self, level, p0, p1, laser_direction):
|
||||
self.__dict__.update(locals())
|
||||
worldobject.WorldObject.__init__(self, level, p0[0], p0[1])
|
||||
worldobject.WorldObject.__init__(self, level, p0[0], max(p0[1], p1[1]) + 48)
|
||||
|
||||
def update(self, e, t, dt):
|
||||
|
||||
|
|
|
@ -115,25 +115,64 @@ class Level4(level.Level):
|
|||
for ((x0, y0), (x1, y1)), direc in self.lasers_orig:
|
||||
self.lasers.append(laser.Laser(
|
||||
self, (x0 * 64, y0 * 48),
|
||||
(x1 * 64, y1 * 48)))
|
||||
(x1 * 64, y1 * 48), direc))
|
||||
|
||||
def draw(self, window):
|
||||
self._blit_background(window)
|
||||
|
||||
objs = self._sorted_objs()
|
||||
objs = self._sorted_objs(self.objects + self.lasers)
|
||||
self._after_sort(itertools.groupby(objs, lambda obj: obj.y + obj.z))
|
||||
for obj in objs:
|
||||
obj.draw(window)
|
||||
|
||||
for obj in self.lasers:
|
||||
obj.draw(window)
|
||||
self.darkness.draw(window)
|
||||
|
||||
for obj in objs:
|
||||
x0, y0 = obj.x / 64, obj.y / 48 - 1
|
||||
if isinstance(obj, mirror.Mirror):
|
||||
for (p0, p1), laser_direc in self.lasers_orig:
|
||||
if p0 == (x0, y0):
|
||||
mirror_direc = Left if obj.left_up else Right
|
||||
do_redraw = {
|
||||
def _after_sort(self, objss):
|
||||
for objs in objss:
|
||||
self._after_sort_line(objs)
|
||||
|
||||
def _after_sort_line(self, objs):
|
||||
is_special = lambda obj: isinstance(obj, mirror.Mirror) or isinstance(obj, laser.Laser)
|
||||
specials, nonspecials = filter(is_special, objs), filter(lambda obj: not is_special(obj), objs)
|
||||
return nonspecials + self._sort_line_specials(specials)
|
||||
|
||||
def _sort_line_specials(self, objs):
|
||||
print(objs)
|
||||
return objs
|
||||
|
||||
# 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):
|
||||
return {
|
||||
(Left, Up): True,
|
||||
(Left, Left): True,
|
||||
(Left, Down): False,
|
||||
|
@ -143,7 +182,3 @@ class Level4(level.Level):
|
|||
(Right, Down): False,
|
||||
(Right, Left): False
|
||||
}[(mirror_direc, laser_direc)]
|
||||
if do_redraw:
|
||||
obj.draw(window)
|
||||
|
||||
self.darkness.draw(window)
|
||||
|
|
Loading…
Reference in New Issue