Mercurial > skaapsteker
annotate skaapsteker/levelscene.py @ 553:62569f486ede
Debug print cleanup.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 10 Apr 2011 01:46:10 +0200 |
parents | b7f912705adb |
children | b83ca72063ea |
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, |
495
a5a57abd5472
Allow K_SPACE wherever we allow K_RETURN.
Jeremy Thurgood <firxen@gmail.com>
parents:
454
diff
changeset
|
5 K_v, K_k, K_RETURN, K_SPACE, 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 |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
523
diff
changeset
|
16 from .sprites import player, base |
248 | 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: |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
523
diff
changeset
|
61 # XXX: NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO! |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
523
diff
changeset
|
62 if isinstance(sprite, base.Monster): |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
523
diff
changeset
|
63 sprite.world = game_state.world |
50
7d411ed02eac
Initial stab at detecting collisions.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
64 self._world.add(sprite) |
302
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
65 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
|
66 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
|
67 for sprite in npcs_and_items: |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
124
diff
changeset
|
68 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
|
69 self._world.add(self._player) |
43 | 70 |
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
|
71 self._build_action_map() |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
270
diff
changeset
|
72 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
|
73 |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
74 def setup_player(self): |
288
ddcfc159dc2a
Combine 'fox' and 'player' sections in game.json.
Simon Cross <hodgestar@gmail.com>
parents:
273
diff
changeset
|
75 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
|
76 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
|
77 self._player.set_facing(doorway.facing) |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
78 self._player.set_image() |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
79 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
|
80 |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
81 # Double tap stuff |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
82 self._last_keydown_time = None |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
83 self._last_keyup_time = None |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
84 |
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
|
85 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
|
86 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
|
87 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
88 self._quit_keys = set([K_q, K_ESCAPE]) |
495
a5a57abd5472
Allow K_SPACE wherever we allow K_RETURN.
Jeremy Thurgood <firxen@gmail.com>
parents:
454
diff
changeset
|
89 self._restart_keys = set([K_x, K_z, K_RETURN, K_SPACE]) |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
90 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
91 self._fast_key_map = { |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
92 K_LEFT: action('left'), |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
93 K_RIGHT: action('right'), |
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
94 K_UP: action('up'), |
106 | 95 } |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
96 self._fast_keys_down = set() |
106 | 97 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
98 self._slow_key_map = { |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
99 K_DOWN: action('down'), |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
100 K_ESCAPE: self._quit, |
173 | 101 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
|
102 } |
106 | 103 if options['dvorak']: |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
104 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
|
105 self._slow_key_map[K_q] = action('fire2') |
348 | 106 self._slow_key_map[K_j] = action('transform') |
408 | 107 self._slow_key_map[K_k] = action('invisible') |
106 | 108 else: |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
109 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
|
110 self._slow_key_map[K_z] = action('fire2') |
348 | 111 self._slow_key_map[K_c] = action('transform') |
408 | 112 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
|
113 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
|
114 |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
115 self._key_tap_map = { |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
116 (K_LEFT, K_LEFT) : action('double_left'), |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
117 (K_RIGHT, K_RIGHT) : action('double_right'), |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
118 (K_UP, K_UP) : action('double_up'), |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
119 } |
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
120 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
121 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
|
122 import menuscene # avoid circular import |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
123 if pause: |
454
95527fd29872
More complete game load/save/restart.
Jeremy Thurgood <firxen@gmail.com>
parents:
446
diff
changeset
|
124 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
|
125 else: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
126 # 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
|
127 # states |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
128 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
129 self._player.restore() |
454
95527fd29872
More complete game load/save/restart.
Jeremy Thurgood <firxen@gmail.com>
parents:
446
diff
changeset
|
130 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
|
131 |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
132 def _restart(self): |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
133 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
134 self._player.restore() |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
135 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
|
136 |
173 | 137 def _toggle_pause(self): |
138 if self._paused: | |
139 self._world.thaw() | |
505
a89ab402b569
Pause music when pressing pause in level.
Simon Cross <hodgestar@gmail.com>
parents:
495
diff
changeset
|
140 self._soundsystem.unpause() |
173 | 141 self._paused = False |
142 else: | |
143 self._world.freeze() | |
505
a89ab402b569
Pause music when pressing pause in level.
Simon Cross <hodgestar@gmail.com>
parents:
495
diff
changeset
|
144 self._soundsystem.pause() |
173 | 145 self._paused = True |
146 | |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
147 def _open_dialogue(self, npc): |
302
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
148 if isinstance(npc, basestring): |
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
290
diff
changeset
|
149 npc = self._npcs[npc] |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
150 if npc.dsm.has_text(): |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
151 if self._dialogue is not None: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
152 self._dialogue.close() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
153 self._world.freeze() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
154 self._dialogue = DialogueWidget(npc) |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
155 else: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
156 self._close_dialogue() |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
157 |
383 | 158 def _open_notification(self, text): |
159 if self._dialogue is not None: | |
160 self._dialogue.close() | |
161 self._world.freeze() | |
162 self._dialogue = NotificationWidget(text) | |
163 | |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
164 def _close_dialogue(self): |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
165 if self._dialogue is not None: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
166 self._world.thaw() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
167 self._dialogue.close() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
168 self._dialogue = None |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
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 leave(self): |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
171 """Freeze the scene, for serialization""" |
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
172 self._world.freeze() |
243
4050e77dade6
Add support for background music tracks
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
173 self._level.leave() |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
174 |
170
aa154c4086cb
Replace scene .freeze and .thaw methods with .enter and .leave.
Simon Cross <hodgestar@gmail.com>
parents:
169
diff
changeset
|
175 def enter(self): |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
176 """Unfreeze""" |
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
177 self._world.thaw() |
243
4050e77dade6
Add support for background music tracks
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
178 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
|
179 |
123 | 180 def draw(self, screen_surface, engine): |
111 | 181 if self._clip_rect is None: |
182 self._clip_rect = pygame.Rect((0, 0), screen_surface.get_size()) | |
15 | 183 |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
184 if not self._paused and not self._dialogue: |
173 | 185 for key in self._fast_keys_down: |
186 self._fast_key_map[key]() | |
187 self._world.update() | |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
188 |
111 | 189 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
|
190 |
111 | 191 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
|
192 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
|
193 self._world.draw(self._level_surface) |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
194 if self._dialogue: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
195 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
|
196 |
313 | 197 self._draw_fox_status() |
198 | |
123 | 199 fps_text_pos = self._clip_rect.left + 10, self._clip_rect.top + 10 |
183 | 200 fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos, shadow='white') |
123 | 201 fps_text.draw(self._level_surface) |
202 | |
173 | 203 if self._paused: |
204 paused_text_pos = self._clip_rect.centerx - 10, self._clip_rect.centery - 10 | |
205 paused_text = Text('Paused', paused_text_pos) | |
206 paused_text.draw(self._level_surface) | |
207 | |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
208 if self._player_dead: |
446 | 209 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
|
210 |
111 | 211 screen_surface.blit(self._level_surface, (0, 0), self._clip_rect) |
212 | |
313 | 213 def _draw_fox_status(self): |
214 """Draw the fox inventory. The tails and the item are drawn on the | |
215 left side of the screen, a health bar and collected tofu and | |
216 scroll counts are shown on the right""" | |
356 | 217 # Convenience shortcuts |
218 fox = self.game_state.world.fox | |
219 fox_hud = constants.FoxHud | |
220 | |
221 # Inventory bg | |
222 bgsurf = pygame.Surface((fox_hud.INVENTORY_SIZE + 2 * 8, | |
223 fox_hud.INVENTORY_SIZE + 2 * 8), | |
224 flags=SRCALPHA) | |
225 bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) | |
226 self._level_surface.blit(bgsurf, (self._clip_rect.left, | |
227 self._clip_rect.top + fox_hud.INVENTORY_START - 8)) | |
313 | 228 |
314 | 229 # Draw inventory |
230 my_item = fox.item | |
231 if my_item: | |
232 # Get image and resize it | |
315
0fc2b9d1a9cb
Recreate inventory image on scene changes
Neil Muller <drnlmuller@gmail.com>
parents:
314
diff
changeset
|
233 if self._player.inventory_image is None: |
0fc2b9d1a9cb
Recreate inventory image on scene changes
Neil Muller <drnlmuller@gmail.com>
parents:
314
diff
changeset
|
234 self._player.make_inventory_image() |
357
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 inv_pos.top += (fox_hud.INVENTORY_SIZE - inv_pos.height) / 2 |
314 | 242 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
|
243 |
356 | 244 # Tail bg |
405 | 245 bgsurf = pygame.Surface((fox_hud.TAILS_WIDTH + 2 * fox_hud.TAILS_BG_MARGIN, |
246 fox_hud.TAILS_HEIGHT + 2 * fox_hud.TAILS_BG_MARGIN), | |
356 | 247 flags=SRCALPHA) |
248 bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) | |
249 self._level_surface.blit(bgsurf, | |
250 (self._clip_rect.left, | |
251 self._clip_rect.top | |
252 + fox_hud.TAIL_START | |
405 | 253 - fox_hud.TAILS_BG_MARGIN)) |
314 | 254 |
318 | 255 # Draw tails |
405 | 256 for tail, position in constants.FoxHud.TAIL_POSITIONS.iteritems(): |
257 has_tail = tail in fox.tails | |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
258 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
|
259 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
|
260 0, 0) |
419
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
261 |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
262 imgs = self._tails[tail] |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
263 size = imgs[0].get_size() |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 self._level_surface.blit(imgs[0], tail_pos) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
271 self._level_surface.blit(imgs[1], tail_pos, area) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
272 else: |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
273 self._level_surface.blit(imgs[int(has_tail)], tail_pos) |
313 | 274 |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
275 # Draw the health bar |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
276 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
|
277 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
|
278 bar.bottomleft = health_bottom |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
279 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
|
280 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
|
281 bar.bottomleft = health_bottom |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
282 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
|
283 |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
284 # Draw scroll count |
523
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
285 pos = self._clip_rect.right - 35, self._clip_rect.top + fox_hud.SCROLL_TOP + 30 |
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
286 count = Text("%s/5" % len(fox.scrolls), pos) |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
287 count.draw(self._level_surface) |
523
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
288 pos = self._clip_rect.right - 35, 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
|
289 self._level_surface.blit(self._scroll, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
290 |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
291 # Draw tofu count |
523
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
292 pos = self._clip_rect.right - 42, self._clip_rect.top + fox_hud.TOFU_TOP + 28 |
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
293 count = Text("% 3s%%" % fox.tofu, pos) |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
294 count.draw(self._level_surface) |
523
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
295 pos = self._clip_rect.right - 35, 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
|
296 self._level_surface.blit(self._tofu, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
297 |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
298 |
111 | 299 def _update_clip_rect(self): |
300 cr = self._clip_rect | |
301 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
|
302 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
|
303 cr.clamp_ip(lr) |
15 | 304 |
270
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 def _detect_key_sequence(self, ev): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
307 if ev.key not in self._fast_key_map: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
308 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
309 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
310 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
311 if ev.type is KEYUP: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
312 if (not self._key_sequence |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
313 or ev.key != self._key_sequence[-1] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
314 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
|
315 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
316 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
317 self._last_keyup_time = time.time() |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
318 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
319 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
320 if ev.type is KEYDOWN: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
321 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
|
322 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
323 self._key_sequence.append(ev.key) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
324 self._last_keydown_time = time.time() |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
325 for seq in self._key_tap_map: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
326 if seq == tuple(self._key_sequence[-len(seq):]): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
327 self._key_sequence = self._key_sequence[-len(seq):] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
328 return True |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
329 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
330 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
331 |
16
e2837dd40607
Show how to use dispatch on levelscene.
Simon Cross <hodgestar@gmail.com>
parents:
15
diff
changeset
|
332 def dispatch(self, ev): |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
333 if ev.type is KEYDOWN: |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
334 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
335 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
336 if ev.key in self._restart_keys: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
337 self._restart() |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
338 elif ev.key in self._quit_keys: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
339 self._quit(False) |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
340 return |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
341 |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
342 if self._dialogue: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
343 self._dialogue.dispatch(ev) |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
344 return |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
345 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
346 if self._detect_key_sequence(ev): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
347 action = self._key_tap_map.get(tuple(self._key_sequence)) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
348 if action is not None: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
349 action() |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 action() |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
355 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
356 elif ev.type is KEYUP: |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
357 self._detect_key_sequence(ev) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
358 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
359 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
|
360 self._fast_keys_down.discard(ev.key) |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
361 |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
362 elif engine.PlayerDied.matches(ev): |
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
363 self._player_dead = True |
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
364 elif engine.OpenDialog.matches(ev): |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
365 self._open_dialogue(ev.npc) |
383 | 366 elif engine.OpenNotification.matches(ev): |
367 self._open_notification(ev.text) | |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
368 elif engine.CloseDialog.matches(ev): |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
369 self._close_dialogue() |
339
a9d760134706
Rename ItemRepopulationEvent to AddSprite before repurposing it for fireballs.
Simon Cross <hodgestar@gmail.com>
parents:
324
diff
changeset
|
370 elif engine.AddSpriteEvent.matches(ev): |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
371 self._world.add(ev.item) |