game ending itself problem...help?

Started by
18 comments, last by BlueBan007 14 years, 11 months ago
As you start off in screen one of my zeldaish game, and you move to screen 2, and then back to screen one for any reason, the game suddenly ends...D: heres the game: zipped game (requires the SDL.dll included) just walk through the opening on the right then back to the left, the program ends... heres the specific code I think may have something to do with it...but im not sure:

..........
..........
 //avatar position X/Y
 int avX, avY;
 //map stats
 const int NumScrWide=5;
 const int NumScrHigh=5;
..........
..........
int main(int args, char *argv[]){
     
     screen(1000, 500, 0, "Tileset Simulation");
     int x = w / 2, y = h-20 ;
     int avatarX=x;
     int avatarY=h/2;
     //screen selector
     int screen=1;
     
     while(!done()){
     .....
     avX=getAvatarX(avatarX,avatarY);
     avY=getAvatarY(avatarX,avatarY);
     avatarX=avX;
     avatarY=avY;
     .....
     screenTester(screen,avatarX,avatarY);
     drawAvatar(avX,avY);
     .....
     .....
     .....
     }




heres the actual screens at least the parts I think are maybe the problem:

else if(screen==1){
          grass();
          
          //left wall
          drawNoPassRect(avX,avY,enemyX,enemyY,0,0,5,h-1,RGB_Red);
          for(int i=0;i<=h;i+=10){
                  drawRect(0,i,5,i+2,RGB_Black);
                  }
          //top wall
          drawNoPassRect(avX,avY,enemyX,enemyY,0,0,w-1,5,RGB_Red);
          for(int i=0;i<=w;i+=10){
                  drawRect(i,0,i+2,5,RGB_Black);
                  }
          //right wall
          drawNoPassRect(avX,avY,enemyX,enemyY,w-5,0,w-1,h-100,RGB_Red);
          drawNoPassRect(avX,avY,enemyX,enemyY,w-5,h-50,w-1,h-1,RGB_Red);
          for(int i=0;i<=h-100;i+=10){
                  drawRect(w-5,i,w-1,i+2,RGB_Black);
                  }
          for(int i=h-50;i<=h-1;i+=10){
                  drawRect(w-5,i,w-1,i+2,RGB_Black);
                  }
          //bottom trees
                   //left
          for(int i=w/2-65;i>=0;i-=50){
                  drawDisk(i,h-15,30,RGB_Darkgreen);
                  } 
          for(int i=w/2-65;i>=0;i-=50){
                  drawDisk(i,h-15,20,RGB_Olive);
                  } 
          for(int i=w/2-65;i>=0;i-=50){
                  drawDisk(i,h-15,10,RGB_Darkgreen);
                  }
                  //right
          for(int i=w/2+65;i<=w;i+=50){
                  drawDisk(i,h-15,30,RGB_Darkgreen);
                  } 
          for(int i=w/2+65;i<=w;i+=50){
                  drawDisk(i,h-15,20,RGB_Olive);
                  } 
          for(int i=w/2+65;i<=w;i+=50){
                  drawDisk(i,h-15,10,RGB_Darkgreen);
                  }
                  //border control
                  drawNoPassRect(avX,avY,enemyX,enemyY,0,h-40,w/2-45,h);
                  drawNoPassRect(avX,avY,enemyX,enemyY,w/2+45,h-40,w,h);
          
          //draw boulder and check if near
          if(drawNoPassRect(avX,avY,enemyX,enemyY,w-95,50,w-50,75,RGB_Gray)==true){nearBoulderLvl[1]=true;}
          else {nearBoulderLvl[1]=false;}
                  
                  //boulder menu
                  if(nearBoulderLvl[1]==true)
                  {
                      menuMakerObjects(keyLvl[1],"Look under boulder?","You found a key!","numKeys",numKeys);
                  }
                  
                 //draw house and
                 //check if near house
                 if(drawHouse(avX,avY,50,50)==true)
                 {
                  nearHouseLvl[1]=true;
                 }else{nearHouseLvl[1]=false;}
                 
                 //house menu    
                 if(nearHouseLvl[1]==true)
                 {
                                         
                 menuMakerDoors("Enter the house?",screen,-1,1,"You need the key!",avX,avY);
          }
        
}

else if(screen==2){
                   .....
                   .....        
                 createEnemy(1,"rabbit",600,200,EnemyX[1],EnemyY[1],numKeys);                                                               
                            
}



and heres the actual changing of the screens:

//actual level changing
          if(avX>w){
                avX=1;
                screen++;     
                     }
          else if(avX<0){
               avX=w;
                screen--;
               }
          else if(avY>h){
               avY=1;
               screen+=NumScrWide;
               }
          else if(avY<0){
               avY=h;
               screen-=NumScrHigh;
               }
               //    



The last two code blocks are both a part of ScreenTester(...) sorry if I cant be more clear on the question...
Advertisement
If it happens when you are switching screens you are probably causing a memory error by drawing out of bounds of the screen.
but it only happens when I leave in an enemy call...if I comment it out it switches fine.

also even with the enemy call it switches fine for every other screen,
just 1--->2--->1 gives the problem.

heres the jist:

1 2 3 4 5


6 7 8 9 10


11...

5x5 map

if you go from one to two, then back to one, it ends the program
nothing else has a problem
I can't off hand see anything that would crash your app. It still sounds like memory thing.

What compiler are you using? This is what a debugger is for. If you are on windows, get visual C++ express (its free) and use its debugger. The great thing about it that it tells you where it crashed, why it crashed and you can view the values of your variables at the time of the crash. This help you in identifying the issue like you wouldn't believe.
Im using dev++ as of now for this project because I cannot get express to work with a SDL project..super complicated...): is there a way I can move a project from dev over to express with the settings saved? so I dont have to mess with the linker or anything?
You're gonna have to start a new project and do everything yourself.

