From 27773ae3917db4de57cd18b13f8a5273a9b0fc43 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Tue, 8 Jan 2013 21:36:22 -0800 Subject: [PATCH] Added MainMenu_survey() to scrns, some minor changes in MainMenu() and the indicator image was rotated. --- bin/indicator.bmp | Bin 9286 -> 6966 bytes core.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++---- main.cpp | 32 +++++++------- main.h | 2 + 4 files changed, 113 insertions(+), 25 deletions(-) diff --git a/bin/indicator.bmp b/bin/indicator.bmp index 59056ea61f54501a5c69ef17c8058b1f50635e77..a89639a3129cb068ef10061880471187b4ec57b6 100644 GIT binary patch literal 6966 zcmZ?rHIrrl12Z700mKGS%*Y@C7H0s;3v)v-M1XeXZ!KxIvtr9%|GOZ?jx z^iaV{LPo?V#{q+g(_cWjRaXx$mXd!ZS}L*<8F1#)8Tx8%heE%yWv2`1iVfN`Is91Ju~)C zLBj8n^xu^QKO4%ww^x2{uXx!Wv@K4p+CVx%*|xx?YI^OCBRj}(0fruZM*{|V28TJG zt_Ol_Px?4r3iP-Y=JPPx|9M=<`;^FUSy8`o;{FvR{4Y-aUz+}}GW&mR&i}fC|BV%Y zJL zJ&O%~ofP&tJ@RKZ#4$<#N;3X~9FzaQA^(44!N2C>zwH%&x~qTnHvF2<{C#rm>+Xo% zsp|E{VhIXvwLVJ@uOPt@NJ{tY-^<9u#2~~V-K^qsCEWc+h}ZqdfEV$>?~)_FX2kr- zi~nDk{2$_&YM^6)Ayf3fwd8+W$-j=$e_bH-zq9y%d-?y)+F!jbpC+|Gnq0B7v3fy6 zW&gX&|Myk=>jk3ne_b_ydfUEFo$_(PtS3wAH?`$;6y#Rq?K`-iC`Z5)b#``w z>JBaj>2O7l?V%o*LcQ-s`aFpSW~-#gW|Hs@(@8{+1tBjnHkUTlFe;qlM&ieK18G)5O2LqR@ki|47 zpHoqw#B&>zvx43yhki|u`I7^5PYN&@|E~ZBPTs$U;{Tl`e>=HCEKPjhCzTvEQZK4oH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Panz<L2-1dp%jezx z`{FpTUd^&g1{VECOH^Ar;WyI=yOB!R^%TN|g?yDn$dyDEUW!xl;`jF`0{#+9#Q9__ zqDND;qxzxpr!*{~=z@W)>qW$NW-AuckxBIJEJaVmjWoi)P9^keGJ#hT6b+G|rV{u@ zG?t+g9xA(>U%7^ocW0shZv~4wb4iqPS!B#nEY7GUrb9zydj^p=(+RyM=834Qq)SVg zRqleHZs9}cmo>!JB~yB%hLjFHi;a4cr58yu>PV7w#7jBII-+i6qHbFvaq8Oxj++OGW@az^}2X!uWv!$ zUWLY3ibg8AqoYvKkR)m<^>#iv*UI?W(n*wUTWM1K$!pWuba^KwZS~|zmE=g}WJ_hj zN|jus8uQV%m!kcskWtakm=wDl|N4FF(H|(Gvb_miXC=ADl`NH3qPKq!czCv+FJq5-! z=!~lr4O-(0B@cO*4NM82&e1c+Op?F8Wdpg#ido&hRnhP(sanyH+i4)La}~h{E=%ozsojX z+==0{21X@}r}fNl`&ImF_pYVnHx=X^F2k$n$NNvEJ6=CVt68O`aC<2`Pw(zmvG0yW kR-T5k`tp9sE^9dP)=3T?JJfIayYn#6e*3xK|4}^t2R~)oIRF3v diff --git a/core.cpp b/core.cpp index 61cbbf7..3d5b43b 100644 --- a/core.cpp +++ b/core.cpp @@ -1,5 +1,7 @@ #include "main.h" +using namespace std; + namespace scrnfunk { // Optimize image on load to reduce processing. @@ -58,7 +60,7 @@ namespace scrnfunk namespace scrns { - // Returns 1 (true) on success, 0 (false) on error. + // Returns a pointer on success, NULL on an error SDL_Surface * initiateSDL(SDL_Surface *screen, int x, int y) { SDL_Surface *vid_init; @@ -101,6 +103,8 @@ namespace scrns fprintf(stderr, "True Type Font initialization failed: %s", SDL_GetError()); return NULL; } + + SDL_FreeSurface(vid_init); // Success return screen; @@ -109,17 +113,17 @@ namespace scrns SDL_Surface * MainMenu() { // Screen - SDL_Surface *screen = 0; - - SDL_Surface *background = 0; - SDL_Surface *characters = 0; - SDL_Surface *message = 0; + SDL_Surface *screen = NULL; + SDL_Surface *background = NULL; + SDL_Surface *characters = NULL; + SDL_Surface *message = NULL; + SDL_Surface *indicator = NULL; // Image filenames const char *background_image = "bin/stage1.bmp"; const char *characters_image = "bin/characters.bmp"; - //const char *indicator_image = "bin/indicator.bmp"; + const char *indicator_image = "bin/indicator.bmp"; // Char SDL_Rect clip[2]; @@ -136,6 +140,7 @@ namespace scrns // Load images background = scrnfunk::load_image(background_image); characters = scrnfunk::load_image(characters_image); + indicator = scrnfunk::load_image(indicator_image); // The troll's coordinates clip[0].x = 0; @@ -219,14 +224,97 @@ namespace scrns scrnfunk::apply_image(620, 370, message, screen); else fprintf(stderr, "TFF Render Text Solid Error: apply error\n"); + + // Remove white around the indicator image + scrnfunk::RemoveColor(indicator, 0xFF, 0xFF, 0xFF); // white + + // Apply starting point of indicator + scrnfunk::apply_image(550, 306, indicator, screen); // Update screen with all applied images if(screen != 0) SDL_Flip(screen); else fprintf(stderr, "Couldn't update screen.\n"); + + // Free old surfaces + SDL_FreeSurface(background); + SDL_FreeSurface(characters); + SDL_FreeSurface(message); + SDL_FreeSurface(indicator); } return screen; } -} + + int MainMenu_survey() + { + // Return values + // 0 -- User wants to quit + // 1 -- User wants option 1 + // 2 -- User wants option 2 + // -1 -- No input + + SDL_Event event; + int current, menu_option; + bool option_wanted = false; + + current = menu_option = 1; + + while(SDL_PollEvent(&event)) + { + if(event.type == SDL_QUIT) + return 0; + + else if(event.type == SDL_KEYDOWN) + { + + if(event.key.keysym.sym == 274) // down arrow key + { + if(menu_option < 2) // Less than the max amount of options + menu_option++; + + cout << "Down Key, menu_option: " << menu_option << endl; + } + + else if(event.key.keysym.sym == 273) // up arrow key + { + if(menu_option > 1) + menu_option--; + + cout << "Up Key, menu_option: " << menu_option << endl; // debugline + } + + else if(event.key.keysym.sym == 13) // enter key + option_wanted = true; + } + + + + if(menu_option != current) + { + switch(menu_option) + { + case 1: + cout << "Case 1 ::: Menu should change to: " << menu_option << endl; // debugline + case 2: + cout << "Case 2 ::: Menu should change to: " << menu_option << endl; // debugline + } + current = menu_option; + } + + else if(option_wanted) + return menu_option; + + } + + return -1; + } + + + + + + + +} \ No newline at end of file diff --git a/main.cpp b/main.cpp index 0792869..86fc3da 100644 --- a/main.cpp +++ b/main.cpp @@ -1,26 +1,24 @@ #include "main.h" +using namespace std; + int main(int argc, char* args[]) -{ - SDL_Event event; - int quit = 1; - +{ SDL_Surface *screen; + int menu_option = -1; + screen = scrns::MainMenu(); - - if(screen == NULL) - return 1; - - // Check if user quit - while(quit == 1) - { - while(SDL_PollEvent(&event)) - { - if(event.type == SDL_QUIT) - quit = 0; + + while(menu_option == -1) + { + menu_option = scrns::MainMenu_survey(); + + if(menu_option == 1) + { + cout << "Starting new game..." << endl; } } - + + SDL_FreeSurface(screen); return 0; } - diff --git a/main.h b/main.h index aa1b219..c27da06 100644 --- a/main.h +++ b/main.h @@ -7,12 +7,14 @@ #include "SDL/SDL_ttf.h" // SDL_tff (2.0.11) // Standard dependencies +#include #include namespace scrns { SDL_Surface * initiateSDL(SDL_Surface *screen, int x, int y); SDL_Surface * MainMenu(); + int MainMenu_survey(); } namespace scrnfunk