Hi, I've been working on an interactive titlescreen which is slowly becoming a simple-ish graphical RPG, and I've been solving all my other issues well enough, but... For some reason, the image of the titlescreen doesn't appear until the user hits the up or down arrow key and I can't identify the problem at all. I'm completely at a loss. This is my first project this complex, and I'm just about begging: Can someone find the flaw?? If someone can point out the problem, I'll be eternally grateful! Here's my code, which still has my terminal/debugging messages:
Code:
#include "SDL/SDL.h"
#include <stdio.h>
#include <stdlib.h>
SDL_Surface *screen;
SDL_Event event;
int menuChoice = 0;
int title(), ttlMenu(), newGame(), loadGame();
int main()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialise SDL: %s\n", SDL_GetError());
return 1;
}
SDL_WM_SetCaption("Super Dungeon Lad", NULL);
screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF);
if (screen == NULL) {
printf("Unsable to set video mode: %s\n", SDL_GetError());
return 1;
}
printf("Success!\n");
title();
while (SDL_WaitEvent(&event) != 0) {
switch (event.type) {
case SDL_QUIT:
exit(0);
}
}
return 0;
}
title() {
SDL_Surface *image;
SDL_Rect src, dest;
src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;
dest.h = 480;
dest.w = 640;
dest.x = 0;
dest.y = 0;
image = SDL_LoadBMP("gfx/titleScrn.bmp");
SDL_BlitSurface(image, &src, screen, &dest);
SDL_UpdateRect(screen, 0, 0, 0, 0);
SDL_Flip(screen);
SDL_FreeSurface(image);
if (menuChoice == 1) {
printf("New Game is selected\n");
ttlMenu();
}
else if (menuChoice == 2) {
printf("Continue is selected\n");
ttlMenu();
}
else {
ttlMenu();
}
}
ttlMenu() {
while (SDL_WaitEvent(&event) !=0) {
switch (event.type) {
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_UP) {
menuChoice = 1;
title();
}
else if (event.key.keysym.sym == SDLK_DOWN) {
menuChoice = 2;
title();
}
else if (event.key.keysym.sym == SDLK_RETURN) {
printf("Enter key is pressed.\n");
if (menuChoice == 1) {
printf("New Game!\n");
newGame();
}
else if (menuChoice == 2) {
printf("Continue!\n");
loadGame();
}
else if (menuChoice == 0) {
printf("BZZT! Nothing selected!\n");
ttlMenu();
}
case SDL_QUIT:
exit(0);
}
}}}
newGame() {
printf("This is where the game would start.\n");
}
loadGame() {
printf("This is where the game would display available save data.\n");
}
I understand my code is probably not perfectly orderly, but I'm doing this for my own learning experience, anyway. I hope someone can be of some help. @_@;