parinho7

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

213 Neutral

About parinho7

  • Rank
    Newbie
  1. Game crashes for no obvious reason, help please

    It works perfectly, thank you. Thanks everyone for the replies, you were all very helpful. May I ask one last thing? Recommendations on book and links to study about FSM for games and also some advanced matters of C++. For example, I now know what this line does MainMenuState() : GameState() but I don't know what the syntax actually mean. Where can I find that? I was also unaware of the existence of "shared_ptr" where can I study about stuff I don't know they exist?!. Thanks again!!
  2. Game crashes for no obvious reason, help please

    Ah, I see. No, it is illegal to modify "this", at least in C++. This means your design has failed, and you need to rethink it. Why do you need different classes for State_Main_Menu, State_Exit, etc...? Is an enum flag not enough? What are you trying to do, exactly? It looks like you are trying to implement a state machine for your GUI, but this is clearly not the right approach here, as the language is very clearly telling you "don't do this". It's my first try to use a finite state machine in my game (the point of the whole game was to learn how to write a FSM), to navigate through the menus. Apparently I need to find some other way to do this. But as I say to my original post I did almost an exact console application that worked this way. Here is the code void CStateManager::change_state(GameStates *cur_state, int next_state){ if (next_state != STATE_NULL) delete cur_state; switch (next_state){ case STATE_MAIN_MENU: cur_state = new State_Main_Menu(); break; case STATE_PLAYING: cur_state = new State_Playing(); break; case STATE_EXIT: cur_state = new State_Exit(); break; } } State_Main_Menu::State_Main_Menu(){ stateID = STATE_MAIN_MENU; nextState = STATE_NULL; } void State_Main_Menu::Event(){ cin >> nextState; } void State_Main_Menu::Update(){ CStateManager::change_state(this, nextState); } void State_Main_Menu::Render(){ cout << "MAIN MENU" << endl; cout << "Press '3' to play" << endl; cout << "Press '0' to continue in Main Menu" << endl; // system("cls"); } int main(int argc, char* argv[]){ GameStates *myState = new State_Main_Menu(); while (myState->Get_nextState() != STATE_EXIT){ myState->Event(); myState->Update(); myState->Render(); } return 0; } and it worked as intended, never get an exception by that code. All I was doing was somewhat copying that and adding the SDL stuff!
  3. Game crashes for no obvious reason, help please

    I understand the problem now, thank you. The call to the function was this: CStateManager::change_state(this, nextState); How can I modify it so that "this" is passed by reference? (If it's possible at all)
  4. Game crashes for no obvious reason, help please

    I hope this will help: I am not familiar with the debugger, I think that the State instance doesn't have a value. For some reason this doesn't work well void CStateManager::change_state(GameStates *cur_state, int next_state){ if (next_state != STATE_NULL) delete cur_state; switch (next_state) { case STATE_MAIN_MENU: cur_state = new State_Main_Menu(); break; case STATE_EXIT: cur_state = new State_Exit(); break; } } and it doesn't execute the cur_state = new State_Exit(); BUT, I have a cout at the constructor and I do get the output so the object is constructed.
  5. I do one thing it runs fine. I try it again, it crashes. what's happening? I am trying to use for the first time a finite state machine in my game. The whole reason of making the game is to use a FSM. So, I have two states, STATE_MAIN_MENU and STATE_EXIT. I have my abstract class, two derived classes for the two states and all. I have already done a similar console application and everything works fine, but here when I am getting from main menu to exit the game crashes, but not all the times. It runs fine for 2-3 times (deletes currentState instance of State_Main_Menu and then currentState = new State_Exit()). The thing is that I put a cout at the constructor of State_Exit and it does construct the class. But then when a function of class is about to run it crushes. I can't explain it any better, I am attaching the code if anyone could help me I'd appreciate it, because I am getting crazy here! Thanks in advance!
  6. Do I need a frame cap?

    I am completing some beginner projects with c++ and SDL and I've read most of the lazy foo and sdltutorials. Up until now I used "frame independent movement" (as one of the tutorials explains) in the games I've made. Searching around I saw that the code in many tutorials uses regulated frame rate (using SDL_Delay). I was thinking witch method is better? Since with "frame independent" the program can run in my pc at about 175 fps isn't it better to just leave it uncapped? I am in a learning process right now and I'd like to learn from people here on this matter. Thanks in advance!
  7. Movement problem in snake game

    [quote name='deathwearer' timestamp='1355187221' post='5009258'] if your game is somewhat "TIck based" (like the original Snake) only allow one direction change per tick. There would be one draw by tick so you couldn't go from up to down without at least going left of right for a tick. [/quote] YES! thank you, problem solved!!!
  8. I am in the process of making a classic snake game but I have a problem with the movement. If the snake goes up it normally won't react if you press down. But if it goes up and then I hit right(or left) and then quickly hit down the program isn't able to render it but apparently it recognizes the change of direction so the snake goes down. Same goes for every other direction. What can I do to fix this? Here is my code help me please. Thanks in advance! [CODE] void CSnake::Event(SDL_Event &amp;event){ if (SDL_KEYDOWN) switch (event.key.keysym.sym){ case SDLK_UP: if (dir!=DOWN){ yVel = -20; xVel = 0; dir = UP; } break; case SDLK_DOWN: if (dir!=UP){ yVel = 20; xVel = 0; dir = DOWN; } break; case SDLK_LEFT: if (dir!=RIGHT){ xVel = -20; yVel = 0; dir=LEFT; } break; case SDLK_RIGHT: if (dir!=LEFT){ xVel = 20; yVel = 0; dir=RIGHT; } break; } } void CSnake::movement(){ if (t_MoveTime <= (SDL_GetTicks()-t_SnakeStarted)){ SDL_Rect front; iSnake = snake.begin(); front.x = (*iSnake).x + xVel; front.y = (*iSnake).y + yVel; snake.push_front(front); snake.pop_back(); t_SnakeStarted = SDL_GetTicks(); } } [/CODE]