As a former dev-c++er, I know the switch is a little hard at first. But once you get it down you will never look back. Have you followed the tutorial on http://cone3d.gamedev.net ?
Lazy Foo has extensive tutorials on how to set up SDL on almost any IDE with any platform.
cone3d is too outdated for me to follow...
and the lazyfoo tut is the one I followed the first time and got lost and confused lol, maybe Im just too baby haha
I went throught the lazyfoo tut again and im closer than ive ever been!

everything is actually compiling, I just get this linker error:

>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree<class std::_Tmap_traits<int,bool,struct std::less<int>,class std::allocator<struct std::pair<int const ,bool> >,0> >::const_iterator::operator==(class std::_Tree<class std::_Tmap_traits<int,bool,struct std::less<int>,class std::allocator<struct std::pair<int const ,bool> >,0> >::const_iterator const &)const " (??8const_iterator@?$_Tree@V?$_Tmap_traits@H_NU?$less@H@std@@V?$allocator@U?$pair@$$CBH_N@std@@@2@$0A@@std@@@std@@QBE_NABV012@@Z)

1>C:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\Debug\SDLproject.exe : fatal error LNK1120: 1 unresolved externals

wha???????????

and in release mode i get this:

1>Linking...
1>main.obj : error LNK2001: unresolved external symbol _SDL_UpdateRect
1>main.obj : error LNK2001: unresolved external symbol _SDL_mutexV
1>main.obj : error LNK2001: unresolved external symbol _SDL_Init
1>main.obj : error LNK2001: unresolved external symbol _SDL_SetVideoMode
1>main.obj : error LNK2001: unresolved external symbol _SDL_DestroyMutex
1>main.obj : error LNK2001: unresolved external symbol _SDL_FillRect
1>main.obj : error LNK2001: unresolved external symbol _SDL_mutexP
1>main.obj : error LNK2001: unresolved external symbol _SDL_WM_SetCaption
1>main.obj : error LNK2001: unresolved external symbol _SDL_PollEvent
1>main.obj : error LNK2001: unresolved external symbol _SDL_EnableUNICODE
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetMouseState
1>main.obj : error LNK2001: unresolved external symbol _SDL_PauseAudio
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetRGB
1>main.obj : error LNK2001: unresolved external symbol _SDL_CloseAudio
1>main.obj : error LNK2001: unresolved external symbol _SDL_OpenAudio
1>main.obj : error LNK2001: unresolved external symbol _SDL_Delay
1>main.obj : error LNK2001: unresolved external symbol _SDL_LockSurface
1>main.obj : error LNK2001: unresolved external symbol _SDL_UnlockSurface
1>main.obj : error LNK2001: unresolved external symbol _SDL_CreateMutex
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetTicks
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetError
1>main.obj : error LNK2001: unresolved external symbol _SDL_MapRGB
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetKeyState
1>main.obj : error LNK2001: unresolved external symbol _SDL_Quit
1>MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
1>C:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\Release\SDLproject.exe : fatal error LNK1120: 25 unresolved externals
1>Build log was saved at "file://c:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\SDLproject\Release\BuildLog.htm"
1>SDLproject - 26 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Go to Project-> [project name] properties -> linker -> input
Make sure you have the following in your "additional dependencies" box: SDL.lib SDLMain.lib

This topic is closed to new replies.

Advertisement