git repos / blockattack-game

commit 20d77c6e

sago007 · 2016-11-12 16:28
20d77c6ea490a1e00c31f498f5f62428090e9ba5 patch · browse files
parent 95ab6b0dcd46d73c9273d1dfc1e9071eb79a85bf

Removed the old "run" on the menu. Also made the mousex and mousey global because the recent resize require that they are set at all times.

Changed files

M source/code/MenuSystem.cpp before
M source/code/MenuSystem.h before
M source/code/ScoresDisplay.cpp before
M source/code/ScoresDisplay.hpp before
M source/code/global.hpp before
M source/code/main.cpp before
M source/code/menudef.cpp before
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 502d39f..e515e6b 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -28,8 +28,8 @@ http://www.blockattack.net
#include "gamecontroller.h"
#include "BlockGame.hpp"
-static int mousex;
-static int mousey;
+static int oldmousex = 0;
+static int oldmousey = 0;
using std::string;
using std::cerr;
@@ -116,7 +116,6 @@ void Menu::drawSelf(SDL_Renderer* target) {
}
drawToScreen(exit);
standardButton.thefont->draw(target, 50, 50, "%s", title.c_str());
- globalData.mouse.Draw(target, SDL_GetTicks(), mousex, mousey);
}
@@ -304,7 +303,7 @@ void Menu::Draw(SDL_Renderer* target) {
drawSelf(target);
}
void Menu::ProcessInput(const SDL_Event& event, bool &processed) {
- UpdateMouseCoordinates(event, mousex, mousey);
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
if ( event.type == SDL_QUIT ) {
Config::getInstance()->setShuttingDown(5);
running = false;
@@ -353,50 +352,34 @@ void Menu::Update() {
bMouseUp=true;
}
- if (abs(mousex-oldmousex)>5 || abs(mousey-oldmousey)>5) {
+ if (abs(globalData.mousex-oldmousex)>5 || abs(globalData.mousey-oldmousey)>5) {
for (int i=0; i< (int)buttons.size(); ++i) {
- if (isClicked(*buttons.at(i),mousex,mousey)) {
+ if (isClicked(*buttons.at(i), globalData.mousex, globalData.mousey)) {
marked = i;
}
}
- if (isClicked(exit, mousex, mousey)) {
+ if (isClicked(exit, globalData.mousex, globalData.mousey)) {
marked = buttons.size();
}
- oldmousex = mousex;
- oldmousey = mousey;
+ oldmousex = globalData.mousex;
+ oldmousey = globalData.mousey;
}
//mouse clicked
if ( (buttonState&SDL_BUTTON(1) )==SDL_BUTTON(1) && bMouseUp) {
bMouseUp = false;
for (int i=0; i< (int)buttons.size(); ++i) {
- if (isClicked(*buttons.at(i),mousex,mousey)) {
+ if (isClicked(*buttons.at(i), globalData.mousex, globalData.mousey)) {
buttons.at(i)->doAction();
if (buttons.at(i)->isPopOnRun()) {
running = false;
}
- mousex = 0;
+ globalData.mousex = 0;
}
}
- if (isClicked(exit, mousex, mousey)) {
+ if (isClicked(exit, globalData.mousex, globalData.mousey)) {
running = false;
}
}
}
-void Menu::run() {
- running = true;
- while (running && !Config::getInstance()->isShuttingDown()) {
- if (!(globalData.highPriority)) {
- SDL_Delay(10);
- }
- SDL_Event event;
- bool processed = false;
- while ( SDL_PollEvent(&event) ) {
- ProcessInput(event,processed);
- }
- Update();
- Draw(screen);
- SDL_RenderPresent(screen);
- }
-}
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 16463f1..8e35941 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h
@@ -96,8 +96,6 @@ private:
std::string title;
void drawSelf(SDL_Renderer* target); //Private function to draw the screen
void placeButtons(); //Rearanges the buttons to the correct place.
- int oldmousex = 0;
- int oldmousey = 0;
bool bMouseUp = false;
public:
//numberOfItems is the expected numberOfItems for vector initialization
@@ -109,9 +107,6 @@ public:
//Add a button to the menu
void addButton(Button *b);
-
- //Run the menu
- void run();
bool IsActive() override;
void Draw(SDL_Renderer* target) override;
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 9b80fa2..d21c826 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp
@@ -170,7 +170,7 @@ void ScoresDisplay::Draw(SDL_Renderer*) {
void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
- UpdateMouseCoordinates(event, mousex, mousey);
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
if (isLeftEvent(event)) {
page++;
@@ -204,12 +204,12 @@ void ScoresDisplay::Update() {
bMouseUp = false;
//The Score button:
- if ((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize)) {
+ if ((globalData.mousex>scoreX) && (globalData.mousex<scoreX+buttonXsize) && (globalData.mousey>scoreY) && (globalData.mousey<scoreY+buttonYsize)) {
isActive = false;
}
//The back button:
- if ((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize)) {
+ if ((globalData.mousex>backX) && (globalData.mousex<backX+buttonXsize) && (globalData.mousey>backY) && (globalData.mousey<backY+buttonYsize)) {
page--;
if (page<0) {
page = numberOfPages-1;
@@ -217,7 +217,7 @@ void ScoresDisplay::Update() {
}
//The next button:
- if ((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize)) {
+ if ((globalData.mousex>nextX) && (globalData.mousex<nextX+buttonXsize) && (globalData.mousey>nextY) && (globalData.mousey<nextY+buttonYsize)) {
page++;
if (page>=numberOfPages) {
page = 0;
diff --git a/source/code/ScoresDisplay.hpp b/source/code/ScoresDisplay.hpp index f8f5d3a..20922e7 100644 --- a/source/code/ScoresDisplay.hpp +++ b/source/code/ScoresDisplay.hpp
@@ -43,8 +43,6 @@ public:
int scoreY = 0;
int buttonXsize = 0;
int buttonYsize = 0;
- int mousex = 0;
- int mousey = 0;
private:
void DrawHighscores(int x, int y, bool endless);
void DrawStats();
diff --git a/source/code/global.hpp b/source/code/global.hpp index c2eccc4..e18d029 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp
@@ -66,6 +66,8 @@ struct GlobalData {
//The xsize and ysize are updated everytime the background is drawn
int xsize = 1024;
int ysize = 768;
+ int mousex = 0;
+ int mousey = 0;
};
extern GlobalData globalData;
diff --git a/source/code/main.cpp b/source/code/main.cpp index 7174326..7870694 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -611,7 +611,6 @@ static string getKeyName(SDL_Keycode key) {
void RunGameState(sago::GameStateInterface& state ) {
- int mousex,mousey;
bool done = false; //We are done!
while (!done && !Config::getInstance()->isShuttingDown()) {
state.Draw(globalData.screen);
@@ -622,7 +621,7 @@ void RunGameState(sago::GameStateInterface& state ) {
bool mustWriteScreenshot = false;
while ( SDL_PollEvent(&event) ) {
- UpdateMouseCoordinates(event, mousex, mousey);
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
if ( event.type == SDL_QUIT ) {
Config::getInstance()->setShuttingDown(5);
done = true;
@@ -639,7 +638,7 @@ void RunGameState(sago::GameStateInterface& state ) {
state.Update();
- globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), mousex, mousey);
+ globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey);
SDL_RenderPresent(globalData.screen);
if (mustWriteScreenshot) {
writeScreenShot();
@@ -886,7 +885,6 @@ int PuzzleLevelSelect(int Type) {
const int xplace = 200;
const int yplace = 300;
int levelNr = 0;
- int mousex, mousey;
int oldmousex = 0;
int oldmousey = 0;
bool levelSelected = false;
@@ -934,7 +932,7 @@ int PuzzleLevelSelect(int Type) {
SDL_Event event;
while ( SDL_PollEvent(&event) ) {
- UpdateMouseCoordinates(event, mousex, mousey);
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
if ( event.type == SDL_QUIT ) {
Config::getInstance()->setShuttingDown(5);
@@ -977,25 +975,25 @@ int PuzzleLevelSelect(int Type) {
SDL_GetKeyboardState(nullptr);
- if (mousex != oldmousex || mousey != oldmousey) {
+ if (globalData.mousex != oldmousex || globalData.mousey != oldmousey) {
int tmpSelected = -1;
int 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)) {
+ if ((60+j*50<globalData.mousey-yplace)&&(globalData.mousey-yplace<j*50+92)) {
tmpSelected = j*10;
}
}
if (tmpSelected != -1) {
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)) {
+ if ((10+k*50<globalData.mousex-xplace)&&(globalData.mousex-xplace<k*50+42)) {
tmpSelected +=k;
selected = tmpSelected;
}
}
}
}
- oldmousey = mousey;
- oldmousex= mousex;
+ oldmousey = globalData.mousey;
+ oldmousex= globalData.mousex;
// If the mouse button is released, make bMouseUp equal true
if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) {
@@ -1008,13 +1006,13 @@ int PuzzleLevelSelect(int Type) {
int levelClicked = -1;
int i;
for (i = 0; (i<nrOfLevels/10)||((i<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)); i++)
- if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92)) {
+ if ((60+i*50<globalData.mousey-yplace)&&(globalData.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)) {
+ if ((10+j*50<globalData.mousex-xplace)&&(globalData.mousex-xplace<j*50+42)) {
levelClicked +=j;
levelSelected = true;
levelNr = levelClicked;
@@ -1035,7 +1033,7 @@ int PuzzleLevelSelect(int Type) {
NFont_Write(globalData.screen, 200,600,totalString.c_str());
}
- globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), mousex, mousey);
+ globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey);
SDL_RenderPresent(globalData.screen); //draws it all to the screen
}
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 369b055..572d591 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp
@@ -182,7 +182,7 @@ static void ChangeKeysMenu(long playernumber) {
km.addButton(&bDown);
km.addButton(&bPush);
km.addButton(&bSwitch);
- km.run();
+ RunGameState(km);
}
static void ChangeKeysMenu1() {
@@ -218,7 +218,7 @@ static void ConfigureMenu() {
cm.addButton(&bPlayer2Name);
cm.addButton(&bPlayer1Keys);
cm.addButton(&bPlayer2Keys);
- cm.run();
+ RunGameState(cm);
}
static void SinglePlayerVsMenu() {
@@ -252,7 +252,7 @@ static void SinglePlayerVsMenu() {
spvs.addButton(&d5);
spvs.addButton(&d6);
spvs.addButton(&d7);
- spvs.run();
+ RunGameState(spvs);
}
static void MultiplayerMenu() {
@@ -264,7 +264,7 @@ static void MultiplayerMenu() {
bVs.setAction(runTwoPlayerVs);
mm.addButton(&bTT);
mm.addButton(&bVs);
- mm.run();
+ RunGameState(mm);
}
void MainMenu() {