Mercurial > nagslang
view nagslang/events.py @ 186:d63c19003aec
Some refactoring and fixing, start of better collision handling.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Tue, 03 Sep 2013 20:06:12 +0200 |
parents | 026297a03963 |
children | db7c8e74efb4 |
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, player=player) class DoorEvent(UserEvent): @classmethod def post(cls, destination, dest_pos): super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos)