Added translucency.
This commit is contained in:
@@ -24,6 +24,10 @@
|
||||
A generic world object.
|
||||
"""
|
||||
|
||||
import pygame
|
||||
import numpy
|
||||
import copy
|
||||
|
||||
class WorldObject(object):
|
||||
def __init__(self, level, x, y, z=0, direction=(1, 0), speed=5,
|
||||
tile_x=64, tile_y=48,
|
||||
@@ -36,6 +40,9 @@ class WorldObject(object):
|
||||
self.holding = None
|
||||
self.holder = None
|
||||
|
||||
if hasattr(self, 'img'):
|
||||
self.img = copy.copy(self.img)
|
||||
|
||||
def set_init_pos(self):
|
||||
self.init_x, self.init_y = self.x, self.y
|
||||
|
||||
@@ -69,6 +76,17 @@ class WorldObject(object):
|
||||
def use(self):
|
||||
pass
|
||||
|
||||
def set_alpha(self, value):
|
||||
"""
|
||||
Set the relative translucency of the per-pixel-alpha image.
|
||||
|
||||
Value between 0 - 1, where 0 is completely transparent and 1 is
|
||||
completely opaque.
|
||||
"""
|
||||
if hasattr(self, 'img') and hasattr(self, 'orig_alpha'):
|
||||
alpha = pygame.surfarray.pixels_alpha(self.img)
|
||||
alpha[:] = (self.orig_alpha * value).astype(numpy.uint8)
|
||||
|
||||
def update(self, e, t, dt):
|
||||
if self.x > self.move_x:
|
||||
self.x -= min(self.speed * dt * self.tile_x,
|
||||
|
||||
Reference in New Issue
Block a user