Mercurial > skaapsteker
annotate skaapsteker/levelscene.py @ 493:cb2060f8316f
Tweak gamestate to fail earlier on unknown items.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 22:41:38 +0200 |
parents | 95527fd29872 |
children | a5a57abd5472 |
rev | line source |
---|---|
15 | 1 """Scene wrapping a level object.""" |
2 | |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
3 from pygame.locals import (KEYDOWN, KEYUP, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT, |
356 | 4 K_SEMICOLON, K_UP, K_c, K_j, K_p, K_q, K_x, K_z, |
408 | 5 K_v, K_k, K_RETURN, SRCALPHA) |
106 | 6 |
248 | 7 import pygame |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
8 import time |
248 | 9 |
106 | 10 from . import options |
248 | 11 from . import engine |
12 from . import level | |
13 from . import physics | |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
14 from . import constants |
318 | 15 from . import data |
248 | 16 from .sprites import player |
17 from .widgets.text import Text | |
383 | 18 from .widgets.bubble import DialogueWidget, NotificationWidget |
248 | 19 |
15 | 20 |
21 class LevelScene(engine.Scene): | |
22 | |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
23 def __init__(self, game_state, soundsystem, doorway_def=None): |
262 | 24 super(LevelScene, self).__init__(game_state, soundsystem) |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
183
diff
changeset
|
25 |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
26 if doorway_def is not None: |
288
ddcfc159dc2a
Combine 'fox' and 'player' sections in game.json.
Simon Cross <hodgestar@gmail.com>
parents:
273
diff
changeset
|
27 fox = self.game_state.world.fox |
ddcfc159dc2a
Combine 'fox' and 'player' sections in game.json.
Simon Cross <hodgestar@gmail.com>
parents:
273
diff
changeset
|
28 fox.level, fox.doorway = doorway_def.split('.') |
ddcfc159dc2a
Combine 'fox' and 'player' sections in game.json.
Simon Cross <hodgestar@gmail.com>
parents:
273
diff
changeset
|
29 self._level = level.Level(self.game_state.world.fox.level, soundsystem) |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
30 self._player_dead = False |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
31 self._dialogue = None |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
183
diff
changeset
|
32 |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
33 self.setup_player() |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
34 |
40
fa1bb94cfa76
Re-factor drawing to blit to a clip rect in the One True Level Surface before blitting that to the screen.
Simon Cross <hodgestar@gmail.com>
parents:
16
diff
changeset
|
35 self._level_surface = self._level.get_surface() |
111 | 36 self._clip_rect = None |
416
3db2fc263d11
Kill sprites that leave the level area.
Simon Cross <hodgestar@gmail.com>
parents:
411
diff
changeset
|
37 self._world = physics.World(self._level_surface.get_rect()) |
173 | 38 self._paused = False |
40
fa1bb94cfa76
Re-factor drawing to blit to a clip rect in the One True Level Surface before blitting that to the screen.
Simon Cross <hodgestar@gmail.com>
parents:
16
diff
changeset
|
39 |
446 | 40 # Prepare a Surface for displaying when Dead |
41 self._dead_overlay = pygame.Surface(constants.SCREEN, flags=SRCALPHA) | |
42 self._dead_overlay.fill((255, 255, 255, 128)) | |
43 death_text_pos = constants.SCREEN[0] / 2, constants.SCREEN[1] / 2 | |
44 death_text = Text("You've died.", death_text_pos, size=24) | |
45 death_text.rect.move_ip(-death_text.rect.width / 2, -death_text.rect.height) | |
46 death_text.draw(self._dead_overlay) | |
47 death_text = Text("Press Escape to exit or Return to restart the level.", death_text_pos) | |
48 death_text.rect.move_ip(-death_text.rect.width / 2, 0) | |
49 death_text.draw(self._dead_overlay) | |
50 | |
318 | 51 # Helper images for hud |
52 self._tofu = data.load_image('icons/tofu.png') | |
53 self._scroll = data.load_image('icons/haiku-scroll.png') | |
405 | 54 self._tails = {} |
55 for tail in constants.FoxHud.TAIL_POSITIONS.iterkeys(): | |
56 image = data.load_image('icons/tails/%s.png' % tail) | |
407
d97840ee6759
graphicsmagicked grayscale tails
Stefano Rivera <stefano@rivera.za.net>
parents:
405
diff
changeset
|
57 grey_image = data.load_image('icons/tails/g_%s.png' % tail) |
405 | 58 self._tails[tail] = (grey_image, image) |
318 | 59 |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
183
diff
changeset
|
60 for sprite in self._level.sprites: |
50
7d411ed02eac
Initial stab at detecting collisions.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
61 self._world.add(sprite) |
302
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
62 npcs_and_items = game_state.create_sprites(self._level.name) |
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
63 self._npcs = dict((s.name, s) for s in npcs_and_items if hasattr(s, 'dsm')) |
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
64 for sprite in npcs_and_items: |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
124
diff
changeset
|
65 self._world.add(sprite) |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
183
diff
changeset
|
66 self._world.add(self._player) |
43 | 67 |
102
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
68 self._build_action_map() |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
270
diff
changeset
|
69 self._key_sequence = [] |
102
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
70 |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
71 def setup_player(self): |
288
ddcfc159dc2a
Combine 'fox' and 'player' sections in game.json.
Simon Cross <hodgestar@gmail.com>
parents:
273
diff
changeset
|
72 doorway = self._level.doorways[self.game_state.world.fox.doorway] |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
73 self._player = player.Player(self.game_state.world, self._soundsystem) |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
74 self._player.set_facing(doorway.facing) |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
75 self._player.set_image() |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
76 self._player.set_pos(doorway._starting_tile_pos) |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
77 |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
78 # Double tap stuff |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
79 self._last_keydown_time = None |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
80 self._last_keyup_time = None |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
81 |
102
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
82 def _build_action_map(self): |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
83 action = lambda s: getattr(self._player, 'action_%s' % s) |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
84 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
85 self._quit_keys = set([K_q, K_ESCAPE]) |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
86 self._restart_keys = set([K_x, K_z, K_RETURN]) |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
87 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
88 self._fast_key_map = { |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
89 K_LEFT: action('left'), |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
90 K_RIGHT: action('right'), |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
91 K_UP: action('up'), |
106 | 92 } |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
93 self._fast_keys_down = set() |
106 | 94 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
95 self._slow_key_map = { |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
96 K_DOWN: action('down'), |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
97 K_ESCAPE: self._quit, |
173 | 98 K_p: self._toggle_pause, |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
99 } |
106 | 100 if options['dvorak']: |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
101 self._slow_key_map[K_SEMICOLON] = action('fire1') |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
102 self._slow_key_map[K_q] = action('fire2') |
348 | 103 self._slow_key_map[K_j] = action('transform') |
408 | 104 self._slow_key_map[K_k] = action('invisible') |
106 | 105 else: |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
106 self._slow_key_map[K_x] = action('fire1') |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
107 self._slow_key_map[K_z] = action('fire2') |
348 | 108 self._slow_key_map[K_c] = action('transform') |
408 | 109 self._slow_key_map[K_v] = action('invisible') |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
110 self._slow_key_map[K_q] = self._quit |
102
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
111 |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
112 self._key_tap_map = { |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
113 (K_LEFT, K_LEFT) : action('double_left'), |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
114 (K_RIGHT, K_RIGHT) : action('double_right'), |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
115 (K_UP, K_UP) : action('double_up'), |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
116 } |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
117 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
118 def _quit(self, pause=True): |
102
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
119 import menuscene # avoid circular import |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
120 if pause: |
454
95527fd29872
More complete game load/save/restart.
Jeremy Thurgood <firxen@gmail.com>
parents:
446
diff
changeset
|
121 engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self._soundsystem)) |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
122 else: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
123 # FIXME: When starting the game, we shoudl ensure we have sane |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
124 # states |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
125 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
126 self._player.restore() |
454
95527fd29872
More complete game load/save/restart.
Jeremy Thurgood <firxen@gmail.com>
parents:
446
diff
changeset
|
127 engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self._soundsystem)) |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
128 |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
129 def _restart(self): |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
130 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
131 self._player.restore() |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
132 engine.ChangeScene.post(LevelScene(self.game_state, self._soundsystem)) |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
133 |
173 | 134 def _toggle_pause(self): |
135 if self._paused: | |
136 self._world.thaw() | |
137 self._paused = False | |
138 else: | |
139 self._world.freeze() | |
140 self._paused = True | |
141 | |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
142 def _open_dialogue(self, npc): |
302
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
143 if isinstance(npc, basestring): |
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
144 npc = self._npcs[npc] |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
145 if npc.dsm.has_text(): |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
146 if self._dialogue is not None: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
147 self._dialogue.close() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
148 self._world.freeze() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
149 self._dialogue = DialogueWidget(npc) |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
150 else: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
151 self._close_dialogue() |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
152 |
383 | 153 def _open_notification(self, text): |
154 if self._dialogue is not None: | |
155 self._dialogue.close() | |
156 self._world.freeze() | |
157 self._dialogue = NotificationWidget(text) | |
158 | |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
159 def _close_dialogue(self): |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
160 if self._dialogue is not None: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
161 self._world.thaw() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
162 self._dialogue.close() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
163 self._dialogue = None |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
164 |
170
aa154c4086cb
Replace scene .freeze and .thaw methods with .enter and .leave.
Simon Cross <hodgestar@gmail.com>
parents:
169
diff
changeset
|
165 def leave(self): |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
166 """Freeze the scene, for serialization""" |
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
167 self._world.freeze() |
243
4050e77dade6
Add support for background music tracks
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
168 self._level.leave() |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
169 |
170
aa154c4086cb
Replace scene .freeze and .thaw methods with .enter and .leave.
Simon Cross <hodgestar@gmail.com>
parents:
169
diff
changeset
|
170 def enter(self): |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
171 """Unfreeze""" |
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
172 self._world.thaw() |
243
4050e77dade6
Add support for background music tracks
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
173 self._level.enter() |
88
bf4adb40ca3c
Rough outline of a player object, completely with statuesque flying fox
Neil Muller <drnlmuller@gmail.com>
parents:
50
diff
changeset
|
174 |
123 | 175 def draw(self, screen_surface, engine): |
111 | 176 if self._clip_rect is None: |
177 self._clip_rect = pygame.Rect((0, 0), screen_surface.get_size()) | |
15 | 178 |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
179 if not self._paused and not self._dialogue: |
173 | 180 for key in self._fast_keys_down: |
181 self._fast_key_map[key]() | |
182 self._world.update() | |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
183 |
111 | 184 self._update_clip_rect() |
40
fa1bb94cfa76
Re-factor drawing to blit to a clip rect in the One True Level Surface before blitting that to the screen.
Simon Cross <hodgestar@gmail.com>
parents:
16
diff
changeset
|
185 |
111 | 186 self._level_surface.set_clip(self._clip_rect) |
40
fa1bb94cfa76
Re-factor drawing to blit to a clip rect in the One True Level Surface before blitting that to the screen.
Simon Cross <hodgestar@gmail.com>
parents:
16
diff
changeset
|
187 self._level.draw(self._level_surface) |
fa1bb94cfa76
Re-factor drawing to blit to a clip rect in the One True Level Surface before blitting that to the screen.
Simon Cross <hodgestar@gmail.com>
parents:
16
diff
changeset
|
188 self._world.draw(self._level_surface) |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
189 if self._dialogue: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
190 self._dialogue.draw(self._level_surface) |
40
fa1bb94cfa76
Re-factor drawing to blit to a clip rect in the One True Level Surface before blitting that to the screen.
Simon Cross <hodgestar@gmail.com>
parents:
16
diff
changeset
|
191 |
313 | 192 self._draw_fox_status() |
193 | |
123 | 194 fps_text_pos = self._clip_rect.left + 10, self._clip_rect.top + 10 |
183 | 195 fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos, shadow='white') |
123 | 196 fps_text.draw(self._level_surface) |
197 | |
173 | 198 if self._paused: |
199 paused_text_pos = self._clip_rect.centerx - 10, self._clip_rect.centery - 10 | |
200 paused_text = Text('Paused', paused_text_pos) | |
201 paused_text.draw(self._level_surface) | |
202 | |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
203 if self._player_dead: |
446 | 204 self._level_surface.blit(self._dead_overlay, self._clip_rect) |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
205 |
111 | 206 screen_surface.blit(self._level_surface, (0, 0), self._clip_rect) |
207 | |
313 | 208 def _draw_fox_status(self): |
209 """Draw the fox inventory. The tails and the item are drawn on the | |
210 left side of the screen, a health bar and collected tofu and | |
211 scroll counts are shown on the right""" | |
356 | 212 # Convenience shortcuts |
213 fox = self.game_state.world.fox | |
214 fox_hud = constants.FoxHud | |
215 | |
216 # Inventory bg | |
217 bgsurf = pygame.Surface((fox_hud.INVENTORY_SIZE + 2 * 8, | |
218 fox_hud.INVENTORY_SIZE + 2 * 8), | |
219 flags=SRCALPHA) | |
220 bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) | |
221 self._level_surface.blit(bgsurf, (self._clip_rect.left, | |
222 self._clip_rect.top + fox_hud.INVENTORY_START - 8)) | |
313 | 223 |
314 | 224 # Draw inventory |
225 my_item = fox.item | |
226 if my_item: | |
227 # Get image and resize it | |
315
0fc2b9d1a9cb
Recreate inventory image on scene changes
Neil Muller <drnlmuller@gmail.com>
parents:
314
diff
changeset
|
228 if self._player.inventory_image is None: |
0fc2b9d1a9cb
Recreate inventory image on scene changes
Neil Muller <drnlmuller@gmail.com>
parents:
314
diff
changeset
|
229 self._player.make_inventory_image() |
357
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
230 inv_pos = self._player.inventory_image.get_rect() |
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
231 inv_pos.move_ip(self._clip_rect.left + 8, |
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
232 self._clip_rect.top + fox_hud.INVENTORY_START) |
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
233 if inv_pos.width < fox_hud.INVENTORY_SIZE: |
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
234 inv_pos.left += (fox_hud.INVENTORY_SIZE - inv_pos.width) / 2 |
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
235 if inv_pos.height < fox_hud.INVENTORY_SIZE: |
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
236 inv_pos.top += (fox_hud.INVENTORY_SIZE - inv_pos.height) / 2 |
314 | 237 self._level_surface.blit(self._player.inventory_image, inv_pos) |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
238 |
356 | 239 # Tail bg |
405 | 240 bgsurf = pygame.Surface((fox_hud.TAILS_WIDTH + 2 * fox_hud.TAILS_BG_MARGIN, |
241 fox_hud.TAILS_HEIGHT + 2 * fox_hud.TAILS_BG_MARGIN), | |
356 | 242 flags=SRCALPHA) |
243 bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) | |
244 self._level_surface.blit(bgsurf, | |
245 (self._clip_rect.left, | |
246 self._clip_rect.top | |
247 + fox_hud.TAIL_START | |
405 | 248 - fox_hud.TAILS_BG_MARGIN)) |
314 | 249 |
318 | 250 # Draw tails |
405 | 251 for tail, position in constants.FoxHud.TAIL_POSITIONS.iteritems(): |
252 has_tail = tail in fox.tails | |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
253 tail_pos = pygame.Rect(self._clip_rect.left + fox_hud.TAILS_BG_MARGIN, |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
254 self._clip_rect.top + fox_hud.TAIL_POSITIONS[tail], |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
255 0, 0) |
419
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
256 |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
257 imgs = self._tails[tail] |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
258 size = imgs[0].get_size() |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
259 if has_tail and tail in ('flight', 'invisibility'): |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
260 area = pygame.Rect(self._player.discharge_level(tail) * size[0], 0, size[0], size[1]) |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
261 self._level_surface.blit(imgs[0], tail_pos) |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
262 self._level_surface.blit(imgs[1], tail_pos.move(area.left, 0), area) |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
263 elif has_tail and tail in ('fireball', 'lightning', 'shield'): |
419
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
264 area = pygame.Rect(0, 0, self._player.recharge_level(tail) * size[0], size[1]) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
265 self._level_surface.blit(imgs[0], tail_pos) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
266 self._level_surface.blit(imgs[1], tail_pos, area) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
267 else: |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
268 self._level_surface.blit(imgs[int(has_tail)], tail_pos) |
313 | 269 |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
270 # Draw the health bar |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
271 health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200 |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
272 bar = pygame.Rect(0, 0, fox_hud.HEALTH_WIDTH, fox_hud.HEALTH_HEIGHT) |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
273 bar.bottomleft = health_bottom |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
274 pygame.draw.rect(self._level_surface, fox_hud.HEALTH_BACKGROUND, bar) |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
275 bar.height = int(fox_hud.HEALTH_HEIGHT * float(max(0, fox.cur_health))/fox.max_health) |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
276 bar.bottomleft = health_bottom |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
277 pygame.draw.rect(self._level_surface, fox_hud.HEALTH_FOREGROUND, bar) |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
278 |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
279 # Draw scroll count |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
280 pos = self._clip_rect.right - 20, self._clip_rect.top + fox_hud.SCROLL_TOP + 5 |
340 | 281 count = Text("%s" % len(fox.scrolls), pos) |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
282 count.draw(self._level_surface) |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
283 pos = self._clip_rect.right - 55, self._clip_rect.top + fox_hud.SCROLL_TOP |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
284 self._level_surface.blit(self._scroll, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
285 |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
286 # Draw tofu count |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
287 pos = self._clip_rect.right - 20, self._clip_rect.top + fox_hud.TOFU_TOP + 5 |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
288 count = Text("%s" % fox.tofu, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
289 count.draw(self._level_surface) |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
290 pos = self._clip_rect.right - 55, self._clip_rect.top + fox_hud.TOFU_TOP |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
291 self._level_surface.blit(self._tofu, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
292 |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
293 |
111 | 294 def _update_clip_rect(self): |
295 cr = self._clip_rect | |
296 lr = self._level_surface.get_rect() | |
150
a5ca417ee39a
Centre camera one tile higher then the midbottom of the player, to avoid bouncing around due to animation size mismatches.
Jeremy Thurgood <firxen@gmail.com>
parents:
145
diff
changeset
|
297 cr.center = self._player.collide_rect.move(0, -level.TILE_SIZE[0]).midbottom |
124
fde3d25cb4b9
Replace custom clamping code with a call to .clamp_ip.
Simon Cross <hodgestar@gmail.com>
parents:
123
diff
changeset
|
298 cr.clamp_ip(lr) |
15 | 299 |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
300 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
301 def _detect_key_sequence(self, ev): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
302 if ev.key not in self._fast_key_map: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
303 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
304 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
305 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
306 if ev.type is KEYUP: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
307 if (not self._key_sequence |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
308 or ev.key != self._key_sequence[-1] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
309 or (time.time() - self._last_keydown_time) > constants.DOUBLE_TAP_TIME): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
310 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
311 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
312 self._last_keyup_time = time.time() |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
313 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
314 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
315 if ev.type is KEYDOWN: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
316 if self._last_keyup_time is None or (time.time() - self._last_keyup_time) > constants.DOUBLE_TAP_TIME: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
317 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
318 self._key_sequence.append(ev.key) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
319 self._last_keydown_time = time.time() |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
320 for seq in self._key_tap_map: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
321 if seq == tuple(self._key_sequence[-len(seq):]): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
322 self._key_sequence = self._key_sequence[-len(seq):] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
323 return True |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
324 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
325 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
326 |
16
e2837dd40607
Show how to use dispatch on levelscene.
Simon Cross <hodgestar@gmail.com>
parents:
15
diff
changeset
|
327 def dispatch(self, ev): |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
328 if ev.type is KEYDOWN: |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
329 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
330 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
331 if ev.key in self._restart_keys: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
332 self._restart() |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
333 elif ev.key in self._quit_keys: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
334 self._quit(False) |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
335 return |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
336 |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
337 if self._dialogue: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
338 self._dialogue.dispatch(ev) |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
339 return |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
340 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
341 if self._detect_key_sequence(ev): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
342 print "Detected double-tap:", self._key_sequence |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
343 action = self._key_tap_map.get(tuple(self._key_sequence)) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
344 if action is not None: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
345 action() |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
346 if ev.key in self._fast_key_map: |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
347 self._fast_keys_down.add(ev.key) |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
348 action = self._slow_key_map.get(ev.key) |
102
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
349 if action is not None: |
2e913a89e69d
Link up key presses to calls to action functions on player and to quitting level.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
350 action() |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
351 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
352 elif ev.type is KEYUP: |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
353 self._detect_key_sequence(ev) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
354 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
355 if ev.key in self._fast_key_map: |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
356 self._fast_keys_down.discard(ev.key) |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
357 |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
358 elif engine.PlayerDied.matches(ev): |
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
359 self._player_dead = True |
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
360 elif engine.OpenDialog.matches(ev): |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
361 self._open_dialogue(ev.npc) |
383 | 362 elif engine.OpenNotification.matches(ev): |
363 self._open_notification(ev.text) | |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
364 elif engine.CloseDialog.matches(ev): |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
365 self._close_dialogue() |
339
a9d760134706
Rename ItemRepopulationEvent to AddSprite before repurposing it for fireballs.
Simon Cross <hodgestar@gmail.com>
parents:
324
diff
changeset
|
366 elif engine.AddSpriteEvent.matches(ev): |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
367 self._world.add(ev.item) |