1
0
mirror of https://github.com/krislamo/Trololo synced 2024-11-10 00:30:35 +00:00

Added MainMenu_survey() to scrns, some minor changes in MainMenu() and the indicator image was rotated.

This commit is contained in:
Kris Lamoureux 2013-01-08 21:36:22 -08:00
parent 1b797b3d69
commit 27773ae391
4 changed files with 113 additions and 25 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

102
core.cpp
View File

@ -1,5 +1,7 @@
#include "main.h" #include "main.h"
using namespace std;
namespace scrnfunk namespace scrnfunk
{ {
// Optimize image on load to reduce processing. // Optimize image on load to reduce processing.
@ -58,7 +60,7 @@ namespace scrnfunk
namespace scrns 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 * initiateSDL(SDL_Surface *screen, int x, int y)
{ {
SDL_Surface *vid_init; SDL_Surface *vid_init;
@ -102,6 +104,8 @@ namespace scrns
return NULL; return NULL;
} }
SDL_FreeSurface(vid_init);
// Success // Success
return screen; return screen;
} }
@ -109,17 +113,17 @@ namespace scrns
SDL_Surface * MainMenu() SDL_Surface * MainMenu()
{ {
// Screen // Screen
SDL_Surface *screen = 0; SDL_Surface *screen = NULL;
SDL_Surface *background = 0;
SDL_Surface *characters = 0;
SDL_Surface *message = 0;
SDL_Surface *background = NULL;
SDL_Surface *characters = NULL;
SDL_Surface *message = NULL;
SDL_Surface *indicator = NULL;
// Image filenames // Image filenames
const char *background_image = "bin/stage1.bmp"; const char *background_image = "bin/stage1.bmp";
const char *characters_image = "bin/characters.bmp"; const char *characters_image = "bin/characters.bmp";
//const char *indicator_image = "bin/indicator.bmp"; const char *indicator_image = "bin/indicator.bmp";
// Char // Char
SDL_Rect clip[2]; SDL_Rect clip[2];
@ -136,6 +140,7 @@ namespace scrns
// Load images // Load images
background = scrnfunk::load_image(background_image); background = scrnfunk::load_image(background_image);
characters = scrnfunk::load_image(characters_image); characters = scrnfunk::load_image(characters_image);
indicator = scrnfunk::load_image(indicator_image);
// The troll's coordinates // The troll's coordinates
clip[0].x = 0; clip[0].x = 0;
@ -220,13 +225,96 @@ namespace scrns
else else
fprintf(stderr, "TFF Render Text Solid Error: apply error\n"); 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 // Update screen with all applied images
if(screen != 0) if(screen != 0)
SDL_Flip(screen); SDL_Flip(screen);
else else
fprintf(stderr, "Couldn't update screen.\n"); fprintf(stderr, "Couldn't update screen.\n");
// Free old surfaces
SDL_FreeSurface(background);
SDL_FreeSurface(characters);
SDL_FreeSurface(message);
SDL_FreeSurface(indicator);
} }
return screen; 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;
}
} }

View File

@ -1,26 +1,24 @@
#include "main.h" #include "main.h"
using namespace std;
int main(int argc, char* args[]) int main(int argc, char* args[])
{ {
SDL_Event event;
int quit = 1;
SDL_Surface *screen; SDL_Surface *screen;
int menu_option = -1;
screen = scrns::MainMenu(); screen = scrns::MainMenu();
if(screen == NULL) while(menu_option == -1)
return 1; {
menu_option = scrns::MainMenu_survey();
// Check if user quit if(menu_option == 1)
while(quit == 1)
{ {
while(SDL_PollEvent(&event)) cout << "Starting new game..." << endl;
{
if(event.type == SDL_QUIT)
quit = 0;
} }
} }
SDL_FreeSurface(screen);
return 0; return 0;
} }

2
main.h
View File

@ -7,12 +7,14 @@
#include "SDL/SDL_ttf.h" // SDL_tff (2.0.11) #include "SDL/SDL_ttf.h" // SDL_tff (2.0.11)
// Standard dependencies // Standard dependencies
#include <iostream>
#include <cstdio> #include <cstdio>
namespace scrns namespace scrns
{ {
SDL_Surface * initiateSDL(SDL_Surface *screen, int x, int y); SDL_Surface * initiateSDL(SDL_Surface *screen, int x, int y);
SDL_Surface * MainMenu(); SDL_Surface * MainMenu();
int MainMenu_survey();
} }
namespace scrnfunk namespace scrnfunk