Moat has been added to level 1.
This commit is contained in:
parent
1ebd4a9c91
commit
9456b30c8c
|
@ -29,12 +29,12 @@ import pygame
|
|||
import worldobject
|
||||
|
||||
class Block(worldobject.WorldObject):
|
||||
def __init__(self, level, x, y, img, movable=False):
|
||||
def __init__(self, level, x, y, img=None, movable=False, visible=True):
|
||||
self.__dict__.update(locals())
|
||||
worldobject.WorldObject.__init__(self, level, x, y, movable=movable)
|
||||
worldobject.WorldObject.__init__(self, level, x, y,
|
||||
movable=movable, visible=visible)
|
||||
|
||||
self.orig_alpha = pygame.surfarray.array_alpha(self.img)
|
||||
self.is_currently_opaque = True
|
||||
|
||||
def update_alpha(self):
|
||||
be_opaque = not (self.y + self.z >= self.level.player.y
|
||||
|
@ -56,16 +56,22 @@ class Block(worldobject.WorldObject):
|
|||
self.holder = obj
|
||||
|
||||
def draw(self, window):
|
||||
window.blit(self.img, (self.x - 32 - self.level.camera_x,
|
||||
self.y - self.img.get_size()[1] + 24
|
||||
- self.level.camera_y))
|
||||
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))
|
||||
|
||||
class InvisBlock(Block):
|
||||
def __init__(self, level, x, y):
|
||||
self.__dict__.update(locals())
|
||||
worldobject.WorldObject.__init__(self, level, x, y, visible=False)
|
||||
|
||||
|
||||
class ArrowBlock(Block):
|
||||
def __init__(self, level, x, y, direction, movable=True, is_up=True):
|
||||
self.__dict__.update(locals())
|
||||
worldobject.WorldObject.__init__(self, level, x, y,
|
||||
direction=direction, movable=movable)
|
||||
self.is_currently_opaque = True
|
||||
|
||||
self.frame = 0
|
||||
self.anim_speed = 15
|
||||
|
@ -115,8 +121,7 @@ class RisingBlock(Block):
|
|||
def __init__(self, level, x, y, movable=False, is_up=True):
|
||||
self.__dict__.update(locals())
|
||||
worldobject.WorldObject.__init__(self, level, x, y, movable=movable)
|
||||
self.is_currently_opaque = True
|
||||
|
||||
|
||||
self.frame = 0
|
||||
self.anim_speed = 15
|
||||
self.setting = [0, 0]
|
||||
|
|
|
@ -56,7 +56,7 @@ class Level(object):
|
|||
if not self.paused:
|
||||
for obj in self.objects:
|
||||
obj.update(e, t, dt)
|
||||
if self.player.is_moving and hasattr(obj, 'update_alpha'):
|
||||
if self.player.is_moving:
|
||||
obj.update_alpha()
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ class Level(object):
|
|||
self.camera_y = (self.player.y - screen_size[1] / 2 - 24)
|
||||
|
||||
def draw(self, window):
|
||||
window.blit(self.background, (0 - self.camera_x, -48 - self.camera_y))
|
||||
window.blit(self.background, (0 - self.camera_x, 0 - self.camera_y))
|
||||
|
||||
for obj in sorted(self.objects, key=lambda obj: (obj.y + obj.z)):
|
||||
obj.draw(window)
|
||||
|
|
|
@ -51,18 +51,18 @@ class Level1(level.Level):
|
|||
self.tiles.append(
|
||||
tile.Tile(self, i*64, j*48, self.imgs['ground1']))
|
||||
|
||||
self.draw_background()
|
||||
|
||||
self.player.set_pos(64 * 10, 48 * 10)
|
||||
self.player.set_pos(64 * 15, 48 * 15)
|
||||
self.player.set_init_pos()
|
||||
|
||||
### Task 2: Rolling stone
|
||||
|
||||
task2_size = 15, 10
|
||||
|
||||
task2_pos = (64 * 20, 48 * 20)
|
||||
|
||||
playfield, nsteps, directions = (
|
||||
logic.rollingstone.generate_simple_unsolved_solvable_extra(
|
||||
10, 10, 7, 20))
|
||||
task2_size[0], task2_size[1], 7, 30))
|
||||
|
||||
for i, j in playfield:
|
||||
self.objects.append(
|
||||
|
@ -75,10 +75,11 @@ class Level1(level.Level):
|
|||
arrow_blocks = []
|
||||
n = 0
|
||||
for i in directions:
|
||||
arrow_blocks.append(block.ArrowBlock(self,
|
||||
task2_pos[0] - 64,
|
||||
task2_pos[1] + 48 * n,
|
||||
i.next_pos((0, 0))))
|
||||
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
|
||||
|
||||
self.objects.extend(arrow_blocks)
|
||||
|
@ -90,7 +91,7 @@ class Level1(level.Level):
|
|||
toggling=True,
|
||||
anim='lever_updown'))
|
||||
|
||||
b = boulder.Boulder(self, task2_pos[0], task2_pos[1],
|
||||
b = boulder.Boulder(self, task2_pos[0], task2_pos[1] - 48,
|
||||
direction=(0, 1))
|
||||
self.objects.append(b)
|
||||
|
||||
|
@ -99,6 +100,73 @@ class Level1(level.Level):
|
|||
task2_pos[1] - 48 * 2,
|
||||
[b.activate],
|
||||
anim='lever_updown'))
|
||||
# Moat sides
|
||||
for i in range(-1, task2_size[1]):
|
||||
self.add_moat(task2_pos[0] - 64,
|
||||
task2_pos[1] + 48 * i,
|
||||
'moat_vertical')
|
||||
for i in range(task2_size[1] - 2):
|
||||
self.add_moat(task2_pos[0] + 64 * task2_size[0],
|
||||
task2_pos[1] + 48 * i,
|
||||
'moat_vertical')
|
||||
for i in range(6, task2_size[0]):
|
||||
self.add_moat(task2_pos[0] + 64 * i,
|
||||
task2_pos[1] - 48,
|
||||
'moat_horizontal')
|
||||
for i in range(task2_size[0] - 2):
|
||||
self.add_moat(task2_pos[0] + 64 * i,
|
||||
task2_pos[1] + 48 * task2_size[1],
|
||||
'moat_horizontal')
|
||||
# Corners
|
||||
self.add_moat(task2_pos[0] + 64 * task2_size[0],
|
||||
task2_pos[1] - 48,
|
||||
'moat_corner_north_flip')
|
||||
self.add_moat(task2_pos[0] - 64,
|
||||
task2_pos[1] + 48 * task2_size[1],
|
||||
'moat_corner_south')
|
||||
|
||||
# Start
|
||||
self.add_moat(task2_pos[0] + 64 * 2,
|
||||
task2_pos[1] - 48,
|
||||
'moat_horizontal')
|
||||
self.add_moat(task2_pos[0] + 64 * 3,
|
||||
task2_pos[1] - 48,
|
||||
'moat_end_horizontal_flip')
|
||||
self.add_moat(task2_pos[0] + 64 * 5,
|
||||
task2_pos[1] - 48,
|
||||
'moat_end_horizontal')
|
||||
self.add_moat(task2_pos[0] - 64,
|
||||
task2_pos[1] - 48 * 2,
|
||||
'moat_corner_north')
|
||||
self.add_moat(task2_pos[0],
|
||||
task2_pos[1] - 48 * 2,
|
||||
'moat_horizontal')
|
||||
self.add_moat(task2_pos[0] + 64,
|
||||
task2_pos[1] - 48 * 2,
|
||||
'moat_corner_north_flip')
|
||||
self.add_moat(task2_pos[0] + 64,
|
||||
task2_pos[1] - 48,
|
||||
'moat_corner_south')
|
||||
|
||||
# End
|
||||
self.add_moat(task2_pos[0] + 64 * task2_size[0],
|
||||
task2_pos[1] + 48 * (task2_size[1] - 2),
|
||||
'moat_corner_south')
|
||||
self.add_moat(task2_pos[0] + 64 * (task2_size[0] + 1),
|
||||
task2_pos[1] + 48 * (task2_size[1] - 2),
|
||||
'moat_corner_north_flip')
|
||||
self.add_moat(task2_pos[0] + 64 * (task2_size[0] + 1),
|
||||
task2_pos[1] + 48 * (task2_size[1] - 1),
|
||||
'moat_vertical')
|
||||
self.add_moat(task2_pos[0] + 64 * (task2_size[0] + 1),
|
||||
task2_pos[1] + 48 * (task2_size[1]),
|
||||
'moat_corner_south_flip')
|
||||
self.add_moat(task2_pos[0] + 64 * (task2_size[0]),
|
||||
task2_pos[1] + 48 * (task2_size[1]),
|
||||
'moat_end_horizontal')
|
||||
self.add_moat(task2_pos[0] + 64 * (task2_size[0] - 2),
|
||||
task2_pos[1] + 48 * (task2_size[1]),
|
||||
'moat_end_horizontal_flip')
|
||||
|
||||
### Task 4: Inverted bits
|
||||
|
||||
|
@ -109,7 +177,7 @@ class Level1(level.Level):
|
|||
self.objects.append(b)
|
||||
|
||||
self.objects.append(lever.Lever(self,
|
||||
task4_pos[0] - 64 * 2,
|
||||
task4_pos[0] - 64 * 3,
|
||||
task4_pos[1] - 48 * 3,
|
||||
[b.activate]))
|
||||
|
||||
|
@ -152,32 +220,32 @@ class Level1(level.Level):
|
|||
risingblocks[i].set_init_pos()
|
||||
risingblocks[n].set_init_pos()
|
||||
|
||||
self.objects.append(block.Block(self, task4_pos[0] + 64 * i,
|
||||
task4_pos[1] - 48 * 4,
|
||||
self.imgs['block1']))
|
||||
# Moat
|
||||
self.add_moat(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 4,
|
||||
'moat_corner_north')
|
||||
self.add_moat(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 3,
|
||||
'moat_vertical')
|
||||
self.add_moat(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 2,
|
||||
'moat_corner_south')
|
||||
self.add_moat(task4_pos[0] - 64, task4_pos[1] - 48 * 2,
|
||||
'moat_end_horizontal_flip')
|
||||
for i in range(10):
|
||||
self.add_moat(task4_pos[0] + 64 * (i - 1), task4_pos[1] - 48 * 4,
|
||||
'moat_horizontal')
|
||||
self.add_moat(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 4,
|
||||
'moat_corner_north_flip')
|
||||
self.add_moat(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 3,
|
||||
'moat_vertical')
|
||||
self.add_moat(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 2,
|
||||
'moat_corner_south_flip')
|
||||
self.add_moat(task4_pos[0] + 64 * 8, task4_pos[1] - 48 * 2,
|
||||
'moat_end_horizontal')
|
||||
|
||||
self.draw_background()
|
||||
|
||||
self.objects.append(block.Block(self, task4_pos[0] - 64,
|
||||
task4_pos[1] - 48 * 2,
|
||||
self.imgs['block1']))
|
||||
self.objects.append(block.Block(self, task4_pos[0] - 64,
|
||||
task4_pos[1] - 48 * 4,
|
||||
self.imgs['block1']))
|
||||
self.objects.append(block.Block(self, task4_pos[0] + 64 * 8,
|
||||
task4_pos[1] - 48 * 4,
|
||||
self.imgs['block1']))
|
||||
self.objects.append(block.Block(self, task4_pos[0] + 64 * 8,
|
||||
task4_pos[1] - 48 * 2,
|
||||
self.imgs['block1']))
|
||||
self.objects.append(block.Block(self, task4_pos[0] + 64 * 9,
|
||||
task4_pos[1] - 48 * 4,
|
||||
self.imgs['block1']))
|
||||
self.objects.append(block.Block(self, task4_pos[0] + 64 * 9,
|
||||
task4_pos[1] - 48 * 3,
|
||||
self.imgs['block1']))
|
||||
self.objects.append(block.Block(self, task4_pos[0] + 64 * 9,
|
||||
task4_pos[1] - 48 * 2,
|
||||
self.imgs['block1']))
|
||||
def add_moat(self, x, y, img):
|
||||
self.tiles.append(tile.Tile(self, x, y, self.imgs[img]))
|
||||
self.objects.append(block.InvisBlock(self, x, y))
|
||||
|
||||
def load(self):
|
||||
"""Load all resources used in the level."""
|
||||
|
@ -199,7 +267,15 @@ class Level1(level.Level):
|
|||
'moat_vertical']
|
||||
for moat in moat_list:
|
||||
self.imgs[moat] = pygame.image.load(os.path.join(
|
||||
self.graphics_dir, 'moat', '%s.png' % block))
|
||||
self.graphics_dir, 'moat', '%s.png' % moat))
|
||||
|
||||
# Special treatment
|
||||
self.imgs['moat_corner_north_flip'] = pygame.transform.flip(
|
||||
self.imgs['moat_corner_north'], 1, 0)
|
||||
self.imgs['moat_corner_south_flip'] = pygame.transform.flip(
|
||||
self.imgs['moat_corner_south'], 1, 0)
|
||||
self.imgs['moat_end_horizontal_flip'] = pygame.transform.flip(
|
||||
self.imgs['moat_end_horizontal'], 1, 0)
|
||||
|
||||
# Load animations
|
||||
for anim, directory in (
|
||||
|
|
|
@ -31,7 +31,7 @@ import copy
|
|||
class WorldObject(object):
|
||||
def __init__(self, level, x, y, z=0, direction=(1, 0), speed=4,
|
||||
tile_x=64, tile_y=48,
|
||||
movable=False, blocking=True, is_moving=False):
|
||||
movable=False, blocking=True, is_moving=False, visible=True):
|
||||
self.__dict__.update(locals())
|
||||
|
||||
self.init_x = self.move_x = self.x = x - (x % self.tile_x)
|
||||
|
@ -41,6 +41,8 @@ class WorldObject(object):
|
|||
self.holding = None
|
||||
self.holder = None
|
||||
|
||||
self.is_currently_opaque = True
|
||||
|
||||
if hasattr(self, 'img'):
|
||||
self.img = copy.copy(self.img)
|
||||
|
||||
|
@ -98,6 +100,9 @@ class WorldObject(object):
|
|||
def activate(self, setting):
|
||||
pass
|
||||
|
||||
def update_alpha(self):
|
||||
pass
|
||||
|
||||
def set_alpha(self, value):
|
||||
"""
|
||||
Set the relative translucency of the per-pixel-alpha image.
|
||||
|
|
Loading…
Reference in New Issue