Skip to content

Commit

Permalink
Added intro music
Browse files Browse the repository at this point in the history
Fixed disable sound
Added preview next piece
  • Loading branch information
Krishna committed Mar 28, 2010
1 parent c530e56 commit 5a7b80b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
4 changes: 2 additions & 2 deletions SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int SoundManager::LoadSound(char* file){

}

int SoundManager::PlaySound(int snd){
int SoundManager::PlaySound(int snd, int loop){
if(snd<0 && snd>=nSounds) return -1;
channel[snd] = Mix_PlayChannel(-1, chunks[snd], 0 /*-1*/);
channel[snd] = Mix_PlayChannel(-1, chunks[snd], loop);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion SoundManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SoundManager {
int LoadSound(char* file);

// snd is the sound ID returned by LoadSound
int PlaySound(int snd);
int PlaySound(int snd, int loop = 0);
int StopSound(int snd);
int PauseSound(int snd);
int ResumeSound(int snd);
Expand Down
21 changes: 17 additions & 4 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Game::Game(int width, int height)
int sz = board_width_ * (board_height_+4);
board_ = new int[ sz ];
std::fill(board_, board_ + sz, -1);
nextPiece = PIECES[ rand() % 6 ];
generateNewPiece();
}

Expand All @@ -179,6 +180,7 @@ void Game::reset()
std::fill(board_, board_ + (board_width_*(board_height_+4)), -1);
linesCleared_ = 0;
score_ = 0;
nextPiece = PIECES[ rand() % 6 ];
generateNewPiece();
}

Expand Down Expand Up @@ -327,14 +329,14 @@ void Game::placePiece(const Piece& p, int x, int y)

void Game::generateNewPiece()
{
piece_ = PIECES[ rand() % 6 ];
piece_ = nextPiece;
nextPiece = PIECES[ rand() % 6 ];

int xleft = (board_width_-3) / 2;

px_ = xleft;
py_ = board_height_ + 3 - piece_.getBottomMargin();

shadowPiece_ = piece_;
sx_ = px_;
sy_ = py_;

Expand Down Expand Up @@ -500,7 +502,6 @@ bool Game::rotateCW()

if(doesPieceFit(npiece, px_, py_))
{
shadowPiece_ = npiece;
placePiece(npiece, px_, py_);
piece_ = npiece;
return true;
Expand All @@ -518,7 +519,6 @@ bool Game::rotateCCW()
Piece npiece = piece_.rotateCCW();
if(doesPieceFit(npiece, px_, py_))
{
shadowPiece_ = npiece;
placePiece(npiece, px_, py_);
piece_ = npiece;
return true;
Expand Down Expand Up @@ -547,3 +547,16 @@ bool Game::moveClearBar()
clearBarPos += 0.2;
}

void Game::getNextPieceColour(int *col)
{
int counter = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0;j<2;j++)
{
col[counter] = nextPiece.getColourIndex(i+1, j+1);
counter++;
}
}

}
3 changes: 2 additions & 1 deletion game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ void dropShadowPiece();
viewer = v;
}
int numBlocksCleared;
Piece nextPiece;
void getNextPieceColour(int *col);
private:
bool doesPieceFit(const Piece& p, int x, int y) const;

Expand All @@ -175,7 +177,6 @@ void dropShadowPiece();
bool stopped_;

Piece piece_;
Piece shadowPiece_;


int* board_;
Expand Down
Binary file added intro.ogg
Binary file not shown.
40 changes: 25 additions & 15 deletions viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ void Viewer::on_realize()


// Load music
introMusic = sm.LoadSound("intro.ogg");
backgroundMusic = sm.LoadSound("lumines.ogg");
moveSound = sm.LoadSound("move.ogg");
turnSound = sm.LoadSound("turn.ogg");
//sm.PlaySound(backgroundMusic);
sm.PlaySound(introMusic, -1);


// Sphere for particles
Expand Down Expand Up @@ -443,7 +444,10 @@ void Viewer::drawAnimatables()

if (animatables[i].frames.size() == 0)
{
animatables.erase(animatables.begin() + i);
//animatables.erase(animatables.begin() + i);
animatables.clear();
readFile("head.txt");
std::cout<<"deleting " << i << "\n";
}

}
Expand Down Expand Up @@ -1009,6 +1013,14 @@ void Viewer::drawScene(bool draw3D)
drawCube(i, j, 7, GL_LINE_LOOP, draw3D);
}
}

// Draw next piece
int nextPieceCol[4];
game->getNextPieceColour(nextPieceCol);
drawCube(2, 19, nextPieceCol[0], GL_QUADS, draw3D);
drawCube(2, 20, nextPieceCol[1], GL_QUADS, draw3D);
drawCube(1, 19, nextPieceCol[2], GL_QUADS, draw3D);
drawCube(1, 20, nextPieceCol[3], GL_QUADS, draw3D);
}
bool Viewer::on_configure_event(GdkEventConfigure* event)
{
Expand Down Expand Up @@ -1118,6 +1130,10 @@ bool Viewer::on_button_press_event(GdkEventButton* event)
soundOnTex = soundOffTex;
soundOffTex = temp;
disableSound = !disableSound;
if (!disableSound)
sm.PlaySound(introMusic, -1);
else
sm.StopSound(introMusic);
}
else if (*ptr == singleSkinModeTex)
{
Expand Down Expand Up @@ -1161,9 +1177,13 @@ bool Viewer::on_button_release_event(GdkEventButton* event)
{
startScalePos[0] = 0;
startScalePos[1] = 0;
if (clickedButton)
if (clickedButton && loadScreen)
{
clickedButton = false;
loadScreen = false;
sm.StopSound(introMusic);
if (!disableSound)
sm.PlaySound(backgroundMusic, -1);
}

if (!shiftIsDown)
Expand Down Expand Up @@ -1204,7 +1224,8 @@ bool Viewer::on_motion_notify_event(GdkEventMotion* event)
if (moveLightSource)
{
// See how much we have moved
x2x1 = (event->x - startPos[0]);
x2x1 = event->x - startPos[0];
x2x1 /= 10;
if (mouseB1Down) // Rotate x
lightPos[0] += x2x1;
if (mouseB2Down) // Rotate y
Expand Down Expand Up @@ -1259,13 +1280,6 @@ bool Viewer::on_motion_notify_event(GdkEventMotion* event)
if (mouseB3Down) // Rotate z
rotationAngleZ += x2x1;

/* if (mouseB1Down) // Rotate x
lightPos[0] += x2x1;
if (mouseB2Down) // Rotate y
lightPos[1] += x2x1;
if (mouseB3Down) // Rotate z
lightPos[2] += x2x1;
*/
// Reset the tickTimer
if (!rotateTimer.connected())
rotateTimer = Glib::signal_timeout().connect(sigc::bind(sigc::mem_fun(*this, &Viewer::on_expose_event), (GdkEventExpose *)NULL), 100);
Expand Down Expand Up @@ -1860,10 +1874,6 @@ bool Viewer::gameTick()
animatables.clear();
readFile("headHappy.txt");
}
else if (animatables.size() == 0)
{
readFile("head.txt");
}

if (game->getLinesCleared() / 10 > (DEFAULT_GAME_SPEED - gameSpeed) / 50 && gameSpeed > 75)
{
Expand Down
1 change: 1 addition & 0 deletions viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Viewer : public Gtk::GL::DrawingArea {
int backgroundMusic;
int turnSound;
int moveSound;
int introMusic;
GLuint square;
float shadowProj[16];
float lightPos[4];
Expand Down

0 comments on commit 5a7b80b

Please sign in to comment.