git repos / blockattack-game

commit 38fa9b68

sago007 · 2016-03-12 08:46
38fa9b68d8142dad32c6bb26f017b6f5326415e7 patch · browse files
parent a23ffbc18a807a46bd979026242bc79e5385d942

Added an exit button. Players using touch or mouse can now go back without touching the keyboard.
Ofcourse mouse and touch has not been reimplemented yet but now we are getting ready

Changed files

M source/code/MenuSystem.cpp before
M source/code/MenuSystem.h before
M source/code/main.cpp before
M source/code/mainVars.inc before
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 24d0b9b..134ac99 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -127,21 +127,6 @@ void Menu::drawSelf() {
mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
}
-void Menu::performClick(int x,int y) {
- vector<Button*>::iterator it;
- for (it = buttons.begin(); it < buttons.end(); it++) {
- Button* b = (*it);
- if (b->isClicked(x,y)) {
- b->doAction();
- }
- if (b->isPopOnRun()) {
- running = false;
- }
- }
- if (exit.isClicked(x,y)) {
- running = false;
- }
-}
void Menu::placeButtons() {
int nextY = 100;
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 12ce9b0..f880fda 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h
@@ -106,7 +106,6 @@ private:
// SDL_Surface *background; //Pointer to the background image
void drawSelf(); //Private function to draw the screen
- void performClick(int x, int y); //Private function to call then a click is detected.
void placeButtons(); //Rearanges the buttons to the correct place.
public:
//numberOfItems is the expected numberOfItems for vector initialization
diff --git a/source/code/main.cpp b/source/code/main.cpp index 06c3114..48ffee4 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -31,7 +31,7 @@ http://www.blockattack.net
#ifndef VERSION_NUMBER
-#define VERSION_NUMBER "2.0.0 SNAPSHOT"
+#define VERSION_NUMBER "2.0.0-SNAPSHOT"
#endif
//If DEBUG is defined: AI info and FPS will be written to screen
@@ -83,6 +83,7 @@ http://www.blockattack.net
#include "common.h"
#include <boost/program_options.hpp>
+#include <SDL2/SDL_timer.h>
/*******************************************************************************
* All variables and constant has been moved to mainVars.inc for the overview. *
@@ -181,6 +182,7 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
smiley[2] = holder.GetSprite("smileys2");
smiley[3] = holder.GetSprite("smileys3");
transCover = holder.GetSprite("trans_cover");
+ bExit = holder.GetSprite("b_exit");
bSkip = holder.GetSprite("b_blank");
bNext = holder.GetSprite("b_blank");
bRetry = holder.GetSprite("b_blank");
@@ -1177,6 +1179,8 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
strHolder = itoa(theGame2->GetSpeedLevel());
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
+ //draw exit
+ bExit.Draw(screen,SDL_GetTicks(), xsize-bExitOffset, ysize-bExitOffset);
}
//player2 finnish
@@ -2185,6 +2189,7 @@ int runGame(int gametype, int level) {
if ((!singlePuzzle)&&(!editorMode)) {
//read mouse events
if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
+ //This is the mouse events
bMouseUp = false;
DrawIMG(backgroundImage, screen, 0, 0);
@@ -2220,7 +2225,10 @@ int runGame(int gametype, int level) {
retryLevel(theGame, SDL_GetTicks());
}
-
+ if (mousex > xsize-bExitOffset && mousex < xsize-bExitOffset+bExitSize &&
+ mousey > ysize-bExitOffset && mousey < ysize-bExitOffset+bExitSize) {
+ done = 1;
+ }
//cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl;
}
diff --git a/source/code/mainVars.inc b/source/code/mainVars.inc index 7b4d1e6..adc5cb4 100644 --- a/source/code/mainVars.inc +++ b/source/code/mainVars.inc
@@ -98,6 +98,9 @@ static sago::SagoSprite transCover; //The transperant block, covers the u
static sago::SagoSprite bSkip;
static sago::SagoSprite bRetry;
sago::SagoSprite bNext;
+static sago::SagoSprite bExit;
+const int bExitSize = 100; //height and width of the exit button
+const int bExitOffset = 140; //pixels from the buttom right corner to the top left of the exit button
sago::SagoSprite menuMarked;
sago::SagoSprite menuUnmarked;