Hello,
I have a menu where I would like the selected text to be changed to the color yellow from the color white. Basiclly it consists of “New Game”, “Game Options”, and “Quit Game”. I want it to start at “New Game”, when “New Game” is selected, the color of the text should yellow. However when the user pressed down, “Game Options” should be selected and that will turn from white to yellow, while “New Game” reverts back to the white color. How would I go about programming this? I’ll post my code in case that helps.
mainvars.h
Code:
const int MAX_WIDTH = 640;
const int MAX_HEIGHT = 480;
const int MAX_DEPTH = 32;
const char* szTitle = “Convict Paradise - DarkScar Games”;
SDL_Surface* gScreen = NULL;
SDL_Event event;
float deltaTime = 0.0f;
int ClockMins = 0;
int ClockSecs = 0;
TTF_Font* Font = NULL;
Uint8* keyStates = SDL_GetKeyState(NULL);
SDL_Surface* LogoImg;
SDL_Rect LogoDest;
SDL_Surface* TitleImg;
SDL_Rect TitleDest;
SDL_Surface* GameClockImg;
SDL_Rect GameClockRect;
SDL_Rect GameClockDest;
SDL_Surface* HealthBarImg[2];
SDL_Rect HealthBarRect[2];
SDL_Rect HealthBarDest[2];
SDL_Surface* GameMenuText[3];
SDL_Rect GameMenuDest[3];
SDL_Color TextColor = {255,255,255}; //white
SDL_Color BackColor = {0,0,255}; //blue
SDL_Color SelectedText = {255,255,0}; //yellow
int x_menu = 250;
int y_menu = 100;
int mouse_x = 0;
int mouse_y = 0;
bool Blood_Enabled = true;
bool Sound_Enabled = true;
float sound_level = 100.0f;
int sound_counter = 0;
bool LogoScreen = true;
bool TitleScreen = false;
bool PlayerSelectScreen = false;
bool GameScreen = false;
bool OptionScreen = false;
bool IntroScreen = false;
bool EndScene = false;
bool GameRunning = true;
void Cleanup()
{
SDL_FreeSurface(LogoImg);
SDL_FreeSurface(TitleImg);
SDL_FreeSurface(GameMenuText[0]);
SDL_FreeSurface(GameMenuText[1]);
SDL_FreeSurface(GameMenuText[2]);
}
Main.cpp
Code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <wchar.h>
#include <time.h>
#include <GL/GL.h>
#include
#include
#include
#include “SDL.h”
#include “SDL_image.h”
#include “SDL_mixer.h”
#include “SDL_ttf.h”
#include “mainvars.h”
#include “convicts.h”
using namespace std;
int main(int argc, char* argv[])
{
/////////////////////////////////
LogoImg = IMG_Load(“Logo.png”);
LogoDest.x = 0;
LogoDest.y = 0;
LogoDest.w = MAX_WIDTH;
LogoDest.h = MAX_HEIGHT;
TitleImg = IMG_Load("Title.png");
TitleDest.x = 0;
TitleDest.y = 0;
TitleDest.w = MAX_WIDTH;
TitleDest.h = MAX_HEIGHT;
////////////////////////////////
///////////////////////////////
Johnny sJohnny;
Johnny *pJohnny;
pJohnny = &sJohnny;
pJohnny->ihealth = 100;
pJohnny->imax_health = pJohnny->ihealth;
pJohnny->istrength = 15;
pJohnny->idefense = 10;
pJohnny->fspeed = 20.f;
pJohnny->szName = "Johnny";
pJohnny->ipoints = 0;
pJohnny->ikills = 0;
pJohnny->iwins = 0;
pJohnny->ilosts = 0;
///////////////////////////////
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
gScreen = SDL_SetVideoMode(MAX_WIDTH,MAX_HEIGHT,MAX_DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF);
if(gScreen == NULL)
{
return 1;
}
SDL_WM_SetCaption(szTitle, NULL);
if(TTF_Init() == -1)
{
return 1;
}
Font = TTF_OpenFont("ARIAL.ttf",25);
///////////////////////////////////
GameMenuText[0] = TTF_RenderText_Solid(Font,"New Game",TextColor);
GameMenuText[1] = TTF_RenderText_Solid(Font,"Game Options",TextColor);
GameMenuText[2] = TTF_RenderText_Solid(Font,"Quit Game",TextColor);
GameMenuDest[0].x = 250;
GameMenuDest[0].y = 100;
GameMenuDest[0].w = 0;
GameMenuDest[0].h = 0;
GameMenuDest[1].x = 250;
GameMenuDest[1].y = 150;
GameMenuDest[1].w = 0;
GameMenuDest[1].h = 0;
GameMenuDest[2].x = 250;
GameMenuDest[2].y = 200;
GameMenuDest[2].w = 0;
GameMenuDest[2].h = 0;
//////////////////////////////////
if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
return 1;
}
while(GameRunning)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
GameRunning = false;
}
if(event.type == SDL_KEYDOWN)
{
if(keyStates[SDLK_ESCAPE])
{
GameRunning = false;
}
if(keyStates[SDLK_RETURN] && LogoScreen == true)
{
LogoScreen = false;
SDL_FillRect(gScreen,NULL,SDL_MapRGB(gScreen->format,0,0,0));
TitleScreen = true;
}
if(keyStates[SDLK_RETURN] && x_menu == GameMenuDest[0].x && y_menu == GameMenuDest[0].y && TitleScreen == true)
{
TitleScreen = false;
SDL_FillRect(gScreen,NULL,SDL_MapRGB(gScreen->format,0,0,0));
PlayerSelectScreen = true;
}
else if(keyStates[SDLK_RETURN] && x_menu = GameMenuDest[1].x && y_menu == GameMenuDest[1].y && TitleScree == true)
{
TitleScreen = false;
SDL_FillRect(gScreen,NULL,SDL_MapRGB(gScreen->format,0,0,0));
OptionScreen = true;
}
else if(keyStates[SDLK_RETURN] && x_menu = GameMenuDest[2].x && y_menu == GameMenuDest[2].y && TitleScreen == true)
{
GameRunning = false;
}
}
if(LogoScreen == true)
{
SDL_BlitSurface(LogoImg,NULL,gScreen,&LogoDest);
}
if(TitleScreen == true)
{
SDL_BlitSurface(TitleImg,NULL,gScreen,&TitleDest);
SDL_BlitSurface(GameMenuText[0],NULL,gScreen,&GameMenuDest[0]);
SDL_BlitSurface(GameMenuText[1],NULL,gScreen,&GameMenuDest[1]);
SDL_BlitSurface(GameMenuText[2],NULL,gScreen,&GameMenuDest[2]);
}
if(PlayerSelectScreen == true)
{
}
if(OptionScreen == true)
{
}
}
if(SDL_Flip(gScreen) == -1)
{
return 1;
}
}
Cleanup();
Mix_CloseAudio();
TTF_CloseFont(Font);
TTF_Quit();
SDL_Quit();
return 0;
}
Thanks for any help.[/code]