Made lever toggle arrow block.
This commit is contained in:
parent
f9e7aa333f
commit
13d3aa1ce9
|
@ -55,4 +55,38 @@ class Block(worldobject.WorldObject):
|
||||||
- self.level.camera_y))
|
- self.level.camera_y))
|
||||||
|
|
||||||
class ArrowBlock(Block):
|
class ArrowBlock(Block):
|
||||||
pass
|
def __init__(self, level, x, y, anim='arrow_up', movable=True, is_up=True):
|
||||||
|
self.__dict__.update(locals())
|
||||||
|
worldobject.WorldObject.__init__(self, level, x, y, movable=movable)
|
||||||
|
|
||||||
|
self.frame = 0
|
||||||
|
self.anim_speed = 15
|
||||||
|
self.setting = False
|
||||||
|
|
||||||
|
def activate(self, setting):
|
||||||
|
self.movable = True
|
||||||
|
if self.check_move(0, 0):
|
||||||
|
self.is_up = not setting
|
||||||
|
self.movable = False
|
||||||
|
|
||||||
|
def update(self, e, t, dt):
|
||||||
|
# Update the animation
|
||||||
|
if not self.is_up:
|
||||||
|
self.frame = min(self.frame + self.anim_speed * dt,
|
||||||
|
len(self.level.imgs[self.anim]) - 1)
|
||||||
|
else:
|
||||||
|
self.frame = max(self.frame - self.anim_speed * dt,
|
||||||
|
0)
|
||||||
|
|
||||||
|
if self.frame == len(self.level.imgs[self.anim]) - 1:
|
||||||
|
self.movable = self.blocking = False
|
||||||
|
self.z = -48
|
||||||
|
else:
|
||||||
|
self.movable = self.blocking = True
|
||||||
|
self.z = 0
|
||||||
|
|
||||||
|
worldobject.WorldObject.update(self, e, t, dt)
|
||||||
|
|
||||||
|
def draw(self, window):
|
||||||
|
self.img = self.level.imgs[self.anim][int(self.frame)]
|
||||||
|
Block.draw(self, window)
|
||||||
|
|
|
@ -47,14 +47,17 @@ class Level1(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']))
|
||||||
|
|
||||||
for i in range(10):
|
# for i in range(10):
|
||||||
self.objects.append(block.Block(self, random.randint(0, 10)*64,
|
# self.objects.append(block.Block(self, random.randint(0, 10)*64,
|
||||||
random.randint(0, 10)*48,
|
# random.randint(0, 10)*48,
|
||||||
self.imgs['block1'],
|
# self.imgs['block1'],
|
||||||
movable=True))
|
# movable=True))
|
||||||
|
|
||||||
self.objects.append(boulder.Boulder(self, 64, 48))
|
self.objects.append(boulder.Boulder(self, 64, 48))
|
||||||
self.objects.append(lever.Lever(self, 128, 48*2, [], toggling=True))
|
arrow_block = block.ArrowBlock(self, 64, 0)
|
||||||
|
lever1 = lever.Lever(self, 128, 48*2, [arrow_block.activate],
|
||||||
|
toggling=True)
|
||||||
|
self.objects.extend([lever1, arrow_block])
|
||||||
self.objects.append(lever.Lever(self, 128, 48*3, [], toggling=False))
|
self.objects.append(lever.Lever(self, 128, 48*3, [], toggling=False))
|
||||||
self.objects.append(lever.Lever(self, 128*2, 48*3, [], toggling=False,
|
self.objects.append(lever.Lever(self, 128*2, 48*3, [], toggling=False,
|
||||||
anim='lever_updown'))
|
anim='lever_updown'))
|
||||||
|
@ -82,7 +85,12 @@ class Level1(level.Level):
|
||||||
('boulder_left', os.path.join('boulder', 'right')),
|
('boulder_left', os.path.join('boulder', 'right')),
|
||||||
|
|
||||||
('lever_updown', os.path.join('lever', 'down-up')),
|
('lever_updown', os.path.join('lever', 'down-up')),
|
||||||
('lever_leftright', os.path.join('lever', 'left-right'))]
|
('lever_leftright', os.path.join('lever', 'left-right')),
|
||||||
|
|
||||||
|
('arrow_up', os.path.join('matt', 'up')),
|
||||||
|
('arrow_right', os.path.join('matt', 'right')),
|
||||||
|
('arrow_down', os.path.join('matt', 'down')),
|
||||||
|
('arrow_left', os.path.join('matt', 'right')),]
|
||||||
):
|
):
|
||||||
|
|
||||||
self.imgs[anim] = []
|
self.imgs[anim] = []
|
||||||
|
|
|
@ -31,7 +31,7 @@ import copy
|
||||||
class WorldObject(object):
|
class WorldObject(object):
|
||||||
def __init__(self, level, x, y, z=0, direction=(1, 0), speed=4,
|
def __init__(self, level, x, y, z=0, direction=(1, 0), speed=4,
|
||||||
tile_x=64, tile_y=48,
|
tile_x=64, tile_y=48,
|
||||||
movable=False):
|
movable=False, blocking=True):
|
||||||
self.__dict__.update(locals())
|
self.__dict__.update(locals())
|
||||||
|
|
||||||
self.init_x = self.move_x = self.x = self.x - (self.x % self.tile_x)
|
self.init_x = self.move_x = self.x = self.x - (self.x % self.tile_x)
|
||||||
|
@ -54,8 +54,8 @@ class WorldObject(object):
|
||||||
for obj in self.level.objects:
|
for obj in self.level.objects:
|
||||||
if (obj.x == self.x + move_x * self.tile_x
|
if (obj.x == self.x + move_x * self.tile_x
|
||||||
and obj.y == self.y + move_y * self.tile_y
|
and obj.y == self.y + move_y * self.tile_y
|
||||||
and obj != self and obj != self.holder
|
and obj is not self and obj is not self.holder
|
||||||
and obj != self.holding):
|
and obj is not self.holding and obj.blocking):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue