git repos / blockattack-game

commit 67a32395

sago007 · 2012-04-19 18:40
67a32395ea2f4f1dbd2dde557497ec7b882515e8 patch · browse files
parent c53e6443d15070255f63c24f440ebebb254fa397

new menu for selecting difficutlty


git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@135 9d7177f8-192b-0410-8f35-a16a89829b06

Changed files

M source/code/MenuSystem.cc before
M source/code/MenuSystem.h before
M source/code/main.cpp before
M source/code/menudef.cpp before
diff --git a/source/code/MenuSystem.cc b/source/code/MenuSystem.cc index 63e80e4..8be23c0 100644 --- a/source/code/MenuSystem.cc +++ b/source/code/MenuSystem.cc
@@ -62,6 +62,7 @@ Button::Button()
label = "";
marked = false;
action = NULL;
+ popOnRun = false;
}
Button::~Button()
@@ -73,6 +74,7 @@ Button::Button(const Button& b)
label = b.label;
marked = b.marked;
action = b.action;
+ popOnRun = false;
}
void Button::setLabel(string text)
@@ -117,6 +119,16 @@ void Button::drawTo(SDL_Surface **surface)
ButtonGfx::thefont.drawCenter(x+ButtonGfx::xsize/2,y+ButtonGfx::ysize/2-ButtonGfx::thefont.getHeight(label.c_str())/2,label.c_str());
}
+void Button::setPopOnRun(bool popOnRun)
+{
+ this->popOnRun = popOnRun;
+}
+
+bool Button::isPopOnRun() const
+{
+ return popOnRun;
+}
+
void Menu::drawSelf()
{
DrawIMG(backgroundImage,screen,0,0);
@@ -136,6 +148,8 @@ void Menu::performClick(int x,int y)
Button *b = (*it);
if(b->isClicked(x,y))
b->doAction();
+ if(b->isPopOnRun())
+ running = false;
}
if(exit.isClicked(x,y))
running = false;
@@ -238,8 +252,11 @@ void Menu::run()
if(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_KP_ENTER )
{
- if(marked < buttons.size())
+ if(marked < buttons.size()) {
buttons.at(marked)->doAction();
+ if(buttons.at(marked)->isPopOnRun())
+ running = false;
+ }
if(marked == buttons.size())
running = false;
}
@@ -286,6 +303,9 @@ void Menu::run()
if(buttons.at(i)->isClicked(mousex,mousey))
{
buttons.at(i)->doAction();
+ if(buttons.at(i)->isPopOnRun())
+ running = false;
+ mousex = 0;
}
}
if(exit.isClicked(mousex,mousey))
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 9eddc42..180bcb3 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h
@@ -57,6 +57,9 @@ private:
string label;
//Pointer to a callback function.
void (*action)(Button *b);
+
+ //If true the menu should also be closed then the button is clicked
+ bool popOnRun;
public:
//Is the button marked?
@@ -77,7 +80,12 @@ public:
bool isClicked(int x,int y); //Returns true if (x,y) is within the borders of the button
virtual void doAction(); //Run the callback function
- void drawTo(SDL_Surface **surface); //Draws to screen
+ void drawTo(SDL_Surface **surface);
+ void setPopOnRun(bool popOnRun);
+ bool isPopOnRun() const; //Draws to screen
+
+ //May hold any other information the callback might need
+ int iGeneric1;
};
diff --git a/source/code/main.cpp b/source/code/main.cpp index 3770d2b..dc5361f 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -3130,7 +3130,7 @@ int StageLevelSelect()
}
//Ask user for what AI level he will compete agains, return the number. Number must be 0..AIlevels
-int startSingleVs()
+/*int startSingleVs()
{
//Where to place the windows
const int xplace = 200;
@@ -3219,7 +3219,7 @@ int startSingleVs()
return 3; //Returns normal
-}
+}*/
//The function that allows the player to choose Level number
void startVsMenu()
@@ -3428,9 +3428,11 @@ void StartSinglePlayerTimeTrial()
strcpy(player2->name, player2name);
}
-void StartSinglePlayerPuzzle()
+int StartSinglePlayerPuzzle(int level)
{
int myLevel = PuzzleLevelSelect();
+ if(myLevel == -1)
+ return 1;
player1->NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
MakeBackground(xsize,ysize,player1,player2);
DrawIMG(background, screen, 0, 0);
@@ -3441,6 +3443,7 @@ void StartSinglePlayerPuzzle()
//vsMode = true;
strcpy(player1->name, player1name);
strcpy(player2->name, player2name);
+ return 0;
}
@@ -3617,30 +3620,6 @@ int main(int argc, char *argv[])
puzzleLoaded = false;
bool weWhereConnected = false;
- //Things used for repeating keystrokes:
- /*bool repeatingS[2] = {false,false};
- bool repeatingW[2] = {false,false};
- bool repeatingN[2] = {false,false};
- bool repeatingE[2] = {false,false};
- const int startRepeat = 200;
- const int repeatDelay = 100; //Repeating
- unsigned long timeHeldP1N = 0;
- unsigned long timeHeldP1S = 0;
- unsigned long timeHeldP1E = 0;
- unsigned long timeHeldP1W = 0;
- unsigned long timeHeldP2N = 0;
- unsigned long timeHeldP2S = 0;
- unsigned long timeHeldP2E = 0;
- unsigned long timeHeldP2W = 0;
- unsigned long timesRepeatedP1N = 0;
- unsigned long timesRepeatedP1S = 0;
- unsigned long timesRepeatedP1E = 0;
- unsigned long timesRepeatedP1W = 0;
- unsigned long timesRepeatedP2N = 0;
- unsigned long timesRepeatedP2S = 0;
- unsigned long timesRepeatedP2E = 0;
- unsigned long timesRepeatedP2W = 0;*/
-
theBallManeger = ballManeger();
theExplosionManeger = explosionManeger();
@@ -3966,7 +3945,7 @@ int main(int argc, char *argv[])
}
-void runGame(int gametype)
+int runGame(int gametype, int level)
{
Uint8 *keys;
int mousex, mousey; //Mouse coordinates
@@ -4054,9 +4033,9 @@ void runGame(int gametype)
MakeBackground(xsize,ysize,&theGame,&theGame2);
else
MakeBackground(xsize,ysize,&theGame);
- DrawIMG(background, screen, 0, 0);
+ /*DrawIMG(background, screen, 0, 0);
DrawEverything(xsize,ysize,&theGame,&theGame2);
- SDL_Flip(screen);
+ SDL_Flip(screen);*/
//game loop
int done = 0;
cout << "Starting game loop" << endl;
@@ -4074,14 +4053,15 @@ void runGame(int gametype)
StartSinglePlayerTimeTrial();
break;
case 3:
- StartSinglePlayerPuzzle();
+ if(StartSinglePlayerPuzzle(level))
+ return 1;
break;
case 4:
{
//1 player - Vs mode
bNewGameOpen = false;
b1playerOpen = false;
- int theAIlevel = startSingleVs();
+ int theAIlevel = level; //startSingleVs();
theGame.NewVsGame(50,100,&theGame2,SDL_GetTicks());
theGame2.NewVsGame(xsize-500,100,&theGame,SDL_GetTicks());
MakeBackground(xsize,ysize,&theGame,&theGame2);
@@ -4103,6 +4083,9 @@ void runGame(int gametype)
break;
};
mustsetupgame = false;
+ DrawIMG(background, screen, 0, 0);
+ DrawEverything(xsize,ysize,&theGame,&theGame2);
+ SDL_Flip(screen);
}
if (!(highPriority)) SDL_Delay(10);
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 4711438..48bc5bb 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp
@@ -102,26 +102,26 @@ void InitMenues()
ButtonGfx::thefont = nf_scoreboard_font;
}
-void runGame(int gametype);
+void runGame(int gametype,int level);
void runSinglePlayerEndless(Button* b)
{
- runGame(0);
+ runGame(0,0);
}
void runSinglePlayerTimeTrial(Button* b)
{
- runGame(1);
+ runGame(1,0);
}
void runSinglePlayerPuzzle(Button* b)
{
- runGame(3);
+ runGame(3,0);
}
void runSinglePlayerVs(Button* b)
{
- runGame(4);
+ runGame(4,b->iGeneric1);
}
void buttonActionMusic(Button* b)
@@ -217,6 +217,48 @@ void ConfigureMenu(Button *b)
cm.run();
}
+void SinglePlayerVsMenu(Button *b)
+{
+ Menu spvs(&screen,_("Single player VS"),true);
+ Button d1,d2,d3,d4,d5,d6,d7;
+ d1.setAction(runSinglePlayerVs);
+ d2.setAction(runSinglePlayerVs);
+ d3.setAction(runSinglePlayerVs);
+ d4.setAction(runSinglePlayerVs);
+ d5.setAction(runSinglePlayerVs);
+ d6.setAction(runSinglePlayerVs);
+ d7.setAction(runSinglePlayerVs);
+ d1.setPopOnRun(true);
+ d2.setPopOnRun(true);
+ d3.setPopOnRun(true);
+ d4.setPopOnRun(true);
+ d5.setPopOnRun(true);
+ d6.setPopOnRun(true);
+ d7.setPopOnRun(true);
+ d1.iGeneric1 = 1;
+ d2.iGeneric1 = 2;
+ d3.iGeneric1 = 3;
+ d4.iGeneric1 = 4;
+ d5.iGeneric1 = 5;
+ d6.iGeneric1 = 6;
+ d7.iGeneric1 = 7;
+ d1.setLabel(_("Very easy"));
+ d2.setLabel(_("Easy"));
+ d3.setLabel(_("Below normal"));
+ d4.setLabel(_("Normal"));
+ d5.setLabel(_("Above normal"));
+ d6.setLabel(_("Hard"));
+ d7.setLabel(_("Hardest"));
+ spvs.addButton(&d1);
+ spvs.addButton(&d2);
+ spvs.addButton(&d3);
+ spvs.addButton(&d4);
+ spvs.addButton(&d5);
+ spvs.addButton(&d6);
+ spvs.addButton(&d7);
+ spvs.run();
+}
+
void MainMenu()
{
InitMenues();
@@ -229,7 +271,7 @@ void MainMenu()
bPuzzle.setLabel(_("Single player - puzzle mode") );
bPuzzle.setAction(runSinglePlayerPuzzle);
bVs1.setLabel(_("Single player - vs") );
- bVs1.setAction(runSinglePlayerVs);
+ bVs1.setAction(SinglePlayerVsMenu);
bConfigure.setLabel(_("Configure") );
bConfigure.setAction(ConfigureMenu);
bHighscore.setLabel(_("Highscores") );