git repos / blockattack-game

commit 42f05434

sago007 · 2012-04-19 20:25
42f054343157bbd9f86af4d6acc23b51d82ab023 patch · browse files
parent aede0664f354f89f2355d5c937f261efa8b5d969

Some small fixes to the mouse hover in LevelSelect


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

Changed files

M source/code/main.cpp before
diff --git a/source/code/main.cpp b/source/code/main.cpp index ed3bf76..90b4b0c 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1700,205 +1700,6 @@ static string getKeyName(SDLKey key)
void MakeBackground(int xsize,int ysize,BlockGame &theGame, BlockGame &theGame2);
-/*int OpenControlsBox(int x, int y, int player)
-{
- int mousex, mousey;
- Uint8 *keys;
- bool done =false;
- string keyname;
- MakeBackground(xsize,ysize);
- while (!done && !Config::getInstance()->isShuttingDown())
- {
- SDL_Delay(10);
- DrawIMG(background, screen, 0, 0);
- DrawIMG(changeButtonsBack,screen,x,y);
- if (player == 0)
- NFont_Write(screen, x+40,y+2,"Player 1 keys");
- else
- NFont_Write(screen, x+40,y+2,"Player 2 keys");
- NFont_Write(screen, x+6,y+50,"Up");
- keyname = getKeyName(keySettings[player].up);
- NFont_Write(screen, x+200,y+50,keyname.c_str());
- NFont_Write(screen, x+6,y+100,"Down");
- keyname = getKeyName(keySettings[player].down);
- NFont_Write(screen, x+200,y+100,keyname.c_str());
- NFont_Write(screen, x+6,y+150,"Left");
- keyname = getKeyName(keySettings[player].left);
- NFont_Write(screen, x+200,y+150,keyname.c_str());
- NFont_Write(screen, x+6,y+200,"Right");
- keyname = getKeyName(keySettings[player].right);
- NFont_Write(screen, x+200,y+200,keyname.c_str());
- NFont_Write(screen, x+6,y+250,"Push");
- keyname = getKeyName(keySettings[player].push);
- NFont_Write(screen, x+200,y+250,keyname.c_str());
- NFont_Write(screen, x+6,y+300,"Change");
- keyname = getKeyName(keySettings[player].change);
- NFont_Write(screen, x+200,y+300,keyname.c_str());
- //Ask for mouse play
- NFont_Write(screen, x+6,y+350,"Mouse play?");
- DrawIMG(iLevelCheckBox,screen,x+220,y+350);
- if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
- DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
- //Ask for joypad play
- NFont_Write(screen, x+300,y+350,"Joypad?");
- DrawIMG(iLevelCheckBox,screen,x+460,y+350);
- if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
- DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
- for (int i=1; i<7; i++)
- DrawIMG(bChange,screen,x+420,y+50*i);
- SDL_Event event;
-
- while (SDL_PollEvent(&event))
- {
- if ( event.type == SDL_QUIT ) {
- Config::getInstance()->setShuttingDown(5);
- done = true;
- }
-
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_ESCAPE)
- done = true;
- }
- } //PollEvent
-
- keys = SDL_GetKeyState(NULL);
-
- SDL_GetMouseState(&mousex,&mousey);
-
- // If the mouse button is released, make bMouseUp equal true
- if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
- {
- bMouseUp=true;
- }
-
- if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
- {
- bMouseUp = false;
-
- if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(50+y)) && (mousey<(90+y)))
- {
- //up
- bool finnish = false;
- while (!finnish)
- while ( SDL_PollEvent(&event) )
- {
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym != SDLK_ESCAPE)
- keySettings[player].up = event.key.keysym.sym;
- finnish = true;
- }
- }
- } //up
- if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(100+y)) && (mousey<(140+y)))
- {
- //down
- bool finnish = false;
- while (!finnish)
- while ( SDL_PollEvent(&event) )
- {
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym != SDLK_ESCAPE)
- keySettings[player].down = event.key.keysym.sym;
- finnish = true;
- }
- }
- } //down
- if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(150+y)) && (mousey<(190+y)))
- {
- //left
- bool finnish = false;
- while (!finnish)
- while ( SDL_PollEvent(&event) )
- {
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym != SDLK_ESCAPE)
- keySettings[player].left = event.key.keysym.sym;
- finnish = true;
- }
- }
- } //left
- if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(200+y)) && (mousey<(240+y)))
- {
- //right
- bool finnish = false;
- while (!finnish)
- while ( SDL_PollEvent(&event) )
- {
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym != SDLK_ESCAPE)
- keySettings[player].right = event.key.keysym.sym;
- finnish = true;
- }
- }
- } //right
- if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(250+y)) && (mousey<(290+y)))
- {
- //push
- bool finnish = false;
- while (!finnish)
- while ( SDL_PollEvent(&event) )
- {
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym != SDLK_ESCAPE)
- keySettings[player].push = event.key.keysym.sym;
- finnish = true;
- }
- }
- } //push
- if ((mousex>(420+x)) && (mousex<(540+x)) && (mousey>(300+y)) && (mousey<(340+y)))
- {
- //change
- bool finnish = false;
- while (!finnish)
- while ( SDL_PollEvent(&event) )
- {
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym != SDLK_ESCAPE)
- keySettings[player].change = event.key.keysym.sym;
- finnish = true;
- }
- }
- } //change
- //mouseplay:
- if ((mousex>(220+x)) && (mousex<(262+x)) && (mousey>(350+y)) && (mousey<(392+y)))
- {
- if (player==0)
- {
- mouseplay1 = !mouseplay1;
- }
- else
- {
- mouseplay2 = !mouseplay2;
- }
- }
- //Joyplay:
- if ((mousex>(460+x)) && (mousex<(502+x)) && (mousey>(350+y)) && (mousey<(392+y)))
- {
- if (player==0)
- {
- joyplay1 = !joyplay1;
- }
- else
- {
- joyplay2 = !joyplay2;
- }
- }
- } //get mouse state
-
- //DrawIMG(mouse,screen,mousex,mousey);
- mouse.PaintTo(screen,mousex,mousey);
- SDL_Flip(screen);
- } //while !done
- DrawIMG(background, screen, 0, 0);
- return 0;
-}**/
//Dialogbox
@@ -2981,11 +2782,12 @@ int PuzzleLevelSelect(int Type)
{
int tmpSelected = -1;
int j;
- for (j = 0; (j<nrOfLevels/10)||((j<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)); j++)
+ for (j = 0; (tmpSelected == -1) && ( (j<nrOfLevels/10)||((j<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)) ); j++)
if ((60+j*50<mousey-yplace)&&(mousey-yplace<j*50+92))
tmpSelected = j*10;
+ cout << j << endl;
if (tmpSelected != -1)
- for (int k = 0; ((k<nrOfStageLevels%(j*10))&&(k<10)); k++)
+ for (int k = 0; (( (!(nrOfLevels%10) || k<nrOfLevels-10*(j-1)) )&&(k<10)); k++)
if ((10+k*50<mousex-xplace)&&(mousex-xplace<k*50+42))
{
tmpSelected +=k;
@@ -3047,252 +2849,6 @@ int PuzzleLevelSelect(int Type)
return levelNr;
}
-//The function that allows the player to choose Level number
-/*int StageLevelSelect()
-{
- const int xplace = 200;
- const int yplace = 300;
- Uint8 *keys;
- int levelNr, mousex, mousey;
- bool levelSelected = false;
- bool tempBool;
- Uint32 tempUInt32;
- Uint32 totalScore = 0;
- Uint32 totalTime = 0;
-
- //Keeps track of background;
- //int nowTime=SDL_GetTicks();
-
- MakeBackground(xsize,ysize);
- ifstream stageFile(stageClearSavePath.c_str(),ios::binary);
- if (stageFile)
- {
- for (int i = 0; i<nrOfStageLevels; i++)
- {
- stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool));
- stageCleared[i]=tempBool;
- }
- if(!stageFile.eof())
- {
- for(int i=0; i<nrOfStageLevels; i++)
- {
- tempUInt32 = 0;
- if(!stageFile.eof())
- stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
- stageScores[i]=tempUInt32;
- totalScore+=tempUInt32;
- }
- for(int i=0; i<nrOfStageLevels; i++)
- {
- tempUInt32 = 0;
- if(!stageFile.eof())
- stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32));
- stageTimes[i]=tempUInt32;
- totalTime += tempUInt32;
- }
- }
- else
- {
- for(int i=0; i<nrOfStageLevels; i++)
- {
- stageScores[i]=0;
- stageTimes[i]=0;
- }
- }
- stageFile.close();
- }
- else
- {
- for (int i=0; i<nrOfStageLevels; i++)
- {
- stageCleared[i]= false;
- stageScores[i]=0;
- stageTimes[i]=0;
- }
- }
-
-
- do
- {
- //nowTime=SDL_GetTicks();
- DrawIMG(background, screen, 0, 0);
- DrawIMG(iCheckBoxArea,screen,xplace,yplace);
- NFont_Write(screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
- for (int i = 0; i < nrOfStageLevels; i++)
- {
- DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
- if (stageCleared[i]==true) DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
- }
-
- SDL_Event event;
- while ( SDL_PollEvent(&event) )
- if ( event.type == SDL_KEYDOWN )
- {
- if ( event.key.keysym.sym == SDLK_ESCAPE )
- {
- levelNr = -1;
- levelSelected = true;
- }
- }
-
- keys = SDL_GetKeyState(NULL);
-
- SDL_GetMouseState(&mousex,&mousey);
-
- // If the mouse button is released, make bMouseUp equal true
- if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
- {
- bMouseUp=true;
- }
-
- if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
- {
- bMouseUp = false;
-
- int levelClicked = -1;
- int i;
- for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
- if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
- levelClicked = i*10;
- i++;
- if (levelClicked != -1)
- for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
- if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
- {
- levelClicked +=j;
- levelSelected = true;
- levelNr = levelClicked;
- }
- }
- //Find what we are over:
- int overLevel = -1;
- int i;
- for (i = 0; (i<nrOfStageLevels/10)||((i<nrOfStageLevels/10+1)&&(nrOfStageLevels%10 != 0)); i++)
- if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92))
- overLevel = i*10;
- i++;
- if (overLevel != -1)
- for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++)
- if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42))
- {
- overLevel +=j;
- string scoreString = _("Best score: 0");
- string timeString = _("Time used: -- : --");
-
- if(stageScores.at(overLevel)>0)
- scoreString = _("Best score: ")+itoa(stageScores[overLevel]);
- if(stageTimes[overLevel]>0)
- timeString = _("Time used: ")+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
-
- NFont_Write(screen, 200,200,scoreString.c_str());
- NFont_Write(screen, 200,250,timeString.c_str());
-
- overLevel;
- }
- string totalString = (format("Total score: %1% in %2%:%3%")%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str(); //"Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
- NFont_Write(screen, 200,600,totalString.c_str());
-
- //DrawIMG(mouse,screen,mousex,mousey);
- mouse.PaintTo(screen,mousex,mousey);
- SDL_Flip(screen); //draws it all to the screen
-
- }
- while (!levelSelected);
- DrawIMG(background, screen, 0, 0);
- return levelNr;
-}*/
-
-//Ask user for what AI level he will compete agains, return the number. Number must be 0..AIlevels
-/*int startSingleVs()
-{
- //Where to place the windows
- const int xplace = 200;
- const int yplace = 100;
- Uint8 *keys; //To take keyboard input
- int mousex, mousey; //To allow mouse
- bool done = false; //When are we done?
-
- MakeBackground(xsize,ysize);
- DrawIMG(changeButtonsBack,background,xplace,yplace);
- NFont_Write(background, xplace+10,yplace+10,_("1 : Very Easy") );
- NFont_Write(background, xplace+10,yplace+40,_("2 : Easy") );
- NFont_Write(background, xplace+10,yplace+70,_("3 : Below Normal") );
- NFont_Write(background, xplace+10,yplace+100,_("4 : Normal") );
- NFont_Write(background, xplace+10,yplace+130,_("5 : Above Normal") );
- NFont_Write(background, xplace+10,yplace+160,_("6 : Hard") );
- NFont_Write(background, xplace+10,yplace+190,_("7 : Hardest") );
- DrawIMG(background, screen, 0, 0);
- SDL_Flip(screen);
- do
- {
-
- SDL_Delay(10);
- SDL_Event event;
- while ( SDL_PollEvent(&event) )
- if ( event.type == SDL_KEYDOWN )
- {
- if ( event.key.keysym.sym == SDLK_KP_ENTER || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN )
- {
- done = true;
- }
- if ( event.key.keysym.sym == SDLK_1 || event.key.keysym.sym == SDLK_KP1 )
- {
- return 0;
- }
- if ( event.key.keysym.sym == SDLK_2 || event.key.keysym.sym == SDLK_KP2 )
- {
- return 1;
- }
- if ( event.key.keysym.sym == SDLK_3 || event.key.keysym.sym == SDLK_KP3 )
- {
- return 2;
- }
- if ( event.key.keysym.sym == SDLK_4 || event.key.keysym.sym == SDLK_KP4 )
- {
- return 3;
- }
- if ( event.key.keysym.sym == SDLK_5 || event.key.keysym.sym == SDLK_KP5 )
- {
- return 4;
- }
- if ( event.key.keysym.sym == SDLK_6 || event.key.keysym.sym == SDLK_KP6 )
- {
- return 5;
- }
- if ( event.key.keysym.sym == SDLK_7 || event.key.keysym.sym == SDLK_KP7 )
- {
- return 6;
- }
- }
-
- // If the mouse button is released, make bMouseUp equal true
- if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
- {
- bMouseUp=true;
- }
-
- if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp)
- {
- bMouseUp = false;
-
- for (int i=0; i<7; i++)
- {
- if ((mousex>xplace+10)&&(mousex<xplace+410)&&(mousey>yplace+10+i*30)&&(mousey<yplace+38+i*30))
- return i;
- }
- }
-
- SDL_GetMouseState(&mousex,&mousey);
- DrawIMG(background, screen, 0, 0);
- //DrawIMG(mouse,screen,mousex,mousey);
- mouse.PaintTo(screen,mousex,mousey);
- SDL_Flip(screen); //draws it all to the screen
- }
- while (!done && !Config::getInstance()->isShuttingDown());
-
-
- return 3; //Returns normal
-}*/
//The function that allows the player to choose Level number
void startVsMenu()
@@ -4348,85 +3904,6 @@ int runGame(int gametype, int level)
*/
mustsetupgame = true;
}
- if ( event.key.keysym.sym == SDLK_F3 )
- {
-#if NETWORK
- if ((!showOptions)&&(!networkActive))
- {
-#else
- if ((!showOptions))
- {
-#endif
- StartSinglePlayerTimeTrial();
- }
- }
- if ( event.key.keysym.sym == SDLK_F5 )
- {
-#if NETWORK
- if ((!showOptions)&&(!networkActive))
-#else
- if ((!showOptions))
-#endif
- {
- int myLevel = PuzzleLevelSelect(1);
- theGame.NewStageGame(myLevel,50,100,SDL_GetTicks());
- MakeBackground(xsize,ysize,&theGame,&theGame2);
- DrawIMG(background, screen, 0, 0);
- closeAllMenus();
- twoPlayers =false;
- theGame2.SetGameOver();
- showGame = true;
- vsMode = false;
- strcpy(theGame.name, player1name);
- strcpy(theGame2.name, player2name);
- }
- }
- if ( event.key.keysym.sym == SDLK_F6 )
- {
-#if NETWORK
- if ((!showOptions)&&(!networkActive))
-#else
- if ((!showOptions))
-#endif
- {
- StartTwoPlayerVs();
- }
- }
- if ( event.key.keysym.sym == SDLK_F4 )
- {
-#if NETWORK
- if ((!showOptions)&&(!networkActive))
-#else
- if ((!showOptions))
-#endif
- {
- StarTwoPlayerTimeTrial();
- }
- }
- if ( event.key.keysym.sym == SDLK_F7 )
- {
-#if NETWORK
- if ((!showOptions)&&(!networkActive))
-#else
- if ((!showOptions))
-#endif
- {
- int myLevel = PuzzleLevelSelect(0);
- theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks());
- MakeBackground(xsize,ysize,&theGame,&theGame2);
- DrawIMG(background, screen, 0, 0);
- closeAllMenus();
- twoPlayers = false;
- theGame2.SetGameOver();
- showGame = true;
- vsMode = true;
- strcpy(theGame.name, player1name);
- strcpy(theGame2.name, player2name);
- }
- }
- if ( event.key.keysym.sym == SDLK_F8 )
- {
- }
if ( event.key.keysym.sym == SDLK_F9 )
{
writeScreenShot();
@@ -4438,7 +3915,7 @@ int runGame(int gametype, int level)
//theGame.CreateGreyGarbage();
//char mitNavn[30];
//SelectThemeDialogbox(300,400,mitNavn);
- MainMenu();
+ //MainMenu();
//OpenScoresDisplay();
} //F11
}
@@ -4913,7 +4390,6 @@ int runGame(int gametype, int level)
oldMousex = mousex;
oldMousey = mousey;
//Draw the mouse:
- //DrawIMG(mouse,screen,mousex,mousey);
mouse.PaintTo(screen,mousex,mousey);
SDL_Flip(screen);
} //game loop