Permalink
Browse files

Sound effects for menus

  • Loading branch information...
1 parent d3deeac commit 5d71bee0771f4b42e67bd74d8b21145e89c13124 @nickg committed Feb 7, 2009
View
Oops, something went wrong.
View
@@ -15,7 +15,7 @@ EXTRA_DIST = images/ship.png images/star.png images/start_option.png \
images/landingpad.png images/landingpadred.png images/title.png \
images/gameover.png \
sounds/firework_1.wav sounds/bomb_explosion.wav \
- sounds/boing1.wav \
+ sounds/boing1.wav sounds/bleep.wav sounds/select.wav \
Default_Font.ttf
nobase_dist_pkgdata_DATA = $(EXTRA_DIST)
View
Binary file not shown.
View
Binary file not shown.
View
@@ -38,6 +38,11 @@ ConfigFile::ConfigFile(string filename)
ConfigFile::~ConfigFile()
{
+ Flush();
+}
+
+void ConfigFile::Flush()
+{
if (dirty) {
ofstream of((GetConfigDir() + filename).c_str());
@@ -49,6 +54,8 @@ ConfigFile::~ConfigFile()
of << (*it).second;
of << endl;
}
+
+ dirty = false;
}
}
View
@@ -1,5 +1,6 @@
+//
// ConfigFile.hpp -- Settings persistence.
-// Copyright (C) 2008 Nick Gasson
+// Copyright (C) 2008-2009 Nick Gasson
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -25,6 +26,8 @@ class ConfigFile {
ConfigFile(string filename = ".lander.config");
~ConfigFile();
+ void Flush();
+
bool has(const string& key) const;
const string& get(const string& key);
View
@@ -1,3 +1,4 @@
+//
// ElectricGate.cpp -- Electric gateway thingys.
// Copyright (C) 2008 Nick Gasson
//
@@ -16,6 +17,7 @@
//
#include "ElectricGate.hpp"
+#include "Ship.hpp"
#include "LoadOnce.hpp"
Image* ElectricGate::gateImage = NULL;
View
@@ -1,3 +1,4 @@
+//
// ElectricGate.hpp -- Electric gateway thingys.
// Copyright (C) 2008 Nick Gasson
//
@@ -19,9 +20,9 @@
#define INC_ELECTRICGATE_HPP
#include "ObjectGrid.hpp"
-#include "Ship.hpp"
#include "Viewport.hpp"
#include "Image.hpp"
+#include "GameObjFwd.hpp"
//
// A line strip used for rendering lightning.
View
@@ -22,6 +22,7 @@
#include "HighScores.hpp"
#include "LoadOnce.hpp"
#include "Input.hpp"
+#include "ConfigFile.hpp"
//
// Constants affecting level generation.
@@ -97,7 +98,10 @@ void Game::NewGame()
lives = 3;
// Start the game
- level = 1;
+ {
+ ConfigFile cfile;
+ level = cfile.get_int("level", 1);
+ }
nextnewlife = 1000;
StartLevel();
}
View
@@ -1,6 +1,6 @@
//
// HighScores.cpp - Implementation of high scores screen.
-// Copyright (C) 2006 Nick Gasson
+// Copyright (C) 2006-2009 Nick Gasson
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
#include "HighScores.hpp"
#include "Input.hpp"
+#include "InterfaceSounds.hpp"
HighScores::HighScores()
: hscoreImage("images/hscore.png"),
@@ -68,6 +69,7 @@ void HighScores::Process()
input.ResetAction(Input::SKIP);
input.ResetAction(Input::FIRE);
input.ResetAction(Input::ABORT);
+ InterfaceSounds::PlaySelect();
}
}
else if (state == hssEnterName) {
@@ -83,6 +85,7 @@ void HighScores::Process()
fade = HS_FADE_IN_SPEED;
input.ResetAction(Input::FIRE);
+ InterfaceSounds::PlaySelect();
}
}
View
@@ -20,6 +20,8 @@
#include "Input.hpp"
#include "OpenGL.hpp"
+const int Input::RESET_TIMEOUT(7);
+
//
// Create a new input manager. Never call this directly: use GetInstance.
//
View
@@ -31,7 +31,8 @@ class Input {
enum Action {
UP, DOWN, LEFT, RIGHT, FIRE,
SKIP, ABORT, DEBUG, PAUSE, THRUST,
- SCREENSHOT
+ SCREENSHOT,
+ NUM_ACTIONS // Must be last
};
static Input& GetInstance();
@@ -49,8 +50,7 @@ class Input {
Input();
~Input();
- static const int NUM_ACTIONS = 11;
- static const int RESET_TIMEOUT = 7; // Frames between key presses
+ static const int RESET_TIMEOUT; // Frames between key presses
SDL_Joystick* joystick;
View
@@ -0,0 +1,35 @@
+//
+// InterfaceSounds.cpp -- User interface sound effects.
+// Copyright (C) 2009 Nick Gasson
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+
+#include "InterfaceSounds.hpp"
+#include "SoundEffect.hpp"
+
+void InterfaceSounds::PlayBleep()
+{
+ static SoundEffect bleepSound(LocateResource("sounds/bleep.wav"));
+
+ bleepSound.Play();
+}
+
+void InterfaceSounds::PlaySelect()
+{
+ static SoundEffect selectSound(LocateResource("sounds/select.wav"));
+
+ selectSound.Play();
+}
View
@@ -0,0 +1,30 @@
+//
+// InterfaceSounds.hpp -- User interface sound effects.
+// Copyright (C) 2009 Nick Gasson
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+
+#ifndef INC_INTERFACE_SOUNDS_HPP
+#define INC_INTERFACE_SOUNDS_HPP
+
+#include "Platform.hpp"
+
+namespace InterfaceSounds {
+ void PlayBleep();
+ void PlaySelect();
+}
+
+#endif
View
@@ -1,6 +1,6 @@
//
// Main.cpp - Program entry point.
-// Copyright (C) 2006 Nick Gasson
+// Copyright (C) 2006-2009 Nick Gasson
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
const int DEFAULT_SOUND = true;
cout << "Lunar Lander " << VERSION << endl << endl
- << "Copyright (C) 2008 Nick Gasson" << endl
+ << "Copyright (C) 2006-2009 Nick Gasson" << endl
<< "This program comes with ABSOLUTELY NO WARRANTY. This is free software, and" << endl
<< "you are welcome to redistribute it under certain conditions. See the GNU" << endl
<< "General Public Licence for details." << endl << endl;
View
@@ -16,7 +16,8 @@ lander_SOURCES = Main.cpp Game.hpp Game.cpp \
Image.cpp AnimatedImage.hpp AnimatedImage.cpp \
Texture.hpp Texture.cpp Options.hpp Options.cpp \
ConfigFile.hpp ConfigFile.cpp SoundEffect.hpp \
- SoundEffect.cpp Fade.hpp Fade.cpp GameObjFwd.hpp
+ SoundEffect.cpp Fade.hpp Fade.cpp GameObjFwd.hpp \
+ InterfaceSounds.hpp InterfaceSounds.cpp
localedir = $(datadir)/locale
View
@@ -1,6 +1,6 @@
//
// Menu.cpp -- Implementation of main menu screen.
-// Copyright (C) 2006 Nick Gasson
+// Copyright (C) 2006-2009 Nick Gasson
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include "OpenGL.hpp"
#include "Game.hpp"
#include "HighScores.hpp"
+#include "InterfaceSounds.hpp"
const double MenuStar::ROTATE_SPEED(0.005);
const double MenuStar::ENLARGE_RATE(0.001);
@@ -88,6 +89,7 @@ void MainMenu::Process()
break;
}
+ InterfaceSounds::PlayBleep();
input.ResetAction(Input::DOWN);
}
else if (input.QueryAction(Input::UP)) {
@@ -106,6 +108,7 @@ void MainMenu::Process()
break;
}
+ InterfaceSounds::PlayBleep();
input.ResetAction(Input::UP);
}
else if (input.QueryAction(Input::FIRE)) {
@@ -125,6 +128,7 @@ void MainMenu::Process()
break;
}
+ InterfaceSounds::PlaySelect();
input.ResetAction(Input::FIRE);
}
else if (input.QueryResetAction(Input::SCREENSHOT))
View
@@ -1,6 +1,6 @@
//
// Menu.hpp -- Defintition of main menu screen.
-// Copyright (C) 2006 Nick Gasson
+// Copyright (C) 2006-2009 Nick Gasson
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include "ScreenManager.hpp"
#include "Image.hpp"
#include "Font.hpp"
-
+#include "SoundEffect.hpp"
class MenuStar {
public:
View
@@ -1,3 +1,4 @@
+//
// Mine.cpp -- Floating space mine things.
// Copyright (C) 2008 Nick Gasson
//
@@ -18,6 +19,7 @@
#include "Mine.hpp"
#include "OpenGL.hpp"
#include "LoadOnce.hpp"
+#include "Ship.hpp"
AnimatedImage* Mine::image = NULL;
@@ -107,13 +109,12 @@ void Mine::Move()
}
// Check if this is ok
- ok = nextx >= objgrid->GetWidth() || nextx < 0
- || nexty > objgrid->GetHeight() || nexty < 0
- || objgrid->IsFilled(nextx, nexty)
- || objgrid->IsFilled(nextx + 1, nexty)
- || objgrid->IsFilled(nextx + 1, nexty + 1)
- || objgrid->IsFilled(nextx, nexty + 1);
- ok = !ok;
+ ok = !(nextx + 1 >= objgrid->GetWidth() || nextx < 0
+ || nexty + 1 >= objgrid->GetHeight() || nexty < 0
+ || objgrid->IsFilled(nextx, nexty)
+ || objgrid->IsFilled(nextx + 1, nexty)
+ || objgrid->IsFilled(nextx + 1, nexty + 1)
+ || objgrid->IsFilled(nextx, nexty + 1));
timeout--;
} while (!ok && timeout > 0);
View
@@ -19,9 +19,9 @@
#define INC_MINE_HPP
#include "ObjectGrid.hpp"
-#include "Ship.hpp"
#include "Viewport.hpp"
#include "AnimatedImage.hpp"
+#include "GameObjFwd.hpp"
class Mine : public StaticObject {
public:
Oops, something went wrong.

0 comments on commit 5d71bee

Please sign in to comment.