diff --git a/res/sounds/spotlight.wav b/res/sounds/spotlight.wav new file mode 100644 index 0000000..8b14a27 Binary files /dev/null and b/res/sounds/spotlight.wav differ diff --git a/src/sj/AbstractScene.d b/src/sj/AbstractScene.d index 3586922..0e87727 100644 --- a/src/sj/AbstractScene.d +++ b/src/sj/AbstractScene.d @@ -17,6 +17,7 @@ class AbstractScene : SceneInterface { } override SceneInterface TakeNextScene() { + scope(exit) next_ = null; return next_; } diff --git a/src/sj/Game.d b/src/sj/Game.d index def121e..e51dc74 100644 --- a/src/sj/Game.d +++ b/src/sj/Game.d @@ -5,6 +5,7 @@ import sj.AbstractGame, sj.FontSet, sj.LobbyWorld, sj.ProgramSet, + sj.SelectScene, sj.TitleScene; /// @@ -17,8 +18,11 @@ class Game : AbstractGame { lobby_ = new LobbyWorld(programs_); - title_ = new TitleScene(lobby_, programs_); - title_.SetupSceneDependency(title_); // TODO: specify proper next scene + title_ = new TitleScene(lobby_, programs_); + select_ = new SelectScene(lobby_, programs_); + + title_.SetupSceneDependency(select_); + select_.SetupSceneDependency(title_); super(title_); } @@ -40,4 +44,6 @@ class Game : AbstractGame { LobbyWorld lobby_; TitleScene title_; + + SelectScene select_; } diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d new file mode 100644 index 0000000..bf201e6 --- /dev/null +++ b/src/sj/SelectScene.d @@ -0,0 +1,61 @@ +/// License: MIT +module sj.SelectScene; + +import derelict.sfml2.audio; + +import sj.AbstractScene, + sj.KeyInput, + sj.LobbyWorld, + sj.ProgramSet, + sj.SceneInterface; + +/// +class SelectScene : AbstractScene { + public: + /// + enum SpotlightSound = cast(ubyte[]) import("sounds/spotlight.wav"); + + /// + this(LobbyWorld lobby, ProgramSet program) { + lobby_ = lobby; + + const buf = SpotlightSound; + spotlight_buffer_ = sfSoundBuffer_createFromMemory(buf.ptr, buf.length); + sound_ = sfSound_create(); + + first_ = true; + } + ~this() { + sfSound_destroy(sound_); + sfSoundBuffer_destroy(spotlight_buffer_); + } + + /// + void SetupSceneDependency(SceneInterface title_scene) { + title_scene_ = title_scene; + } + + override void Update(KeyInput input) { + if (first_) { + sfSound_setBuffer(sound_, spotlight_buffer_); + sfSound_play(sound_); + } + first_ = false; + + if (input.up) GoNextScene(title_scene_); + } + override void Draw() { + lobby_.Draw(); + } + + private: + SceneInterface title_scene_; + + LobbyWorld lobby_; + + sfSoundBuffer* spotlight_buffer_; + + sfSound* sound_; + + bool first_; +} diff --git a/src/sj/TitleScene.d b/src/sj/TitleScene.d index ebf1f86..562fb1b 100644 --- a/src/sj/TitleScene.d +++ b/src/sj/TitleScene.d @@ -38,6 +38,8 @@ class TitleScene : AbstractScene { override void Update(KeyInput input) { lobby_.cube_matrix.rotation += vec3(PI/600, PI/600, PI/600); + + if (input.down) GoNextScene(next_scene_); } override void Draw() { lobby_.Draw();