diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 2e54008..e01172a 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -21,6 +21,17 @@ http://blockattack.sf.net =========================================================================== */ +//Some definitions +//The game is divided in frames. FALLTIME means the blocks will fall one block every FRAMELENGTH*FALLTIME millisecond +#define FRAMELENGTH 50 +#define HANGTIME 40 +#define FALLTIME 20 +//Don't change the following, they are fundamental and later some functions are hardcoded +#define BLOCKFALL 10000 +#define BLOCKWAIT 100000 +#define BLOCKHANG 1000 +#define GARBAGE 1000000 +#define CHAINPLACE 10000000 #include "BlockGame.hpp" #include @@ -180,16 +191,6 @@ bool BlockGame::isGameOver() return bGameOver; } -int BlockGame::GetTopX() -{ - return topx; -} - -int BlockGame::GetTopY() -{ - return topy; -} - Sint32 BlockGame::GetGameStartedAt() { return gameStartedAt; @@ -311,7 +312,7 @@ bool BlockGame::popGarbage(Uint8 *width, Uint8 *height, Uint8 *type) //Instead of creating new object new game is called, to prevent memory leaks -void BlockGame::NewGame(int tx, int ty, unsigned int ticks) +void BlockGame::NewGame( unsigned int ticks) { this->ticks = ticks; stageButtonStatus = SBdontShow; @@ -324,8 +325,6 @@ void BlockGame::NewGame(int tx, int ty, unsigned int ticks) lastNrOfPlayers = 1; //At least one player :-) nrPushedPixel = 0; nrStops = 0; - topx = tx; - topy = ty; cursorx = 2; cursory = 3; stop = 0; @@ -366,20 +365,20 @@ void BlockGame::NewGame(int tx, int ty, unsigned int ticks) ActionPerformed(ACTION_NEW,""); } //NewGame -void BlockGame::NewTimeTrialGame(int x,int y, unsigned int ticks) +void BlockGame::NewTimeTrialGame( unsigned int ticks) { - NewGame(x,y,ticks); + NewGame(ticks); ActionPerformed(ACTION_NEWTT,""); timetrial = true; putStartBlocks(); } //Starts a new stage game, takes level as input! -void BlockGame::NewStageGame(int level, int tx, int ty,unsigned int ticks) +void BlockGame::NewStageGame(int level, unsigned int ticks) { if (level > -1) { - NewGame(tx, ty,ticks); + NewGame(ticks); stageClear = true; Level = level; Stats::getInstance()->addOne("PlayedStageLevel"+itoa2(level)); @@ -389,11 +388,11 @@ void BlockGame::NewStageGame(int level, int tx, int ty,unsigned int ticks) } } -void BlockGame::NewPuzzleGame(int level, int tx, int ty, unsigned int ticks) +void BlockGame::NewPuzzleGame(int level, unsigned int ticks) { if (level>-1) { - NewGame(tx, ty,ticks); + NewGame(ticks); puzzleMode = true; Level = level; MovesLeft = nrOfMovesAllowed[Level]; @@ -431,31 +430,33 @@ void BlockGame::NewPuzzleGame(int level, int tx, int ty, unsigned int ticks) //Replay the current level void BlockGame::retryLevel(unsigned int ticks) { - if(puzzleMode) - NewPuzzleGame(Level,topx,topy,ticks); - else if(stageClear) - NewStageGame(Level,topx,topy,ticks); + if (puzzleMode) { + NewPuzzleGame(Level, ticks); + } + else if (stageClear) { + NewStageGame(Level, ticks); + } } //Play the next level void BlockGame::nextLevel(unsigned int ticks) { - if(puzzleMode) - { - if(Level1) - theTextManeger.addText(topx-10+j*bsize, topy+12*bsize-i*bsize, tempS, 1000); + if (chainSize[chain]>1) { + AddText(j, i, tempS, 1000); + } } } } //This was there text was added diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 725f539..d74228d 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -26,21 +26,8 @@ http://blockattack.sf.net #include "stats.h" #include "common.h" -#include "SDL.h" #include "replay.h" - -//Some definitions -//The game is divided in frames. FALLTIME means the blocks will fall one block every FRAMELENGTH*FALLTIME millisecond -#define FRAMELENGTH 50 -#define HANGTIME 40 -#define FALLTIME 20 -//Don't change the following, they are fundamental and later some functions are hardcoded -#define BLOCKFALL 10000 -#define BLOCKWAIT 100000 -#define BLOCKHANG 1000 -#define GARBAGE 1000000 -#define CHAINPLACE 10000000 #define NUMBEROFCHAINS 100 #define ACTION_UPDATE 0 @@ -113,7 +100,6 @@ protected: bool timetrial, stageClear, vsMode, puzzleMode; int Level; //Only used in stageClear and puzzle (not implemented) int stageClearLimit; //stores number of lines user must clear to win - int topx, topy; int combo; int chain; int cursorx; //stores cursor position @@ -153,12 +139,14 @@ public: //Also enables AI 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 left, int color) {}; + virtual void AddExplosion(int x, int y) {}; + int GetScore(); int GetHandicap(); bool isGameOver(); - int GetTopX(); - int GetTopY(); Sint32 GetGameStartedAt(); Sint32 GetGameEndedAt(); bool isTimeTrial(); @@ -176,21 +164,21 @@ public: void MoveCursorTo(int x, int y); bool GetIsWinner(); //Instead of creating new object new game is called, to prevent memory leaks - void NewGame(int tx, int ty, unsigned int ticks); - void NewTimeTrialGame(int x,int y, unsigned int ticks); + void NewGame(unsigned int ticks); + void NewTimeTrialGame(unsigned int ticks); //Starts a new stage game, takes level as input! - void NewStageGame(int level, int tx, int ty,unsigned int ticks); - void NewPuzzleGame(int level, int tx, int ty, unsigned int ticks); + void NewStageGame(int level, unsigned int ticks); + void NewPuzzleGame(int level, unsigned int ticks); //Replay the current level void retryLevel(unsigned int ticks); //Play the next level void nextLevel(unsigned int ticks); //Starts new Vs Game (two Player) - void NewVsGame(int tx, int ty, BlockGame *target,unsigned int ticks); + void NewVsGame(BlockGame *target,unsigned int ticks); //Starts new Vs Game (two Player) - void NewVsGame(int tx, int ty, BlockGame *target, bool AI,unsigned int ticks); + void NewVsGame(BlockGame *target, bool AI,unsigned int ticks); //We want to play the replay (must have been loaded beforehand) - void playReplay(int tx, int ty, unsigned int ticks, Replay r); + void playReplay(unsigned int ticks, const Replay& r); void putStartBlocks(Uint32 n); //Creates garbage using a given wide and height bool CreateGarbage(int wide, int height); @@ -218,7 +206,7 @@ public: int GotAction(unsigned int &tick,int &action,string ¶m); #if NETWORK //network play - void playNetwork(int tx, int ty,unsigned int ticks); + void playNetwork(unsigned int ticks); #endif //Prints "winner" and ends game void setPlayerWon(); diff --git a/source/code/Makefile b/source/code/Makefile index e368034..c92daee 100644 --- a/source/code/Makefile +++ b/source/code/Makefile @@ -10,7 +10,7 @@ ifdef CROSS CXX=$(CROSS)g++ endif -BASE_CFLAGS=-c $(shell $(CROSS)sdl-config --cflags) +BASE_CFLAGS=-c $(shell $(CROSS)sdl-config --cflags) -std=c++11 ifndef BUILDDIR BUILDDIR=build diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp index 282e147..034d252 100644 --- a/source/code/NetworkThing.hpp +++ b/source/code/NetworkThing.hpp @@ -311,8 +311,8 @@ public: ENetPacket * answerPacket = enet_packet_create("version4",sizeof("version4"),ENET_PACKET_FLAG_RELIABLE); enet_host_broadcast (server, 3, answerPacket); theSeed = time(0)/4; - bgHome->NewVsGame(50,100,bgAway,SDL_GetTicks()); - bgAway->NewVsGame(xsize-500,100,bgHome,SDL_GetTicks()); + bgHome->NewVsGame(bgAway, SDL_GetTicks()); + bgAway->NewVsGame(bgHome, SDL_GetTicks()); bgHome->putStartBlocks(theSeed); ENetPacket * timePacket = enet_packet_create(&theSeed,sizeof(theSeed),ENET_PACKET_FLAG_RELIABLE); enet_host_broadcast (server, 3, timePacket); diff --git a/source/code/main.cpp b/source/code/main.cpp index bf0260e..ab83280 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1268,13 +1268,32 @@ public: sBoard = SDL_DisplayFormat(tmp); SDL_FreeSurface(tmp); //BlockGame::BlockGame(tx,ty); - BlockGame::topx = tx; - BlockGame::topy = ty; + topx = tx; + topy = ty; } ~BlockGameSdl() { SDL_FreeSurface(sBoard); } + + int GetTopX() { + return topx; + } + int GetTopY() { + return topy; + } + + void AddText(int x, int y, const std::string& text, int time) override { + theTextManeger.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time); + } + + void AddBall(int x, int y, bool left, int color) override { + theBallManeger.addBall(topx+40+x*bsize, topy+bsize*12-y*bsize, left, color); + } + + void AddExplosion(int x, int y) override { + theExplosionManeger.addExplosion(topx-10+x*bsize, topy+bsize*12-10-y*bsize); + } private: void convertSurface() { @@ -1666,6 +1685,9 @@ public: BlockGame::Update(newtick); DoPaintJob(); } + +private: + int topx, topy; }; @@ -2609,7 +2631,7 @@ static void MakeBackground(int xsize,int ysize) } //Generates the background with red board backs -static void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *theGame2) +static void MakeBackground(int xsize,int ysize,BlockGameSdl *theGame, BlockGameSdl *theGame2) { MakeBackground(xsize,ysize); DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68); @@ -2617,7 +2639,7 @@ static void MakeBackground(int xsize,int ysize,BlockGame *theGame, BlockGame *th standardBackground = false; } -static void MakeBackground(int xsize, int ysize, BlockGame *theGame) +static void MakeBackground(int xsize, int ysize, BlockGameSdl *theGame) { MakeBackground(xsize,ysize); DrawIMG(boardBackBack,background,theGame->GetTopX()-60,theGame->GetTopY()-68); @@ -3042,7 +3064,7 @@ static BlockGameSdl *player2; static void StartSinglePlayerEndless() { //1 player - endless - player1->NewGame(50,100,SDL_GetTicks()); + player1->NewGame(SDL_GetTicks()); player1->putStartBlocks(time(0)); bNewGameOpen = false; b1playerOpen = false; @@ -3055,7 +3077,7 @@ static void StartSinglePlayerEndless() static void StartSinglePlayerTimeTrial() { - player1->NewTimeTrialGame(50,100,SDL_GetTicks()); + player1->NewTimeTrialGame(SDL_GetTicks()); closeAllMenus(); twoPlayers =false; player2->SetGameOver(); @@ -3070,7 +3092,7 @@ static int StartSinglePlayerPuzzle(int level) int myLevel = PuzzleLevelSelect(0); if(myLevel == -1) return 1; - player1->NewPuzzleGame(myLevel,50,100,SDL_GetTicks()); + player1->NewPuzzleGame(myLevel,SDL_GetTicks()); MakeBackground(xsize,ysize,player1,player2); DrawIMG(background, screen, 0, 0); closeAllMenus(); @@ -3086,8 +3108,8 @@ static int StartSinglePlayerPuzzle(int level) static void StarTwoPlayerTimeTrial() { - player1->NewTimeTrialGame(50,100,SDL_GetTicks()); - player2->NewTimeTrialGame(xsize-500,100,SDL_GetTicks()); + player1->NewTimeTrialGame(SDL_GetTicks()); + player2->NewTimeTrialGame(SDL_GetTicks()); int theTime = time(0); player1->putStartBlocks(theTime); player2->putStartBlocks(theTime); @@ -3108,8 +3130,8 @@ static void StarTwoPlayerTimeTrial() static void StartTwoPlayerVs() { //2 player - VsMode - player1->NewVsGame(50,100,player2,SDL_GetTicks()); - player2->NewVsGame(xsize-500,100,player1,SDL_GetTicks()); + player1->NewVsGame(player2,SDL_GetTicks()); + player2->NewVsGame(player1,SDL_GetTicks()); bNewGameOpen = false; //vsMode = true; twoPlayers = true; @@ -3133,9 +3155,9 @@ static void StartReplay(string filename) { Replay r1,r2; r1.loadReplay(filename); - player1->playReplay(50,100,SDL_GetTicks(),r1); + player1->playReplay(SDL_GetTicks(),r1); r2.loadReplay2(filename); - player2->playReplay(xsize-500,100,SDL_GetTicks(),r2); + player2->playReplay(SDL_GetTicks(),r2); } static void StartHostServer() @@ -3534,7 +3556,7 @@ int main(int argc, char *argv[]) if (singlePuzzle) { LoadPuzzleStages(); - theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks()); + theGame.NewPuzzleGame(singlePuzzleNr, SDL_GetTicks()); showGame = true; } //Draws everything to screen @@ -3672,7 +3694,7 @@ int runGame(int gametype, int level) if (singlePuzzle) { LoadPuzzleStages(); - theGame.NewPuzzleGame(singlePuzzleNr,0,0,SDL_GetTicks()); + theGame.NewPuzzleGame(singlePuzzleNr, SDL_GetTicks()); showGame = true; } //Draws everything to screen @@ -3705,7 +3727,7 @@ int runGame(int gametype, int level) int myLevel = PuzzleLevelSelect(1); if(myLevel == -1) return 1; - theGame.NewStageGame(myLevel,50,100,SDL_GetTicks()); + theGame.NewStageGame(myLevel,SDL_GetTicks()); MakeBackground(xsize,ysize,&theGame,&theGame2); DrawIMG(background, screen, 0, 0); closeAllMenus(); @@ -3726,8 +3748,8 @@ int runGame(int gametype, int level) bNewGameOpen = false; b1playerOpen = false; int theAIlevel = level; //startSingleVs(); - theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks()); - theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks()); + theGame.NewVsGame(&theGame2, SDL_GetTicks()); + theGame2.NewVsGame(&theGame, SDL_GetTicks()); MakeBackground(xsize,ysize,&theGame,&theGame2); DrawIMG(background, screen, 0, 0); twoPlayers = true; //Single player, but AI plays @@ -3798,9 +3820,9 @@ int runGame(int gametype, int level) networkPlay=true; if (!weWhereConnected) //We have just connected { - theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks()); + theGame.NewVsGame(&theGame2,SDL_GetTicks()); theGame.putStartBlocks(nt.theSeed); - theGame2.playNetwork(xsize-500,100,SDL_GetTicks()); + theGame2.playNetwork(SDL_GetTicks()); nt.theGameHasStarted(); DrawIMG(background, screen, 0, 0); }