Mercurial > nagslang
annotate nagslang/events.py @ 398:e36e6101b766
Restarting the level restores health
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 07 Sep 2013 01:12:21 +0200 |
parents | 76f053cf2322 |
children | 7fcde01ea50e |
rev | line source |
---|---|
18 | 1 """Events to post.""" |
2 | |
20 | 3 import pygame |
186
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
180
diff
changeset
|
4 import pygame.locals |
18 | 5 |
6 | |
7 class Event(object): | |
8 TYPE = None | |
9 | |
10 @classmethod | |
11 def post(cls, **data): | |
20 | 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 | 18 |
19 | |
20 class QuitEvent(Event): | |
20 | 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 | |
180
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
39 def post(cls, new_screen, player=None): |
276
3153196517fc
Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents:
261
diff
changeset
|
40 super(ScreenChange, cls).post(screen=new_screen) |
180
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
41 |
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
42 |
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
43 class DoorEvent(UserEvent): |
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
44 @classmethod |
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
45 def post(cls, destination, dest_pos): |
026297a03963
Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door
Neil Muller <drnlmuller@gmail.com>
parents:
20
diff
changeset
|
46 super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos) |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
186
diff
changeset
|
47 |
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
186
diff
changeset
|
48 |
308
3dee86b6c216
Enemies leave corpses
Stefano Rivera <stefano@rivera.za.net>
parents:
305
diff
changeset
|
49 class EnemyDeathEvent(UserEvent): |
3dee86b6c216
Enemies leave corpses
Stefano Rivera <stefano@rivera.za.net>
parents:
305
diff
changeset
|
50 @classmethod |
391
866cdc74b26a
Use Result to handle enemy death (but keep the event for accounting purposes)
Stefano Rivera <stefano@rivera.za.net>
parents:
363
diff
changeset
|
51 def post(cls): |
866cdc74b26a
Use Result to handle enemy death (but keep the event for accounting purposes)
Stefano Rivera <stefano@rivera.za.net>
parents:
363
diff
changeset
|
52 super(EnemyDeathEvent, cls).post() |