From: Simon Cross Date: Sun, 11 May 2014 15:06:23 +0000 (+0200) Subject: Initial user events for Naja. X-Git-Tag: 0.1~427 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=1436eedb964abfa4d1c3b06813b832133812c7a5;p=naja.git Initial user events for Naja. --- diff --git a/naja/events.py b/naja/events.py new file mode 100644 index 0000000..b2cdee1 --- /dev/null +++ b/naja/events.py @@ -0,0 +1,28 @@ +""" +Custom Pygame events. +""" + +import pygame.event as pge + + +class NajaEvent(pge.Event): + + TYPE = "UNKNOWN" + + @classmethod + def post(cls, **attributes): + event = pge.Event(pge.USEREVENT, naja_event_type=cls.TYPE, + **attributes) + pge.post(event) + + @classmethod + def matches(cls, ev): + return ev.type == pge.USEREVENT and ev.naja_event_type == cls.TYPE + + +class SceneChangeEvent(NajaEvent): + TYPE = "SCENE_CHANGE" + + @classmethod + def post(cls, scene): + super(SceneChangeEvent, cls).post(scene=scene)