ok,here im with some new question, and also a exemple that works,
im making a simple game, now im working on the menu, i make a code that works, but i tink that not is the best way to do that, and now want that you guys say waht you tink about this.
here is what it does it print 3 menu options:
iniciar
continuar
opcoes
when you press “Up” our “Down” you move on the 3 options, the selected option is printed in RED, and the others in brown.
for this i create a variable (menupos, that starts with value 1 (iniciar))
im also include a screenshot to you guys see the result, im using Sfont to draw the text…
now, how to make this more clean ? and more fast, because i tink that it uses a lot of resources.
thanks for your help.
here come the source:----------------------------------------------
int menu(){
menuinicio:;
show_img(“imagens/menu.bmp”, 0, 100); //print background menu image(menu.bmp)
//load fonts:—>
SFont_Font* fVermel;
SFont_Font* fMarrom;
fMarrom = SFont_InitFont(IMG_Load(“fontes/marrong.png”));
fVermel = SFont_InitFont(IMG_Load(“fontes/arial_red_24_b.png”));
//<—end load Font
//print menu options
SFont_Write(screen, fVermel, 25, 340, “Iniciar”);
SFont_Write(screen, fMarrom, 25, 380, “Continuar”);
SFont_Write(screen, fMarrom, 25, 420, “Opcoes”);
SDL_UpdateRect(screen, 0, 0, 0, 0); //update all
int done=0;
int menupos=1;
while(done == 0)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}
Uint8* keys;
keys = SDL_GetKeyState(NULL);
// printf(“valor de menupos: %d .\n”, menupos ); //just for debug test
SDL_Delay(100);
if ( keys[SDLK_UP] ) {menupos = menupos--;
if (menupos <= 1){menupos =1;}
if (menupos == 1){
SFont_Write(screen, fVermel, 25, 340, "Iniciar");
SFont_Write(screen, fMarrom, 25, 380, "Continuar");
SFont_Write(screen, fMarrom, 25, 420, "Opcoes");
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
if (menupos == 2){
SFont_Write(screen, fMarrom, 25, 340, "Iniciar");
SFont_Write(screen, fVermel, 25, 380, "Continuar");
SFont_Write(screen, fMarrom, 25, 420, "Opcoes");
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
if (menupos == 3){
SFont_Write(screen, fMarrom, 25, 340, "Iniciar");
SFont_Write(screen, fMarrom, 25, 380, "Continuar");
SFont_Write(screen, fVermel, 25, 420, "Opcoes");
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
}
if ( keys[SDLK_DOWN] ) {menupos = menupos++;
if (menupos >= 3){menupos =3;}
if (menupos == 1){
SFont_Write(screen, fVermel, 25, 340, "Iniciar");
SFont_Write(screen, fMarrom, 25, 380, "Continuar");
SFont_Write(screen, fMarrom, 25, 420, "Opcoes");
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
if (menupos == 2){
SFont_Write(screen, fMarrom, 25, 340, "Iniciar");
SFont_Write(screen, fVermel, 25, 380, "Continuar");
SFont_Write(screen, fMarrom, 25, 420, "Opcoes");
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
if (menupos == 3){
SFont_Write(screen, fMarrom, 25, 340, "Iniciar");
SFont_Write(screen, fMarrom, 25, 380, "Continuar");
SFont_Write(screen, fVermel, 25, 420, "Opcoes");
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
}
if ( keys[SDLK_RETURN] ){if (menupos == 3){
show_img("imagens/tvteste.bmp", 0, 8000);
SDL_UpdateRect(screen, 0, 0, 0, 0);
goto menuinicio;
}
}
}
SDL_Delay(300);
}
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: image/jpeg
Size: 7470 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040608/cfcdf960/attachment.jpeg