Mercurial > skaapsteker
annotate skaapsteker/levelscene.py @ 601:73bdeb3d3f7e pyweek12
Bump version to 0.2
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 10 Apr 2011 20:07:19 +0200 |
parents | 91ad18a5acf1 |
children | 851c8726696c |
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! |
562
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
561
diff
changeset
|
62 if isinstance(sprite, base.Monster) or isinstance(sprite, base.CelestialDoorway): |
549
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: |
561 | 156 self._close_dialogue(npc) |
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 | |
555
b83ca72063ea
Fix bug where one NPC's dialogue could close anothers.
Simon Cross <hodgestar@gmail.com>
parents:
553
diff
changeset
|
164 def _close_dialogue(self, npc): |
b83ca72063ea
Fix bug where one NPC's dialogue could close anothers.
Simon Cross <hodgestar@gmail.com>
parents:
553
diff
changeset
|
165 if isinstance(npc, basestring): |
b83ca72063ea
Fix bug where one NPC's dialogue could close anothers.
Simon Cross <hodgestar@gmail.com>
parents:
553
diff
changeset
|
166 npc = self._npcs[npc] |
b83ca72063ea
Fix bug where one NPC's dialogue could close anothers.
Simon Cross <hodgestar@gmail.com>
parents:
553
diff
changeset
|
167 # below works for notifications too since they don't have .npc and send None |
b83ca72063ea
Fix bug where one NPC's dialogue could close anothers.
Simon Cross <hodgestar@gmail.com>
parents:
553
diff
changeset
|
168 if self._dialogue is not None and getattr(self._dialogue, 'npc', None) is npc: |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
169 self._world.thaw() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
170 self._dialogue.close() |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
171 self._dialogue = None |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
172 |
170
aa154c4086cb
Replace scene .freeze and .thaw methods with .enter and .leave.
Simon Cross <hodgestar@gmail.com>
parents:
169
diff
changeset
|
173 def leave(self): |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
174 """Freeze the scene, for serialization""" |
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
175 self._world.freeze() |
243
4050e77dade6
Add support for background music tracks
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
176 self._level.leave() |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
177 |
170
aa154c4086cb
Replace scene .freeze and .thaw methods with .enter and .leave.
Simon Cross <hodgestar@gmail.com>
parents:
169
diff
changeset
|
178 def enter(self): |
104
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
179 """Unfreeze""" |
12ce1d131a72
Hack in resume game option
Neil Muller <drnlmuller@gmail.com>
parents:
102
diff
changeset
|
180 self._world.thaw() |
243
4050e77dade6
Add support for background music tracks
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
181 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
|
182 |
123 | 183 def draw(self, screen_surface, engine): |
111 | 184 if self._clip_rect is None: |
185 self._clip_rect = pygame.Rect((0, 0), screen_surface.get_size()) | |
15 | 186 |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
187 if not self._paused and not self._dialogue: |
173 | 188 for key in self._fast_keys_down: |
189 self._fast_key_map[key]() | |
190 self._world.update() | |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
191 |
111 | 192 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
|
193 |
111 | 194 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
|
195 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
|
196 self._world.draw(self._level_surface) |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
197 if self._dialogue: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
198 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
|
199 |
313 | 200 self._draw_fox_status() |
201 | |
123 | 202 fps_text_pos = self._clip_rect.left + 10, self._clip_rect.top + 10 |
183 | 203 fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos, shadow='white') |
123 | 204 fps_text.draw(self._level_surface) |
205 | |
173 | 206 if self._paused: |
207 paused_text_pos = self._clip_rect.centerx - 10, self._clip_rect.centery - 10 | |
208 paused_text = Text('Paused', paused_text_pos) | |
209 paused_text.draw(self._level_surface) | |
210 | |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
211 if self._player_dead: |
446 | 212 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
|
213 |
111 | 214 screen_surface.blit(self._level_surface, (0, 0), self._clip_rect) |
215 | |
313 | 216 def _draw_fox_status(self): |
217 """Draw the fox inventory. The tails and the item are drawn on the | |
218 left side of the screen, a health bar and collected tofu and | |
219 scroll counts are shown on the right""" | |
356 | 220 # Convenience shortcuts |
221 fox = self.game_state.world.fox | |
222 fox_hud = constants.FoxHud | |
223 | |
224 # Inventory bg | |
225 bgsurf = pygame.Surface((fox_hud.INVENTORY_SIZE + 2 * 8, | |
226 fox_hud.INVENTORY_SIZE + 2 * 8), | |
227 flags=SRCALPHA) | |
228 bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) | |
229 self._level_surface.blit(bgsurf, (self._clip_rect.left, | |
230 self._clip_rect.top + fox_hud.INVENTORY_START - 8)) | |
313 | 231 |
314 | 232 # Draw inventory |
233 my_item = fox.item | |
234 if my_item: | |
235 # Get image and resize it | |
315
0fc2b9d1a9cb
Recreate inventory image on scene changes
Neil Muller <drnlmuller@gmail.com>
parents:
314
diff
changeset
|
236 if self._player.inventory_image is None: |
0fc2b9d1a9cb
Recreate inventory image on scene changes
Neil Muller <drnlmuller@gmail.com>
parents:
314
diff
changeset
|
237 self._player.make_inventory_image() |
357
742731e6e6fd
Centre small inventory items rather than resizing
Stefano Rivera <stefano@rivera.za.net>
parents:
356
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 inv_pos.top += (fox_hud.INVENTORY_SIZE - inv_pos.height) / 2 |
314 | 245 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
|
246 |
356 | 247 # Tail bg |
405 | 248 bgsurf = pygame.Surface((fox_hud.TAILS_WIDTH + 2 * fox_hud.TAILS_BG_MARGIN, |
249 fox_hud.TAILS_HEIGHT + 2 * fox_hud.TAILS_BG_MARGIN), | |
356 | 250 flags=SRCALPHA) |
251 bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) | |
252 self._level_surface.blit(bgsurf, | |
253 (self._clip_rect.left, | |
254 self._clip_rect.top | |
255 + fox_hud.TAIL_START | |
405 | 256 - fox_hud.TAILS_BG_MARGIN)) |
314 | 257 |
318 | 258 # Draw tails |
405 | 259 for tail, position in constants.FoxHud.TAIL_POSITIONS.iteritems(): |
260 has_tail = tail in fox.tails | |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
261 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
|
262 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
|
263 0, 0) |
419
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
264 |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
265 imgs = self._tails[tail] |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
266 size = imgs[0].get_size() |
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 self._level_surface.blit(imgs[0], tail_pos) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
274 self._level_surface.blit(imgs[1], tail_pos, area) |
845e8e94219f
Show recharge in tails
Stefano Rivera <stefano@rivera.za.net>
parents:
416
diff
changeset
|
275 else: |
430
25efc74ac19c
Hook up flight and invisibility discharge
Stefano Rivera <stefano@rivera.za.net>
parents:
419
diff
changeset
|
276 self._level_surface.blit(imgs[int(has_tail)], tail_pos) |
313 | 277 |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
278 # Draw the health bar |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
279 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
|
280 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
|
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_BACKGROUND, bar) |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
283 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
|
284 bar.bottomleft = health_bottom |
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
285 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
|
286 |
390
93f13f7d97f2
Initial fire rate-limiting
Stefano Rivera <stefano@rivera.za.net>
parents:
383
diff
changeset
|
287 # Draw scroll count |
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 + 30 |
c7c3f55554d4
add tofu and scroll totals to the hud
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
505
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 self._level_surface.blit(self._scroll, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
293 |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
294 # Draw tofu count |
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 - 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
|
296 count = Text("% 3s%%" % fox.tofu, pos) |
324
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
297 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
|
298 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
|
299 self._level_surface.blit(self._tofu, pos) |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
300 |
ca428c1451a2
Hook up drawing tofu and scroll counts
Neil Muller <drnlmuller@gmail.com>
parents:
318
diff
changeset
|
301 |
111 | 302 def _update_clip_rect(self): |
303 cr = self._clip_rect | |
304 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
|
305 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
|
306 cr.clamp_ip(lr) |
15 | 307 |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
308 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
309 def _detect_key_sequence(self, ev): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
310 if ev.key not in self._fast_key_map: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
311 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
312 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
313 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
314 if ev.type is KEYUP: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
315 if (not self._key_sequence |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
316 or ev.key != self._key_sequence[-1] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
317 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
|
318 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
319 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
320 self._last_keyup_time = time.time() |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
321 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
322 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
323 if ev.type is KEYDOWN: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
324 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
|
325 self._key_sequence = [] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
326 self._key_sequence.append(ev.key) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
327 self._last_keydown_time = time.time() |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
328 for seq in self._key_tap_map: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
329 if seq == tuple(self._key_sequence[-len(seq):]): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
330 self._key_sequence = self._key_sequence[-len(seq):] |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
331 return True |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
332 return False |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
333 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
334 |
16
e2837dd40607
Show how to use dispatch on levelscene.
Simon Cross <hodgestar@gmail.com>
parents:
15
diff
changeset
|
335 def dispatch(self, ev): |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
336 if ev.type is KEYDOWN: |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
337 |
244
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
338 if self._player_dead: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
339 if ev.key in self._restart_keys: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
340 self._restart() |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
341 elif ev.key in self._quit_keys: |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
342 self._quit(False) |
5bbf90e6a94b
Add minimal support for player death
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
343 return |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
344 |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
345 if self._dialogue: |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
346 self._dialogue.dispatch(ev) |
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
347 return |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
348 |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
349 if self._detect_key_sequence(ev): |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
350 action = self._key_tap_map.get(tuple(self._key_sequence)) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
351 if action is not None: |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
352 action() |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 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
|
357 action() |
270
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 elif ev.type is KEYUP: |
270
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
360 self._detect_key_sequence(ev) |
e47efa33903b
Fixed key sequence handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
361 |
169
b7a8f4a677e1
Replace key repeating with custom tracking of fast keys.
Simon Cross <hodgestar@gmail.com>
parents:
165
diff
changeset
|
362 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
|
363 self._fast_keys_down.discard(ev.key) |
265
7628467eecd9
Add double-key tap support
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
364 |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
365 elif engine.PlayerDied.matches(ev): |
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
366 self._player_dead = True |
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
367 elif engine.OpenDialog.matches(ev): |
251
432f6997d306
More hooking up of interacting with NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
250
diff
changeset
|
368 self._open_dialogue(ev.npc) |
383 | 369 elif engine.OpenNotification.matches(ev): |
370 self._open_notification(ev.text) | |
250
8d7edd77bfbf
Start hooking up NPC interactions.
Simon Cross <hodgestar@gmail.com>
parents:
248
diff
changeset
|
371 elif engine.CloseDialog.matches(ev): |
555
b83ca72063ea
Fix bug where one NPC's dialogue could close anothers.
Simon Cross <hodgestar@gmail.com>
parents:
553
diff
changeset
|
372 self._close_dialogue(ev.npc) |
339
a9d760134706
Rename ItemRepopulationEvent to AddSprite before repurposing it for fireballs.
Simon Cross <hodgestar@gmail.com>
parents:
324
diff
changeset
|
373 elif engine.AddSpriteEvent.matches(ev): |
290
c68f2f3efc7f
Item dropping and swapping.
Jeremy Thurgood <firxen@gmail.com>
parents:
288
diff
changeset
|
374 self._world.add(ev.item) |