Changeset 364:72a91d64c088 for nagslang


Ignore:
Timestamp:
Sep 6, 2013, 6:45:02 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
rebase_source:
f34a3c6b9d3f80c1238bc0d07ba7c57b889e47b5
Message:

Keycard doors.

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r363 r364  
    77from nagslang import puzzle
    88from nagslang import render
    9 from nagslang.mutators import FLIP_H
     9from nagslang.mutators import FLIP_H, ImageOverlay
    1010from nagslang.constants import (
    1111    COLLISION_TYPE_DOOR, COLLISION_TYPE_FURNITURE, COLLISION_TYPE_PROJECTILE,
     
    349349                 key_item=None):
    350350        self._key_item = key_item
     351        overlay = ImageOverlay(
     352            resources.get_image('objects', '%s.png' % (key_item,)))
    351353        super(KeyedDoor, self).__init__(
    352354            space, position, destination, dest_pos, angle,
    353             render.ImageRenderer(resources.get_image('objects', 'door.png')),
     355            render.ImageRenderer(resources.get_image(
     356                'objects', 'door.png', transforms=(overlay,))),
    354357            environment.ItemRequiredCondition(key_item),
    355358        )
     
    578581    def apply_effect(self, protagonist):
    579582        protagonist.force_wolf_form()
     583
     584
     585class KeyCard(CollectibleGameObject):
     586    def __init__(self, space, position, name):
     587        body = make_body(None, None, position)
     588        self.shape = pymunk.Circle(body, 20)
     589        super(KeyCard, self).__init__(
     590            space, name, self.shape,
     591            render.ImageRenderer(
     592                resources.get_image('objects', '%s.png' % (name,))),
     593        )
     594
     595    @classmethod
     596    def requires(cls):
     597        return [("name", "string"), ("position", "coordinates"),
     598                ("item_name", "string")]
  • 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.