source: nagslang/events.py@ 185:dfacd08b8566

Last change on this file since 185:dfacd08b8566 was 180:026297a03963, checked in by Neil Muller <drnlmuller@…>, 8 years ago

Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door

File size: 987 bytes
Line 
1"""Events to post."""
2
3import pygame
4
5
6class Event(object):
7 TYPE = None
8
9 @classmethod
10 def post(cls, **data):
11 ev = pygame.event.Event(cls.TYPE, **data)
12 pygame.event.post(ev)
13
14 @classmethod
15 def matches(cls, ev):
16 return ev.type == cls.TYPE
17
18
19class QuitEvent(Event):
20 TYPE = pygame.locals.QUIT
21
22
23class UserEvent(Event):
24 TYPE = pygame.locals.USEREVENT
25
26 @classmethod
27 def post(cls, **data):
28 super(UserEvent, cls).post(user_type=cls.__name__, **data)
29
30 @classmethod
31 def matches(cls, ev):
32 return (super(UserEvent, cls).matches(ev)
33 and ev.user_type == cls.__name__)
34
35
36class ScreenChange(UserEvent):
37 @classmethod
38 def post(cls, new_screen, player=None):
39 super(ScreenChange, cls).post(screen=new_screen, player=player)
40
41
42class DoorEvent(UserEvent):
43 @classmethod
44 def post(cls, destination, dest_pos):
45 super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos)
Note: See TracBrowser for help on using the repository browser.