view nagslang/events.py @ 391:866cdc74b26a

Use Result to handle enemy death (but keep the event for accounting purposes)
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 07 Sep 2013 00:42:09 +0200
parents 3dd08e18580f
children 8d961e05b7b6
line wrap: on
line source

"""Events to post."""

import pygame
import pygame.locals


class Event(object):
    TYPE = None

    @classmethod
    def post(cls, **data):
        ev = pygame.event.Event(cls.TYPE, **data)
        pygame.event.post(ev)

    @classmethod
    def matches(cls, ev):
        return ev.type == cls.TYPE


class QuitEvent(Event):
    TYPE = pygame.locals.QUIT


class UserEvent(Event):
    TYPE = pygame.locals.USEREVENT

    @classmethod
    def post(cls, **data):
        super(UserEvent, cls).post(user_type=cls.__name__, **data)

    @classmethod
    def matches(cls, ev):
        return (super(UserEvent, cls).matches(ev)
                and ev.user_type == cls.__name__)


class ScreenChange(UserEvent):
    @classmethod
    def post(cls, new_screen, player=None):
        super(ScreenChange, cls).post(screen=new_screen)


class DoorEvent(UserEvent):
    @classmethod
    def post(cls, destination, dest_pos):
        super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos)


class FireEvent(UserEvent):
    @classmethod
    def post(cls, source, impulse, damage, bullet_type, source_collision_type):
        super(FireEvent, cls).post(source=source, impulse=impulse,
                                   damage=damage, bullet_type=bullet_type,
                                   source_collision_type=source_collision_type)


class EnemyDeathEvent(UserEvent):
    @classmethod
    def post(cls):
        super(EnemyDeathEvent, cls).post()


class ClawEvent(UserEvent):
    @classmethod
    def post(cls, source, vector, damage):
        super(ClawEvent, cls).post(source=source, vector=vector, damage=damage)