Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Jul 2009
Offline Last Active May 12 2013 03:40 PM

Topics I've Started

Game crashes for no obvious reason, help please

01 January 2013 - 07:24 PM

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!

Do I need a frame cap?

25 December 2012 - 08:18 PM

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!

Movement problem in snake game

10 December 2012 - 06:12 PM

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!

void CSnake::Event(SDL_Event &event){
switch (event.key.keysym.sym){
  case SDLK_UP:
   if (dir!=DOWN){
	yVel = -20;
	xVel = 0;
	dir = UP;
  case SDLK_DOWN:
   if (dir!=UP){
	yVel = 20;
	xVel = 0;
	dir = DOWN;
  case SDLK_LEFT:
   if (dir!=RIGHT){
	xVel = -20;
	yVel = 0;
  case SDLK_RIGHT:
   if (dir!=LEFT){
	xVel = 20;
	yVel = 0;
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;
  t_SnakeStarted = SDL_GetTicks();