   Game not working (SDL on windows, using VS 2008)
  hey there,I've been, for the past 3 days, coding a game of Pong. I thought it would be a nice start into the world of SDL game development.As a guide i was following Lazy Foo's programing tutorials and articles, so if the coding seems similar, it is for that reason.Now i got the code to compile but there are some serious flaws with it. I was wondering if any one would like to have a look at my code and maybe steer me in the right direction (I've spent that last 6 or so hours trying to fix it).The problems i can see is an error with my SDL event handling/state machine.thank you.   
  If you can post your source code here (using [ source ]  tags) or provide a link to it, and also provide a detailed explanation of what's going wrong with your program, someone will probably be able to help you (or at least offer some suggestions).Posting your code here would probably be best (even better would be to post only the relevant code, or post a simple, complete, working program that demonstrates the problem).   ;  hmm i guess i'll start with the first problem (of many)This is the class declaration of the menu gamestate#ifndef MENU_H#define MENU_H#include "SDL.h"#include "gamestate.h"#include "enum.h"class Menu: public GameState{private://Surfaces used to dislay the background and the two options in the menu screenSDL_Surface* background;//selection bullet rectSDL_Rect selection;//menu state variablesmenuState currentMenuChoice;menuState nextMenuChoice;public:Menu();~Menu();//menu state functionsvoid handle_events();void logic();void render();};#endifThis is the actual code for the functions#include "SDL.h"#include "menu.h"#include "functions.h"#include "globals.h"Menu::Menu(){//load backgroundbackground = load_image("backgroundMenu.png");//set the current menu selection on New Game and next menu choice on nullcurrentMenuChoice = NEWGAME_MENUSTATE;nextMenuChoice = NULL_MENUSTATE;selection.h = 10;selection.w = 10;selection.x = 233;selection.y = 231;}Menu::~Menu(){//Free the surfacesSDL_FreeSurface( background );//To be safebackground = NULL;}void Menu::handle_events(){while( SDL_PollEvent( &event ) ){//If up or down is pressed change the selection respectivelyif( event.type == SDL_KEYDOWN ){switch( event.key.keysym.sym ){//If up or down is pressed change the selection respectivelycase SDLK_UP:case SDLK_DOWN:if( currentMenuChoice == NEWGAME_MENUSTATE ){nextMenuChoice = QUITGAME_MENUSTATE;}if( currentMenuChoice == QUITGAME_MENUSTATE ){nextMenuChoice = NEWGAME_MENUSTATE;}break;//if enter is hit, change to the proper statecase SDLK_RETURN:if( currentMenuChoice == NEWGAME_MENUSTATE ){set_next_gamestate( COURT_STATE );}else if( currentMenuChoice == QUITGAME_MENUSTATE ){set_next_gamestate( EXIT_STATE );}break;}}else if( event.type == SDL_QUIT ){set_next_gamestate( EXIT_STATE );}}}void Menu::logic(){switch( nextMenuChoice ){case NEWGAME_MENUSTATE:selection.x = 233;selection.y = 231;nextMenuChoice = NULL_MENUSTATE;currentMenuChoice = NEWGAME_MENUSTATE;break;case QUITGAME_MENUSTATE:selection.x = 281;selection.y = 269;nextMenuChoice = NULL_MENUSTATE;currentMenuChoice = QUITGAME_MENUSTATE;break;}}void Menu::render(){//Draw background on screenSDL_BlitSurface( background, NULL, screen, NULL );//Draw selection bulletfill_area( selection, 0x00, 0x00, 0x00 );}This works in a loop like this:while( gamestateID != EXIT_STATE)    { //State event handling   currentGamestate->handle_events();currentGamestate->logic();//Change the state if needed   change_gamestate(); //State rendering   currentGamestate->render(); //Update the screen   if( SDL_Flip( screen ) == -1 )   {  return 1;  }}/source]Now the problem here is that in the game, if i get to the quit game part and hit enter nothing happens, nor if i hit the red x.;  Now, I'm not sure, but it looks like it could be a problem with the change_state() code. Could you post that as well?   ;  yeah I thought so too, but for the life of me i can't find an error. So lets hope you guys do :).void change_gamestate(){//If the next state is neither null (no state change required) or exit ( the game'll just quite on the next loop test)if( nextGamestate != NULL_STATE ){if(nextGamestate != EXIT_STATE){delete currentGamestate;}switch( nextGamestate ){case INTRO_STATE:currentGamestate = new Intro();break;case MENU_STATE:currentGamestate = new Menu();break;case COURT_STATE:currentGamestate = new Court();break;}//Update gamestate variablesgamestateID = nextGamestate;nextGamestate = NULL_STATE;}}{/source];  Have you tried stepping through the code in the debugger?   ;  to be honest, I'm very bad with the debugger in vs   ;Quote:to be honest, I'm very bad with the debugger in vsWell, that's usually the best way to solve problems like this. In fact, being able to use the debugger effectively is practically a requirement for any serious C or C++ development.Can you tell us where you're getting hung up when trying to use the debugger? If so, we can probably give you some tips to get you started.   ;Quote:Original post by Iscarrito be honest, I'm very bad with the debugger in vsIt takes some practice:F9 - Toggle break point (pauses execution at this line)F10 - Step over (executes next line of code)F11 - Step intoShift-F11 - Step out (return)F5 - Resume executionDebug->Break all - Pause executionTake advantage of the Debug->Windows->Autos/Locals/Watch windows, as they'll tell you the current values of variables of interest and the return values of functions.  Don't forget about the Debug->Call Stack window which allows you to trace where an exception was thrown and combined with the variable windows, you can tell what conditions caused this error to occur.   ;  Hey thanks man, well i fixed the no exiting problem, thanks the error was in set_next_gamestate(). instead of checking the current stateID for exiting, it checked the nextgamestate. Effectively never changing the state to exit.Well I'll keep working on it more, so i can pinpoint the function that is causing the other problem (the paddles refuse to move :P)Thanks everyone. Still need to get better with the debugger :).Edit: to answer you, i was getting hung up on why the game wouldn't load my images and fonts, I didn't know i needed to put them in another folder :P[Edited by - Iscarri on May 16, 2010 6:28:47 PM]