diff --git a/SoundManager.cpp b/SoundManager.cpp index a3b4f8b..d696420 100644 --- a/SoundManager.cpp +++ b/SoundManager.cpp @@ -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; } diff --git a/SoundManager.hpp b/SoundManager.hpp index 58eb522..22476b4 100644 --- a/SoundManager.hpp +++ b/SoundManager.hpp @@ -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); diff --git a/game.cpp b/game.cpp index 2499da4..16506ac 100644 --- a/game.cpp +++ b/game.cpp @@ -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(); } @@ -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(); } @@ -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_; @@ -500,7 +502,6 @@ bool Game::rotateCW() if(doesPieceFit(npiece, px_, py_)) { - shadowPiece_ = npiece; placePiece(npiece, px_, py_); piece_ = npiece; return true; @@ -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; @@ -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++; + } + } + +} diff --git a/game.hpp b/game.hpp index f6be04b..23a426a 100644 --- a/game.hpp +++ b/game.hpp @@ -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; @@ -175,7 +177,6 @@ void dropShadowPiece(); bool stopped_; Piece piece_; - Piece shadowPiece_; int* board_; diff --git a/intro.ogg b/intro.ogg new file mode 100644 index 0000000..77df809 Binary files /dev/null and b/intro.ogg differ diff --git a/viewer.cpp b/viewer.cpp index cf2e52b..2067d48 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -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 @@ -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"; } } @@ -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) { @@ -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) { @@ -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) @@ -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 @@ -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); @@ -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) { diff --git a/viewer.hpp b/viewer.hpp index b23c5c1..38e66e8 100644 --- a/viewer.hpp +++ b/viewer.hpp @@ -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];