Mercurial > nagslang
annotate nagslang/events.py @ 391:866cdc74b26a
Use Result to handle enemy death (but keep the event for accounting purposes)
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 07 Sep 2013 00:42:09 +0200 |
parents | 3dd08e18580f |
children | 8d961e05b7b6 |
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 |
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
186
diff
changeset
|
49 class FireEvent(UserEvent): |
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
186
diff
changeset
|
50 @classmethod |
363
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
333
diff
changeset
|
51 def post(cls, source, impulse, damage, bullet_type, source_collision_type): |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
276
diff
changeset
|
52 super(FireEvent, cls).post(source=source, impulse=impulse, |
363
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
333
diff
changeset
|
53 damage=damage, bullet_type=bullet_type, |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
276
diff
changeset
|
54 source_collision_type=source_collision_type) |
308
3dee86b6c216
Enemies leave corpses
Stefano Rivera <stefano@rivera.za.net>
parents:
305
diff
changeset
|
55 |
3dee86b6c216
Enemies leave corpses
Stefano Rivera <stefano@rivera.za.net>
parents:
305
diff
changeset
|
56 |
3dee86b6c216
Enemies leave corpses
Stefano Rivera <stefano@rivera.za.net>
parents:
305
diff
changeset
|
57 class EnemyDeathEvent(UserEvent): |
3dee86b6c216
Enemies leave corpses
Stefano Rivera <stefano@rivera.za.net>
parents:
305
diff
changeset
|
58 @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
|
59 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
|
60 super(EnemyDeathEvent, cls).post() |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
308
diff
changeset
|
61 |
313 | 62 |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
308
diff
changeset
|
63 class ClawEvent(UserEvent): |
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
308
diff
changeset
|
64 @classmethod |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
313
diff
changeset
|
65 def post(cls, source, vector, damage): |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
313
diff
changeset
|
66 super(ClawEvent, cls).post(source=source, vector=vector, damage=damage) |