Ignore:
Timestamp:
09/06/13 18:45:02 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Rebase:
66333461336336623964336638306331323338626330643037626137633537623838396534376235
Message:

Keycard doors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/mutators.py

    r56 r364  
    22
    33import pygame
    4 from pygame.transform import rotate, flip
     4from pygame.transform import rotate, flip, scale
    55
    66
     
    4040
    4141
     42class ImageOverlay(Mutator):
     43    '''Overlay another image onto an image'''
     44    def __init__(self, image, offset=(0, 0), halfsize=True, blend=0):
     45        super(ImageOverlay, self).__init__(
     46            ImageOverlay.overlay, image, offset, halfsize, blend)
     47
     48    @classmethod
     49    def overlay(self, image, overlay, offset, halfsize, blend):
     50        image = image.copy()
     51        if halfsize:
     52            new_size = (overlay.get_width() / 2, overlay.get_height() / 2)
     53            overlay = scale(overlay, new_size)
     54        offset_x = image.get_width() / 2 - overlay.get_width() / 2 + offset[0]
     55        offset_y = image.get_width() / 2 - overlay.get_width() / 2 + offset[1]
     56        image.blit(overlay, (offset_x, offset_y), None, blend)
     57        return image
     58
     59
    4260# Identity mutator
    4361NULL = Mutator(lambda x: x)
Note: See TracChangeset for help on using the changeset viewer.