git repos / blockattack-game

commit 313ecd1b

sago007 · 2015-08-22 20:38
313ecd1b6e846dcd43025a1e9c4a04627e82e381 patch · browse files
parent 055218be684764da6d46baa24fe9b43f53f62b8c

Moved more SDL event outside BlockGame

Changed files

M source/code/BlockGame.cpp before
M source/code/BlockGame.hpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index dbddcae..564aca9 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -525,7 +525,7 @@ void BlockGame::setPlayerWon()
TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
}
bGameOver = true;
- if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
+ PlayerWonEvent();
if(!AI_Enabled && !bReplaying)
{
Stats::getInstance()->addOne("totalWins");
@@ -1019,7 +1019,7 @@ void BlockGame::ClearBlocks()
{
board[i][j]=-1;
setChain=true;
- if (SoundEnabled)Mix_PlayChannel(0, boing, 0);
+ BlockPopEvent();
}
if (board[i][j]!=-1)
if ((setChain)&&((board[i][j]/GARBAGE)%10!=1)&&((board[i][j]/GARBAGE)%10!=2))
@@ -1240,7 +1240,9 @@ void BlockGame::ClearBlocks()
if (chainUsed[i]==true)
{
if ((vsMode)&&(chainSize[i]>1)) garbageTarget->CreateGarbage(6, chainSize[i]-1);
- if ((SoundEnabled)&&(chainSize[i]>4))Mix_PlayChannel(1, applause, 0);
+ if (chainSize[i]>4) {
+ LongChainDoneEvent();
+ }
if(chainSize[i]>1 && !puzzleMode && !AI_Enabled)
Stats::getInstance()->addOne((string)"chainX"+itoa(chainSize[i]));
chainUsed[i]=false;
@@ -1449,7 +1451,7 @@ void BlockGame::PushLineInternal()
{
if ((!vsMode)&&(theTopScoresEndless.isHighScore(score))&&(!AI_Enabled))
{
- if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
+ EndlessHighscoreEvent();
theTopScoresEndless.addScore(name, score);
if(verboseLevel)
cout << "New high score!" << endl;
@@ -1981,7 +1983,6 @@ void BlockGame::Update()
}
if ((TowerHeight>12)&&(prevTowerHeight<13)&&(!puzzleMode))
{
- //if (SoundEnabled) Mix_PlayChannel(1, heartBeat, 0);
stop+=1000;
}
@@ -2053,7 +2054,7 @@ void BlockGame::Update()
if ((timetrial) && (!bGameOver) && (nowTime>gameStartedAt+2*60*1000))
{
SetGameOver();
- if(!NoSound && SoundEnabled)Mix_PlayChannel(1,counterFinalChunk,0);
+ TimeTrialEndEvent();
if ((theTopScoresTimeTrial.isHighScore(score))&&(!AI_Enabled))
{
theTopScoresTimeTrial.addScore(name, score);
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 74f7470..6c7f484 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -142,9 +142,14 @@ public:
void setAIlevel(Uint8 aiLevel);
Uint8 getAIlevel();
- virtual void AddText(int x, int y, const std::string& text, int time) {};
- virtual void AddBall(int x, int y, bool right, int color) {};
- virtual void AddExplosion(int x, int y) {};
+ virtual void AddText(int x, int y, const std::string& text, int time) const {}
+ virtual void AddBall(int x, int y, bool right, int color) const {}
+ virtual void AddExplosion(int x, int y) const {}
+ virtual void PlayerWonEvent() const {}
+ virtual void BlockPopEvent() const {}
+ virtual void LongChainDoneEvent() const {}
+ virtual void TimeTrialEndEvent() const {}
+ virtual void EndlessHighscoreEvent() const {}
int GetScore();
int GetHandicap();
diff --git a/source/code/main.cpp b/source/code/main.cpp index 14cef66..eb7b6aa 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1242,17 +1242,43 @@ public:
return topy;
}
- void AddText(int x, int y, const std::string& text, int time) override {
+ void AddText(int x, int y, const std::string& text, int time) const override {
theTextManeger.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time);
}
- void AddBall(int x, int y, bool right, int color) override {
+ void AddBall(int x, int y, bool right, int color) const override {
theBallManeger.addBall(topx+40+x*bsize, topy+bsize*12-y*bsize, left, color);
}
- void AddExplosion(int x, int y) override {
+ void AddExplosion(int x, int y) const override {
theExplosionManeger.addExplosion(topx-10+x*bsize, topy+bsize*12-10-y*bsize);
}
+
+ void PlayerWonEvent() const override {
+ if (!SoundEnabled) {return;}
+ Mix_PlayChannel(1, applause, 0);
+ }
+
+ void BlockPopEvent() const override {
+ if (!SoundEnabled) {return;}
+ Mix_PlayChannel(0, boing, 0);
+ }
+
+ void LongChainDoneEvent() const override {
+ if (!SoundEnabled) {return;}
+ Mix_PlayChannel(1, applause, 0);
+ }
+
+ void TimeTrialEndEvent() const override {
+ if(!NoSound && SoundEnabled) {
+ Mix_PlayChannel(1,counterFinalChunk,0);
+ }
+ }
+
+ void EndlessHighscoreEvent() const override {
+ if (!SoundEnabled) { return; }
+ Mix_PlayChannel(1, applause, 0);
+ }
private:
void convertSurface()
{