Redid block loading mechanism. Added the lifted image to the block.
This commit is contained in:
parent
1f552640e5
commit
502039e3f8
|
@ -27,33 +27,56 @@ A generic block. And other block derivatives.
|
|||
import pygame
|
||||
|
||||
import worldobject
|
||||
import copy
|
||||
|
||||
class Block(worldobject.WorldObject):
|
||||
def __init__(self, level, x, y, img=None, movable=False, visible=True):
|
||||
def __init__(self, level, x, y, img_str='block1',
|
||||
movable=False, visible=True):
|
||||
self.__dict__.update(locals())
|
||||
worldobject.WorldObject.__init__(self, level, x, y,
|
||||
movable=movable, visible=visible)
|
||||
|
||||
self.orig_alpha = pygame.surfarray.array_alpha(self.img)
|
||||
self.load()
|
||||
|
||||
def update_alpha(self):
|
||||
be_opaque = not (self.y + self.z >= self.level.player.y
|
||||
+ self.level.player.z)
|
||||
if be_opaque and not self.is_currently_opaque:
|
||||
self.is_currently_opaque = True
|
||||
self.set_alpha(1)
|
||||
elif not be_opaque and self.is_currently_opaque:
|
||||
self.is_currently_opaque = False
|
||||
self.set_alpha(0.5)
|
||||
# self.orig_alphas = {
|
||||
# 'normal':
|
||||
# pygame.surfarray.array_alpha(self.level.imgs[self.img_str]),
|
||||
# 'lifted':
|
||||
# pygame.surfarray.array_alpha(
|
||||
# self.level.imgs[self.img_str + '_lifted'])}
|
||||
|
||||
# self.orig_alpha = self.orig_alphas['normal']
|
||||
|
||||
def load(self):
|
||||
if not isinstance(self.img_str, str):
|
||||
self.img_str = self.level.reverse_imgs[self.img_str]
|
||||
|
||||
self.img = self.level.imgs[self.img_str]
|
||||
|
||||
# def update_alpha(self):
|
||||
# be_opaque = not (self.y + self.z >= self.level.player.move_y
|
||||
# + self.level.player.move_z)
|
||||
# if be_opaque and not self.is_currently_opaque:
|
||||
# self.is_currently_opaque = True
|
||||
# self.set_alpha(1)
|
||||
# elif not be_opaque and self.is_currently_opaque:
|
||||
# self.is_currently_opaque = False
|
||||
# self.set_alpha(0.5)
|
||||
|
||||
def use(self, obj):
|
||||
if self.movable:
|
||||
if obj == self.holder:
|
||||
obj.holding = None
|
||||
self.holder = None
|
||||
if hasattr(self, 'img_str'):
|
||||
self.img = self.level.imgs[self.img_str]
|
||||
# self.orig_alpha = self.orig_alphas['normal']
|
||||
else:
|
||||
obj.holding = self
|
||||
self.holder = obj
|
||||
if hasattr(self, 'img_str'):
|
||||
self.img = self.level.imgs[self.img_str + '_lifted']
|
||||
# self.orig_alpha = self.orig_alphas['lifted']
|
||||
|
||||
def draw(self, window):
|
||||
if self.visible:
|
||||
|
|
|
@ -39,6 +39,10 @@ class Level(object):
|
|||
|
||||
self.load()
|
||||
|
||||
self.reverse_imgs = (
|
||||
dict([(val, key) for (key, val)
|
||||
in self.imgs.iteritems() if not isinstance(val, list)]))
|
||||
|
||||
self.camera_x = 0
|
||||
self.camera_y = 0
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ class Level1(level.Level):
|
|||
self.imgs[o] = pygame.image.load(os.path.join(
|
||||
self.graphics_dir, 'tiles', '%s.png' % o))
|
||||
|
||||
l = ['block1']
|
||||
l = ['block1', 'block1_lifted']
|
||||
for o in l:
|
||||
self.imgs[o] = pygame.image.load(os.path.join(
|
||||
self.graphics_dir, 'blocks', '%s.png' % o))
|
||||
|
|
Loading…
Reference in New Issue