From 3d76f7fdbdf281d61a427a33ebe17c8bafc14c46 Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Thu, 9 Aug 2012 12:43:18 +0200 Subject: [PATCH] Now only updates alpha when it has to. Much faster. --- robotgame/block.py | 15 +++++++++++---- robotgame/level3.py | 6 ------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/robotgame/block.py b/robotgame/block.py index e57d07b..39019fc 100644 --- a/robotgame/block.py +++ b/robotgame/block.py @@ -34,12 +34,17 @@ class Block(worldobject.WorldObject): worldobject.WorldObject.__init__(self, level, x, y, movable=movable) self.orig_alpha = pygame.surfarray.array_alpha(self.img) + self.is_currently_opaque = True def update_alpha(self): - if (self.y + self.z >= self.level.player.y + self.level.player.z): - self.set_alpha(0.5) - else: + 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) def use(self, obj): if self.movable: @@ -60,6 +65,7 @@ class ArrowBlock(Block): 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 @@ -109,7 +115,8 @@ 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] diff --git a/robotgame/level3.py b/robotgame/level3.py index 4b185ef..a044a86 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -136,9 +136,3 @@ class Level3(level.Level): def restart(self): for obj in self.objects: obj.reset_pos() - -def infrange(): - n = 0 - while True: - yield n - n += 1