5 import pygame.locals as pgl
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
20 class GameScene(Scene):
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))
33 self.add(RobotWidget(state))
35 sound.play_sound('startup.ogg')
36 background_track = random.choice(TUNES)
37 sound.play_music(background_track, 0.25)
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:
44 SceneChangeEvent.post(MenuScene)
46 if options.cheat_enabled:
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()