1 | """Events to post.""" |
---|
2 | |
---|
3 | import pygame |
---|
4 | import pygame.locals |
---|
5 | |
---|
6 | |
---|
7 | class Event(object): |
---|
8 | TYPE = None |
---|
9 | |
---|
10 | @classmethod |
---|
11 | def post(cls, **data): |
---|
12 | ev = pygame.event.Event(cls.TYPE, **data) |
---|
13 | pygame.event.post(ev) |
---|
14 | |
---|
15 | @classmethod |
---|
16 | def matches(cls, ev): |
---|
17 | return ev.type == cls.TYPE |
---|
18 | |
---|
19 | |
---|
20 | class QuitEvent(Event): |
---|
21 | TYPE = pygame.locals.QUIT |
---|
22 | |
---|
23 | |
---|
24 | class UserEvent(Event): |
---|
25 | TYPE = pygame.locals.USEREVENT |
---|
26 | |
---|
27 | @classmethod |
---|
28 | def post(cls, **data): |
---|
29 | super(UserEvent, cls).post(user_type=cls.__name__, **data) |
---|
30 | |
---|
31 | @classmethod |
---|
32 | def matches(cls, ev): |
---|
33 | return (super(UserEvent, cls).matches(ev) |
---|
34 | and ev.user_type == cls.__name__) |
---|
35 | |
---|
36 | |
---|
37 | class ScreenChange(UserEvent): |
---|
38 | @classmethod |
---|
39 | def post(cls, new_screen, player=None): |
---|
40 | super(ScreenChange, cls).post(screen=new_screen) |
---|
41 | |
---|
42 | |
---|
43 | class DoorEvent(UserEvent): |
---|
44 | @classmethod |
---|
45 | def post(cls, destination, dest_pos): |
---|
46 | super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos) |
---|
47 | |
---|
48 | |
---|
49 | class FireEvent(UserEvent): |
---|
50 | @classmethod |
---|
51 | def post(cls, source, impulse, damage, bullet_type, source_collision_type): |
---|
52 | super(FireEvent, cls).post(source=source, impulse=impulse, |
---|
53 | damage=damage, bullet_type=bullet_type, |
---|
54 | source_collision_type=source_collision_type) |
---|
55 | |
---|
56 | |
---|
57 | class EnemyDeathEvent(UserEvent): |
---|
58 | @classmethod |
---|
59 | def post(cls): |
---|
60 | super(EnemyDeathEvent, cls).post() |
---|
61 | |
---|
62 | |
---|
63 | class ClawEvent(UserEvent): |
---|
64 | @classmethod |
---|
65 | def post(cls, source, vector, damage): |
---|
66 | super(ClawEvent, cls).post(source=source, vector=vector, damage=damage) |
---|