I feel nothing for you.
[naja.git] / naja / scenes / game.py
1 """
2 Gameboard scene.
3 """
4
5 import pygame.locals as pgl
6 import random
7
8 from naja.constants import KEYS, TUNES
9 from naja.events import SceneChangeEvent, finish_event
10 from naja.options import options
11 from naja.scenes.scene import Scene
12 from naja.sound import sound
13 from naja.widgets.board import BoardWidget
14 from naja.widgets.player_bits import PlayerBitsWidget
15 from naja.widgets.game_bits import GameBitsWidget
16 from naja.widgets.info_area import InfoAreaWidget
17 from naja.widgets.robot import RobotWidget
18
19
20 class GameScene(Scene):
21     """
22     Gameboard scene.
23     """
24
25     def __init__(self, state, play_sound=True):
26         super(GameScene, self).__init__(state)
27         self.add(PlayerBitsWidget((0, 0), state))
28         info = InfoAreaWidget((480, 0), state)
29         self.board_widget = BoardWidget((0, 60), state, info)
30         self.add(self.board_widget)
31         self.add(GameBitsWidget((0, 540), state))
32         self.add(info)
33         self.add(RobotWidget(state))
34         if play_sound:
35             sound.play_sound('startup.ogg')
36             background_track = random.choice(TUNES)
37             sound.play_music(background_track, 0.25)
38
39     def handle_scene_event(self, ev):
40         from naja.scenes.menu import MenuScene
41         if ev.type == pgl.KEYDOWN:
42             if ev.key in KEYS.QUIT:
43                 sound.stop()
44                 SceneChangeEvent.post(MenuScene)
45                 return
46             if options.cheat_enabled:
47                 if ev.key == pgl.K_0:
48                     self.state.player.bits.toggle_bit(0)
49                 elif ev.key == pgl.K_1:
50                     self.state.player.bits.toggle_bit(1)
51                 elif ev.key == pgl.K_2:
52                     self.state.player.bits.toggle_bit(2)
53                 elif ev.key == pgl.K_3:
54                     self.state.player.bits.toggle_bit(3)
55                 elif ev.key == pgl.K_4:
56                     self.state.player.bits.toggle_bit(4)
57                 elif ev.key == pgl.K_5:
58                     self.state.player.bits.toggle_bit(5)
59                 elif ev.key == pgl.K_6:
60                     self.state.player.bits.toggle_bit(6)
61                 elif ev.key == pgl.K_7:
62                     self.state.player.bits.toggle_bit(7)
63                 elif ev.key == pgl.K_EQUALS:
64                     self.state.gameboard.gain_health()
65                 return finish_event()