Mercurial > nagslang
annotate nagslang/events.py @ 305:ce11e1cae0ed
Enemies now die
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Fri, 06 Sep 2013 00:17:22 +0200 |
parents | 47226c661ae2 |
children | 3dee86b6c216 |
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 |
305 | 51 def post(cls, source, impulse, damage, 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, |
305 | 53 damage=damage, |
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) |